Exemplo n.º 1
0
        private void OutputSp(List <Model.Table> tables, Model.CreateStyle createStyle)
        {
            string path = createStyle.CreatePath;

            Directory.CreateDirectory(path);
            CodeFactory.CodeAccess.CreateSpFile(tables, path);
        }
Exemplo n.º 2
0
        private void OutputStoreProcedure(List <Model.Table> tables, Model.CreateStyle createStyle)
        {
            string path = createStyle.CreateFilePath;

            Directory.CreateDirectory(path);
            CodeFactory.StoreProcedureAccess.CreateStoreProcedureFile(db, tables, path);
        }
Exemplo n.º 3
0
 private Model.CreateStyle GetOutputCreateStyle()
 {
     Model.CreateStyle createStyle = new Model.CreateStyle();
     createStyle.CreatePath                      = txtPath.Text;
     createStyle.HasCreateBLL                    = chkModel.Checked;
     createStyle.HasCreateDAL                    = chkDAL.Checked;
     createStyle.HasCreateDALFactory             = chkDALFactory.Checked;
     createStyle.HasCreateDBUtility              = chkDBUtility.Checked;
     createStyle.HasCreateIDAL                   = chkIDAL.Checked;
     createStyle.HasCreateModel                  = chkModel.Checked;
     createStyle.HasCreateUserControl            = chkUserControl.Checked;
     createStyle.HasCreateICacheDependency       = chkICacheDependency.Checked;
     createStyle.HasCreateTableCacheDependency   = chkTableCacheDependency.Checked;
     createStyle.HasCreateCacheDependencyFactory = chkCacheDependencyFactory.Checked;
     return(createStyle);
 }
Exemplo n.º 4
0
        //关于注册
        //private void CheckRegister()
        //{
        //    if (File.Exists(Reg.filePath))
        //    {
        //        StreamReader sr = new StreamReader(Reg.filePath);
        //        string tmp = sr.ReadToEnd();
        //        sr.Close();
        //        if (tmp == Registers.Registers.GetValue())
        //        {
        //            chkUserControl.Enabled = chkUserControl.Checked = true;
        //        }
        //    }
        //}

        private void btnOutputCode_Click(object sender, EventArgs e)
        {
            #region 判断生成的条件
            if (lstSelectedTables.Items.Count <= 0)
            {
                FormMain.ShowMessage("未选择任何表!");
                return;
            }
            if (MessageBox.Show("确定要输出代码吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            #endregion

            List <Model.Table> tables      = GetOutputTables();
            Model.CodeStyle    codeStyle   = GetOutputCodeStyle();
            Model.CreateStyle  createStyle = GetOutputCreateStyle();

            if (Directory.Exists(createStyle.CreatePath))
            {
                if (MessageBox.Show("该目录已存在,是否删除?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        Directory.Delete(createStyle.CreatePath, true);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }

            OutputCode(tables, codeStyle, createStyle);

            CreateSln(createStyle);

            progressBar1.Value = 0;

            if (MessageBox.Show("成功生成,是否打开目录?", "恭喜", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Process.Start(createStyle.CreatePath);
            }
        }
Exemplo n.º 5
0
        private void btnOutputSp_Click(object sender, EventArgs e)
        {
            #region 判断生成的条件
            if (lstSelectedTables.Items.Count <= 0)
            {
                FormMain.ShowMessage("未选择任何表!");
                return;
            }
            if (MessageBox.Show("确定要输出存储过程吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            #endregion

            List <Model.Table> tables      = GetOutputTables();
            Model.CreateStyle  createStyle = GetOutputCreateStyle();

            OutputSp(tables, createStyle);

            if (MessageBox.Show("成功生成,是否打开目录?", "恭喜", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Process.Start(createStyle.CreatePath);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 输出代码
        /// </summary>
        private void OutputCode(List <Model.Table> tables, Model.CodeStyle codeStyle, Model.CreateStyle createStyle)
        {
            string slnDictionary;

            switch (VSVersion)
            {
            case VSVersionFrames.VS2005:
                slnDictionary = "Template2005";
                break;

            case VSVersionFrames.VS2008:
                slnDictionary = "Template2008";
                break;

            case VSVersionFrames.VS2010:
            default:
                slnDictionary = "Template2010";
                break;
            }

            if (createStyle.HasCreateModel)
            {
                string pathModel = CreateFilePath + "\\Model";
                CopyFiles(string.Format("{0}\\{1}\\Model", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathModel);
                CodeFactory.CodeAccess.CreateModelFile(db, tables, codeStyle, pathModel);
            }
            progressBar1.Value = 10;

            if (createStyle.HasCreateIDAL)
            {
                string pathIDAL = CreateFilePath + "\\IDAL";
                CopyFiles(string.Format("{0}\\{1}\\IDAL", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathIDAL);
                CodeFactory.CodeAccess.CreateIDALFile(db, tables, codeStyle, pathIDAL);
            }
            progressBar1.Value = 20;

            if (createStyle.HasCreateDAL)
            {
                string pathDAL = CreateFilePath + "\\" + codeStyle.DALFrame.ToString();
                CopyFiles(string.Format("{0}\\{1}\\{2}", Model.CreateStyle.CURRENT_PATH, slnDictionary, codeStyle.DALFrame.ToString()), pathDAL);
                CodeFactory.CodeAccess.CreateDALFile(db, tables, codeStyle, pathDAL);
            }
            progressBar1.Value = 30;

            if (createStyle.HasCreateBL)
            {
                string pathBL;
                pathBL = CreateFilePath + "\\" + codeStyle.BlFrame.ToString();
                CopyFiles(string.Format("{0}\\{1}\\{2}", Model.CreateStyle.CURRENT_PATH, slnDictionary, codeStyle.BlFrame.ToString()), pathBL);
                CodeFactory.CodeAccess.CreateBLFile(db, tables, codeStyle, pathBL);
            }
            progressBar1.Value = 40;

            if (createStyle.HasCreateUserControl)
            {
                string pathUserControl = CreateFilePath + "\\Web\\Controls";
                CopyFiles(string.Format("{0}\\{1}\\Web", Model.CreateStyle.CURRENT_PATH, slnDictionary), CreateFilePath + "\\Web");
                CodeFactory.CodeAccess.CreateUserControl(db, tables, codeStyle, pathUserControl);
            }
            progressBar1.Value = 50;

            if (createStyle.HasCreateDALFactory)
            {
                string pathDALFactory = CreateFilePath + "\\DALFactory";
                CopyFiles(string.Format("{0}\\{1}\\DALFactory", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathDALFactory);
                CodeFactory.CodeAccess.CreateDALFactoryFile(tables, codeStyle, pathDALFactory);
            }
            progressBar1.Value = 50;

            if (createStyle.HasCreateDBULibrary)
            {
                string pathDBUtility = CreateFilePath + "\\DBUtility";
                CopyFiles(string.Format("{0}\\{1}\\DBUtility", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathDBUtility);
            }
            progressBar1.Value = 60;

            if (createStyle.HasCreateICacheDependency)
            {
                string pathICacheDependency = CreateFilePath + "\\ICacheDependency";
                CopyFiles(string.Format("{0}\\{1}\\ICacheDependency", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathICacheDependency);
                CodeFactory.CodeAccess.CreateICacheDependencyFile(codeStyle, pathICacheDependency);
            }
            progressBar1.Value = 70;

            if (createStyle.HasCreateTableCacheDependency)
            {
                string pathTableCacheDependency = CreateFilePath + "\\TableCacheDependency";
                CopyFiles(string.Format("{0}\\{1}\\TableCacheDependency", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathTableCacheDependency);
                CodeFactory.CodeAccess.CreateTableCacheDependencyFile(db, tables, codeStyle, pathTableCacheDependency);
            }
            progressBar1.Value = 80;

            if (createStyle.HasCreateCacheDependencyFactory)
            {
                string pathCacheDependencyFactory = CreateFilePath + "\\CacheDependencyFactory";
                CopyFiles(string.Format("{0}\\{1}\\CacheDependencyFactory", Model.CreateStyle.CURRENT_PATH, slnDictionary), pathCacheDependencyFactory);
                CodeFactory.CodeAccess.CreateCacheDependencyFactoryFile(tables, codeStyle, pathCacheDependencyFactory);
            }
            progressBar1.Value = 90;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 创建Sln文件
        /// </summary>
        private void CreateSln(Model.CreateStyle createStyle, Model.CodeStyle codeStyle)
        {
            StringBuilder sln = new StringBuilder();

            switch (VSVersion)
            {
            case VSVersionFrames.VS2005:
                sln.AppendLine("Microsoft Visual Studio Solution File, Format Version 9.00");
                sln.AppendLine("# Visual Studio 2005");
                break;

            case VSVersionFrames.VS2008:
                sln.AppendLine("Microsoft Visual Studio Solution File, Format Version 10.00");
                sln.AppendLine("# Visual Studio 2008");
                break;

            default:
                sln.AppendLine("Microsoft Visual Studio Solution File, Format Version 11.00");
                sln.AppendLine("# Visual Studio 2010");
                break;
            }

            if (createStyle.HasCreateBL)
            {
                switch (codeStyle.BlFrame)
                {
                case Model.CodeStyle.BLFrame.BLS:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\BLS.csproj"));
                    break;

                case Model.CodeStyle.BLFrame.BLL:
                default:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\BLL.csproj"));
                    break;
                }
            }

            if (createStyle.HasCreateDAL)
            {
                switch (codeStyle.DALFrame)
                {
                case Model.CodeStyle.DALFrames.AccessDAL:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\AccessDAL.csproj"));
                    break;

                case Model.CodeStyle.DALFrames.SqlServerDAL:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\SqlServerDAL.csproj"));
                    break;

                case Model.CodeStyle.DALFrames.MySqlDAL:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\MySqlDAL.csproj"));
                    break;

                case Model.CodeStyle.DALFrames.OracleDAL:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\OracleDAL.csproj"));
                    break;

                case Model.CodeStyle.DALFrames.SQLiteDAL:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\SQLiteDAL.csproj"));
                    break;

                default:
                    sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\DAL.csproj"));
                    break;
                }
            }

            if (createStyle.HasCreateDALFactory)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\DALFactory.csproj"));
            }

            if (createStyle.HasCreateDBULibrary)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\DBUtility.csproj"));
            }

            if (createStyle.HasCreateIDAL)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\IDAL.csproj"));
            }

            if (createStyle.HasCreateModel)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\Model.csproj"));
            }

            if (createStyle.HasCreateICacheDependency)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\ICacheDependency.csproj"));
            }

            if (createStyle.HasCreateTableCacheDependency)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\TableCacheDependency.csproj"));
            }

            if (createStyle.HasCreateCacheDependencyFactory)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\CacheDependencyFactory.csproj"));
            }

            if (createStyle.HasCreateUserControl)
            {
                sln.AppendLine(CodeUtility.FileStream.ReadFile(Model.CreateStyle.CURRENT_PATH + "\\Sln\\Web.csproj"));
            }

            Directory.CreateDirectory(CreateFilePath);
            StreamWriter sw = new StreamWriter(CreateFilePath + "\\Socansoft.sln");

            sw.Write(sln.ToString());
            sw.Close();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 输出代码
        /// </summary>
        /// <param name="lstTable"></param>
        /// <param name="codeStyle"></param>
        /// <param name="createStyle"></param>
        private void OutputCode(List <Model.Table> tables, Model.CodeStyle codeStyle, Model.CreateStyle createStyle)
        {
            if (createStyle.HasCreateModel)
            {
                string pathModel = createStyle.CreatePath + "\\Model";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\Model", pathModel);
                CodeFactory.CodeAccess.CreateModelFile(tables, codeStyle, pathModel);
            }
            progressBar1.Value = 10;

            if (createStyle.HasCreateIDAL)
            {
                string pathIDAL = createStyle.CreatePath + "\\IDAL";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\IDAL", pathIDAL);
                CodeFactory.CodeAccess.CreateIDALFile(tables, codeStyle, pathIDAL);
            }
            progressBar1.Value = 20;

            if (createStyle.HasCreateDAL)
            {
                string pathDAL;
                if (_dbtype == Model.Database.DatabaseType.Access)
                {
                    pathDAL = createStyle.CreatePath + "\\AccessDAL";
                    CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\AccessDAL", pathDAL);
                }
                else
                {
                    pathDAL = createStyle.CreatePath + "\\SqlServerDAL";
                    CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\SqlServerDAL", pathDAL);
                }
                CodeFactory.CodeAccess.CreateDALFile(_dbtype, tables, codeStyle, pathDAL);
            }
            progressBar1.Value = 30;

            if (createStyle.HasCreateBLL)
            {
                string pathBLL = createStyle.CreatePath + "\\BLL";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\BLL", pathBLL);
                CodeFactory.CodeAccess.CreateBLLFile(_dbtype, tables, codeStyle, pathBLL);
            }
            progressBar1.Value = 40;

            if (createStyle.HasCreateUserControl)
            {
                string pathUserControl = createStyle.CreatePath + "\\" + txtWebPath.Text + "\\" + txtControlsPath.Text;
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\Web", createStyle.CreatePath + "\\" + txtWebPath.Text);
                CodeFactory.CodeAccess.CreateUserControl(tables, codeStyle, pathUserControl);
            }
            progressBar1.Value = 50;

            if (createStyle.HasCreateDALFactory)
            {
                string pathDALFactory = createStyle.CreatePath + "\\DALFactory";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\DALFactory", pathDALFactory);
                CodeFactory.CodeAccess.CreateDALFactoryFile(tables, codeStyle, pathDALFactory);
            }
            progressBar1.Value = 50;

            if (createStyle.HasCreateDBUtility)
            {
                string pathDBUtility = createStyle.CreatePath + "\\DBUtility";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\DBUtility", pathDBUtility);
            }
            progressBar1.Value = 60;

            if (createStyle.HasCreateICacheDependency)
            {
                string pathICacheDependency = createStyle.CreatePath + "\\ICacheDependency";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\ICacheDependency", pathICacheDependency);
                CodeFactory.CodeAccess.CreateICacheDependencyFile(codeStyle, pathICacheDependency);
            }
            progressBar1.Value = 70;

            if (createStyle.HasCreateTableCacheDependency)
            {
                string pathTableCacheDependency = createStyle.CreatePath + "\\TableCacheDependency";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\TableCacheDependency", pathTableCacheDependency);
                CodeFactory.CodeAccess.CreateTableCacheDependencyFile(_dbName, tables, codeStyle, pathTableCacheDependency);
            }
            progressBar1.Value = 80;

            if (createStyle.HasCreateCacheDependencyFactory)
            {
                string pathCacheDependencyFactory = createStyle.CreatePath + "\\CacheDependencyFactory";
                CopyFiles(System.Windows.Forms.Application.StartupPath + "\\Template\\CacheDependencyFactory", pathCacheDependencyFactory);
                CodeFactory.CodeAccess.CreateCacheDependencyFactoryFile(tables, codeStyle, pathCacheDependencyFactory);
            }
            progressBar1.Value = 90;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 创建Sln文件
        /// </summary>
        private void CreateSln(Model.CreateStyle createStyle)
        {
            StringBuilder sln = new StringBuilder();

            sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\Head.csproj"));

            if (createStyle.HasCreateBLL)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\BLL.csproj"));
            }

            if (createStyle.HasCreateDAL)
            {
                if (_dbtype == Model.Database.DatabaseType.Access)
                {
                    sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\AccessDAL.csproj"));
                }
                else
                {
                    sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\SQLServerDAL.csproj"));
                }
            }

            if (createStyle.HasCreateDALFactory)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\DALFactory.csproj"));
            }

            if (createStyle.HasCreateDBUtility)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\DBUtility.csproj"));
            }

            if (createStyle.HasCreateIDAL)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\IDAL.csproj"));
            }

            if (createStyle.HasCreateModel)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\Model.csproj"));
            }

            if (createStyle.HasCreateICacheDependency)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\ICacheDependency.csproj"));
            }

            if (createStyle.HasCreateTableCacheDependency)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\TableCacheDependency.csproj"));
            }

            if (createStyle.HasCreateCacheDependencyFactory)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\CacheDependencyFactory.csproj"));
            }

            if (createStyle.HasCreateUserControl)
            {
                sln.AppendLine(ReadString(System.Windows.Forms.Application.StartupPath + "\\Sln\\Web.csproj"));
            }

            Directory.CreateDirectory(createStyle.CreatePath);
            StreamWriter sw = new StreamWriter(createStyle.CreatePath + "\\Web.sln");

            sw.Write(sln.ToString());
            sw.Close();
        }