⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codemaker.cs

📁 通过数据库结构自动 生成三层结构代码,相当不错的一款软件
💻 CS
📖 第 1 页 / 共 5 页
字号:
namespace Codematic
{
    using Codematic.UserControls;
    using LTP.BuilderWeb;
    using LTP.CmConfig;
    using LTP.CodeBuild;
    using LTP.CodeHelper;
    using LTP.IDBO;
    using LTP.Utility;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Windows.Forms;

    public class CodeMaker : Form
    {
        private Button btn_Ok;
        private Button btn_SelAll;
        private Button btn_SelClear;
        private Button btn_SelI;
        private Button btn_SetKey;
        private CheckBox chk_CS_Add;
        private CheckBox chk_CS_Delete;
        private CheckBox chk_CS_Exists;
        private CheckBox chk_CS_GetList;
        private CheckBox chk_CS_GetMaxID;
        private CheckBox chk_CS_GetModel;
        private CheckBox chk_CS_GetModelByCache;
        private CheckBox chk_CS_Update;
        private CheckBox chk_DB_Add;
        private CheckBox chk_DB_Delete;
        private CheckBox chk_DB_Exists;
        private CheckBox chk_DB_GetList;
        private CheckBox chk_DB_GetMaxID;
        private CheckBox chk_DB_GetModel;
        private CheckBox chk_DB_Update;
        private CheckBox chk_Web_Add;
        private CheckBox chk_Web_HasKey;
        private CheckBox chk_Web_Show;
        private CheckBox chk_Web_Update;
        private DALTypeAddIn cm_blltype;
        private DALTypeAddIn cm_daltype;
        public UcCodeView codeview;
        private IContainer components;
        private string dbname;
        private IDbObject dbobj;
        private GroupBox groupBox_AppType;
        private GroupBox groupBox_DALType;
        private GroupBox groupBox_DB;
        private GroupBox groupBox_F3;
        private GroupBox groupBox_FrameSel;
        private GroupBox groupBox_Method;
        private GroupBox groupBox_Parameter;
        private GroupBox groupBox_Select;
        private GroupBox groupBox_Type;
        private GroupBox groupBox_Web;
        private ImageList imglistDB;
        private ImageList imgListTabpage;
        private ImageList imglistView;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label label6;
        private Label label7;
        private Label lblkeycount;
        private ListBox list_KeyField;
        private ListView listView1;
        private NameRule namerule = new NameRule();
        private Panel panel1;
        private Panel panel2;
        private RadioButton radbtn_AppType_Web;
        private RadioButton radbtn_AppType_Winform;
        private RadioButton radbtn_DB_DDL;
        private RadioButton radbtn_DB_Proc;
        private RadioButton radbtn_F3_BLL;
        private RadioButton radbtn_F3_DAL;
        private RadioButton radbtn_F3_DALFactory;
        private RadioButton radbtn_F3_IDAL;
        private RadioButton radbtn_F3_Model;
        private RadioButton radbtn_Frame_F3;
        private RadioButton radbtn_Frame_One;
        private RadioButton radbtn_Frame_S3;
        private RadioButton radbtn_Type_CS;
        private RadioButton radbtn_Type_DB;
        private RadioButton radbtn_Type_Web;
        private RadioButton radbtn_Web_Aspx;
        private RadioButton radbtn_Web_AspxCS;
        private string servername;
        private ModuleSettings setting;
        private Splitter splitter1;
        private TabControl tabControl1;
        private string tablename;
        private TabPage tabPage1;
        private TabPage tabPage2;
        private Thread thread;
        private ToolStripButton toolStripButton2;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripSplitButton toolStripSplitButton1;
        private TextBox txtClassName;
        private TextBox txtNameSpace;
        private TextBox txtNameSpace2;
        private TextBox txtProcPrefix;
        private TextBox txtProjectName;
        private TextBox txtTabname;
        private ToolStripMenuItem 列表ToolStripMenuItem;
        private ToolStripMenuItem 详细信息ToolStripMenuItem;

        public CodeMaker()
        {
            this.InitializeComponent();
            this.list_KeyField.Height = 0x16;
            this.codeview = new UcCodeView();
            this.tabPage2.Controls.Add(this.codeview);
            this.SetListViewMenu("colum");
            this.CreatView();
            this.SetFormConfig();
            if (((DbView) Application.OpenForms["DbView"]) != null)
            {
                try
                {
                    this.thread = new Thread(new ThreadStart(this.Showlistview));
                    this.thread.Start();
                }
                catch
                {
                }
            }
        }

        private void BindlistViewCol(string Dbname, string TableName)
        {
            this.chk_CS_GetMaxID.Checked = true;
            List<LTP.CodeHelper.ColumnInfo> columnInfoList = this.dbobj.GetColumnInfoList(Dbname, TableName);
            if ((columnInfoList != null) && (columnInfoList.Count > 0))
            {
                this.listView1.Items.Clear();
                this.list_KeyField.Items.Clear();
                this.chk_CS_GetMaxID.Enabled = true;
                foreach (LTP.CodeHelper.ColumnInfo info in columnInfoList)
                {
                    string colorder = info.Colorder;
                    string columnName = info.ColumnName;
                    string typeName = info.TypeName;
                    string length = info.Length;
                    if (typeName == "nvarchar")
                    {
                        length = (int.Parse(length) / 2).ToString();
                    }
                    string preci = info.Preci;
                    string scale = info.Scale;
                    string defaultVal = info.DefaultVal;
                    string deText = info.DeText;
                    string text = info.IsIdentity ? "√" : "";
                    string str8 = info.IsPK ? "√" : "";
                    string str9 = info.cisNull ? "√" : "";
                    ListViewItem item = new ListViewItem(colorder, 0);
                    item.ImageIndex = 4;
                    item.SubItems.Add(columnName);
                    item.SubItems.Add(typeName);
                    item.SubItems.Add(length);
                    item.SubItems.Add(scale);
                    item.SubItems.Add(text);
                    if ((str8 == "√") && (str9.Trim() == ""))
                    {
                        this.list_KeyField.Items.Add(columnName);
                        if (text == "√")
                        {
                            this.chk_CS_GetMaxID.Checked = false;
                            this.chk_CS_GetMaxID.Enabled = false;
                            this.chk_DB_GetMaxID.Checked = false;
                            this.chk_DB_GetMaxID.Enabled = false;
                        }
                    }
                    else
                    {
                        str8 = "";
                        if (text == "√")
                        {
                            this.list_KeyField.Items.Add(columnName);
                            this.chk_CS_GetMaxID.Checked = false;
                            this.chk_CS_GetMaxID.Enabled = false;
                            this.chk_DB_GetMaxID.Checked = false;
                            this.chk_DB_GetMaxID.Enabled = false;
                        }
                    }
                    item.SubItems.Add(str8);
                    item.SubItems.Add(str9);
                    item.SubItems.Add(defaultVal);
                    this.listView1.Items.AddRange(new ListViewItem[] { item });
                }
            }
            this.btn_SelAll_Click(null, null);
            this.txtTabname.Text = TableName;
            this.txtClassName.Text = TableName;
            this.lblkeycount.Text = this.list_KeyField.Items.Count.ToString() + "个主键";
        }

        private void btn_Ok_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count < 1)
            {
                MessageBox.Show("没有任何可以生成的项!", "请选择", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if ((this.list_KeyField.Items.Count != 0) || (MessageBox.Show("没有主键字段和条件字段,你确认要继续生成?", "主键提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No))
            {
                try
                {
                    if (this.radbtn_Type_DB.Checked)
                    {
                        this.CreatDB();
                    }
                    if (this.radbtn_Type_CS.Checked)
                    {
                        this.CreatCS();
                    }
                    if (this.radbtn_Type_Web.Checked)
                    {
                        this.CreatWeb();
                    }
                }
                catch (SystemException exception)
                {
                    MessageBox.Show("生成代码失败,请关闭后重新打开再试。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    LogInfo.WriteLog(exception.Message);
                }
                if (this.radbtn_Frame_One.Checked)
                {
                    this.setting.AppFrame = "One";
                }
                if (this.radbtn_Frame_S3.Checked)
                {
                    this.setting.AppFrame = "S3";
                }
                if (this.radbtn_Frame_F3.Checked)
                {
                    this.setting.AppFrame = "F3";
                }
                this.setting.DALType = this.GetDALType();
                this.setting.BLLType = this.GetBLLType();
                this.setting.ProjectName = this.txtProjectName.Text;
                this.setting.Namepace = this.txtNameSpace.Text;
                this.setting.Folder = this.txtNameSpace2.Text;
                this.setting.ProcPrefix = this.txtProcPrefix.Text;
                ModuleConfig.SaveSettings(this.setting);
            }
        }

        private void btn_SelAll_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.listView1.Items)
            {
                if (!item.Checked)
                {
                    item.Checked = true;
                }
            }
        }

        private void btn_SelClear_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in this.listView1.Items)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -