Example #1
0
        /// <summary>
        /// 实体生成
        /// </summary>
        private void GenerateModel()
        {
            _isOk = false;

            if (string.IsNullOrEmpty(txtnamespace.Text))
            {
                MessageBox.Show("命名空间不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(txtClassName.Text))
            {
                MessageBox.Show("类名不能为空!");
                return;
            }

            UtilsHelper.WriteNamespace(txtnamespace.Text);

            List <ColumnInfo> columns = UtilsHelper.GetColumnInfos(columnsdt);

            foreach (ColumnInfo col in columns)
            {
                col.IsPrimaryKey = false;

                foreach (object o in cbPrimarykey.Items)
                {
                    if (col.Name.Equals(o.ToString()))
                    {
                        col.IsPrimaryKey = true;
                        break;
                    }
                }
            }

            EntityCodeBuilder builder = new EntityCodeBuilder(TableName, txtnamespace.Text, txtClassName.Text, columns, IsView, cbToupperFrstword.Checked, ConnectionModel.DbType);

            var cs = builder.Builder();

            if (string.IsNullOrEmpty(cs))
            {
                txtContent.Text = "当前表无任何主键,请在详情界面上选择某行添加为主键后再执行此操作";
            }
            else
            {
                txtContent.Text = cs;
            }

            _isOk = true;
        }
Example #2
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);
            }
        }