316 lines
8.8 KiB
C#
316 lines
8.8 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Data;
|
|||
|
|
using CYQ.Data.SQL;
|
|||
|
|
|
|||
|
|
namespace CYQ.Data.Table
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>нṹ<D0BD><E1B9B9>ѡ<EFBFBD><D1A1>
|
|||
|
|
/// </summary>
|
|||
|
|
[Flags]
|
|||
|
|
public enum AlterOp
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD>״̬
|
|||
|
|
/// </summary>
|
|||
|
|
None = 0,
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>״̬
|
|||
|
|
/// </summary>
|
|||
|
|
AddOrModify = 1,
|
|||
|
|
/// <summary>
|
|||
|
|
/// ɾ<><C9BE><EFBFBD><EFBFBD>״̬
|
|||
|
|
/// </summary>
|
|||
|
|
Drop = 2,
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
|
/// </summary>
|
|||
|
|
Rename = 4
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Ԫ<EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public partial class MCellStruct
|
|||
|
|
{
|
|||
|
|
private MDataColumn _MDataColumn = null;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public MDataColumn MDataColumn
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _MDataColumn;
|
|||
|
|
}
|
|||
|
|
internal set
|
|||
|
|
{
|
|||
|
|
_MDataColumn = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD><C7B7><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>и<EFBFBD>ʽУ<CABD><D0A3>
|
|||
|
|
/// </summary>
|
|||
|
|
//public bool IsCheckValue = true;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD><C7B7>ؼ<EFBFBD><D8BC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsPrimaryKey = false;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD>Ψһ<CEA8><D2BB><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsUniqueKey = false;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsForeignKey = false;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string FKTableName;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string Description;
|
|||
|
|
private object _DefaultValue;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ĭ<><C4AC>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
public object DefaultValue
|
|||
|
|
{
|
|||
|
|
get { return _DefaultValue; }
|
|||
|
|
set {
|
|||
|
|
int groupID=DataType.GetGroup(SqlType);
|
|||
|
|
if (groupID == 1 || groupID == 3)
|
|||
|
|
{
|
|||
|
|
string defaultValue = Convert.ToString(value);
|
|||
|
|
if (!string.IsNullOrEmpty(defaultValue) && (defaultValue[0] == 'N' || defaultValue[0]=='('))
|
|||
|
|
{
|
|||
|
|
defaultValue = defaultValue.Trim('N','(', ')');//<2F><><EFBFBD><EFBFBD>int<6E><74>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD>⡣
|
|||
|
|
}
|
|||
|
|
_DefaultValue = defaultValue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_DefaultValue = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ΪNull
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsCanNull;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsAutoIncrement;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>AlterOpΪRenameʱ<65><CAB1><EFBFBD>ã<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string OldName;
|
|||
|
|
private string _ColumnName = string.Empty;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string ColumnName
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _ColumnName;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_ColumnName = value;
|
|||
|
|
if (_MDataColumn != null)
|
|||
|
|
{
|
|||
|
|
_MDataColumn.IsColumnNameChanged = true;//<2F><><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD><D1B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public string TableName;
|
|||
|
|
private SqlDbType _SqlType;
|
|||
|
|
/// <summary>
|
|||
|
|
/// SqlDbType<70><65><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public SqlDbType SqlType
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _SqlType;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_SqlType = value;
|
|||
|
|
ValueType = DataType.GetType(_SqlType, DalType);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public int MaxSize;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ȣ<EFBFBD>С<EFBFBD><D0A1>λ<EFBFBD><CEBB>
|
|||
|
|
/// </summary>
|
|||
|
|
public short Scale;
|
|||
|
|
/// <summary>
|
|||
|
|
/// ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
internal string SqlTypeName;
|
|||
|
|
internal Type ValueType;
|
|||
|
|
private DalType dalType = DalType.None;
|
|||
|
|
internal DalType DalType
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (_MDataColumn != null)
|
|||
|
|
{
|
|||
|
|
return _MDataColumn.dalType;
|
|||
|
|
}
|
|||
|
|
return dalType;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private AlterOp _AlterOp = AlterOp.None;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>нṹ<D0BD>ı<EFBFBD>״̬
|
|||
|
|
/// </summary>
|
|||
|
|
public AlterOp AlterOp
|
|||
|
|
{
|
|||
|
|
get { return _AlterOp; }
|
|||
|
|
set { _AlterOp = value; }
|
|||
|
|
}
|
|||
|
|
//<2F>ڲ<EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>Ϊ<EFBFBD><CEAA>ʱʹ<CAB1><CAB9>
|
|||
|
|
internal int ReaderIndex = -1;
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|||
|
|
internal MCellStruct(DalType dalType)
|
|||
|
|
{
|
|||
|
|
this.dalType = dalType;
|
|||
|
|
}
|
|||
|
|
public MCellStruct(string columnName, SqlDbType sqlType)
|
|||
|
|
{
|
|||
|
|
Init(columnName, sqlType, false, true, false, -1, null);
|
|||
|
|
}
|
|||
|
|
public MCellStruct(string columnName, SqlDbType sqlType, bool isAutoIncrement, bool isCanNull, int maxSize)
|
|||
|
|
{
|
|||
|
|
Init(columnName, sqlType, isAutoIncrement, isCanNull, false, maxSize, null);
|
|||
|
|
}
|
|||
|
|
internal void Init(string columnName, SqlDbType sqlType, bool isAutoIncrement, bool isCanNull, bool isPrimaryKey, int maxSize, object defaultValue)
|
|||
|
|
{
|
|||
|
|
ColumnName = columnName.Trim();
|
|||
|
|
SqlType = sqlType;
|
|||
|
|
IsAutoIncrement = isAutoIncrement;
|
|||
|
|
IsCanNull = isCanNull;
|
|||
|
|
MaxSize = maxSize;
|
|||
|
|
IsPrimaryKey = isPrimaryKey;
|
|||
|
|
DefaultValue = defaultValue;
|
|||
|
|
}
|
|||
|
|
internal void Load(MCellStruct ms)
|
|||
|
|
{
|
|||
|
|
ColumnName = ms.ColumnName;
|
|||
|
|
SqlType = ms.SqlType;
|
|||
|
|
IsAutoIncrement = ms.IsAutoIncrement;
|
|||
|
|
IsCanNull = ms.IsCanNull;
|
|||
|
|
MaxSize = ms.MaxSize;
|
|||
|
|
Scale = ms.Scale;
|
|||
|
|
IsPrimaryKey = ms.IsPrimaryKey;
|
|||
|
|
IsUniqueKey = ms.IsUniqueKey;
|
|||
|
|
IsForeignKey = ms.IsForeignKey;
|
|||
|
|
FKTableName = ms.FKTableName;
|
|||
|
|
SqlTypeName = ms.SqlTypeName;
|
|||
|
|
AlterOp = ms.AlterOp;
|
|||
|
|
|
|||
|
|
if (ms.DefaultValue != null)
|
|||
|
|
{
|
|||
|
|
DefaultValue = ms.DefaultValue;
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(ms.Description))
|
|||
|
|
{
|
|||
|
|
Description = ms.Description;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>¡һ<C2A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public MCellStruct Clone()
|
|||
|
|
{
|
|||
|
|
MCellStruct ms = new MCellStruct(dalType);
|
|||
|
|
ms.ColumnName = ColumnName;
|
|||
|
|
ms.SqlType = SqlType;
|
|||
|
|
ms.IsAutoIncrement = IsAutoIncrement;
|
|||
|
|
ms.IsCanNull = IsCanNull;
|
|||
|
|
ms.MaxSize = MaxSize;
|
|||
|
|
ms.Scale = Scale;
|
|||
|
|
ms.IsPrimaryKey = IsPrimaryKey;
|
|||
|
|
ms.IsUniqueKey = IsUniqueKey;
|
|||
|
|
ms.IsForeignKey = IsForeignKey;
|
|||
|
|
ms.FKTableName = FKTableName;
|
|||
|
|
ms.SqlTypeName = SqlTypeName;
|
|||
|
|
ms.DefaultValue = DefaultValue;
|
|||
|
|
ms.Description = Description;
|
|||
|
|
ms.MDataColumn = MDataColumn;
|
|||
|
|
ms.AlterOp = AlterOp;
|
|||
|
|
ms.TableName = TableName;
|
|||
|
|
return ms;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public partial class MCellStruct // <20><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ϊ<>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
public MCellStruct Set(object value)
|
|||
|
|
{
|
|||
|
|
Set(value, -1);
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
public MCellStruct Set(object value, int state)
|
|||
|
|
{
|
|||
|
|
if (_MDataColumn != null)
|
|||
|
|
{
|
|||
|
|
MDataTable dt = _MDataColumn._Table;
|
|||
|
|
if (dt != null && dt.Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
int index = _MDataColumn.GetIndex(ColumnName);
|
|||
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|||
|
|
{
|
|||
|
|
dt.Rows[i].Set(index, value, state);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ظ<EFBFBD><D8B8>е<EFBFBD>where In <20><><EFBFBD><EFBFBD> : Name in("aa","bb")
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string GetWhereIn()
|
|||
|
|
{
|
|||
|
|
if (_MDataColumn != null)
|
|||
|
|
{
|
|||
|
|
MDataTable dt = _MDataColumn._Table;
|
|||
|
|
if (dt != null && dt.Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
List<string> items = dt.GetColumnItems<string>(ColumnName, BreakOp.NullOrEmpty, true);
|
|||
|
|
if (items != null && items.Count > 0)
|
|||
|
|
{
|
|||
|
|
return SqlCreate.GetWhereIn(this, items, dalType);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|