示例#1
0
        private void btnAll_Click(object sender, EventArgs e)
        {
            if (TableTreeView.Nodes.Count == 0)
            {
                MessageBox.Show("请先连接数据库", "提示");
                return;
            }

            const string sPath        = ".\\Zephyr.Generator.Code";
            const string sPathModel   = sPath + "\\model\\";
            const string sPathMapping = sPath + "\\Mapping\\";
            const string sPathDAL     = sPath + "\\Repository\\";
            const string sPathBLL     = sPath + "\\I_Repository\\";

            deleteFilesAndCreateDir(sPathModel);
            deleteFilesAndCreateDir(sPathDAL);
            deleteFilesAndCreateDir(sPathBLL);

            foreach (TreeNode tn in TableTreeView.Nodes[0].Nodes)
            {
                var CurrentTable = tn.Tag as Table;
                var gen          = new Generator(CurrentTable);
                var sModel       = gen.GenModel();
                var sMapping     = gen.GenMapping();
                var sDAL         = gen.GenDAL();
                var sBLL         = gen.GenBLL();

                if (CurrentTable == null || tn.Tag.Equals(RootNodeTag))
                {
                    continue;
                }
                //输出到文件中 model
                using (TextWriter tw = new StreamWriter(new BufferedStream(new FileStream(sPathModel + CurrentTable.TableName + ".cs", FileMode.Create, FileAccess.Write)), System.Text.Encoding.GetEncoding("gbk")))
                {
                    tw.Write(sModel);
                }
                //输出到文件中 model 映射文件
                using (TextWriter tw = new StreamWriter(new BufferedStream(new FileStream(sPathMapping + CurrentTable.TableName + ".cs", FileMode.Create, FileAccess.Write)), System.Text.Encoding.GetEncoding("gbk")))
                {
                    tw.Write(sMapping);
                }
                //输出到文件中 dal
                using (TextWriter tw = new StreamWriter(new BufferedStream(new FileStream(sPathDAL + CurrentTable.TableName + "Repository.cs", FileMode.Create, FileAccess.Write)), System.Text.Encoding.GetEncoding("gbk")))
                {
                    tw.Write(sDAL);
                }

                //输出到文件中 bll
                using (TextWriter tw = new StreamWriter(new BufferedStream(new FileStream(sPathBLL + "I" + CurrentTable.TableName + "Repository.cs", FileMode.Create, FileAccess.Write)), System.Text.Encoding.GetEncoding("gbk")))
                {
                    tw.Write(sBLL);
                }
            }
            System.Diagnostics.Process.Start(sPath); //打开文件夹
        }
示例#2
0
        private void btnCode_Click(object sender, EventArgs e)
        {
            if (this.TableTreeView.SelectedNode == null || this.TableTreeView.SelectedNode.Tag == null || TableTreeView.SelectedNode.Tag.Equals(RootNodeTag))
            {
                MessageBox.Show("请选择当前需要生成的表", "提示");
                return;
            }

            var CurrentTable = TableTreeView.SelectedNode.Tag as Table;
            var gen          = new Generator(CurrentTable)
            {
                BillName = txtBillName.Text, FileName = txtFileName.Text, ModuleName = txtModule.Text
            };

            foreach (TreeNode node in TableTreeView.Nodes)
            {
                var T = node.Tag as Table;
                if (T != null && T.TableName == txtDetailTable.Text.Trim())
                {
                    gen.DetailTable = T;
                }
            }

            if (gen.DetailTable == null)
            {
                gen.DetailTable = CurrentTable;
            }

            this.ModelEdit.Text   = gen.GenModel();
            this.DalEdit.Text     = gen.GenDAL();
            this.BllEdit.Text     = gen.GenBLL();
            this.WebListEdit.Text = gen.GenMapping();

            //this.WebListEdit.Text = gen.GenListAspx();
            //this.WebListJsEdit.Text = gen.GenListJs();
            //this.txtEditAspx.Text = gen.GenEditAspx();
            //this.txtEditJs.Text = gen.GenEditJs();
        }