示例#1
0
        public Dictionary <string, string> GenerateEntityCode(string szNamespace, DatabaseTableCollection dbTableCollection)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            foreach (DatabaseTable dbTable in dbTableCollection.DatabaseTables)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("/*************************************************");
                sb.AppendLine(string.Format("*{0} Entity", dbTable.CsEntityName));
                sb.AppendLine(string.Format("* Generation Date: {0}", DateTime.Now));
                sb.AppendLine("*************************************************/");
                sb.AppendLine();
                sb.AppendLine("using System;");
                sb.AppendLine("using System.Text;");
                sb.AppendLine();
                sb.AppendLine("namespace " + szNamespace + ".Lib.Domain");
                sb.AppendLine("{");
                sb.AppendLine(string.Format("    public class {0}: EntityBase, IAggregateRoot", dbTable.CsEntityName));
                sb.AppendLine("    {");
                GeneratePropertiesCodeRegion(dbTable, sb);
                sb.AppendLine();
                GenerateCtorsCodeRegion(dbTable, sb);
                GenerateNestedClassMetadataCodeRegion(dbTable, sb);
                sb.AppendLine("    }");
                sb.AppendLine("}");
                dictionary.Add(dbTable.CsEntityName, sb.ToString());
            }
            if (_gloOptions.TargetPlatform == Platform.netFramework11)
            {
                dictionary.Add("NullableWrappers", NullableWrapperTypeGenerator.GetAllNullableClasses(szNamespace));
            }
            return(dictionary);
        }
示例#2
0
        public Dictionary <string, string> GenerateDataLayerCode(string szNamespace, DatabaseTableCollection dbTableCollection)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            foreach (DatabaseTable dbTable in dbTableCollection.DatabaseTables)
            {
                SetCurrentDataLayerClassName(dbTable.CsEntityName);
                StringBuilder sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("/*");
                sb.AppendLine(string.Format("****** {0} Data", dbTable.CsEntityName));
                sb.AppendLine(string.Format("****** Generation Date: {0}", (object)DateTime.Now));
                sb.AppendLine("*/");
                sb.AppendLine();
                sb.AppendLine("using System;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine();
                sb.AppendLine("using " + szNamespace + ".Lib.Domain;");
                sb.AppendLine("using " + szNamespace + ".Lib.Repo.Interface;");
                sb.AppendLine("using " + szNamespace + ".Lib.Common.Constant;");
                sb.AppendLine();
                sb.AppendLine("namespace " + szNamespace + ".Repo.Impl");
                sb.AppendLine("{");
                sb.AppendLine(string.Format("    public class {0} : {1}<{2}>, {3}", _currentDataLayerClassName, _options.DataLayerClassSuffix, dbTable.CsEntityName, _currentDataLayerInterfaceName));
                sb.AppendLine("    {");
                if (this._options.TargetPlatform == Platform.netFramework11)
                {
                    sb.AppendLine("        #region Generated");
                }
                this.AppendCtorsDataLayerCode(dbTable, sb);
                //AppendEntityFillerDataLayerCode(dbTable, sb);
                // AppendFirstEntityFillerDataLayerCode(dbTable, sb);
                // AppendEntityListFillerDataLayerCode(dbTable, sb);
                // if (dbTable.HasDeletedDisabled)
                //    this.AppendMarkByIdDataLayerCode(dbTable, sb);
                //this.AppendInsertDataLayerCode(dbTable, sb);
                //this.AppendUpdateDataLayerCode(dbTable, sb);
                //this.AppendDeleteByIdDataLayerCode(dbTable, sb);
                //if (this._options.GenerateDeleteByForeignKey)
                //this.AppendDeleteByForeignKeyDataLayerCodes(dbTable, sb);
                //this.AppendSelectDataLayerCode(dbTable, sb);
                //this.AppendSelectByIdDataLayerCode(dbTable, sb);
                //this.AppendSelectByForeignKeyDataLayerCodes(dbTable, sb);
                if (this._options.TargetPlatform == Platform.netFramework11)
                {
                    sb.AppendLine("        #endregion");
                }
                sb.AppendLine("    }");
                sb.AppendLine("}");
                dictionary.Add(dbTable.CsEntityName, sb.ToString());
            }
            return(dictionary);
        }
示例#3
0
        public string GenerateSpScripts(DatabaseTableCollection dbTableCollection, DateTime datetimeTimestamp)
        {
            StringBuilder sb = new StringBuilder();

            foreach (DatabaseTable dbTable in dbTableCollection.DatabaseTables)
            {
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("--|");
                sb.AppendLine("--|");
                sb.AppendLine("--| " + dbTable.SqlTableName + "'s Stored Procedures");
                sb.AppendLine("--|");
                if (this.options.GenerateDropAllTableSPs)
                {
                    this.AppendDropAllTableSPs(dbTable, sb);
                }
                this.AppendDropMarkByIdSP(dbTable, sb);
                this.AppendDropMarkByForeignKeySPs(dbTable, sb);
                if (dbTable.HasDeletedDisabled)
                {
                    this.AppendMarkByIdSP(dbTable, sb, datetimeTimestamp);
                }
                this.AppendDropInsertSp(dbTable, sb);
                this.AppendInsertSP(dbTable, sb, datetimeTimestamp);
                this.AppendDropUpdateSp(dbTable, sb);
                this.AppendUpdateSP(dbTable, sb, datetimeTimestamp);
                this.AppendDropDeleteByIdSP(dbTable, sb);
                this.AppendDeleteByIdSP(dbTable, sb, datetimeTimestamp);
                if (this.options.GenerateDeleteByForeignKey)
                {
                    this.AppendDropDeleteByForeignKeySPs(dbTable, sb);
                    this.AppendDeleteByForeignKeySPs(dbTable, sb, datetimeTimestamp);
                }
                this.AppendDropSelectSP(dbTable, sb);
                this.AppendSelectSP(dbTable, sb, datetimeTimestamp);
                this.AppendDropSelectByIdSP(dbTable, sb);
                this.AppendSelectByIdSP(dbTable, sb, datetimeTimestamp);
                this.AppendDropSelectByForeignKeySPs(dbTable, sb);
                this.AppendSelectByForeignKeySPs(dbTable, sb, datetimeTimestamp);
            }
            return(sb.ToString());
        }
示例#4
0
        public Dictionary <string, string> GenerateDataLayerCode(string szNamespace, DatabaseTableCollection dbTableCollection)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            foreach (DatabaseTable dbTable in dbTableCollection.DatabaseTables)
            {
                SetCurrentDataLayerClassName(dbTable.CsEntityName);
                StringBuilder sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("/*");
                sb.AppendLine(string.Format("****** {0} Data", dbTable.CsEntityName));
                sb.AppendLine(string.Format("****** Generation Date: {0}", (object)DateTime.Now));
                sb.AppendLine("*/");
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("using " + szNamespace + ".Lib.Domain;");
                sb.AppendLine();
                sb.AppendLine("namespace " + szNamespace + ".Repo.Interface");
                sb.AppendLine("{");
                sb.AppendLine(string.Format("    public interface {0} : I{1}<{2}>", _currentDataLayerInterfaceName, _options.DataLayerClassSuffix, dbTable.CsEntityName));
                sb.AppendLine("    {");
                if (this._options.TargetPlatform == Platform.netFramework11)
                {
                    sb.AppendLine("        #region Generated");
                }
                if (this._options.TargetPlatform == Platform.netFramework11)
                {
                    sb.AppendLine("        #endregion");
                }
                sb.AppendLine("    }");
                sb.AppendLine("}");
                dictionary.Add(dbTable.CsEntityName, sb.ToString());
            }
            return(dictionary);
        }
示例#5
0
        public Dictionary <string, string> GenerateBusinessLayerCode(string szNamespace, DatabaseTableCollection dbTableCollection)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            foreach (DatabaseTable dbTable in dbTableCollection.DatabaseTables)
            {
                this.SetCurrentDataLayerClassName(dbTable.CsEntityName);
                this.SetCurrentBusinessLayerClassName(dbTable.CsEntityName);
                StringBuilder sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("/*");
                sb.AppendLine(string.Format("***** {0}", _currentBusinessLayerClassName));
                sb.AppendLine(string.Format("***** Generation Date: {0}", (object)DateTime.Now));
                sb.AppendLine("*/");
                sb.AppendLine();
                sb.AppendLine("#region references");
                sb.AppendLine("using " + szNamespace + ".Lib.Domain;");
                sb.AppendLine("using " + szNamespace + ".Lib.Model;");
                sb.AppendLine("using " + szNamespace + ".Repo.Interface;");
                sb.AppendLine("using " + szNamespace + ".Service.Interface;");
                sb.AppendLine("#endregion");
                sb.AppendLine();
                sb.AppendLine("namespace " + szNamespace + ".Lib.Service.Impl");
                sb.AppendLine("{");
                sb.AppendLine(string.Format("    public class {0} : {1}<{2}>, {3}",
                                            _currentBusinessLayerClassName, _options.DomainLogicLayerSuffix, dbTable.CsEntityName, _currentBusinessLayerInterfaceName));
                sb.AppendLine("    {");
                sb.AppendLine(string.Format("    private readonly {0} {1};", _currentDataLayerInterfaceInstanceName, _currentDataLayerInterfaceInstanceName));

                if (_options.TargetPlatform == Platform.netFramework11)
                {
                    sb.AppendLine("        #region Generated");
                }
                AppendCtorsBusinessLayerCode(sb);
                //AppendInsertBusinessLayerCode(dbTable, sb);
                //AppendUpdateBusinessLayerCode(dbTable, sb);
                //if (dbTable.HasDeletedDisabled)
                //    AppendMarkByIdBusinessLayerCode(dbTable, sb);
                //AppendDeleteByIdBusinessLayerCode(dbTable, sb);
                //if (_options.GenerateDeleteByForeignKey)
                //    AppendDeleteByForeignKeyBusinessLayerCodes(dbTable, sb);
                //AppendSelectBusinessLayerCode(dbTable, sb);
                //AppendSelectByIdBusinessLayerCode(dbTable, sb);
                //AppendSelectByForeignKeyBusinessLayerCodes(dbTable, sb);
                //AppendSampleTransactionalMethodCode(dbTable, sb);
                if (_options.TargetPlatform == Platform.netFramework11)
                {
                    sb.AppendLine("        #endregion");
                }
                sb.AppendLine("    }");
                sb.AppendLine("}");
                dictionary.Add(dbTable.CsEntityName, sb.ToString());
            }
            return(dictionary);
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                if (string.IsNullOrEmpty(this.txtNamespace.Text) || this.tvwTables.Nodes.Count == 0)
                {
                    return;
                }
                List <TreeNode>         listTables        = (from TreeNode treeNode in tvwTables.Nodes[0].Nodes where treeNode.Checked select treeNode).ToList();
                DatabaseTableCollection dbTableCollection = new DatabaseTableCollection(options, listTables, ConnectionProvider.GetDbConnection());
                string   text = this.txtNamespace.Text;
                DateTime now  = DateTime.Now;
                this.txtSPs.Text                    = this.gloSQLScript = new StoredProcedureGenerator(this.options).GenerateSpScripts(dbTableCollection, now);
                this.txtDataSupertype.Text          = this.gloDataSupertype = new DataLayerGenerator(this.options).GenerateDataLayerSupertypeCode(this.txtNamespace.Text);
                this.txtBusinessLayerSupertype.Text = this._gloBusinessSupertype = new BusinessLayerGenerator(this.options).GenerateBusinessLayerSupertypeCode(this.txtNamespace.Text);
                this._gloDictEntities               = new EntityLayerGenerator(this.options).GenerateEntityCode(text, dbTableCollection);


                StringBuilder stringBuilder1 = new StringBuilder();
                foreach (string str in this._gloDictEntities.Values)
                {
                    stringBuilder1.AppendLine(str);
                }
                this.txtEntities.Text = stringBuilder1.ToString();



                _gloDictDataLayer = new DataLayerGenerator(this.options).GenerateDataLayerCode(text, dbTableCollection);
                StringBuilder stringBuilder2 = new StringBuilder();
                foreach (string str in this._gloDictDataLayer.Values)
                {
                    stringBuilder2.AppendLine(str);
                }
                txtDataLayer.Text = stringBuilder2.ToString();



                _gloDictDataLayerInterface = new DataLayerInterfaceGenerator(this.options).GenerateDataLayerCode(text, dbTableCollection);
                StringBuilder stringBuilderIData = new StringBuilder();
                foreach (string str in this._gloDictDataLayerInterface.Values)
                {
                    stringBuilderIData.AppendLine(str);
                }
                this.txtIDataLayer.Text = stringBuilderIData.ToString();



                this._gloDictBusinessLayer = new BusinessLayerGenerator(this.options).GenerateBusinessLayerCode(text, dbTableCollection);
                StringBuilder stringBuilder3 = new StringBuilder();
                foreach (string str in this._gloDictBusinessLayer.Values)
                {
                    stringBuilder3.AppendLine(str);
                }
                this.txtDomainLogic.Text = stringBuilder3.ToString();


                this._gloDictBusinessLayerInterface = new BusinessLayerInterfaceGenerator(this.options).GenerateBusinessLayerCode(text, dbTableCollection);
                StringBuilder stringBuilderIService = new StringBuilder();
                foreach (string str in this._gloDictBusinessLayerInterface.Values)
                {
                    stringBuilderIService.AppendLine(str);
                }
                txtIDomainLogic.Text = stringBuilderIService.ToString();


                this._gloDictInfrastructure = new Dictionary <string, string>();
                this._gloDictInfrastructure.Add("NullabletypeBase", NullableWrapperTypeGenerator.GetNullableAbstractBase(text));
                StringBuilder stringBuilder4 = new StringBuilder();
                foreach (string str in this._gloDictInfrastructure.Values)
                {
                    stringBuilder4.AppendLine(str);
                }
                this.txtInfrastructure.Text = stringBuilder4.ToString();
                stopwatch.Stop();
                this.lblGenerationInfo.Text       = "Processing Time: " + (object)stopwatch.ElapsedMilliseconds + "ms";
                this.tabControlOutput.SelectedTab = this.tabPageSPs;
            }
            catch (SqlException ex)
            {
                this.lblGenerationInfo.Text = ex.Message;
            }
            catch (Exception ex)
            {
                int num = (int)MessageBox.Show(ex.Message, this.messageTextProvider.GetMessage(MessageTypes.Error), MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }