private void SqlListItem_Click(object CommandBarControl, ref bool Handled, ref bool CancelDefault) { try { SelectFileInfo selectFileInfo = this.GetSelectFileInfo(); if (selectFileInfo == null) { return; } if (!selectFileInfo.IsExistsCodeConfig()) { return; } if (!selectFileInfo.IsExistsWTFConfig()) { return; } BusinessNodeInfo businessNodeInfo = this.GetBusinessNodeInfo(selectFileInfo); if (businessNodeInfo == null) { Handled = true; return; } SqlListForm sqlListForm = new SqlListForm(selectFileInfo, businessNodeInfo); sqlListForm.Show(); } catch (Exception ex) { MessageBox.Show("新建列表页抛出异常,异常信息:" + ex.ToString()); return; } Handled = true; }
private void LoadTableSchema(string ConnectionStringName) { if (!string.IsNullOrWhiteSpace(ConnectionStringName)) { this.gvdTables.AutoGenerateColumns = false; this._ConnectionString = this._CodeConfigHelper.GetConnectionString(ConnectionStringName, out this._Database); try { this._TableRuleSchemaList = SqlSchemaHelper.GetAllRuleTables(this._Database, this._ConnectionString, true); this._TableRuleSchemaList = (from x in this._TableRuleSchemaList where this._BusinessNodeInfoList.Keys.Contains(x.TableName) select x).ToList <TableRuleSchema>(); foreach (TableRuleSchema current in this._TableRuleSchemaList) { BusinessNodeInfo objBusinessNodeInfo = this._BusinessNodeInfoList[current.TableName]; current.IsCreate = true; CodeConfigHelper.BusinessNodeToTableRuleSchema(objBusinessNodeInfo, current); } this.gvdTables.DataSource = this._TableRuleSchemaList; } catch (Exception ex) { MessageBox.Show("加载表错误,异常信息:" + ex.ToString()); } } }
private void SqlEditItem_Click(object CommandBarControl, ref bool Handled, ref bool CancelDefault) { try { SelectFileInfo selectFileInfo = this.GetSelectFileInfo(); if (selectFileInfo != null) { if (selectFileInfo.IsExistsCodeConfig()) { BusinessNodeInfo businessNodeInfo = this.GetBusinessNodeInfo(selectFileInfo); if (businessNodeInfo == null) { Handled = true; } else { SqlEditForm sqlEditForm = new SqlEditForm(selectFileInfo, businessNodeInfo); sqlEditForm.Show(); Handled = true; } } } } catch (Exception ex) { MessageBox.Show("新建编辑页抛出异常,异常信息:" + ex.ToString()); } }
public BusinessNodeInfo GetBusiness(string EntityName) { XmlNode xmlNode = this.CodeConfig.SelectSingleNode("//BusinessConfig/Business[@EntityName='" + EntityName + "']"); BusinessNodeInfo result; if (xmlNode == null) { result = null; } else { BusinessNodeInfo businessNodeInfo = new BusinessNodeInfo { TableName = xmlNode.ReadAttribute("TableName", ""), ConnectionKeyOrConnectionString = xmlNode.ReadAttribute("ConnectionKeyOrConnectionString", ""), LogModuleType = xmlNode.ReadAttribute("LogModuleType", ""), IsMongoDB = bool.Parse(xmlNode.ReadAttribute("IsMongoDB", "false")), IsCheckFieldLength = bool.Parse(xmlNode.ReadAttribute("IsCheckFieldLength", "true")), EntityName = xmlNode.ReadAttribute("EntityName", ""), ConnectionKey = xmlNode.ReadAttribute("ConnectionKey", ""), UIProjectName = xmlNode.ReadAttribute("UIProjectName", ""), UIProjectPath = xmlNode.ReadAttribute("UIProjectPath", ""), ModuleID = xmlNode.ReadAttribute("ModuleID", ""), EditUrl = xmlNode.ReadAttribute("EditUrl", ""), ListUrl = xmlNode.ReadAttribute("ListUrl", ""), Description = xmlNode.ReadAttribute("Description", "") }; result = businessNodeInfo; } return(result); }
private void LoadTableSchema(string ConnectionStringName) { if (!string.IsNullOrWhiteSpace(ConnectionStringName)) { this.gvdTables.AutoGenerateColumns = false; this._ConnectionString = this._CodeConfigHelper.GetConnectionString(ConnectionStringName, out this._Database); try { this._TableRuleSchemaList = SqlSchemaHelper.GetAllRuleTables(this._Database, this._ConnectionString, !this.IsView.Checked); List <BusinessNodeInfo> business = this._CodeConfigHelper.GetBusiness(); using (List <TableRuleSchema> .Enumerator enumerator = this._TableRuleSchemaList.GetEnumerator()) { while (enumerator.MoveNext()) { TableRuleSchema objTableRuleSchema = enumerator.Current; BusinessNodeInfo objBusinessNodeInfo = business.FirstOrDefault((BusinessNodeInfo s) => s.TableName == objTableRuleSchema.TableName); CodeConfigHelper.BusinessNodeToTableRuleSchema(objBusinessNodeInfo, objTableRuleSchema); } } this.gvdTables.DataSource = this._TableRuleSchemaList; } catch (Exception ex) { MessageBox.Show("加载表错误,异常信息:" + ex.ToString()); } } }
public List <BusinessNodeInfo> GetBusiness() { List <BusinessNodeInfo> list = new List <BusinessNodeInfo>(); foreach (XmlNode objXmlNode in this._XmlDocument.SelectNodes("//CodeConfig/BusinessConfig/Business")) { BusinessNodeInfo item = new BusinessNodeInfo { TableName = objXmlNode.ReadAttribute("TableName", ""), ConnectionKeyOrConnectionString = objXmlNode.ReadAttribute("ConnectionKeyOrConnectionString", ""), LogModuleType = objXmlNode.ReadAttribute("LogModuleType", ""), IsMongoDB = bool.Parse(objXmlNode.ReadAttribute("IsMongoDB", "false")), IsCheckFieldLength = bool.Parse(objXmlNode.ReadAttribute("IsCheckFieldLength", "true")), EntityName = objXmlNode.ReadAttribute("EntityName", ""), ConnectionKey = objXmlNode.ReadAttribute("ConnectionKey", ""), UIProjectName = objXmlNode.ReadAttribute("UIProjectName", ""), UIProjectPath = objXmlNode.ReadAttribute("UIProjectPath", ""), ModuleID = objXmlNode.ReadAttribute("ModuleID", ""), EditUrl = objXmlNode.ReadAttribute("EditUrl", ""), ListUrl = objXmlNode.ReadAttribute("ListUrl", ""), Description = objXmlNode.ReadAttribute("Description", "") }; list.Add(item); } return(list); }
public BusinessNodeInfo GetBusinessNodeInfo(SelectFileInfo objSelectFileInfo) { BusinessNodeInfo result; if (!objSelectFileInfo.IsExistsCodeConfig()) { result = null; } else { string itemPathEntityName = objSelectFileInfo.GetItemPathEntityName(); if (string.IsNullOrWhiteSpace(itemPathEntityName)) { MessageBox.Show(objSelectFileInfo.ItemFileName + ".cs,不是基础业务层类,因此无法更新或新增"); result = null; } else { CodeConfigHelper codeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (!codeConfigHelper.LoadCodeConfigXml()) { result = null; } else { BusinessNodeInfo business = codeConfigHelper.GetBusiness(itemPathEntityName); if (business == null) { if (MessageBox.Show(itemPathEntityName + "实体未配置业务XML?是否配置吗?", "", MessageBoxButtons.OKCancel) != DialogResult.OK) { result = null; } else { Dictionary <string, BusinessNodeInfo> dictionary = new Dictionary <string, BusinessNodeInfo>(); BusinessNodeInfo readFileBusinessNodeInfo = CodeConfigHelper.GetReadFileBusinessNodeInfo(itemPathEntityName, objSelectFileInfo.ProjectPath); if (readFileBusinessNodeInfo == null) { MessageBox.Show(objSelectFileInfo.ItemFileName + ".cs,不是基础业务层类,因此无法配置XML"); result = null; } else { dictionary.Add(readFileBusinessNodeInfo.TableName, readFileBusinessNodeInfo); AKeyAddCodeConfig aKeyAddCodeConfig = new AKeyAddCodeConfig(objSelectFileInfo, dictionary); aKeyAddCodeConfig.Show(); result = null; } } } else { result = business; } } } } return(result); }
public static BusinessNodeInfo GetReadFileBusinessNodeInfo(string entityName, string projectPath) { string path = projectPath + "\\DataEntity\\" + entityName + ".cs"; string path2 = projectPath + "\\Business\\Biz" + entityName + ".cs"; string path3 = projectPath + "\\DataAccess\\Da" + entityName + ".cs"; BusinessNodeInfo result; if (!File.Exists(path) || !File.Exists(path2) || !File.Exists(path3)) { result = null; } else { Dictionary <string, BusinessNodeInfo> dictionary = new Dictionary <string, BusinessNodeInfo>(); string input = File.ReadAllText(path); Regex regex = new Regex("public[\\w ]+_id", RegexOptions.IgnoreCase); MatchCollection matchCollection = regex.Matches(input); bool isMongoDB = matchCollection.Count > 0; string connectionKeyOrConnectionString = string.Empty; string logModuleType = ""; string input2 = File.ReadAllText(path2); regex = new Regex("this\\(\\\"(?<connectionKey>[\\w\\.]*)\\\",\\s*dataObjectParam\\)", RegexOptions.IgnoreCase); matchCollection = regex.Matches(input2); if (matchCollection.Count > 0) { connectionKeyOrConnectionString = matchCollection[0].Groups["connectionKey"].Value; } regex = new Regex("Log.LogModuleType\\s*=\\s*\\\"(?<logModuleType>[\\w]*)\\\"", RegexOptions.IgnoreCase); matchCollection = regex.Matches(input2); if (matchCollection.Count > 0) { logModuleType = matchCollection[0].Groups["logModuleType"].Value; } string input3 = File.ReadAllText(path3); regex = new Regex(":\\s*base\\(\\\"(?<tableName>\\w*)\\\",", RegexOptions.IgnoreCase); string tableName = ""; matchCollection = regex.Matches(input3); if (matchCollection.Count > 0) { tableName = matchCollection[0].Groups["tableName"].Value; } BusinessNodeInfo businessNodeInfo = new BusinessNodeInfo { EntityName = entityName, ConnectionKeyOrConnectionString = connectionKeyOrConnectionString, LogModuleType = logModuleType, IsMongoDB = isMongoDB, IsCheckFieldLength = true, TableName = tableName, EditUrl = "", ListUrl = "", ModuleID = "" }; result = businessNodeInfo; } return(result); }
public string GetBusinessNodeInfoExistsLogModuleType() { BusinessNodeInfo businessNodeInfo = (from s in this.GetBusiness() where s.LogModuleType != "" select s).FirstOrDefault <BusinessNodeInfo>(); string result; if (businessNodeInfo != null) { result = businessNodeInfo.LogModuleType; } else { result = ""; } return(result); }
public string GetBusinessNodeInfoExistsConnectionString() { BusinessNodeInfo businessNodeInfo = (from s in this.GetBusiness() where s.ConnectionKeyOrConnectionString != "" select s).FirstOrDefault <BusinessNodeInfo>(); string result; if (businessNodeInfo != null) { result = businessNodeInfo.ConnectionKeyOrConnectionString; } else { result = ""; } return(result); }
public SqlListForm(SelectFileInfo objSelectFileInfo, BusinessNodeInfo objBusinessNodeInfo) { this.InitializeComponent(); this._SelectFileInfo = objSelectFileInfo; this._CodeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (this._CodeConfigHelper.LoadCodeConfigXml()) { this._BusinessNodeInfo = objBusinessNodeInfo; this.Text = this._BusinessNodeInfo.TableName + "列表界面生成"; string text = ""; string text2 = ""; this._CodeConfigHelper.GetBusinessNodeInfoUIPath(objBusinessNodeInfo, out text, out text2); this.txtUIProjectPath.Text = text; this.txtUIProjectName.Text = text2; this.txtModuleID.Text = this._BusinessNodeInfo.ModuleID; this.txtEditUrl.Text = (string.IsNullOrWhiteSpace(this._BusinessNodeInfo.EditUrl) ? (objBusinessNodeInfo.EntityName + "Edit.aspx") : this._BusinessNodeInfo.EditUrl); } }
public static void BusinessNodeToTableRuleSchema(BusinessNodeInfo objBusinessNodeInfo, TableRuleSchema objTableRuleSchema) { if (objBusinessNodeInfo != null && objTableRuleSchema != null) { objTableRuleSchema.LogModuleType = objBusinessNodeInfo.LogModuleType; objTableRuleSchema.ConnectionKeyOrConnectionString = objBusinessNodeInfo.ConnectionKeyOrConnectionString; objTableRuleSchema.EntityName = objBusinessNodeInfo.EntityName; objTableRuleSchema.ConnectionKey = objBusinessNodeInfo.ConnectionKey; objTableRuleSchema.IsMongoDB = objBusinessNodeInfo.IsMongoDB; objTableRuleSchema.IsCheckFieldLength = objBusinessNodeInfo.IsCheckFieldLength; objTableRuleSchema.UIProjectPath = objBusinessNodeInfo.UIProjectPath; objTableRuleSchema.UIProjectName = objBusinessNodeInfo.UIProjectName; objTableRuleSchema.EditUrl = objBusinessNodeInfo.EditUrl; objTableRuleSchema.ListUrl = objBusinessNodeInfo.ListUrl; objTableRuleSchema.ModuleID = objBusinessNodeInfo.ModuleID; if (string.IsNullOrWhiteSpace(objTableRuleSchema.Description)) { objTableRuleSchema.Description = objBusinessNodeInfo.Description; } } }
public void GetBusinessNodeInfoUIPath(BusinessNodeInfo objBusinessNodeInfo, out string UIProjectPath, out string UIProjectName) { UIProjectPath = "Gao7.ManaeWeb\\Manage\\XXXX"; UIProjectName = "Gao7.ManaeWeb"; if (!string.IsNullOrWhiteSpace(objBusinessNodeInfo.UIProjectPath) || !string.IsNullOrWhiteSpace(objBusinessNodeInfo.UIProjectName)) { UIProjectPath = objBusinessNodeInfo.UIProjectPath; UIProjectName = objBusinessNodeInfo.UIProjectName; } else { BusinessNodeInfo businessNodeInfo = (from s in this.GetBusiness() where s.UIProjectPath != "" && s.UIProjectName != "" select s).FirstOrDefault <BusinessNodeInfo>(); if (businessNodeInfo != null) { UIProjectPath = businessNodeInfo.UIProjectPath; UIProjectName = businessNodeInfo.UIProjectName; } } }
public SqlEditForm(SelectFileInfo objSelectFileInfo, BusinessNodeInfo objBusinessNodeInfo) { this.InitializeComponent(); this._SelectFileInfo = objSelectFileInfo; this._CodeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (this._CodeConfigHelper.LoadCodeConfigXml()) { this._BusinessNodeInfo = objBusinessNodeInfo; this.Text = this._BusinessNodeInfo.TableName + "编辑界面生成"; string text = ""; string text2 = ""; this._CodeConfigHelper.GetBusinessNodeInfoUIPath(objBusinessNodeInfo, out text, out text2); this.txtUIProjectPath.Text = text; this.txtUIProjectName.Text = text2; this.txtBackUrl.Text = (string.IsNullOrWhiteSpace(this._BusinessNodeInfo.ListUrl) ? (objBusinessNodeInfo.EntityName + "List.aspx") : this._BusinessNodeInfo.ListUrl); this.gvdData.AutoGenerateColumns = false; string schemaName = ""; string connectionString = this._CodeConfigHelper.GetConnectionString(this._BusinessNodeInfo.ConnectionKey, out schemaName); this._CurrentColumnList = SqlSchemaHelper.GetTableColumnsSchema(schemaName, this._BusinessNodeInfo.TableName, this._CodeConfigHelper, connectionString); this.gvdData.DataSource = (from s in this._CurrentColumnList where s.ColumnType == "Common" && !s.FieldName.ToLower().Contains("guid") select s).ToList <ColumnEditSchema>(); } }
public TableRuleSchema CreateItemTableRuleSchema(SelectFileInfo objSelectFileInfo) { TableRuleSchema result; if (!objSelectFileInfo.IsExistsCodeConfig()) { result = null; } else { string itemPathEntityName = objSelectFileInfo.GetItemPathEntityName(); if (string.IsNullOrWhiteSpace(itemPathEntityName)) { MessageBox.Show(objSelectFileInfo.ItemFileName + ".cs,不是基础业务层类,因此无法更新或新增"); result = null; } else { CodeConfigHelper codeConfigHelper = new CodeConfigHelper(objSelectFileInfo.CodeConfigPath); if (!codeConfigHelper.LoadCodeConfigXml()) { result = null; } else { BusinessNodeInfo business = codeConfigHelper.GetBusiness(itemPathEntityName); if (business == null) { if (MessageBox.Show(itemPathEntityName + "实体未配置业务XML?是否配置吗?", "", MessageBoxButtons.OKCancel) != DialogResult.OK) { result = null; } else { Dictionary <string, BusinessNodeInfo> dictionary = new Dictionary <string, BusinessNodeInfo>(); BusinessNodeInfo readFileBusinessNodeInfo = CodeConfigHelper.GetReadFileBusinessNodeInfo(itemPathEntityName, objSelectFileInfo.ProjectPath); if (readFileBusinessNodeInfo == null) { MessageBox.Show(objSelectFileInfo.ItemFileName + ".cs,不是基础业务层类,因此无法配置XML"); result = null; } else { dictionary.Add(readFileBusinessNodeInfo.TableName, readFileBusinessNodeInfo); AKeyAddCodeConfig aKeyAddCodeConfig = new AKeyAddCodeConfig(objSelectFileInfo, dictionary); aKeyAddCodeConfig.Show(); result = null; } } } else { string schemaName = ""; string connectionString = codeConfigHelper.GetConnectionString(business.ConnectionKey, out schemaName); if (string.IsNullOrWhiteSpace(connectionString)) { if (MessageBox.Show("连接串键值(" + business.ConnectionKey + ")不存在,要配置连接吗?", "", MessageBoxButtons.OKCancel) == DialogResult.OK) { ConnectConfigFrom connectConfigFrom = new ConnectConfigFrom(objSelectFileInfo); connectConfigFrom.Show(); } result = null; } else { string tableName = business.TableName; try { TableRuleSchema tableRuleSchema = SqlSchemaHelper.GetAllRuleTables(schemaName, connectionString, true).FirstOrDefault((TableRuleSchema s) => s.TableName == tableName); if (tableRuleSchema == null) { MessageBox.Show("数据库找不到此:" + tableName + ",请检查配置是否正确"); result = null; } else { CodeConfigHelper.BusinessNodeToTableRuleSchema(business, tableRuleSchema); tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(connectionString, schemaName, tableRuleSchema.TableName, codeConfigHelper); result = tableRuleSchema; } } catch (Exception ex) { MessageBox.Show("更新代码出现异常,异常错误:" + ex.ToString()); result = null; } } } } } } return(result); }
private void AddCodeConfigItem_Click(object commandBarControl, ref bool handled, ref bool cancelDefault) { try { SelectFileInfo selectFileInfo = this.GetSelectFileInfo(); if (selectFileInfo == null) { return; } if (!selectFileInfo.IsExistsCodeConfig()) { handled = true; return; } CodeConfigHelper codeConfigHelper = new CodeConfigHelper(selectFileInfo.CodeConfigPath); if (!codeConfigHelper.LoadCodeConfigXml()) { return; } if (!Directory.Exists(selectFileInfo.ProjectPath + "\\DataAccess") || !Directory.Exists(selectFileInfo.ProjectPath + "\\Business") || !Directory.Exists(selectFileInfo.ProjectPath + "\\DataEntity")) { DialogResult dialogResult = MessageBox.Show("业务层不存在,要新增业务层吗?", "", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { SqlRuleCodeForm sqlRuleCodeForm = new SqlRuleCodeForm(selectFileInfo); sqlRuleCodeForm.Show(); } handled = true; return; } string[] files = Directory.GetFiles(selectFileInfo.ProjectPath + "\\DataAccess", "Da*.cs"); string[] files2 = Directory.GetFiles(selectFileInfo.ProjectPath + "\\Business", "Biz*.cs"); string[] files3 = Directory.GetFiles(selectFileInfo.ProjectPath + "\\DataEntity", "*.cs"); if (files.Count <string>() <= 0 || files2.Count <string>() <= 0 || files3.Count <string>() <= 0) { DialogResult dialogResult = MessageBox.Show("业务层不存在,要新增业务层吗?", "", MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { SqlRuleCodeForm sqlRuleCodeForm = new SqlRuleCodeForm(selectFileInfo); sqlRuleCodeForm.Show(); } handled = true; return; } Dictionary <string, BusinessNodeInfo> dictionary = new Dictionary <string, BusinessNodeInfo>(); List <BusinessNodeInfo> business = codeConfigHelper.GetBusiness(); string[] array = files3; for (int i = 0; i < array.Length; i++) { string path = array[i]; string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path); string value = Path.Combine(selectFileInfo.ProjectPath, "DataAccess", "Da" + fileNameWithoutExtension + ".cs"); string value2 = Path.Combine(selectFileInfo.ProjectPath, "Business", "Biz" + fileNameWithoutExtension + ".cs"); if (files.Contains(value) && files2.Contains(value2)) { BusinessNodeInfo objBusinessNodeInfo = CodeConfigHelper.GetReadFileBusinessNodeInfo(fileNameWithoutExtension, selectFileInfo.ProjectPath); if (objBusinessNodeInfo != null) { BusinessNodeInfo businessNodeInfo = business.FirstOrDefault((BusinessNodeInfo s) => s.TableName == objBusinessNodeInfo.TableName); if (businessNodeInfo == null) { dictionary.Add(objBusinessNodeInfo.TableName, objBusinessNodeInfo); } else { businessNodeInfo.ConnectionKeyOrConnectionString = objBusinessNodeInfo.ConnectionKeyOrConnectionString; businessNodeInfo.LogModuleType = objBusinessNodeInfo.LogModuleType; businessNodeInfo.IsMongoDB = objBusinessNodeInfo.IsMongoDB; dictionary.Add(businessNodeInfo.TableName, businessNodeInfo); } } } } AKeyAddCodeConfig aKeyAddCodeConfig = new AKeyAddCodeConfig(selectFileInfo, dictionary); aKeyAddCodeConfig.Show(); handled = true; } catch (Exception ex) { MessageBox.Show("一键生成配置:" + ex.Message); } handled = true; }