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

📄 codetemp.cs

📁 通过数据库结构自动 生成三层结构代码,相当不错的一款软件
💻 CS
📖 第 1 页 / 共 2 页
字号:
            }
            List<LTP.CodeHelper.ColumnInfo> list2 = new List<LTP.CodeHelper.ColumnInfo>();
            foreach (DataRow row in rowArray)
            {
                string str = row["Colorder"].ToString();
                string str2 = row["ColumnName"].ToString();
                string str3 = row["TypeName"].ToString();
                string str4 = row["IsIdentity"].ToString();
                string str5 = row["IsPK"].ToString();
                string str6 = row["Length"].ToString();
                string str7 = row["Preci"].ToString();
                string str8 = row["Scale"].ToString();
                string str9 = row["cisNull"].ToString();
                string str10 = row["DefaultVal"].ToString();
                string str11 = row["DeText"].ToString();
                LTP.CodeHelper.ColumnInfo item = new LTP.CodeHelper.ColumnInfo();
                item.Colorder = str;
                item.ColumnName = str2;
                item.TypeName = str3;
                item.IsIdentity = str4 == "√";
                item.IsPK = str5 == "√";
                item.Length = str6;
                item.Preci = str7;
                item.Scale = str8;
                item.cisNull = str9 == "√";
                item.DefaultVal = str10;
                item.DeText = str11;
                list2.Add(item);
            }
            return list2;
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(CodeTemp));
            this.listView1 = new ListView();
            this.splitter1 = new Splitter();
            this.imglistView = new ImageList(this.components);
            this.panel1 = new Panel();
            this.btn_Run = new Button();
            this.groupBox2 = new GroupBox();
            this.list_KeyField = new ListBox();
            this.btn_SetKey = new Button();
            this.btn_SelClear = new Button();
            this.btn_SelI = new Button();
            this.btn_SelAll = new Button();
            this.groupBox1 = new GroupBox();
            this.txtTemplate = new RichTextBox();
            this.statusStrip1 = new StatusStrip();
            this.StatusLabel1 = new ToolStripStatusLabel();
            this.panel1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.statusStrip1.SuspendLayout();
            base.SuspendLayout();
            this.listView1.Dock = DockStyle.Top;
            this.listView1.Location = new Point(0, 0);
            this.listView1.Name = "listView1";
            this.listView1.Size = new Size(0x251, 0xa8);
            this.listView1.TabIndex = 0;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.splitter1.Dock = DockStyle.Top;
            this.splitter1.Location = new Point(0, 0xa8);
            this.splitter1.Name = "splitter1";
            this.splitter1.Size = new Size(0x251, 3);
            this.splitter1.TabIndex = 1;
            this.splitter1.TabStop = false;
            this.imglistView.ImageStream = (ImageListStreamer) manager.GetObject("imglistView.ImageStream");
            this.imglistView.TransparentColor = Color.Transparent;
            this.imglistView.Images.SetKeyName(0, "fild2.gif");
            this.panel1.Controls.Add(this.groupBox1);
            this.panel1.Controls.Add(this.groupBox2);
            this.panel1.Dock = DockStyle.Fill;
            this.panel1.Location = new Point(0, 0xab);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x251, 0x121);
            this.panel1.TabIndex = 2;
            this.btn_Run.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btn_Run.Location = new Point(0x1ec, 0x1cb);
            this.btn_Run.Name = "btn_Run";
            this.btn_Run.Size = new Size(0x4b, 0x17);
            this.btn_Run.TabIndex = 8;
            this.btn_Run.Text = "生成";
            this.btn_Run.UseVisualStyleBackColor = true;
            this.btn_Run.Click += new EventHandler(this.btn_Run_Click);
            this.groupBox2.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.groupBox2.Controls.Add(this.list_KeyField);
            this.groupBox2.Controls.Add(this.btn_SetKey);
            this.groupBox2.Controls.Add(this.btn_SelClear);
            this.groupBox2.Controls.Add(this.btn_SelI);
            this.groupBox2.Controls.Add(this.btn_SelAll);
            this.groupBox2.Location = new Point(3, 1);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x247, 0x34);
            this.groupBox2.TabIndex = 6;
            this.groupBox2.TabStop = false;
            this.list_KeyField.FormattingEnabled = true;
            this.list_KeyField.ItemHeight = 12;
            this.list_KeyField.Location = new Point(0x1b3, 14);
            this.list_KeyField.Name = "list_KeyField";
            this.list_KeyField.Size = new Size(0x81, 0x1c);
            this.list_KeyField.TabIndex = 1;
            this.btn_SetKey.Location = new Point(0x141, 0x11);
            this.btn_SetKey.Name = "btn_SetKey";
            this.btn_SetKey.Size = new Size(0x6c, 0x17);
            this.btn_SetKey.TabIndex = 0;
            this.btn_SetKey.Text = "主键(条件)字段";
            this.btn_SetKey.UseVisualStyleBackColor = true;
            this.btn_SetKey.Click += new EventHandler(this.btn_SetKey_Click);
            this.btn_SelClear.Location = new Point(0xb2, 0x11);
            this.btn_SelClear.Name = "btn_SelClear";
            this.btn_SelClear.Size = new Size(0x4b, 0x17);
            this.btn_SelClear.TabIndex = 0;
            this.btn_SelClear.Text = "清空";
            this.btn_SelClear.UseVisualStyleBackColor = true;
            this.btn_SelClear.Click += new EventHandler(this.btn_SelClear_Click);
            this.btn_SelI.Location = new Point(0x61, 0x11);
            this.btn_SelI.Name = "btn_SelI";
            this.btn_SelI.Size = new Size(0x4b, 0x17);
            this.btn_SelI.TabIndex = 0;
            this.btn_SelI.Text = "反选";
            this.btn_SelI.UseVisualStyleBackColor = true;
            this.btn_SelI.Click += new EventHandler(this.btn_SelI_Click);
            this.btn_SelAll.Location = new Point(0x10, 0x11);
            this.btn_SelAll.Name = "btn_SelAll";
            this.btn_SelAll.Size = new Size(0x4b, 0x17);
            this.btn_SelAll.TabIndex = 0;
            this.btn_SelAll.Text = "全选";
            this.btn_SelAll.UseVisualStyleBackColor = true;
            this.btn_SelAll.Click += new EventHandler(this.btn_SelAll_Click);
            this.groupBox1.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.groupBox1.Controls.Add(this.txtTemplate);
            this.groupBox1.Location = new Point(3, 0x38);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x247, 0xe9);
            this.groupBox1.TabIndex = 9;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "模版";
            this.txtTemplate.Dock = DockStyle.Fill;
            this.txtTemplate.Location = new Point(3, 0x11);
            this.txtTemplate.Name = "txtTemplate";
            this.txtTemplate.Size = new Size(0x241, 0xd5);
            this.txtTemplate.TabIndex = 8;
            this.txtTemplate.Text = "";
            this.statusStrip1.Items.AddRange(new ToolStripItem[] { this.StatusLabel1 });
            this.statusStrip1.Location = new Point(0, 460);
            this.statusStrip1.Name = "statusStrip1";
            this.statusStrip1.Size = new Size(0x251, 0x16);
            this.statusStrip1.TabIndex = 3;
            this.statusStrip1.Text = "statusStrip1";
            this.StatusLabel1.Name = "StatusLabel1";
            this.StatusLabel1.Size = new Size(0, 0x11);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x251, 0x1e2);
            base.Controls.Add(this.panel1);
            base.Controls.Add(this.btn_Run);
            base.Controls.Add(this.statusStrip1);
            base.Controls.Add(this.splitter1);
            base.Controls.Add(this.listView1);
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "CodeTemp";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "代码生成";
            this.panel1.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            this.statusStrip1.ResumeLayout(false);
            this.statusStrip1.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void Run()
        {
            this.StatusLabel1.Text = "正在生成...";
            string strxslt = @"Template\temp.xslt";
            try
            {
                string text = this.txtTemplate.Text;
                XmlDocument document = new XmlDocument();
                document.LoadXml(text);
                document.Save(@"Template\temp.xslt");
            }
            catch (Exception exception)
            {
                this.StatusLabel1.Text = "模版格式有误:" + exception.Message;
                return;
            }
            string code = "";
            try
            {
                code = new BuilderTemp(this.dbobj, this.dbname, this.tablename, this.GetFieldlist(), this.GetKeyFields(), strxslt).GetCode();
            }
            catch (Exception exception2)
            {
                this.StatusLabel1.Text = "代码转换失败!" + exception2.Message;
                return;
            }
            string path = @"Template\tempcode.cs";
            StreamWriter writer = new StreamWriter(path, false, Encoding.Default);
            writer.Write(code);
            writer.Flush();
            writer.Close();
            this.StatusLabel1.Text = "生成成功。";
            this.mainfrm.AddSinglePage(new CodeEditor(path, "cs"), "Class1.cs");
        }

        public void SetListView(DbView dbviewfrm)
        {
            TreeNode selectedNode = dbviewfrm.treeView1.SelectedNode;
            if (selectedNode != null)
            {
                string str = selectedNode.Tag.ToString();
                if (str == null)
                {
                    goto Label_011F;
                }
                if (!(str == "table") && !(str == "view"))
                {
                    if (str == "column")
                    {
                        this.servername = selectedNode.Parent.Parent.Parent.Parent.Text;
                        this.dbname = selectedNode.Parent.Parent.Parent.Text;
                        this.tablename = selectedNode.Parent.Text;
                        this.dbobj = ObjHelper.CreatDbObj(this.servername);
                        this.BindlistViewCol(this.dbname, this.tablename);
                        return;
                    }
                    goto Label_011F;
                }
                this.servername = selectedNode.Parent.Parent.Parent.Text;
                this.dbname = selectedNode.Parent.Parent.Text;
                this.tablename = selectedNode.Text;
                this.dbobj = ObjHelper.CreatDbObj(this.servername);
                this.BindlistViewCol(this.dbname, this.tablename);
            }
            return;
        Label_011F:
            this.listView1.Items.Clear();
        }

        private void Showlistview()
        {
            DbView dbviewfrm = (DbView) Application.OpenForms["DbView"];
            if (dbviewfrm.treeView1.InvokeRequired)
            {
                SetListCallback method = new SetListCallback(this.Showlistview);
                dbviewfrm.Invoke(method, null);
            }
            else
            {
                this.SetListView(dbviewfrm);
            }
        }

        private delegate void SetListCallback();
    }
}

⌨️ 快捷键说明

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