예제 #1
0
        /// <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);
        }
예제 #2
0
 /// <summary>生成Model
 ///
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">e</param>
 private void cmdGenModel_Click(object sender, EventArgs e)
 {
     switch (m_codeGenType)
     {
     case CodeGenType.WinFromSimpleQuery:
         IModelMaker    modelMaker     = ModelMakerManager.GetModelMaker(m_dbSchema.SqlType);
         BasicParameter basicParameter = ParameterManager.GetBasicParameter(cboTable.Text.Trim());
         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);
         break;
     }
 }
예제 #3
0
        // 实体预览
        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (lsbright.Items.Count == 0)
            {
                MessageBox.Show(@"请选择操作表.");
                return;
            }
            if (m_modelMaker == null)
            {
                m_modelMaker = ModelMakerManager.GetModelMaker(m_dbSchema.SqlType);
            }
            string strTableName = lsbright.Items[0].ToString();

            txtCode.Text = m_modelMaker.GenModelCode(m_basicParameter.NameSpace, strTableName, strTableName, m_dbSchema.DatabaseSchema.ConnectionString, m_basicParameter.Author);
        }
예제 #4
0
        /// <summary>生成Model
        ///
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void cmdGenModel_Click(object sender, EventArgs e)
        {
            IModelMaker modelMaker = ModelMakerManager.GetModelMaker(m_dbSchema.SqlType);

            if (m_codeGenType == CodeGenType.WinFromParentChildEditWithDialog)
            {
                BasicParameter basicParameterDetail = ParameterManager.GetBasicParameter(cboTableDetail.Text.Trim());
                string         strContentDetail     = modelMaker.GenModelCode(basicParameterDetail.NameSpace, cboTableDetail.Text,
                                                                              basicParameterDetail.ClassName, m_dbSchema.DatabaseSchema.ConnectionString, basicParameterDetail.Author);
                string strFolderDetail = basicParameterDetail.OutFolderPath + "\\Model\\";
                FileHelper.GenFile(strFolderDetail, basicParameterDetail.ClassName + ".cs", strContentDetail, false);
            }
            BasicParameter basicParameter = ParameterManager.GetBasicParameter(cboTable.Text.Trim());
            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);
        }
예제 #5
0
        //生成代码
        private void btnGen_Click(object sender, EventArgs e)
        {
            if (lsbright.Items.Count == 0)
            {
                MessageBox.Show(@"请选择操作表.");
                return;
            }
            if (m_basicParameter.OutFolderPath == string.Empty)
            {
                MessageBox.Show(@"请在基础设置里面设置代码生成路径");
                return;
            }
            if (string.IsNullOrEmpty(m_basicParameter.NameSpace))
            {
                MessageBox.Show(@"请在基础设置里面设置命名空间.");
                return;
            }
            if (!Directory.Exists(m_basicParameter.OutFolderPath))
            {
                Directory.CreateDirectory(m_basicParameter.OutFolderPath);
            }

            #region 生成实体

            string strOutPutModel;
            if (m_basicParameter.OutFolderPath.Substring(m_basicParameter.OutFolderPath.Length - 2, 2) == "\\")
            {
                strOutPutModel = m_basicParameter.OutFolderPath + "Model\\";
            }
            else
            {
                strOutPutModel = m_basicParameter.OutFolderPath + "\\Model\\";
            }
            if (!Directory.Exists(strOutPutModel))
            {
                Directory.CreateDirectory(strOutPutModel);
            }

            string strPrefix = txtPrefix.Text.Trim();
            foreach (string strTableName in lsbright.Items)
            {
                var strClassName = strTableName;
                if (strPrefix.Length > 0)
                {
                    strClassName = strTableName.Replace(strPrefix, "");
                }
                strClassName = strClassName.Substring(0, 1).ToUpper() + strClassName.Substring(1);
                string       strFilePath = strOutPutModel + strClassName + ".cs";
                StreamWriter sw          = new StreamWriter(strFilePath, false);
                if (m_modelMaker == null)
                {
                    m_modelMaker = ModelMakerManager.GetModelMaker(m_dbSchema.SqlType);
                }
                sw.Write(m_modelMaker.GenModelCode(m_basicParameter.NameSpace, strTableName, strClassName, m_dbSchema.DatabaseSchema.ConnectionString, m_basicParameter.Author));
                sw.Flush();
                sw.Close();
                sw.Dispose();
            }

            #endregion 生成实体

            MessageBox.Show(@"代码生成功.");
            txtCode.Text = @"代码已生成到:" + m_basicParameter.OutFolderPath;
            System.Diagnostics.Process.Start(m_basicParameter.OutFolderPath);
        }