private void 实体批量生成ToolStripMenuItem_Click(object sender, EventArgs e) { BasicParameter basicParameter = ParameterManager.GetBasicParameter(string.Empty); FrmModelCreater frmModelCreater = new FrmModelCreater(basicParameter, m_dbSchema); frmModelCreater.ShowDialog(); }
public FrmModelCreater(BasicParameter basicParameter, DbSchema dbSchema) { InitializeComponent(); #region 设置高亮显示属性 txtCode.ShowEOLMarkers = false; txtCode.ShowHRuler = false; txtCode.ShowInvalidLines = false; txtCode.ShowMatchingBracket = true; txtCode.ShowSpaces = false; txtCode.ShowTabs = false; txtCode.ShowVRuler = false; txtCode.AllowCaretBeyondEOL = false; txtCode.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("C#"); txtCode.Encoding = Encoding.GetEncoding("GB2312"); #endregion 设置高亮显示属性 this.m_basicParameter = basicParameter; this.m_dbSchema = dbSchema; foreach (var item in m_dbSchema.DatabaseSchema.Tables) { m_lstLeft.Add(item.Name); lsbleft.Items.Add(item.Name); } }
public string[] Construct(CodeMakeBulider bulider, BasicParameter basicParameter, BaseParameter baseParameter) { string[] strArray = new string[2]; strArray[0] = bulider.GenWinFormCS(basicParameter, baseParameter); strArray[1] = bulider.GenWinFormDesign(basicParameter, baseParameter); return(strArray); }
/// <summary>生成实体对象 /// /// </summary> /// <param name="sender">sender</param> /// <param name="e">e</param> private void cmdCreateModel_Click(object sender, EventArgs e) { IModelMaker modelMaker = ModelMakerManager.GetModelMaker(m_dbSchema.SqlType); BasicParameter basicParameter = ParameterManager.GetBasicParameter(GlobalHelp.TreeView.SelectedNode.Text); string strContent = modelMaker.GenModelCode(basicParameter.NameSpace, basicParameter.TableName, basicParameter.ClassName, m_dbSchema.DatabaseSchema.ConnectionString, basicParameter.Author); string strFolder = basicParameter.OutFolderPath + "\\Model\\"; FileHelper.GenFile(strFolder, basicParameter.ClassName + ".cs", strContent); }
/// <summary>生成DAL /// /// </summary> /// <param name="sender">sender</param> /// <param name="e">e</param> private void cmdGenDAL_Click(object sender, EventArgs e) { switch (m_codeGenType) { case CodeGenType.WinFromSimpleQuery: IDalMaker dalMaker = DalMakerManager.GetDalMaker(m_dbSchema.SqlType); BasicParameter basicParameter = ParameterManager.GetBasicParameter(cboTable.Text.Trim()); string strContent = dalMaker.GenDalCode(basicParameter.NameSpace, basicParameter.TableName, basicParameter.ClassName, m_dbSchema.DatabaseSchema.ConnectionString); string strFolder = basicParameter.OutFolderPath + "\\DAL\\"; FileHelper.GenFile(strFolder, basicParameter.ClassName + "DAL.cs", strContent); break; } }
/// <summary>生成CS /// /// </summary> /// <param name="sender">sender</param> /// <param name="e">e</param> private void cmdGenCode_Click(object sender, EventArgs e) { CodeMakeDirector director = new CodeMakeDirector(); BasicParameter basicParameter = ParameterManager.GetBasicParameter(cboTable.Text.Trim()); basicParameter.Conn = m_dbSchema.DatabaseSchema.ConnectionString; m_baseParameter = GetBaseParameter(); switch (m_codeGenType) { #region WinFromSimpleQuery/WinFromEditWithDialog case CodeGenType.WinFromSimpleQuery: case CodeGenType.WinFromEditWithDialog: if (m_codeGenType == CodeGenType.WinFromEditWithDialog) { CodeMakeBulider bulider = new TemplateWinFromEditWithDialog(); string[] strArray = director.Construct(bulider, basicParameter, m_baseParameter); string strFrmDialogClassName = "Frm" + basicParameter.ClassName + "SimpleDialog.cs"; string strFrmDialogClassNameDesigner = "Frm" + basicParameter.ClassName + "SimpleDialog.Designer.cs"; FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmDialogClassName, strArray[0], false); FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmDialogClassNameDesigner, strArray[1], false); } CodeMakeBulider buliderSimple = new TemplateWinFormSimpleQuery(); string[] strArraySimple = director.Construct(buliderSimple, basicParameter, m_baseParameter); string strFrmClassName = "Frm" + basicParameter.ClassName + "SimpleQuery.cs"; string strFrmClassNameDesigner = "Frm" + basicParameter.ClassName + "SimpleQuery.Designer.cs"; FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmClassName, strArraySimple[0], false); FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmClassNameDesigner, strArraySimple[1]); break; #endregion #region WinFromTreeEditWithDialog case CodeGenType.WinFromTreeEditWithDialog: CodeMakeBulider buliderTree = new TemplateWinFromEditWithDialog(); string[] strArrayTree = director.Construct(buliderTree, basicParameter, m_baseParameter); string strFrmTreeDialogClassName = "Frm" + basicParameter.ClassName + "TreeDialog.cs"; string strFrmTreeDialogClassNameDesigner = "Frm" + basicParameter.ClassName + "TreeDialog.cs"; FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmTreeDialogClassName, strArrayTree[0], false); FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmTreeDialogClassNameDesigner, strArrayTree[1], false); CodeMakeBulider buliderTreeQuery = new TemplateWinFormTreeQuery(); string[] strArrayTreeQuery = director.Construct(buliderTreeQuery, basicParameter, m_baseParameter); string strFrmTreeClassName = "Frm" + basicParameter.ClassName + "TreeQuery.cs"; string strFrmTreeClassNameDesigner = "Frm" + basicParameter.ClassName + "TreeQuery.Designer.cs"; FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmTreeClassName, strArrayTreeQuery[0], false); FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmTreeClassNameDesigner, strArrayTreeQuery[1]); break; #endregion } }
/// <summary>生成DAL /// /// </summary> /// <param name="sender">sender</param> /// <param name="e">e</param> private void cmdGenDAL_Click(object sender, EventArgs e) { IDalMaker dalMaker = DalMakerManager.GetDalMaker(m_dbSchema.SqlType); if (m_codeGenType == CodeGenType.WinFromParentChildEditWithDialog) { BasicParameter basicParameterDetail = ParameterManager.GetBasicParameter(cboTableDetail.Text.Trim()); string strContentDetail = dalMaker.GenDalCode(basicParameterDetail.NameSpace, basicParameterDetail.TableName, basicParameterDetail.ClassName, m_dbSchema.DatabaseSchema.ConnectionString); string strFolderDetail = basicParameterDetail.OutFolderPath + "\\DAL\\"; FileHelper.GenFile(strFolderDetail, basicParameterDetail.ClassName + "DAL.cs", strContentDetail, false); } BasicParameter basicParameter = ParameterManager.GetBasicParameter(cboTable.Text.Trim()); string strContent = dalMaker.GenDalCode(basicParameter.NameSpace, basicParameter.TableName, basicParameter.ClassName, m_dbSchema.DatabaseSchema.ConnectionString); string strFolder = basicParameter.OutFolderPath + "\\DAL\\"; FileHelper.GenFile(strFolder, basicParameter.ClassName + "DAL.cs", strContent); }
private void btnOK_Click(object sender, EventArgs e) { string strReturnMsg = CheckInput(m_codeGenType); if (strReturnMsg != string.Empty) { MessageBox.Show(strReturnMsg); return; } BasicParameter basicParameter = ParameterManager.GetBasicParameter(string.Empty); StringBuilder sbSql = new StringBuilder(); sbSql.Append("\""); sbSql.Append(txtSql.Text.Replace("\r\n", " ")); sbSql.Append(" WHERE \" + strWhere + \" "); sbSql.Append(txtSql1.Text.Replace("\r\n", " ")); sbSql.Append(" "); sbSql.Append(txtSql2.Text.Replace("\r\n", " ")); sbSql.Append("\""); NestQueryParameter nestQueryParameter = new NestQueryParameter { CodeGenType = CodeGenType.WinFromNestQuery, Key1 = txtKey.Text.Trim(), Key2 = txtKey1.Text.Trim(), Key3 = txtKey2.Text.Trim(), Sql = sbSql.ToString(), DataTableQuery = m_dtQuery, FormClassName = txtClassName.Text.Trim() }; CodeMakeDirector director = new CodeMakeDirector(); CodeMakeBulider bulider = new TemplateWinFormNestQuery(); string[] strArray = director.Construct(bulider, basicParameter, nestQueryParameter); string strFrmDialogClassName = txtClassName.Text.Trim() + ".cs"; string strContentCS = strArray[0]; FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmDialogClassName, strContentCS, false); string strFrmDialogClassNameDesigner = txtClassName.Text.Trim() + ".Designer.cs"; string strContentDesigner = strArray[1]; FileHelper.GenFile(basicParameter.OutFolderPath + "\\Code\\", strFrmDialogClassNameDesigner, strContentDesigner); }
public static BasicParameter GetBasicParameter(string strTableName) { BasicParameter basicPara = new BasicParameter(); SetDal setDal = new SetDal(); //12,代码生成路径 ,13,默认数据库连接字符串 List <Set> lstSet = setDal.GetListArray(" SetKey in ('12','13','14','15','16')"); //输出路径 if (lstSet.FirstOrDefault(t => t.SetKey == "12") != null) { var firstOrDefault = lstSet.FirstOrDefault(t => t.SetKey == "12"); if (firstOrDefault != null) { basicPara.OutFolderPath = firstOrDefault.SetValue; } } //默认数据库连接字符串 if (lstSet.FirstOrDefault(t => t.SetKey == "13") != null) { var orDefault = lstSet.FirstOrDefault(t => t.SetKey == "13"); if (orDefault != null) { basicPara.Conn = orDefault.SetValue; } } //默认作者 if (lstSet.FirstOrDefault(t => t.SetKey == "14") != null) { var @default = lstSet.FirstOrDefault(t => t.SetKey == "14"); if (@default != null) { basicPara.Author = @default.SetValue; } } //主命名空间 if (lstSet.FirstOrDefault(t => t.SetKey == "15") != null) { var firstOrDefault1 = lstSet.FirstOrDefault(t => t.SetKey == "15"); if (firstOrDefault1 != null) { basicPara.NameSpace = firstOrDefault1.SetValue; } } //去除表前缀 if (lstSet.FirstOrDefault(t => t.SetKey == "16") != null) { var firstOrDefault2 = lstSet.FirstOrDefault(t => t.SetKey == "16"); if (firstOrDefault2 != null) { basicPara.TablePrefix = firstOrDefault2.SetValue; } } if (strTableName != string.Empty) { //表名 basicPara.TableName = strTableName; //类名 string strClassName = strTableName; if (basicPara.TablePrefix != string.Empty) { strClassName = strTableName.Replace(basicPara.TablePrefix, ""); } basicPara.ClassName = strClassName.Substring(0, 1).ToUpper() + strClassName.Substring(1); } return(basicPara); }
public abstract string GenWinFormCS(BasicParameter basicParameter, BaseParameter baseParameter);