コード例 #1
0
        public ActionResult CreateCode(BaseConfigModel baseConfigModel)
        {
            baseConfigModel.DataBaseLinkName = "";
            DataBaseLinkEntity dataBaseLinkEntity = new DataBaseLinkBLL().GetEntity(baseConfigModel.DataBaseLinkId);
            string             connectionString   = ConfigurationManager.ConnectionStrings["BaseDb"].ConnectionString;

            if (connectionString != dataBaseLinkEntity.F_DbConnection)
            {
                baseConfigModel.DataBaseLinkName = dataBaseLinkEntity.F_DBName;
                baseConfigModel.DataBaseLinkType = dataBaseLinkEntity.F_DbType;
            }
            string[]    tableNameLists        = baseConfigModel.DataBaseTableName.Split(',');
            string[]    tablePkLists          = baseConfigModel.DataBaseTablePK.Split(',');
            string[]    tableDescriptionLists = baseConfigModel.Description.Split(',');
            ServiceCode default_Template      = new ServiceCode();

            for (int i = 0; i < tableNameLists.Length; i++)
            {
                baseConfigModel.DataBaseTableName = tableNameLists[i];
                baseConfigModel.DataBaseTablePK   = tablePkLists[i];
                baseConfigModel.Description       = tableDescriptionLists[i];

                baseConfigModel.EntityClassName   = tableNameLists[i] + "Entity";
                baseConfigModel.MapClassName      = tableNameLists[i] + "Map";
                baseConfigModel.ServiceClassName  = tableNameLists[i] + "Service";
                baseConfigModel.IServiceClassName = tableNameLists[i] + "IService";
                baseConfigModel.BusinesClassName  = tableNameLists[i] + "BLL";

                var    tableFiled       = new DataBaseTableBLL(baseConfigModel.DataBaseLinkId).GetTableFiledList(baseConfigModel.DataBaseLinkId, baseConfigModel.DataBaseTableName);
                string entitybuilder    = default_Template.EntityBuilder(baseConfigModel, DataHelper.ListToDataTable <DataBaseTableFieldEntity>(tableFiled.ToList()));
                string entitymapbuilder = default_Template.EntityMapBuilder(baseConfigModel);
                string servicebuilder   = default_Template.ServiceBuilder(baseConfigModel);
                string iservicebuilder  = default_Template.IServiceBuilder(baseConfigModel);
                string businesbuilder   = default_Template.BusinesBuilder(baseConfigModel);

                var jsonData = new
                {
                    entityCode    = entitybuilder,
                    entitymapCode = entitymapbuilder,
                    serviceCode   = servicebuilder,
                    iserviceCode  = iservicebuilder,
                    businesCode   = businesbuilder,
                };
                CreateCodeFile.CreateExecution(baseConfigModel, jsonData.ToJson());
            }

            return(Success("恭喜您,创建成功!"));
        }
コード例 #2
0
        public ActionResult LookCode(BaseConfigModel baseConfigModel)
        {
            ServiceCode default_Template = new ServiceCode();
            var         tableFiled       = new DataBaseTableBLL(baseConfigModel.DataBaseLinkId).GetTableFiledList(baseConfigModel.DataBaseLinkId, baseConfigModel.DataBaseTableName);

            baseConfigModel.DataBaseLinkName = "";
            DataBaseLinkEntity dataBaseLinkEntity = new DataBaseLinkBLL().GetEntity(baseConfigModel.DataBaseLinkId);
            string             connectionString   = ConfigurationManager.ConnectionStrings["BaseDb"].ConnectionString;

            if (connectionString != dataBaseLinkEntity.F_DbConnection)
            {
                baseConfigModel.DataBaseLinkName = dataBaseLinkEntity.F_DBName;
                baseConfigModel.DataBaseLinkType = dataBaseLinkEntity.F_DbType;
                if (ConfigurationManager.ConnectionStrings[dataBaseLinkEntity.F_DBName] == null)
                {
                    string providerName = "System.Data.SqlClient";
                    if (dataBaseLinkEntity.F_DbType == "MySql")
                    {
                        providerName = "MySql.Data.MySqlClient";
                    }
                    else if (dataBaseLinkEntity.F_DbType == "Oracle")
                    {
                        providerName = "Oracle.ManagedDataAccess.Client";
                    }
                    Config.UpdateOrCreateConnectionString("XmlConfig\\database.config", dataBaseLinkEntity.F_DBName, dataBaseLinkEntity.F_DbConnection, providerName);
                }
            }
            string entitybuilder    = default_Template.EntityBuilder(baseConfigModel, DataHelper.ListToDataTable <DataBaseTableFieldEntity>(tableFiled.ToList()));
            string entitymapbuilder = default_Template.EntityMapBuilder(baseConfigModel);
            string servicebuilder   = default_Template.ServiceBuilder(baseConfigModel);
            string iservicebuilder  = default_Template.IServiceBuilder(baseConfigModel);
            string businesbuilder   = default_Template.BusinesBuilder(baseConfigModel);
            var    jsonData         = new
            {
                entityCode    = entitybuilder,
                entitymapCode = entitymapbuilder,
                serviceCode   = servicebuilder,
                iserviceCode  = iservicebuilder,
                businesCode   = businesbuilder,
            };

            return(ToJsonResult(jsonData));
        }