Skip to content

Commit

Permalink
288: MDataTable增加对MDataRow的隐式转换(2016-07-11)
Browse files Browse the repository at this point in the history
289:MDataRow和MDataColumns增加ToTable()方法(2016-07-11)
  • Loading branch information
cyq1162 committed Jul 11, 2016
1 parent 9068bcc commit 75b0757
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 41 deletions.
28 changes: 14 additions & 14 deletions Action/AppConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ namespace CYQ.Data
internal static class AppConst
{
#region License 常量
internal const string Lic_Error_Contact = "\r\nContact email:[email protected];QQ:272657997\r\n site : http://www.cyqdata.com/cyqdata";
//internal const string Lic_Error_AtNight = "Sorry ! You need to get a license key when you run it at night!";
internal const string Lic_Error_NotBuyProvider = "Sorry ! Your license key not contains this provider function : ";
internal const string Lic_Error_InvalidVersion = "Sorry ! Your license key version invalid!";
internal const string Lic_Error_InvalidKey = "Sorry ! Your license key is invalid!";
internal const string Lic_PublicKey = "CYQ.Data.License";
internal const string Lic_FilePre = "file:\\";
internal const string Lic_UseKeyFileName = "cyq.data.keys";
//internal const string Lic_DevKeyFileName = "/cyq.data.dev.keys";
internal const string Lic_MacKeyType = "mac";
internal const string Lic_DllKeyType = "dll";
internal const string Lic_AriesCore = "Aries.Core";
internal const string Lic_AriesLogic = "Aries.Logic";
//internal const string Lic_Error_Contact = "\r\nContact email:[email protected];QQ:272657997\r\n site : http://www.cyqdata.com/cyqdata";
////internal const string Lic_Error_AtNight = "Sorry ! You need to get a license key when you run it at night!";
//internal const string Lic_Error_NotBuyProvider = "Sorry ! Your license key not contains this provider function : ";
//internal const string Lic_Error_InvalidVersion = "Sorry ! Your license key version invalid!";
//internal const string Lic_Error_InvalidKey = "Sorry ! Your license key is invalid!";
//internal const string Lic_PublicKey = "CYQ.Data.License";
//internal const string Lic_UseKeyFileName = "cyq.data.keys";
////internal const string Lic_DevKeyFileName = "/cyq.data.dev.keys";
//internal const string Lic_MacKeyType = "mac";
//internal const string Lic_DllKeyType = "dll";
//internal const string Lic_AriesCore = "Aries.Core";
//internal const string Lic_AriesLogic = "Aries.Logic";
#endregion

#region 全局
internal const string FilePre = "file:\\";
internal const string Global_NotImplemented = "The method or operation is not implemented.";
#endregion

Expand Down Expand Up @@ -87,7 +87,7 @@ internal static string RunFolderPath
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
_DLLFullName = ass.FullName;
_RunfolderPath = ass.CodeBase;
_RunfolderPath = System.IO.Path.GetDirectoryName(_RunfolderPath).Replace(AppConst.Lic_FilePre, string.Empty)+"\\";
_RunfolderPath = System.IO.Path.GetDirectoryName(_RunfolderPath).Replace(AppConst.FilePre, string.Empty)+"\\";
}
return _RunfolderPath;
}
Expand Down
2 changes: 1 addition & 1 deletion Action/MAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public bool Insert(bool autoSetValue, InsertOp option)
CheckDisposed();
if (autoSetValue)
{
_UI.GetAll(true);
_UI.GetAll(true && !AllowInsertID);//允许插入ID时,也需要获取主键。
}
AopResult aopResult = AopResult.Default;
if (_aop.IsCustomAop)
Expand Down
2 changes: 1 addition & 1 deletion DAL/OracleDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private bool IsUseOdpNet
try
{
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
path = System.IO.Path.GetDirectoryName(ass.CodeBase).Replace(AppConst.Lic_FilePre, string.Empty);
path = System.IO.Path.GetDirectoryName(ass.CodeBase).Replace(AppConst.FilePre, string.Empty);
ass = null;
}
catch
Expand Down
84 changes: 65 additions & 19 deletions Table/MDataColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,52 @@ internal void AddRelateionTableName(string tableName)
relationTables.Add(tableName);
}
}

/// <summary>
/// 将表结构的数据转成Table显示
/// </summary>
/// <returns></returns>
public MDataTable ToTable()
{
string tableName = string.Empty;
if (_Table != null)
{
tableName = _Table.TableName;
}
MDataTable dt = new MDataTable(tableName);
dt.Columns.Add("ColumnName");
dt.Columns.Add("MaxSize");
dt.Columns.Add("Scale");
dt.Columns.Add("IsCanNull");
dt.Columns.Add("IsAutoIncrement");
dt.Columns.Add("SqlType");
dt.Columns.Add("IsPrimaryKey");
dt.Columns.Add("IsUniqueKey");
dt.Columns.Add("IsPrimaryKey");
dt.Columns.Add("FKTableName");
dt.Columns.Add("DefaultValue");
dt.Columns.Add("Description");


for (int i = 0; i < Count; i++)
{
MCellStruct ms = this[i];
dt.NewRow(true)
.Set(0, ms.ColumnName)
.Set(1, ms.MaxSize)
.Set(2, ms.Scale)
.Set(3, ms.IsCanNull)
.Set(4, ms.IsAutoIncrement)
.Set(5, ms.SqlType)
.Set(6, ms.IsPrimaryKey)
.Set(7, ms.IsUniqueKey)
.Set(8, ms.IsForeignKey)
.Set(9, ms.FKTableName)
.Set(10, ms.DefaultValue)
.Set(11, ms.Description);
}
return dt;
}
}
public partial class MDataColumn
{
Expand Down Expand Up @@ -470,10 +516,10 @@ public static MDataColumn CreateFrom(string jsonOrFileName, bool readTxtOrXml)
foreach (MDataRow row in dt.Rows)
{
MCellStruct cs = new MCellStruct(
row.Get<string>("ColumnName"),
row.Get<string>("ColumnName"),
DataType.GetSqlType(row.Get<string>("SqlType", "string")),
row.Get<bool>("IsAutoIncrement", false),
row.Get<bool>("IsCanNull", false),
row.Get<bool>("IsAutoIncrement", false),
row.Get<bool>("IsCanNull", false),
row.Get<int>("MaxSize", -1));
cs.Scale = row.Get<short>("Scale");
cs.IsPrimaryKey = row.Get<bool>("IsPrimaryKey", false);
Expand Down Expand Up @@ -502,21 +548,21 @@ public static MDataColumn CreateFrom(string jsonOrFileName, bool readTxtOrXml)
return mdc;
}

internal bool AcceptChanges(AcceptOp op)
{
if (_Table == null)
{
return false;
}
return AcceptChanges(op, _Table.TableName, _Table.Conn);
}
internal bool AcceptChanges(AcceptOp op, string tableName, string newConn)
{
if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(newConn) || Count == 0)
{
return false;
}
return true;
}
//internal bool AcceptChanges(AcceptOp op)
//{
// if (_Table == null)
// {
// return false;
// }
// return AcceptChanges(op, _Table.TableName, _Table.Conn);
//}
//internal bool AcceptChanges(AcceptOp op, string tableName, string newConn)
//{
// if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(newConn) || Count == 0)
// {
// return false;
// }
// return true;
//}
}
}
14 changes: 9 additions & 5 deletions Table/MDataRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,18 @@ public T Get<T>(object key, T defaultValue)


/// <summary>
/// 转成MDataTable
/// 将行的数据转成两列(ColumnName、Value)的表
/// </summary>
public MDataTable ToTable()
{
MDataTable mTable = new MDataTable(_TableName);
mTable.LoadRow(this);
return mTable;
MDataTable dt = new MDataTable(TableName);
dt.Columns.Add("ColumnName");
dt.Columns.Add("Value");
for (int i = 0; i < Count; i++)
{
dt.NewRow(true).Set(0, this[i].ColumnName).Set(1, this[i].ToString());
}
return dt;
}


Expand Down Expand Up @@ -1197,7 +1202,6 @@ internal void SetToEntity(ref object obj, MDataRow row)
}
}


}
public partial class MDataRow : System.ComponentModel.ICustomTypeDescriptor
{
Expand Down
12 changes: 11 additions & 1 deletion Table/MDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public static implicit operator MDataTable(DbDataReader sdr)
return dt;
}


/// <summary>
/// 从DataTable隐式转换成MDataTable
/// </summary>
Expand Down Expand Up @@ -209,6 +208,17 @@ public static implicit operator MDataTable(List<MDataRow> rows)
mdt.Rows.AddRange(rows);
return mdt;
}
/// <summary>
/// 将一行数据装载成一个表。
/// </summary>
/// <returns></returns>
public static implicit operator MDataTable(MDataRow row)
{
MDataTable mTable = new MDataTable(row.TableName);
mTable.Conn = row.Conn;
mTable.LoadRow(row);
return mTable;
}
#endregion

#region 属性
Expand Down
2 changes: 2 additions & 0 deletions 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,6 @@
285: ����MSSQL��Timestamp�ֶβ��������µ����⣨2016-07-10��
286: ����SQLite��SQLiteDataReader��datetime�Ĵ����������������쳣���⣨2016-07-11��
287: ����MDataTable��Join����׷����û��ʾ�����⣨2016-07-11��
288: MDataTable���Ӷ�MDataRow����ʽת����2016-07-11��
289��MDataRow��MDataColumns����ToTable()������2016-07-11��

0 comments on commit 75b0757

Please sign in to comment.