private void doRun() { if (listBox.Items.Count <= 0) return; string tabName = listBox.Items[listBox.SelectedIndex].ToString(); if (string.IsNullOrEmpty(tabName)) return; bool isView = false; if (tabName.IndexOf("* ") == 0) { tabName = tabName.Substring(2); isView = true; } string dalCode = string.Empty; string idalCode = string.Empty; string bllCode = string.Empty; string sqlCode = string.Empty; string baseCode = string.Empty; if (!string.IsNullOrEmpty(config.ModelPath) && config.OPList[listBox.SelectedIndex].Entity && config.DesignPattern == "Model-DAL-BLL") { tabPage1.Text = textBox1.Text + ".Model." + tabName; textBox.Text = TableStructureFactory.GetTableStructCode(config, tabName, textBox1.Text, out idalCode, out dalCode, out bllCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.ModelPath + "\\Model\\"); Pub.Class.FileDirectory.FileDelete(config.ModelPath + "\\Model\\" + tabName + ".cs"); FileDirectory.FileWrite(config.ModelPath + "\\Model\\" + tabName + ".cs", textBox.Text); } if (!string.IsNullOrEmpty(config.EntityPath) && config.OPList[listBox.SelectedIndex].Entity && config.DesignPattern != "Model-DAL-BLL") { tabPage1.Text = textBox1.Text + ".Entity." + tabName; textBox.Text = TableStructureFactory.GetTableStructCode(config, tabName, textBox1.Text, out baseCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.EntityPath + "\\Entity\\"); Pub.Class.FileDirectory.FileDelete(config.EntityPath + "\\Entity\\" + tabName + ".cs"); FileDirectory.FileWrite(config.EntityPath + "\\Entity\\" + tabName + ".cs", textBox.Text); } if (config.DesignPattern == "Model-DAL-BLL" && !string.IsNullOrEmpty(config.DALPath) && config.OPList[listBox.SelectedIndex].Entity) { tabPage2.Text = textBox1.Text + "." + config.TemplateName.Split('-')[3] + "DAL." + tabName + "DAL"; textBox2.Text = dalCode; Pub.Class.FileDirectory.DirectoryCreate(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\"); Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.DirectoryCreate(config.IDALPath + "\\IDAL\\"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); if (!string.IsNullOrEmpty(textBox2.Text.Trim())) { FileDirectory.FileWrite(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs", textBox2.Text); FileDirectory.FileWrite(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs", idalCode); } else { Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); } tabPage3.Text = textBox1.Text + ".BLL." + tabName + "BLL"; textBox3.Text = bllCode; Pub.Class.FileDirectory.DirectoryCreate(config.BLLPath + "\\BLL\\"); Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); if (!string.IsNullOrEmpty(textBox3.Text.Trim())) { FileDirectory.FileWrite(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs", textBox3.Text); sbSqlCode.AppendLine(sqlCode); textBox4.Text = sqlCode; } else { Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); } if (btnStart.Enabled) Clipboard.SetDataObject(textBox.Text); } if (config.DesignPattern != "Model-DAL-BLL" && !string.IsNullOrEmpty(config.FactoryPath) && config.OPList[listBox.SelectedIndex].Entity) { tabPage2.Text = textBox1.Text + "." + config.DesignPatternExtName + "." + tabName + "" + config.DesignPatternExtName + ""; textBox2.Text = baseCode; Pub.Class.FileDirectory.DirectoryCreate(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\"); Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); if (!string.IsNullOrEmpty(textBox2.Text.Trim())) { FileDirectory.FileWrite(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs", textBox2.Text); sbSqlCode.AppendLine(sqlCode); textBox3.Text = sqlCode; } else { Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); } if (btnStart.Enabled) Clipboard.SetDataObject(textBox.Text); } }
public static void Run(bool exit = false) { if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll) { Pub.Class.FileDirectory.DirectoryCreate(config.AdminPath + "\\xml\\"); Pub.Class.FileDirectory.FileDelete(config.AdminPath + "\\xml\\db.aspx"); FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "<div class='MenuTitlebar' style='top: 12px; left: 12px; width: 168px; height: 25px;' title='数据库管理'><table cellspacing='0' cellpadding='0'><tbody><tr style='width: 185px; height: 25px;'><td class='MenuTitlebarLeft_Head' style='width: 13px;'/><td class='MenuTitlebarMiddle_Head' style='width: 130px;'><div class='MenuTitle_Head' style='width: 130px; height: 25px; line-height: 25px;'>数据库管理</div></td><td class='MenuTitlebarRight_Open_Head' style='width: 25px;'/></tr></tbody></table></div>\n\r<div class='MenuBody_Head' style='border-width: 0px 1px 1px; padding: 9px 0px; overflow: hidden; top: 37px; left: 12px; width: 166px; opacity: 1;'>"); } StringBuilder sbSqlCode = new StringBuilder(); tables.Clear(); config.OPList = TableStructureFactory.LoadOPList(config, entity => { tables.Add((entity.isView ? "* " : "") + entity.Name); }); foreach (string key in tables) { string tabName = key; bool isView = false; if (tabName.IndexOf("* ") == 0) { tabName = tabName.Substring(2); isView = true; } TableOperator to = config.OPList.Where(p => p.Table == tabName).FirstOrDefault(); string dalCode = string.Empty; string idalCode = string.Empty; string bllCode = string.Empty; string sqlCode = string.Empty; string baseCode = string.Empty; if (!string.IsNullOrEmpty(config.ModelPath) && to.Entity && config.DesignPattern == "Model-DAL-BLL") { string code = TableStructureFactory.GetTableStructCode(config, tabName, config.Project, out idalCode, out dalCode, out bllCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.ModelPath + "\\Model\\"); Pub.Class.FileDirectory.FileDelete(config.ModelPath + "\\Model\\" + tabName + ".cs"); FileDirectory.FileWrite(config.ModelPath + "\\Model\\" + tabName + ".cs", code); } if (!string.IsNullOrEmpty(config.EntityPath) && to.Entity && config.DesignPattern != "Model-DAL-BLL") { string code = TableStructureFactory.GetTableStructCode(config, tabName, config.Project, out baseCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.EntityPath + "\\Entity\\"); Pub.Class.FileDirectory.FileDelete(config.EntityPath + "\\Entity\\" + tabName + ".cs"); FileDirectory.FileWrite(config.EntityPath + "\\Entity\\" + tabName + ".cs", code); } if (config.DesignPattern == "Model-DAL-BLL" && !string.IsNullOrEmpty(config.DALPath) && to.Entity) { Pub.Class.FileDirectory.DirectoryCreate(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\"); Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.DirectoryCreate(config.IDALPath + "\\IDAL\\"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); if (!string.IsNullOrEmpty(dalCode.Trim())) { FileDirectory.FileWrite(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs", dalCode); FileDirectory.FileWrite(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs", idalCode); } else { Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); } Pub.Class.FileDirectory.DirectoryCreate(config.BLLPath + "\\BLL\\"); Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); if (!string.IsNullOrEmpty(bllCode.Trim())) { FileDirectory.FileWrite(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs", bllCode); sbSqlCode.AppendLine(sqlCode); } else { Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); } } if (config.DesignPattern != "Model-DAL-BLL" && !string.IsNullOrEmpty(config.FactoryPath) && to.Entity) { Pub.Class.FileDirectory.DirectoryCreate(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\"); Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); if (!string.IsNullOrEmpty(baseCode.Trim())) { FileDirectory.FileWrite(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs", baseCode); sbSqlCode.AppendLine(sqlCode); } else { Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); } } WriteLog(tabName + " 生成成功!"); } if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll) { FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "</div>"); } if (!string.IsNullOrEmpty(config.DALPath)) { string extFile = Server2.GetMapPath("") + "\\ext\\Sql\\SqlCode.sql"; string extCode = FileDirectory.FileReadAll(extFile, Encoding.UTF8).ToString(); Pub.Class.FileDirectory.DirectoryCreate(Server2.GetMapPath("") + "\\SQLCode\\"); string code = sbSqlCode.ToString() + "\r\n" + extCode; if (code.Trim().Length > 10) { FileDirectory.FileWrite(Server2.GetMapPath("") + "\\SQLCode\\SQLCode" + Rand.RndDateStr() + ".sql", sbSqlCode.ToString() + "\r\n" + extCode); } } WriteLog("共 {0} 张表!", tables.Count); WriteLog("END"); Input(exit); }