public bool AddProperty(SQLTableInfo dbi, KeelExt.ModelKind km) { string C*K = "√"; bool i = false; string t_fieldname = ClearBadChars(dbi.t_fieldname); CodeAttributeDeclaration cad = null; try { if (dbi.t_tablekey == C*K) { cad = new CodeAttributeDeclaration(new CodeTypeReference(typeof(Keel.ORM.KeyFieldAttribute))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_fieldname))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(Keel.DB.Common.NowDataBase.PasteDBType(dbi.t_fieldtype).ToString()))); if (dbi.t_identity != C*K) { cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(false))); } } else { cad = new CodeAttributeDeclaration(new CodeTypeReference(typeof(Keel.ORM.DataFieldAttribute))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_fieldname))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(Keel.DB.Common.NowDataBase.PasteDBType(dbi.t_fieldtype).ToString()))); if (Kit.SlnKeel.ModelForUI) { cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression((object)dbi.t_fielddefaultvalue))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression((dbi.t_fieldcannull == C*K)))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_fielddesc))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_fieldindex))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_fieldlenght))); } if (dbi.t_fieldiscomputed == C*K || dbi.t_identity == C*K) { cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_fieldiscomputed == C*K))); cad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(dbi.t_identity == C*K))); } } Type t = Keel.DB.Common.NowDataBase.PasteType(dbi.t_fieldtype); switch (km) { case KeelExt.ModelKind.DotNetAndC: int len = (int)dbi.t_fieldbitcount > dbi.t_fieldlenght ? dbi.t_fieldbitcount : dbi.t_fieldlenght; i = AddPropertyStruct(t_fieldname, t, cad, len, dbi.t_fielddesc.ToString()); break; case KeelExt.ModelKind.DotNetAndDotNet: default: i = AddProperty(t_fieldname, t, cad, (string)dbi.t_fielddesc); break; } } catch (Exception ex) { Common.ShowInfo(string.Format("在处理属性{0}时遇到未料到的异常:{1}", dbi.t_fieldname, ex.Message)); } return(i); }
private static bool FindByTableName(SQLTableInfo di) { return(di.t_tablename == tablenamenow.Trim()); }
public void GenDefControl(int dis, ref bool lr, ref int sum, ref int maxwinwidth, ref int maxwinheight, SQLTableInfo item) { sum++; IComponent iclbl = this.AddControl(typeof(Label), "lbl" + BaseGengerator.ClearBadChars(item.t_fieldname)); (iclbl as Label).Text = ((item.t_fielddesc != null && item.t_fielddesc as string != "") ? item.t_fielddesc : item.t_fieldname) as string; IComponent ictxt; Type t = Keel.DB.Common.NowDataBase.PasteType(item.t_fieldtype); if (t.Equals(typeof(string))) { ictxt = this.AddControl(typeof(TextBox), "txt" + BaseGengerator.ClearBadChars(item.t_fieldname)); } else if (t.Equals(typeof(DateTime))) { ictxt = this.AddControl(typeof(DateTimePicker), "dtp" + BaseGengerator.ClearBadChars(item.t_fieldname)); } else if (t.Equals(typeof(decimal)) || t.Equals(typeof(Int32)) || t.Equals(typeof(float)) || t.Equals(typeof(double)) || t.Equals(typeof(byte)) || t.Equals(typeof(int)) || t.Equals(typeof(Int16)) || t.Equals(typeof(Int64)) ) { ictxt = this.AddControl(typeof(NumericUpDown), "nud" + item.t_fieldname); } else { ictxt = this.AddControl(typeof(TextBox), "txt_unsupport_type_" + item.t_fieldname); } int y; int xxx = Math.DivRem(sum, 2, out y) + y; // (ictxt as Control).Tag = item.t_fieldname; (ictxt as Control).TabIndex = (int)item.t_fieldindex; switch (lr) { default: case true: (iclbl as Label).Location = new Point(20 + 300, dis * xxx); (ictxt as Control).Location = new Point(20 + 300 + (iclbl as Label).Width + dis, dis * xxx); int fw = (ictxt as Control).Left + (ictxt as Control).Width; int fh = (ictxt as Control).Top + (ictxt as Control).Height; maxwinwidth = maxwinwidth > fw ? maxwinwidth : fw; maxwinheight = maxwinheight > fh ? maxwinheight : fh; lr = false; break; case false: (iclbl as Label).Location = new Point(20, dis * xxx); (ictxt as Control).Location = new Point(20 + (iclbl as Label).Width + dis, dis * xxx); lr = true; break; } }
private void GenControl(int dis, ref bool lr, ref int sum, ref int maxwinwidth, ref int maxwinheight, SQLTableInfo item) { if (CreateControl != null) { CreateControl(this, dis, ref lr, ref sum, ref maxwinwidth, ref maxwinheight, item); } else { GenDefControl(dis, ref lr, ref sum, ref maxwinwidth, ref maxwinheight, item); } }
public static List <SQLTableInfo> GetSqlTableInfoList() { List <SQLTableInfo> dbix = new List <SQLTableInfo>(); if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.SQLServer)) { DBHelper <SQLTableInfo> dbi = new DBHelper <SQLTableInfo>(); dbix = dbi.GetDataViewForObjectList(); dbix.AddRange(dbi.GetDataViewForObjectList("ViewInfo")); } else if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.MSAccess)) { KeelKit.Core.DBInformer dbi = new DBInformer(Kit.SlnKeel.ConnectString); //Hashtable dtm = list != "ViewInfo" ? dbi.GetUserTables() : dbi.GetUserViews(); Hashtable dtm = dbi.GetUserTables(); foreach (DictionaryEntry tb in dtm) { ArrayList al = dbi.GetTableColumns(tb.Key.ToString()); DataTable pk = dbi.GetPrimaryKeys(tb.Key.ToString()); string keyx = ""; if (pk != null && pk.Rows.Count > 0) { keyx = pk.Rows[0]["COLUMN_NAME"].ToString(); // t_identity=pk.Rows[0]["COLUMN_NAME"].ToString () } DataTable fk = dbi.GetForeignKeys(tb.Key.ToString()); foreach (var item in al) { SQLTableInfo st = new SQLTableInfo(); DataFieldMetadata dfm = item as DataFieldMetadata; st.t_fieldbitcount = dfm.Size; st.t_fieldcannull = dfm.IsNullable ? OK : ""; st.t_fielddefaultvalue = dfm.DefaultValueStr as string; //st.t_fielddesc = //st.t_fieldindex = //st.t_fieldiscomputed st.t_fieldlenght = dfm.Size; st.t_fieldname = dfm.Name; //st.t_fieldscale = st.t_fieldtype = dbi.ConvertDataType2DBType(dfm.FieldType); st.t_identity = dfm.Name == keyx ? OK : ""; st.t_tablekey = dfm.Name == keyx ? OK : ""; st.t_tablename = dfm.Table; dbix.Add(st); } } } else { System.Data.Common.DbConnection dbc = Keel.DB.Common.NowDataBase.GetProviderFactory().CreateConnection(); dbc.ConnectionString = Keel.DB.Common.NowDataBase.ConnectString; dbc.Open(); DataTable dt = dbc.GetSchema("Columns"); for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; SQLTableInfo sti = new SQLTableInfo(); try { sti.t_fieldbitcount = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? 0 : (int)(ulong)dr["CHARACTER_MAXIMUM_LENGTH"]; sti.t_fieldcannull = ((string)dr["IS_NULLABLE"] != "NO" ? OK : ""); sti.t_fielddefaultvalue = dr["COLUMN_DEFAULT"] as string; sti.t_fielddesc = (string)dr["COLUMN_COMMENT"]; sti.t_fieldindex = (int)((ulong)dr["ORDINAL_POSITION"]); sti.t_fieldiscomputed = ""; sti.t_fieldlenght = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? 0 : (int)(ulong)dr["CHARACTER_MAXIMUM_LENGTH"]; sti.t_fieldname = (string)dr["COLUMN_NAME"]; sti.t_fieldscale = dr["NUMERIC_SCALE"] == DBNull.Value ? 0 : (int)(ulong)dr["NUMERIC_SCALE"]; sti.t_fieldtype = (string)dr["DATA_TYPE"]; sti.t_identity = dr["EXTRA"] == DBNull.Value ? "" : (((string)dr["EXTRA"]).Contains("auto_increment") ? OK : ""); sti.t_tabledesc = (dr["TABLE_CATALOG"] as string + "," + dr["CHARACTER_SET_NAME"] as string); sti.t_tablekey = ((string)dr["COLUMN_KEY"] == "PRI" ? OK : ""); sti.t_tablename = (string)dr["TABLE_NAME"]; } catch (Exception ex) { Common.ShowInfo(ex.Message + "\r\n" + ex.StackTrace); } dbix.Add(sti); } dbc.Close(); } return(dbix); }
public bool AddProperty(SQLTableInfo dbi) { return(AddProperty(dbi, KeelExt.ModelKind.DotNetAndDotNet)); }