Exemple #1
0
        void ThreadWork()
        {
            SetBtnDisable();
            string strnamespace = this.txtNamespace.Text.Trim();
            string strfolder    = this.txtTargetFolder.Text.Trim();
            int    tblCount     = this.listTable2.Items.Count;

            SetprogressBar1Max(tblCount);
            SetprogressBar1Val(1);
            SetlblStatuText("0");

            #region 循环每个表

            for (int i = 0; i < tblCount; i++)
            {
                string tablename = this.listTable2.Items[i].ToString();
                this.ClassName = tablename;
                DataTable         dtkey   = dbobj.GetKeyName(dbname, tablename);
                List <ColumnInfo> collist = dbobj.GetColumnInfoList(dbname, tablename);
                this.BuilderEntity(this.OutPutPath, tablename);
                this.BuilderTable(this.OutPutPath, tablename);
                this.BuilderManager(this.OutPutPath, tablename);
                string fileName = this.OutPutPath + "\\" + this.Project + ".BizLogic\\IService\\" + "I" + className + "Service.cs";
                this.BuilderIServic(fileName, tablename);
                fileName = this.OutPutPath + "\\" + this.Project + ".BizLogic\\Service\\" + className + "Service.cs";
                this.BuilderService(fileName, tablename);
                SetprogressBar1Val(i + 1);
                SetlblStatuText((i + 1).ToString());
            }

            #endregion

            SetBtnEnable();
            this.Invoke(new MethodInvoker(() => { MessageBox.Show(this, "代码批量生成成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); }));
        }
Exemple #2
0
 public List <ColumnInfo> GetColumnInfo(string tableName = null)
 {
     if (string.IsNullOrEmpty(tableName))
     {
         tableName = this.TableName;
     }
     return(dbObject.GetColumnInfoList(this.DBName, tableName));
 }
Exemple #3
0
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            EntityBuilder builder;

            foreach (string o in lbright.Items)
            {
                var ro = !string.IsNullOrWhiteSpace(txtTableStar.Text.Trim())
                    ? o.Trim().Replace(' ', '_').Replace(txtTableStar.Text.Trim(), "")
                    : o.Trim().Replace(' ', '_');
                //var wjj = string.IsNullOrWhiteSpace(txt_wjj.Text.Trim()) ? "" : "." + txt_wjj.Text.Trim();
                //修改原因:需要生成简写表名,同时类名也需要改 例 Com_aa 需要Com文件夹 aa类  命名空间Com.aa
                //修改后效果:根据txtTableStar文本框所填内容来识别去除内容  by kelyljk 2016-2-2
                builder = new EntityBuilder(o, txtNamaspace.Text, //+ wjj
                                            ro,
                                            Utils.GetColumnInfos(dbObject.GetColumnInfoList(DatabaseName, o)),
                                            tableview[o],
                                            cbToupperFrstword.Checked,
                                            ConnectionModel.DbType);
                builder.TablePre  = txtPre.Text.Trim();
                builder.TableNext = txtNext.Text.Trim();
                var path = txtPath.Text + "\\" + txt_wjj.Text.Trim();
                //修改后效果:自动生成路劲文件夹 by kelyljk 2016-2-2
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //修改原因:需要生成简写表名 例 Com_aa 需要Com文件夹 aa类
                //修改后效果:根据txtTableStar文本框所填内容来识别去除内容  by kelyljk 2016-2-2
                String fileName = builder.TablePre + ro + builder.TableNext;
                fileName = fileName.Replace(" ", "");
                using (StreamWriter sw = new StreamWriter(Path.Combine(path,
                                                                       fileName + ".cs"),
                                                          false,
                                                          Encoding.UTF8))
                {
                    sw.Write(builder.Builder(TplContent));
                    sw.Close();
                }

                backgroundWorker1.ReportProgress(1);

                System.Threading.Thread.Sleep(1);
            }
        }
Exemple #4
0
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            _noneWorkCount = 0;

            EntityCodeBuilder builder;

            foreach (object o in lbright.Items)
            {
                builder = new EntityCodeBuilder(o.ToString(), txtNamaspace.Text, o.ToString().Trim().Replace(" ", ""), UtilsHelper.GetColumnInfos(dbObject.GetColumnInfoList(DatabaseName, o.ToString())), tableview[o.ToString()], cbToupperFrstword.Checked);

                var cs = builder.Builder();

                if (!string.IsNullOrEmpty(cs))
                {
                    using (StreamWriter sw = new StreamWriter(Path.Combine(txtPath.Text, o.ToString().Trim().Replace(' ', '_') + ".cs"), false, Encoding.UTF8))
                    {
                        sw.Write(cs);
                        sw.Flush();
                    }
                }
                else
                {
                    _noneWorkCount++;
                }

                backgroundWorker1.ReportProgress(1);

                System.Threading.Thread.Sleep(1);
            }
        }
Exemple #5
0
        private void BindlistViewCol(string Dbname, string TableName)
        {
            SetListViewMenu("colum");
            //创建列表
            this.listView1.Columns.Clear();
            this.listView1.Items.Clear();
            this.listView1.LargeImageList = imglistView;
            this.listView1.SmallImageList = imglistView;
            this.listView1.View           = View.Details;
            this.listView1.GridLines      = true;
            this.listView1.FullRowSelect  = true;

            listView1.Columns.Add("序号", 60, HorizontalAlignment.Left);
            listView1.Columns.Add("列名", 110, HorizontalAlignment.Left);
            listView1.Columns.Add("数据类型", 80, HorizontalAlignment.Left);
            listView1.Columns.Add("长度", 40, HorizontalAlignment.Left);
            listView1.Columns.Add("小数", 40, HorizontalAlignment.Left);
            listView1.Columns.Add("标识", 40, HorizontalAlignment.Center);
            listView1.Columns.Add("主键", 40, HorizontalAlignment.Center);
            listView1.Columns.Add("允许空", 60, HorizontalAlignment.Center);
            listView1.Columns.Add("默认值", 100, HorizontalAlignment.Left);
            //listView1.Columns.Add("字段说明", 100, HorizontalAlignment.Left);

            var collist = dbObject.GetColumnInfoList(Dbname, TableName);

            if ((collist != null) && (collist.Count > 0))
            {
                foreach (var col in collist)
                {
                    var order      = col.ColOrder;
                    var columnName = col.ColumnName;
                    var columnType = col.TypeName;
                    var Length     = col.Length;
                    switch (columnType)
                    {
                    case "varchar":
                    case "nvarchar":
                    case "char":
                    case "nchar":
                    case "varbinary":
                    {
                        Length = CodeCommon.GetDataTypeLenVal(columnType, Length);
                    }
                    break;

                    default:
                        break;
                    }

                    var Preci       = col.Preci;
                    var Scale       = col.Scale;
                    var defaultVal  = col.DefaultVal;
                    var description = col.ColDescription;
                    var IsIdentity  = (col.IsIdentity) ? "√" : "";
                    var ispk        = (col.IsPK) ? "√" : "";
                    var isnull      = (col.IsNull) ? "√" : "";

                    var item1 = new ListViewItem(order, 0);
                    item1.ImageIndex = 4;
                    item1.SubItems.Add(columnName);
                    item1.SubItems.Add(columnType);
                    item1.SubItems.Add(Length);
                    item1.SubItems.Add(Scale);
                    item1.SubItems.Add(IsIdentity);
                    if ((ispk == "√") && (isnull.Trim() == ""))
                    {
                    }
                    else
                    {
                        ispk = "";
                    }
                    item1.SubItems.Add(ispk);
                    item1.SubItems.Add(isnull);
                    item1.SubItems.Add(defaultVal);

                    listView1.Items.AddRange(new ListViewItem[] { item1 });
                }
            }
        }
Exemple #6
0
        public DataSourse GetData(string constr)
        {
            DataSourse dataSourse = new DataSourse();
            string     dbName     = constr.Substring(0, constr.IndexOf(";")).Substring(constr.IndexOf("=") + 1);
            IDbObject  dbObject   = (IDbObject) new DataAccess();

            dbObject.DbConnectStr = constr;
            List <string>    tables = dbObject.GetTables(dbName);
            List <TableData> list1  = new List <TableData>();
            List <Reference> list2  = new List <Reference>();

            if (tables != null && tables.Count > 0)
            {
                foreach (string tableName in tables)
                {
                    TableData tableData = new TableData();
                    tableData.Code = tableName;
                    tableData.Name = tableName;
                    tableData.Id   = tableName;
                    List <string> list3          = new List <string>();
                    DataTable     columnInfoList = dbObject.GetColumnInfoList(dbName, tableName);
                    List <Column> list4          = new List <Column>();
                    foreach (DataRow row in (InternalDataCollectionBase)columnInfoList.Rows)
                    {
                        Column column1 = new Column();
                        column1.Code      = DataRowExtensions.Field <string>(row, 1).Trim();
                        column1.Comment   = DataRowExtensions.Field <string>(row, 15).Trim();
                        column1.DataType  = DataRowExtensions.Field <string>(row, 2).Trim();
                        column1.Displayed = "true";
                        Column column2 = column1;
                        string str1    = tableName;
                        int    num     = DataRowExtensions.Field <int>(row, 0);
                        string str2    = num.ToString();
                        string str3    = str1 + str2;
                        column2.Id = str3;
                        Column column3 = column1;
                        num = DataRowExtensions.Field <int>(row, 3);
                        string str4 = num.ToString();
                        column3.Length    = str4;
                        column1.Mandatory = DataRowExtensions.Field <string>(row, 13).Trim() == "√" ? "" : "1";
                        column1.Name      = DataRowExtensions.Field <string>(row, 1).Trim();
                        column1.TableCode = tableName;
                        column1.TableId   = tableData.Id;
                        if (DataRowExtensions.Field <string>(row, 7).Trim() != "d")
                        {
                            list3.Add(column1.Id);
                        }
                        list4.Add(column1);
                    }
                    tableData.Columns = list4;
                    if (list3.Count > 0)
                    {
                        tableData.PrimaryKey = new Key()
                        {
                            KeyId     = Guid.NewGuid().ToString(),
                            ColumnRef = list3.ToArray()
                        }
                    }
                    ;
                    list1.Add(tableData);
                }
            }
            if (list1 != null && list1.Count > 0)
            {
                foreach (TableData tableData in list1)
                {
                    TableData tab = tableData;
                    foreach (DataRow dataRow in (InternalDataCollectionBase)dbObject.GetTableRefrence(dbName, tab.Code).Rows)
                    {
                        DataRow   item = dataRow;
                        Reference r    = new Reference();
                        r.ParentTable          = Enumerable.SingleOrDefault <string>(Enumerable.Select <TableData, string>(Enumerable.Where <TableData>((IEnumerable <TableData>)list1, (Func <TableData, bool>)(t => t.Code == DataRowExtensions.Field <string>(item, 1).Trim())), (Func <TableData, string>)(t => t.Id)));
                        r.ParentTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) =>
                        {
                            var fAnonymousType2 = new
                            {
                                t = t,
                                f = f
                            };
                            return(fAnonymousType2);
                        }), param0 => param0.t.Id == r.ParentTable), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 2).Trim()), param0 => param0.f.Id));
                        r.Id                  = Guid.NewGuid().ToString();
                        r.ChildTable          = tab.Id;
                        r.ChildTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) =>
                        {
                            var fAnonymousType2 = new
                            {
                                t = t,
                                f = f
                            };
                            return(fAnonymousType2);
                        }), param0 => param0.t.Id == tab.Id), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 0).Trim()), param0 => param0.f.Id));
                        list2.Add(r);
                    }
                }
            }
            dataSourse.ListTable     = list1;
            dataSourse.ListReference = list2;
            DataTable       vieWs = dbObject.GetVIEWs(dbName);
            List <ViewData> list5 = new List <ViewData>();

            if (vieWs != null && vieWs.Rows != null && vieWs.Rows.Count > 0)
            {
                foreach (DataRow row in (InternalDataCollectionBase)vieWs.Rows)
                {
                    string str = DataRowExtensions.Field <string>(row, 0);
                    if (!string.IsNullOrWhiteSpace(str))
                    {
                        string    objectViewInfo = dbObject.GetObjectViewInfo(dbName, str);
                        DataTable dataTable      = dbObject.QueryViewInfo(dbName, str);
                        ViewData  viewData       = new ViewData();
                        viewData.Code     = str;
                        viewData.Name     = str;
                        viewData.Id       = str;
                        viewData.SQLQuery = objectViewInfo;
                        List <Column> list3 = new List <Column>();
                        foreach (DataColumn dataColumn in (InternalDataCollectionBase)dataTable.Columns)
                        {
                            list3.Add(new Column()
                            {
                                Name = dataColumn.ColumnName,
                                Code = dataColumn.ColumnName,
                                Id   = Guid.NewGuid().ToString()
                            });
                        }
                        viewData.Columns = list3;
                        list5.Add(viewData);
                    }
                }
            }
            dataSourse.ListView = list5;
            return(dataSourse);
        }
    }
Exemple #7
0
        private void GenerateHTML()
        {
            try
            {
                var htmlBody = new StringBuilder();

                #region 产生文档,写入标题
                htmlBody.Append("<div class=\"styledb\">数据库名:" + dbSet.DbName + "</div>");
                var tabletitle = "表名:" + this.TableName;
                #endregion

                #region 循环每一个列,产生一行数据
                var colList = idbObj.GetColumnInfoList(dbSet.DbName, this.TableName);
                var rc      = colList.Count;
                if ((colList.Count > 0))
                {
                    htmlBody.Append("<div class=\"styletab\">" + tabletitle + "</div>");
                    htmlBody.Append("<div><table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"90%\">");
                    //网页风格
                    htmlBody.Append("<tr><td bgcolor=\"#FBFBFB\">");
                    htmlBody.Append("<table cellspacing=\"0\" cellpadding=\"5\" border=\"1\" width=\"100%\" bordercolorlight=\"#D7D7E5\" bordercolordark=\"#D3D8E0\">");
                    htmlBody.Append("<tr bgcolor=\"#F0F0F0\">");

                    htmlBody.Append("<td>序号</td>");
                    htmlBody.Append("<td>列名</td>");
                    htmlBody.Append("<td>数据类型</td>");
                    htmlBody.Append("<td>长度</td>");
                    htmlBody.Append("<td>小数位</td>");
                    htmlBody.Append("<td>标识</td>");
                    htmlBody.Append("<td>主键</td>");
                    htmlBody.Append("<td>允许空</td>");
                    htmlBody.Append("<td>默认值</td>");
                    htmlBody.Append("<td>描述</td>");
                    htmlBody.Append("</tr>");

                    int rowIndex;
                    //string strText;
                    for (rowIndex = 0; rowIndex < rc; rowIndex++)
                    {
                        var col         = (ColumnInfo)colList[rowIndex];
                        var order       = col.ColOrder;
                        var colum       = col.ColumnName;
                        var typename    = col.TypeName;
                        var length      = col.Length == "" ? "&nbsp;" : col.Length;
                        var scale       = col.Scale == "" ? "&nbsp;" : col.Scale;
                        var IsIdentity  = col.IsIdentity.ToString().ToLower() == "true" ? "是" : "&nbsp;";
                        var PK          = col.IsPK.ToString().ToLower() == "true" ? "是" : "&nbsp;";
                        var isnull      = col.IsNull.ToString().ToLower() == "true" ? "是" : "否";
                        var defaultstr  = col.DefaultVal.ToString().Trim() == "" ? "&nbsp;" : col.DefaultVal.ToString();
                        var description = col.ColDescription.ToString().Trim() == "" ? "&nbsp;" : col.ColDescription.ToString();
                        if (length.Trim() == "-1")
                        {
                            length = "MAX";
                        }

                        htmlBody.Append("<tr>");
                        htmlBody.Append("<td>" + order + "</td>");
                        htmlBody.Append("<td>" + colum + "</td>");
                        htmlBody.Append("<td>" + typename + "</td>");
                        htmlBody.Append("<td>" + length + "</td>");
                        htmlBody.Append("<td>" + scale + "</td>");
                        htmlBody.Append("<td>" + IsIdentity + "</td>");
                        htmlBody.Append("<td>" + PK + "</td>");
                        htmlBody.Append("<td>" + isnull + "</td>");
                        htmlBody.Append("<td>" + defaultstr + "</td>");
                        htmlBody.Append("<td>" + description + "</td>");
                        htmlBody.Append("</tr>");
                    }
                }

                htmlBody.Append("</table>");
                htmlBody.Append("</td>");
                htmlBody.Append("</tr>");
                htmlBody.Append("</table>");
                htmlBody.Append("</div>");
                #endregion

                wbDoc.DocumentText = htmlBody.ToString();
            }
            catch (Exception ex)
            {
                var htmlBody = new StringBuilder();
                htmlBody.Append(@"<h3><strong><span style=\""color:#006600;font-size:18px;background-color:#FFE500;\"">生成文档出错了...</span></strong></h3>");
                htmlBody.Append(@"<p><span><span style=\""line-height:27px;color:#E53333;\""><b>出错信息为:</b></span></span></p>");
                htmlBody.Append("   " + ex.ToString());
                wbDoc.DocumentText = htmlBody.ToString();
            }
        }
Exemple #8
0
        public void GenerateDataGridView()
        {
            if (this.CurrentDbViewForm == null)
            {
                MessageBox.Show("无可用对象!");
            }

            dgvDefine.AutoGenerateColumns = false;

            #region 手动生成列(已注释)

            /*
             * DataGridViewTextBoxColumn colAttribute = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "ColumnName";
             * colAttribute.HeaderText = "属性名称";
             * colAttribute.Name = "colAttribute";
             *
             * DataGridViewComboBoxColumn colType = new System.Windows.Forms.DataGridViewComboBoxColumn();
             * colAttribute.DataPropertyName = "TypeName";
             * colAttribute.HeaderText = "类型";
             * colAttribute.Name = "colType";
             *
             * DataGridViewTextBoxColumn colTitle = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "ColDescription";
             * colAttribute.HeaderText = "标题";
             * colAttribute.Name = "colTitle";
             *
             * DataGridViewTextBoxColumn colDTColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "ColumnName";
             * colAttribute.HeaderText = "列名";
             * colAttribute.Name = "colDTColumnName";
             *
             * DataGridViewComboBoxColumn colDTDataType = new System.Windows.Forms.DataGridViewComboBoxColumn();
             * colAttribute.DataPropertyName = "";
             * colAttribute.HeaderText = "数据类型";
             * colAttribute.Name = "colDTDataType";
             *
             * DataGridViewTextBoxColumn colDTDataLength = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "Length";
             * colAttribute.HeaderText = "长度";
             * colAttribute.Name = "colDTDataLength";
             *
             * DataGridViewTextBoxColumn colDTDataPreci = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "Preci";
             * colAttribute.HeaderText = "小数";
             * colAttribute.Name = "colDTDataPreci";
             *
             * DataGridViewCheckBoxColumn colDTDataNull = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             * colAttribute.DataPropertyName = "IsNull";
             * colAttribute.HeaderText = "非空";
             * colDTDataNull.Width = 45;
             * colAttribute.Name = "colDTDataNull";
             *
             * DataGridViewCheckBoxColumn colDTDataPrimaryKey = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             * colAttribute.DataPropertyName = "IsPK";
             * colAttribute.HeaderText = "主键";
             * colDTDataNull.Width = 45;
             * colAttribute.Name = "colDTDataPrimaryKey";
             *
             * DataGridViewCheckBoxColumn colDTDataIdentity = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             * colAttribute.DataPropertyName = "IsIdentity";
             * colAttribute.HeaderText = "自增";
             * colDTDataNull.Width = 45;
             * colAttribute.Name = "colDTDataIdentity";
             *
             * DataGridViewTextBoxColumn colDTDataDefaultValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "DefaultVal";
             * colAttribute.HeaderText = "默认值";
             * colAttribute.Name = "colDTDataDefaultValue";
             *
             * this.dgvDefine.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[]
             * {
             *  colAttribute, colType, colTitle, colDTColumnName, colDTDataType, colDTDataLength,
             *  colDTDataPreci, colDTDataNull, colDTDataPrimaryKey, colDTDataIdentity, colDTDataDefaultValue
             * });
             */
            #endregion

            var selectedNode = this.CurrentDbViewForm.treeView1.SelectedNode;
            if (selectedNode == null)
            {
                return;
            }
            this.ServerName = selectedNode.Parent.Parent.Parent.Text;
            this.DBName     = selectedNode.Parent.Parent.Text;
            this.TableName  = selectedNode.Text;

            txtName.Text      = this.TableName;
            txtTableName.Text = this.TableName;
            dbSet             = DbConfig.GetSetting(this.ServerName);

            var listDataTypeRefer = GetDataTypeRefer();
            colType.ValueMember      = "To";
            colType.DisplayMember    = "To";
            colType.DataPropertyName = "To";
            colType.DataSource       = listDataTypeRefer;

            colDTDataType.ValueMember      = "From";
            colDTDataType.DisplayMember    = "From";
            colDTDataType.DataPropertyName = "From";
            colDTDataType.DataSource       = listDataTypeRefer;
            //todo:这儿要尽量做到通用。
            idbObj = DBOMaker.CreateDbObj(dbSet.DbType);
            idbObj.DbConnectStr = dbSet.ConnectStr;
            var colList = idbObj.GetColumnInfoList(this.DBName, this.TableName);
            dgvDefine.DataSource = colList;
        }