Ejemplo n.º 1
0
 private void CSEDItem_Click(object CommandBarControl, ref bool Handled, ref bool CancelDefault)
 {
     try
     {
         SelectFileInfo selectFileInfo = this.GetSelectFileInfo();
         if (selectFileInfo == null)
         {
             return;
         }
         if (!selectFileInfo.IsExistsCodeConfig())
         {
             return;
         }
         string itemPathEntityName = selectFileInfo.GetItemPathEntityName();
         string text = Path.Combine(selectFileInfo.ProjectPath, "DataEntity");
         if (!Directory.Exists(text))
         {
             selectFileInfo.Project.ProjectItems.AddFolder("DataEntity", "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}");
         }
         string path  = Path.Combine(text, itemPathEntityName + ".cs");
         string path2 = Path.Combine(selectFileInfo.ProjectPath, "DataAccess");
         if (!Directory.Exists(path2))
         {
             selectFileInfo.Project.ProjectItems.AddFolder("DataAccess", "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}");
         }
         string          path3           = Path.Combine(selectFileInfo.ProjectPath, "DataAccess", "Da" + itemPathEntityName + ".cs");
         TableRuleSchema tableRuleSchema = this.CreateItemTableRuleSchema(selectFileInfo);
         if (tableRuleSchema == null)
         {
             Handled = true;
             return;
         }
         string       text2        = tableRuleSchema.ToDataEntity(selectFileInfo.ProjectName);
         DialogResult dialogResult = MessageBox.Show("确定要更新" + tableRuleSchema.EntityName + "实体层吗?此更新不可恢复!", "", MessageBoxButtons.OKCancel);
         if (dialogResult == DialogResult.OK)
         {
             File.WriteAllText(path, text2, Encoding.UTF8);
         }
         else
         {
             Common.ShowCodeForm(text2);
         }
         text2        = tableRuleSchema.ToSqlDaRule(selectFileInfo.ProjectName);
         dialogResult = MessageBox.Show("确定要更新" + tableRuleSchema.EntityName + "数据访问层吗?此更新不可恢复!", "", MessageBoxButtons.OKCancel);
         if (dialogResult == DialogResult.OK)
         {
             File.WriteAllText(path3, text2, Encoding.UTF8);
         }
         else
         {
             Common.ShowCodeForm(text2);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("更新代码出现异常,异常错误:" + ex.ToString());
         return;
     }
     Handled = true;
 }
Ejemplo n.º 2
0
 private void gvdTables_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (this.gvdTables.Columns[e.ColumnIndex].Name == "SetCheck")
     {
         if (!string.IsNullOrEmpty(this.CurrentEditTable))
         {
             List <ColumnRuleSchema> columns    = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == this.CurrentEditTable).Columns;
             IEnumerator             enumerator = ((IEnumerable)this.gvwTableCols.Rows).GetEnumerator();
             {
                 while (enumerator.MoveNext())
                 {
                     DataGridViewRow  dataGridViewRow  = (DataGridViewRow)enumerator.Current;
                     string           FieldName        = dataGridViewRow.ReadCell("FieldName", "");
                     ColumnRuleSchema columnRuleSchema = columns.First((ColumnRuleSchema s) => s.FieldName == FieldName);
                     columnRuleSchema.IsXmlField   = this.CheckIsXmlField(columnRuleSchema, dataGridViewRow);
                     columnRuleSchema.IsCheck      = bool.Parse(dataGridViewRow.ReadCell("IsCheck", ""));
                     columnRuleSchema.ErrorMessage = dataGridViewRow.ReadCell("ErrorMessage", "");
                     columnRuleSchema.FieldTitle   = dataGridViewRow.ReadCell("FieldTitle", "");
                 }
             }
         }
         string TableName = this.gvdTables.Rows[e.RowIndex].ReadCell("TableName", "");
         this.CurrentEditTable = TableName;
         TableRuleSchema tableRuleSchema = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == TableName);
         if (tableRuleSchema.Columns.Count == 0)
         {
             tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(this._ConnectionString, this._Database, TableName, this._CodeConfigHelper);
         }
         this.gvwTableCols.AutoGenerateColumns = false;
         this.gvwTableCols.DataSource          = tableRuleSchema.Columns;
     }
 }
Ejemplo n.º 3
0
 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());
         }
     }
 }
Ejemplo n.º 4
0
        private void btnRuleCode_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.CurrentEditTable))
            {
                List <ColumnRuleSchema> columns    = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == this.CurrentEditTable).Columns;
                IEnumerator             enumerator = ((IEnumerable)this.gvwTableCols.Rows).GetEnumerator();
                {
                    while (enumerator.MoveNext())
                    {
                        DataGridViewRow  dataGridViewRow  = (DataGridViewRow)enumerator.Current;
                        string           FieldName        = dataGridViewRow.ReadCell("FieldName", "");
                        ColumnRuleSchema columnRuleSchema = columns.First((ColumnRuleSchema s) => s.FieldName == FieldName);
                        columnRuleSchema.IsXmlField   = this.CheckIsXmlField(columnRuleSchema, dataGridViewRow);
                        columnRuleSchema.IsCheck      = bool.Parse(dataGridViewRow.ReadCell("IsCheck", ""));
                        columnRuleSchema.ErrorMessage = dataGridViewRow.ReadCell("ErrorMessage", "");
                        columnRuleSchema.FieldTitle   = dataGridViewRow.ReadCell("FieldTitle", "");
                    }
                }
            }
            IEnumerator enumerator2 = ((IEnumerable)this.gvdTables.Rows).GetEnumerator();
            {
                while (enumerator2.MoveNext())
                {
                    DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator2.Current;
                    string          TableName       = dataGridViewRow.ReadCell("TableName", "");
                    TableRuleSchema tableRuleSchema = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == TableName);
                    tableRuleSchema.IsCreate           = bool.Parse(dataGridViewRow.ReadCell("IsCreate", ""));
                    tableRuleSchema.Description        = dataGridViewRow.ReadCell("Description", "");
                    tableRuleSchema.EntityName         = dataGridViewRow.ReadCell("EntityName", "");
                    tableRuleSchema.IsMongoDB          = bool.Parse(dataGridViewRow.ReadCell("IsMongoDB", ""));
                    tableRuleSchema.IsCheckFieldLength = bool.Parse(dataGridViewRow.ReadCell("IsCheckFieldLength", ""));
                    tableRuleSchema.ConnectionKeyOrConnectionString = dataGridViewRow.ReadCell("ConnectionKeyOrConnectionString", "");
                    tableRuleSchema.LogModuleType = dataGridViewRow.ReadCell("LogModuleType", "");
                    tableRuleSchema.UIProjectName = dataGridViewRow.ReadCell("UIProjectName", this.txtUIProjectName.Text);
                    tableRuleSchema.UIProjectPath = dataGridViewRow.ReadCell("UIProjectPath", this.txtUIProjectPath.Text);
                    if (tableRuleSchema.IsCreate && tableRuleSchema.Columns.Count == 0)
                    {
                        tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(this._ConnectionString, this._Database, tableRuleSchema.TableName, this._CodeConfigHelper);
                    }
                }
            }
            int num = (from s in this._TableRuleSchemaList
                       where s.IsCreate
                       select s).Count <TableRuleSchema>();

            if (num == 0)
            {
                MessageBox.Show("请要生成的表");
            }
            else
            {
                this._CodeConfigHelper.UpdateXml((from s in this._TableRuleSchemaList
                                                  where s.IsCreate
                                                  select s).ToList <TableRuleSchema>(), this.boxConnectString.SelectedItem.ToString());
                MessageBox.Show("一键生成配置文件成功");
            }
        }
Ejemplo n.º 5
0
 private void CSItem_Click(object CommandBarControl, ref bool Handled, ref bool CancelDefault)
 {
     try
     {
         SelectFileInfo selectFileInfo = this.GetSelectFileInfo();
         if (selectFileInfo == null)
         {
             return;
         }
         if (!selectFileInfo.IsExistsCodeConfig())
         {
             return;
         }
         TableRuleSchema tableRuleSchema = this.CreateItemTableRuleSchema(selectFileInfo);
         if (tableRuleSchema == null)
         {
             Handled = true;
             return;
         }
         string text = "";
         if (selectFileInfo.ProjectItemPath.IndexOf("DataEntity") > 0)
         {
             text = tableRuleSchema.ToDataEntity(selectFileInfo.ProjectName);
         }
         else if (selectFileInfo.ProjectItemPath.IndexOf("DataAccess") > 0)
         {
             text = tableRuleSchema.ToSqlDaRule(selectFileInfo.ProjectName);
         }
         else if (selectFileInfo.ProjectItemPath.IndexOf("Business") > 0)
         {
             text = tableRuleSchema.ToSqlBizRule(selectFileInfo.ProjectName);
         }
         DialogResult dialogResult = MessageBox.Show("确定要更新" + selectFileInfo.ItemFileName + "文件吗?此更新不可恢复!", "", MessageBoxButtons.OKCancel);
         if (dialogResult == DialogResult.OK)
         {
             File.WriteAllText(selectFileInfo.ProjectItemPath, text, Encoding.UTF8);
             MessageBox.Show("更新成功");
         }
         else
         {
             Common.ShowCodeForm(text);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("更新代码出现异常,异常错误:" + ex.ToString());
         return;
     }
     Handled = true;
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private List <TableRuleSchema> ProcessData()
        {
            if (!string.IsNullOrEmpty(this.CurrentEditTable))
            {
                List <ColumnRuleSchema> columns    = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == this.CurrentEditTable).Columns;
                IEnumerator             enumerator = ((IEnumerable)this.gvwTableCols.Rows).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    DataGridViewRow  dataGridViewRow  = (DataGridViewRow)enumerator.Current;
                    string           FieldName        = dataGridViewRow.ReadCell("FieldName", "");
                    ColumnRuleSchema columnRuleSchema = columns.First((ColumnRuleSchema s) => s.FieldName == FieldName);
                    columnRuleSchema.IsXmlField   = this.CheckIsXmlField(columnRuleSchema, dataGridViewRow);
                    columnRuleSchema.IsCheck      = bool.Parse(dataGridViewRow.ReadCell("IsCheck", ""));
                    columnRuleSchema.ErrorMessage = dataGridViewRow.ReadCell("ErrorMessage", "");
                    columnRuleSchema.FieldTitle   = dataGridViewRow.ReadCell("FieldTitle", "");
                }
            }
            List <TableRuleSchema> result;
            IEnumerator            enumerator2 = ((IEnumerable)this.gvdTables.Rows).GetEnumerator();

            while (enumerator2.MoveNext())
            {
                DataGridViewRow dataGridViewRow = (DataGridViewRow)enumerator2.Current;
                string          TableName       = dataGridViewRow.ReadCell("TableName", "");
                string          text            = dataGridViewRow.ReadCell("LogModuleType", "");
                text = (string.IsNullOrWhiteSpace(text) ? ((this.boxLogType.SelectedItem == null) ? "" : this.boxLogType.SelectedItem.ToString()) : text);
                string text2 = dataGridViewRow.ReadCell("ConnectionKeyOrConnectionString", "");
                text2 = (string.IsNullOrWhiteSpace(text2) ? this.txtConnectionKey.Text : text2);
                TableRuleSchema tableRuleSchema = this._TableRuleSchemaList.First((TableRuleSchema s) => s.TableName == TableName);
                tableRuleSchema.IsCreate           = bool.Parse(dataGridViewRow.ReadCell("IsCreate", ""));
                tableRuleSchema.Description        = dataGridViewRow.ReadCell("Description", "");
                tableRuleSchema.EntityName         = dataGridViewRow.ReadCell("EntityName", "");
                tableRuleSchema.IsMongoDB          = bool.Parse(dataGridViewRow.ReadCell("IsMongoDB", ""));
                tableRuleSchema.IsCheckFieldLength = bool.Parse(dataGridViewRow.ReadCell("IsCheckFieldLength", ""));
                tableRuleSchema.ConnectionKeyOrConnectionString = text2;
                tableRuleSchema.LogModuleType = text;
                if (tableRuleSchema.IsCreate && string.IsNullOrWhiteSpace(tableRuleSchema.LogModuleType))
                {
                    MessageBox.Show("表名:" + TableName + ",请输入日志类型或选择日志类型");
                    result = null;
                    return(result);
                }
                if (tableRuleSchema.IsCreate && tableRuleSchema.Columns.Count == 0)
                {
                    tableRuleSchema.Columns = SqlSchemaHelper.GetTableRuleColumnsSchema(this._ConnectionString, this._Database, tableRuleSchema.TableName, this._CodeConfigHelper);
                }
            }
            List <TableRuleSchema> list = (from s in this._TableRuleSchemaList
                                           where s.IsCreate
                                           select s).ToList <TableRuleSchema>();

            if (list.Count <TableRuleSchema>() == 0)
            {
                MessageBox.Show("请选择表");
                result = null;
            }
            else
            {
                result = list;
            }
            return(result);
        }
Ejemplo n.º 8
0
 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;
         }
     }
 }