private void CreateCode() { TreeNode dbNode = node.Parent.Parent; TreeNode serverNode = Form1.form_Database.GetRoot(node); if (dbNode == null || serverNode == null) { return; } List<Model.BuilderMethods> methods = new List<Model.BuilderMethods>(); if (checkBox_add.Checked) methods.Add(Model.BuilderMethods.Add); if (checkBox_count.Checked) methods.Add(Model.BuilderMethods.Count); if (checkBox_delete.Checked) methods.Add(Model.BuilderMethods.Delete); if (checkBox_exists.Checked) methods.Add(Model.BuilderMethods.Exists); if (checkBox_getall.Checked) methods.Add(Model.BuilderMethods.SelectAll); if (checkBox_getbykey.Checked) methods.Add(Model.BuilderMethods.SelectByKey); if (checkBox_update.Checked) methods.Add(Model.BuilderMethods.Update); Model.Servers server = (Model.Servers)((Model.TreeNodeTag)serverNode.Tag).Tag; Business.CreateCode CreateCode = new Business.CreateCode(server.Type); Model.CodeCreate param = new Model.CodeCreate(); param.ClassName = this.textBox2.Text.IsNullOrEmpty() ? ((Model.TreeNodeTag)node.Tag).Tag.ToString() : this.textBox2.Text.Trim(); param.DbName = ((Model.TreeNodeTag)dbNode.Tag).Tag.ToString(); param.NameSpace = ""; param.NameSpace1 = ""; param.ServerID = server.ID; param.TableName = ((Model.TreeNodeTag)node.Tag).Tag.ToString(); param.BuilderType = this.radioButton1.Checked ? Model.BuilderType.Default : Model.BuilderType.Factory; param.MethodList = methods; param.CNSC = new Common.Config_NameSpaceClass().GetDefault(); Form_Code_Area fca_model = new Form_Code_Area(CreateCode.GetModelClass(param), string.Format("实体类({0})", param.TableName)); fca_model.Show(Form1.Instance.dockPanel1); Form_Code_Area fca_data = new Form_Code_Area(CreateCode.GetDataClass(param), string.Format("数据类({0})", param.TableName)); fca_data.Show(Form1.Instance.dockPanel1); Form_Code_Area fca_business = new Form_Code_Area(CreateCode.GetBusinessClass(param), string.Format("业务类({0})", param.TableName)); fca_business.Show(Form1.Instance.dockPanel1); if (param.BuilderType == Model.BuilderType.Factory) { Form_Code_Area fca_interface = new Form_Code_Area(CreateCode.GetInterfaceClass(param), string.Format("接口类({0})", param.TableName)); fca_interface.Show(Form1.Instance.dockPanel1); Form_Code_Area fca_factory = new Form_Code_Area(CreateCode.GetFactoryClass(param), string.Format("工厂类({0})", param.TableName)); fca_factory.Show(Form1.Instance.dockPanel1); } this.Close(); }
private void CreateToDir() { List <TreeNode> NodeList = Form1.form_Database.GetTreeView1Selected(); if (NodeList.Count == 0) { return; } TreeNode serverNode = Form1.form_Database.GetRoot(NodeList.First()); TreeNode dbNode = NodeList.First().Parent.Parent; List <Model.BuilderMethods> methods = new List <Model.BuilderMethods>(); if (checkBox_add.Checked) { methods.Add(Model.BuilderMethods.Add); } if (checkBox_count.Checked) { methods.Add(Model.BuilderMethods.Count); } if (checkBox_delete.Checked) { methods.Add(Model.BuilderMethods.Delete); } if (checkBox_exists.Checked) { methods.Add(Model.BuilderMethods.Exists); } if (checkBox_getall.Checked) { methods.Add(Model.BuilderMethods.SelectAll); } if (checkBox_getbykey.Checked) { methods.Add(Model.BuilderMethods.SelectByKey); } if (checkBox_update.Checked) { methods.Add(Model.BuilderMethods.Update); } Model.Servers server = (Model.Servers)((Model.TreeNodeTag)serverNode.Tag).Tag; Business.CreateCode CreateCode = new Business.CreateCode(server.Type); Model.CodeCreate param = new Model.CodeCreate(); param.DbName = ((Model.TreeNodeTag)dbNode.Tag).Tag.ToString(); param.NameSpace = ""; param.NameSpace1 = ""; param.ServerID = server.ID; param.BuilderType = this.radioButton1.Checked ? Model.BuilderType.Default : Model.BuilderType.Factory; param.MethodList = methods; param.CNSC = new Common.Config_NameSpaceClass().GetDefault(); Business.CreateCode CreateCodeInstince = new Business.CreateCode(server.Type); StreamWriter sw; string FileName = string.Empty; foreach (TreeNode node in NodeList) { param.TableName = ((Model.TreeNodeTag)node.Tag).Tag.ToString(); param.ClassName = param.TableName; //生成实体类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Model, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetModelClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); //生成数据类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Data, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetDataClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); //生成业务类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Business, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetBusinessClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); if (param.BuilderType == Model.BuilderType.Factory) { //生成接口类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Interface, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetInterfaceClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); //生成工厂类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Factory, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetFactoryClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); } } MessageBox.Show("生成完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.label8.Text = "生成已完成"; this.button6.Enabled = true; }
private void CreateToDir() { List<TreeNode> NodeList = Form1.form_Database.GetTreeView1Selected(); if (NodeList.Count == 0) { return; } TreeNode serverNode = Form1.form_Database.GetRoot(NodeList.First()); TreeNode dbNode = NodeList.First().Parent.Parent; List<Model.BuilderMethods> methods = new List<Model.BuilderMethods>(); if (checkBox_add.Checked) methods.Add(Model.BuilderMethods.Add); if (checkBox_count.Checked) methods.Add(Model.BuilderMethods.Count); if (checkBox_delete.Checked) methods.Add(Model.BuilderMethods.Delete); if (checkBox_exists.Checked) methods.Add(Model.BuilderMethods.Exists); if (checkBox_getall.Checked) methods.Add(Model.BuilderMethods.SelectAll); if (checkBox_getbykey.Checked) methods.Add(Model.BuilderMethods.SelectByKey); if (checkBox_update.Checked) methods.Add(Model.BuilderMethods.Update); Model.Servers server = (Model.Servers)((Model.TreeNodeTag)serverNode.Tag).Tag; Business.CreateCode CreateCode = new Business.CreateCode(server.Type); Model.CodeCreate param = new Model.CodeCreate(); param.DbName = ((Model.TreeNodeTag)dbNode.Tag).Tag.ToString(); param.NameSpace = ""; param.NameSpace1 = ""; param.ServerID = server.ID; param.BuilderType = this.radioButton1.Checked ? Model.BuilderType.Default : Model.BuilderType.Factory; param.MethodList = methods; param.CNSC = new Common.Config_NameSpaceClass().GetDefault(); Business.CreateCode CreateCodeInstince = new Business.CreateCode(server.Type); StreamWriter sw; string FileName = string.Empty; foreach (TreeNode node in NodeList) { param.TableName = ((Model.TreeNodeTag)node.Tag).Tag.ToString(); param.ClassName = param.TableName; //生成实体类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Model, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetModelClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); //生成数据类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Data, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetDataClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); //生成业务类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Business, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetBusinessClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); if (param.BuilderType == Model.BuilderType.Factory) { //生成接口类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Interface, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetInterfaceClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); //生成工厂类 FileName = Common.Func.ExistsDirectory(string.Format("{0}\\{1}.{2}\\{3}{4}.cs", this.textBox_dir.Text, param.NameSpace, param.CNSC.Factory, param.NameSpace1.IsNullOrEmpty() ? "" : param.NameSpace1 + "\\", param.ClassName)); sw = File.CreateText(FileName); sw.Write(CreateCodeInstince.GetFactoryClass(param)); sw.Close(); sw.Dispose(); label8.Text = string.Format("生成文件:{0}", FileName); } } MessageBox.Show("生成完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.label8.Text = "生成已完成"; this.button6.Enabled = true; }
private void CreateCode() { TreeNode dbNode = node.Parent.Parent; TreeNode serverNode = Form1.form_Database.GetRoot(node); if (dbNode == null || serverNode == null) { return; } List <Model.BuilderMethods> methods = new List <Model.BuilderMethods>(); if (checkBox_add.Checked) { methods.Add(Model.BuilderMethods.Add); } if (checkBox_count.Checked) { methods.Add(Model.BuilderMethods.Count); } if (checkBox_delete.Checked) { methods.Add(Model.BuilderMethods.Delete); } if (checkBox_exists.Checked) { methods.Add(Model.BuilderMethods.Exists); } if (checkBox_getall.Checked) { methods.Add(Model.BuilderMethods.SelectAll); } if (checkBox_getbykey.Checked) { methods.Add(Model.BuilderMethods.SelectByKey); } if (checkBox_update.Checked) { methods.Add(Model.BuilderMethods.Update); } Model.Servers server = (Model.Servers)((Model.TreeNodeTag)serverNode.Tag).Tag; Business.CreateCode CreateCode = new Business.CreateCode(server.Type); Model.CodeCreate param = new Model.CodeCreate(); param.ClassName = this.textBox2.Text.IsNullOrEmpty() ? ((Model.TreeNodeTag)node.Tag).Tag.ToString() : this.textBox2.Text.Trim(); param.DbName = ((Model.TreeNodeTag)dbNode.Tag).Tag.ToString(); param.NameSpace = ""; param.NameSpace1 = ""; param.ServerID = server.ID; param.TableName = ((Model.TreeNodeTag)node.Tag).Tag.ToString(); param.BuilderType = this.radioButton1.Checked ? Model.BuilderType.Default : Model.BuilderType.Factory; param.MethodList = methods; param.CNSC = new Common.Config_NameSpaceClass().GetDefault(); Form_Code_Area fca_model = new Form_Code_Area(CreateCode.GetModelClass(param), string.Format("实体类({0})", param.TableName)); fca_model.Show(Form1.Instance.dockPanel1); Form_Code_Area fca_data = new Form_Code_Area(CreateCode.GetDataClass(param), string.Format("数据类({0})", param.TableName)); fca_data.Show(Form1.Instance.dockPanel1); Form_Code_Area fca_business = new Form_Code_Area(CreateCode.GetBusinessClass(param), string.Format("业务类({0})", param.TableName)); fca_business.Show(Form1.Instance.dockPanel1); if (param.BuilderType == Model.BuilderType.Factory) { Form_Code_Area fca_interface = new Form_Code_Area(CreateCode.GetInterfaceClass(param), string.Format("接口类({0})", param.TableName)); fca_interface.Show(Form1.Instance.dockPanel1); Form_Code_Area fca_factory = new Form_Code_Area(CreateCode.GetFactoryClass(param), string.Format("工厂类({0})", param.TableName)); fca_factory.Show(Form1.Instance.dockPanel1); } this.Close(); }