public void GeneratedCode() { Common.ShowInfo("正在检查数据库是否可用!"); if (Kit.CheckDataBase()) { Common.ShowInfo("正在从数据库中读取表信息..."); EnvDTE.Project pjt = Kit.GetProjectModel(); DBHelper <SQLTableInfo> dbi = new DBHelper <SQLTableInfo>(); DataTable DBFullInfo = dbi.GetDataViewForDataTable(); string lsttab = (Kit.SlnKeel.DataTables + Kit.SlnKeel.DataViews); DataRow[] tbs = DBFullInfo.Select("t_fieldindex =1");//查询出所有的 for (int i = 0; i < tbs.Length; i++) { DataRow dr = tbs[i]; string t_tablename = dr["t_tablename"].ToString(); if (lsttab.ToLower().Contains(t_tablename.ToLower().Trim() + ";")) { DataRow[] fields = DBFullInfo.Select("t_tablename ='" + t_tablename + "'"); Common.ShowInfo("正在生成表:" + t_tablename + "..."); BuildTable_HFile(t_tablename, fields); BuildTable_CFile(t_tablename, fields); } } Common.ShowInfo("生成完毕!"); DBFullInfo.Dispose();; } }
public static bool GeneratedCode(string sql, EnvDTE.Project pjt, string classname) { bool ok = Kit.CheckDataBase(); if (ok) { DBOperator <Keel.DB.Common> obc = new DBOperator <Keel.DB.Common>(); DataTable dt = obc.ExecuteFillDataTable(sql); ok = false; if (classname == null || classname == "") { classname = dt.TableName; } if (classname != null && classname != "") { ViewGenerator mg = new ViewGenerator((string)pjt.Properties.Item("RootNamespace").Value, classname, sql); for (int i = 0; i < dt.Columns.Count; i++) { DataColumn dc = dt.Columns[i]; mg.AddProperty(dc.ColumnName, dc.DataType, null); } cfLangType cl = Kit.GetProjectLangType(pjt); string filename = mg.Save(pjt.FileName, cl); pjt.ProjectItems.AddFromFile(filename); ok = true; } } return(ok); }
public static void GeneratedCode(KeelExt.ModelKind mk) { Common.ShowInfo("正在检查数据库是否可用!"); if (Kit.CheckDataBase()) { Common.ShowInfo("正在从数据库中读取表信息..."); EnvDTE.Project pjt = Kit.GetProjectModel(); List <SQLTableInfo> dbix = GetSqlTableInfoList(); string[] lsttab = (Kit.SlnKeel.DataTables + Kit.SlnKeel.DataViews).Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string keelcpp = null; foreach (var item in lsttab) { #region 生成一个model tablenamenow = item; Common.ShowInfo(string.Format("正在生成{0}的实体,请稍候...", tablenamenow)); Predicate <SQLTableInfo> pdbi = new Predicate <SQLTableInfo>(FindByTableName); List <SQLTableInfo> lstdb = dbix.FindAll(pdbi); ModelGengerator mg = new ModelGengerator(Kit.GetRootNamespace(pjt), item); if (mk == KeelExt.ModelKind.DotNetAndC) { mg.AddStruct(tablenamenow); mg.AddFunForStructModel(); } foreach (var tableitem in lstdb) { mg.AddProperty(tableitem, mk); mg.AddTableNameConst(tableitem.t_fieldname, tableitem.t_tabledesc); } mg.AddCtor(lstdb, mk); cfLangType cl = Kit.GetProjectLangType(pjt); string filename = mg.Save(pjt.FullName, cl); AddFileToProject(pjt, filename); if (cl == cfLangType.CPP) { keelcpp += string.Format("#include \"{0}\"", new System.IO.FileInfo(filename).Name) + Environment.NewLine; } Common.ShowInfo(string.Format("恭喜!{0}的实体保存完毕!", tablenamenow)); #endregion } ForCpptoDo(pjt, keelcpp); Common.ShowInfo(string.Format("全部实体生成完毕,开始生产DBContext")); GenDAL(lsttab); Common.ShowInfo(string.Format("KeelKit所需生成的内容生成完毕!")); } }
public static void GeneratedCode() { Project pjt = null; _DBFullInfo = null; try { pjt = KeelKit.Kit.GetProjectModel(); if (pjt != null) { Config.ConnectString = KeelKit.Kit.SlnKeel.ConnectString; Config.OutPathCSharp = new System.IO.FileInfo(pjt.FileName).DirectoryName; Config.cs_Namespace = KeelKit.Kit.GetRootNamespace(pjt); if (Kit.CheckDataBase()) { _DBFullInfo = InitDBFullInfo(); } } } catch (Exception ex) { KeelKit.Common.ShowInfo("KeelKit.Generator.Grove 在初始化数据库信息时遇到问题:" + ex.Message); } if (pjt != null && _DBFullInfo != null) { DataRow[] tbs = DBFullInfo.Select("t_fieldindex =1");//查询出所有的 string lsttab = (Kit.SlnKeel.DataTables + Kit.SlnKeel.DataViews); for (int i = 0; i < tbs.Length; i++) { DataRow dr = tbs[i]; string t_tablename = dr["t_tablename"].ToString(); if (lsttab.ToLower().Contains(t_tablename.ToLower().Trim() + ";")) { KeelKit.Common.ShowInfo("KeelKit.Generator.Grove正在生成" + t_tablename); DataRow[] fields = DBFullInfo.Select("t_tablename ='" + t_tablename + "'"); string filename = BuildCSStruct(t_tablename, fields); pjt.ProjectItems.AddFromFile(filename); } } KeelKit.Common.ShowInfo("KeelKit.Generator.Grove生成完毕!"); } else { KeelKit.Common.ShowInfo("KeelKit.Generator.Grove 请先指定Model项目并保证数据库可用!"); } }
public static void GeneratedCode() { Common.ShowInfo("正在检查数据库是否可用!"); if (Kit.CheckDataBase()) { Common.ShowInfo("正在从数据库中读取表信息..."); EnvDTE.Project pjt = Kit.GetProjectComponent(); DBHelper <SQLTableInfo> dbi = new DBHelper <SQLTableInfo>(); List <SQLTableInfo> dbix = dbi.GetDataViewForObjectList(); string[] lsttab = Kit.SlnKeel.DataTableForms.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var item in lsttab) { tablenamenow = item; Common.ShowInfo(string.Format("正在生成{0}的控件,请稍候...", tablenamenow)); Predicate <SQLTableInfo> pdbi = new Predicate <SQLTableInfo>(FindByTableName); List <SQLTableInfo> lstdb = dbix.FindAll(pdbi); WebFormBaseGengerator mg; try { mg = new WebFormBaseGengerator(pjt, "ctl_" + item + "_Keel", lstdb); bool genok = mg.GenWebForm(); if (genok) { Common.ShowInfo(string.Format("{0}成功生成,正在保存...", tablenamenow)); } else { Common.ShowInfo(string.Format("抱歉!{0}的控件生成失败!", tablenamenow)); continue; } } catch (Exception ex) { Common.ShowInfo(string.Format("抱歉!{0}的控件生成失败!由于发生了异常:{1}", tablenamenow, ex.Message)); } } Common.chExc("SaveAll", ""); Common.ShowInfo(string.Format("全部控件生成完毕!")); } }
public static List <SQLTableName> GetSQLList(string list) { Kit.CheckDataBase(); List <SQLTableName> lsttab = null; if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.SQLServer)) { DBHelper <SQLTableName> dbt = new DBHelper <SQLTableName>(); lsttab = dbt.GetDataViewForObjectList(list); } else if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.MSAccess)) { lsttab = new List <SQLTableName>(); KeelKit.Core.DBInformer dbi = new DBInformer(Kit.SlnKeel.ConnectString); Hashtable dtm = list != "ViewInfo" ? dbi.GetUserTables() : dbi.GetUserViews(); foreach (DictionaryEntry tb in dtm) { SQLTableName st = new SQLTableName(); st.name = tb.Key.ToString(); lsttab.Add(st); } } else { lsttab = new List <SQLTableName>(); System.Data.Common.DbConnection dbc = Keel.DB.Common.NowDataBase.GetProviderFactory().CreateConnection(); dbc.ConnectionString = Keel.DB.Common.NowDataBase.ConnectString; dbc.Open(); DataTable dt = dbc.GetSchema(list != "ViewInfo" ? "Tables" : "Views"); for (int i = 0; i < dt.Rows.Count; i++) { lsttab.Add(new SQLTableName() { name = (string)dt.Rows[i]["TABLE_NAME"] }); } dbc.Close(); } return(lsttab); }
public static bool GeneratedCode(EnvDTE.Project pjt, string classname) { bool ok = Kit.CheckDataBase(); if (ok) { DBHelper <SPInfos> dbspi = new DBHelper <SPInfos>(); List <SPInfos> lspi = dbspi.GetDataViewForObjectList(); ok = false; if (classname == null || classname == "") { classname = "DALSP"; } string[] dttmp = Kit.SlnKeel.DataSP.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); SPGengerator mg = new SPGengerator(Kit.GetRootNamespace(pjt), classname); List <KeelKit.Generators.SQLTableName> stb = Generators.SPGengerator.GetSPNameList(); foreach (var item in dttmp) { Predicate <SPInfos> pdbi = new Predicate <SPInfos>(FindByTableName); spnamenow = item; List <SPInfos> lstdb = lspi.FindAll(pdbi); try { mg.AddMethod(lstdb, item); } catch (Exception) { } } cfLangType cl = Kit.GetProjectLangType(pjt); string filename = mg.Save(Path.GetDirectoryName(pjt.FullName) + "\\" + classname, cl, new DGetFileNames(GetFileNames)); pjt.ProjectItems.AddFromFile(filename); ok = true; } return(ok); }
public static void GeneratedCode(DCreateControl dc, string fieldlist, string tablename) { Common.ShowInfo("正在检查数据库是否可用!"); if (Kit.CheckDataBase()) { Common.ShowInfo("正在从数据库中读取表信息..."); EnvDTE.Project pjt = Kit.GetProjectComponent(); List <SQLTableInfo> dbix = ModelGengerator.GetSqlTableInfoList(); SQLTableInfo[] dbix_111 = dbix.ToArray(); if (fieldlist != null && fieldlist != "" && tablename != null && tablename != "") { var xf = from f in dbix_111 where f.t_tablename.ToLower() == tablename.ToLower() && fieldlist.Contains(f.t_fieldname + ";") select f; dbix = xf.ToList(); } string[] lsttab = ((tablename != null) ? tablename + ";" : (Kit.SlnKeel.DataTableForms + Kit.SlnKeel.DataViewForms)).Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var item in lsttab) { CreateControlByTable(dc, pjt, dbix, item, item + (fieldlist != null ? "_diy_" + fieldlist.Replace(";", "") : "")); } Common.chExc("SaveAll", ""); Common.ShowInfo(string.Format("全部控件生成完毕!")); } }