private static string ParamCreate(AzMetaCloumEntity azMetaCloum, AzClassCreatProperty classCreatProperty)
        {
            StringBuilder stringBuilder = new StringBuilder();
            MetaDataType  metaDataType  = MetaDataTypeHandle.GetMetaDataType(azMetaCloum.FldType);

            stringBuilder.AddLineStatement("param = new SqlParameter();", 2);
            stringBuilder.AddLineStatement("param.ParameterName = \"@" + azMetaCloum.FldName + "\";", 2);
            if (azMetaCloum.IsOutParam == 0)
            {
                if (azMetaCloum.IsNullable == false)
                {
                    stringBuilder.AddLineStatement($"param.Value={BaseConstants.ParamPer}Item.{azMetaCloum.FldNameTo};", 2);
                }
                else
                {
                    stringBuilder.AddLineStatement($"if ({BaseConstants.ParamPer}Item.{azMetaCloum.FldNameTo}==null)", 2);
                    stringBuilder.AddLineStatement(" {param.Value = System.DBNull.Value;}", 2);
                    stringBuilder.AddLineStatement($"else", 2);
                    stringBuilder.AddLineStatement($"{{ param.Value={BaseConstants.ParamPer}Item.{azMetaCloum.FldNameTo};}};", 2);
                }
            }
            else
            {
                stringBuilder.AddLineStatement("param.Direction = ParameterDirection.Output;}", 2);
            }
            if (metaDataType.CodeSign == 2)
            {
                stringBuilder.AddLineStatement($"param.Size = {azMetaCloum.FldLenCode};", 2);
            }
            stringBuilder.AddLineStatement($"param.SqlDbType = SqlDbType.{metaDataType.DBCodeType};", 2);
            stringBuilder.AddLineStatement("cmd.Parameters.Add(param);", 2);
            stringBuilder.AppendLine();
            return(stringBuilder.ToString());
        }
Exemple #2
0
        private List <string> GetCreateList(List <string> list, AzClassCreatProperty itemproperty)
        {
            List <string> templist = new List <string>();
            var           s        = list.Where(m => m == "AzthinkerView").FirstOrDefault();

            if (string.IsNullOrEmpty(s))
            {
                return(list);
            }
            templist.AddRange(list);
            templist.Remove("AzthinkerView");
            templist.Add("AzthinkerView_Create");
            templist.Add("AzthinkerView_Delete");
            templist.Add("AzthinkerView_Details");
            templist.Add("AzthinkerView_Edit");
            if (itemproperty.HasControllerAsynPage)
            {
                templist.Add("AzthinkerView_IndexPage");
                templist.Add("AzthinkerView_IndexPageDetails");
            }
            else
            {
                templist.Add("AzthinkerView_Index");
            }


            return(templist);
        }
Exemple #3
0
        public static bool GetAzCreateItemEnable(string opCreate, AzClassCreatProperty creatProperty)
        {
            AzCreateItem azCreateItem = GetAzCreateItem(creatProperty);
            var          props        = TypeDescriptor.GetProperties(typeof(AzCreateItem)).Find(opCreate, true);

            if (props == null)
            {
                return(false);
            }

            return((bool)props.GetValue(azCreateItem));
        }
Exemple #4
0
        private string CheckMasterSetIsValid(AzMetaTableEntity checkitem, bool showDialogue)
        {
            AzClassCreatProperty creatProperty = AzCdgnClassProperty.GetItemClassCreatProperty(checkitem);

            if (creatProperty.ObjPresentation.IsSchemaForOther)
            {
                if (showDialogue)
                {
                    GeneralHelpler.SomethingError($"当前项目{checkitem.ClassName}({checkitem.ClassDisPlay})为“结构查询”,不能生成代码!");
                }

                return($"{checkitem.ClassName}({checkitem.ClassDisPlay})");
            }

            return(string.Empty);
        }
        public static string DefaultValuesCreate(IEnumerable <AzMetaCloumEntity> azMetaCloums, AzClassCreatProperty classPro)
        {
            if (classPro.HasDtoConstruction != true)
            {
                return("//字段属性无默认初始化".AddPerTab(2));
            }
            StringBuilder stringBuilder = new StringBuilder();

            foreach (var col in azMetaCloums)
            {
                if ((col.IsIdentity != true) && (col.IsSelect == true) && (col.IsDefvalue == true))
                {
                    stringBuilder.AddLineStatement($"{col.FldNameTo} = {col.Defvalue };");
                }
            }
            return(stringBuilder.ToString());
        }
        public static string Sql_Fragment_For_Update(IEnumerable <AzMetaCloumEntity> azMetaCloums, AzClassCreatProperty classPro)
        {
            StringBuilder stringBuilder = new StringBuilder();
            StringBuilder s1            = new StringBuilder();
            StringBuilder s2            = new StringBuilder();

            s2.AddLineStatement($"{BaseConstants.ParamPer}StrBuilder.Append(\"Update [a0] Set \"); ", 2);
            stringBuilder.AddLineStatement("#region  更新SQL语句字串", 2);
            int rowcount = 0; string comma = ""; int tabcount = 0;

            #region cols
            foreach (var col in azMetaCloums)
            {
                if ((col.IsDataField == true) && (col.IsSelect == true) && (col.IsUpdata == true) && (col.IsIdentity != true))
                {
                    if (tabcount > 0)
                    {
                        comma = ",";
                    }

                    if (string.IsNullOrWhiteSpace(s1.ToString()))
                    {
                        s1.Append($"{BaseConstants.ParamPer}StrBuilder.Append(\"{comma}[a0].[{col.FldName}]=@{col.FldName}");
                    }
                    else
                    {
                        s1.Append($",[a0].[{col.FldName}]=@{col.FldName}");
                    }
                    if (rowcount == 5)
                    {
                        s2.AddLineStatement(s1.ToString() + "\");", 2);
                        rowcount = 0;
                        s1.Clear();
                        tabcount += 1;
                    }
                    rowcount += 1;
                }
            }
            #endregion

            if (!string.IsNullOrWhiteSpace(s1.ToString()))
            {
                s2.AddLineStatement($"{s1.ToString()} From {classPro.ObjPresentation.UpdateTableName} As [a0]\");", 2);
            }
            stringBuilder.Append(s2.ToString());
            stringBuilder.AddLineStatement("#endregion");
            return(stringBuilder.ToString());
        }
        public static (string codesInfo, string addInfo) Sql_Fragment_For_Insert(IEnumerable <AzMetaCloumEntity> azMetaCloums, AzClassCreatProperty classPro)
        {
            StringBuilder stringBuilder = new StringBuilder();
            StringBuilder stringBuilder1 = new StringBuilder();
            StringBuilder stringBuilder2 = new StringBuilder();
            StringBuilder s1 = new StringBuilder();
            StringBuilder s2 = new StringBuilder();
            string        Item2 = string.Empty;
            int           idcount = 0; int rowcount = 0; string comma = ""; int tabcount = 0;

            stringBuilder1.AddLineStatement($"{BaseConstants.ParamPer}StrBuilder.Append(\" Insert Into {classPro.ObjPresentation.UpdateTableName}(\");", 2);
            stringBuilder2.AddLineStatement($"{BaseConstants.ParamPer}StrBuilder.Append(\" Values( \");", 2);
            stringBuilder.AddLineStatement($"#region  增加SQL语句字串", 2);
            #region cols


            foreach (var col in azMetaCloums)
            {
                if (col.IsIdentity == true)
                {
                    idcount = 1;
                }

                if ((col.IsDataField == true) && (col.IsCreate == true) && (col.IsSelect == true) && (col.IsIdentity != true))
                {
                    if (tabcount > 0)
                    {
                        comma = ",";
                    }

                    if (string.IsNullOrWhiteSpace(s1.ToString()))
                    {
                        s1.Append($"{BaseConstants.ParamPer}StrBuilder.Append(\"{comma}[{col.FldName}]");
                        s2.Append($"{BaseConstants.ParamPer}StrBuilder.Append(\"{comma}@{col.FldName}");
                    }
                    else
                    {
                        s1.Append($",[{col.FldName}]");
                        s2.Append($",@{col.FldName}");
                    }
                    if (rowcount == 5)
                    {
                        stringBuilder1.AddLineStatement(s1.ToString() + "\");", 2);
                        stringBuilder2.AddLineStatement(s2.ToString() + "\");", 2);
                        rowcount = 0;
                        s1.Clear();
                        s2.Clear();
                        tabcount += 1;
                    }
                    rowcount += 1;
                }
            }
            #endregion

            if (string.IsNullOrWhiteSpace(s1.ToString()))
            {
                s1.AddLineStatement($"{BaseConstants.ParamPer}StrBuilder.Append(\")\");", 2);
                stringBuilder1.Append(s1);
            }
            else
            {
                stringBuilder1.Append(s1.ToString() + ")\");");
            }

            if (string.IsNullOrWhiteSpace(s2.ToString()))
            {
                s2.AddLineStatement($"{BaseConstants.ParamPer}StrBuilder.Append(\")\");", 2);
                stringBuilder2.Append(s2);
            }
            else
            {
                stringBuilder2.Append(s2.ToString() + ")\");");
            }

            //   stringBuilder2.Append(s2.ToString() + ")\");");
            stringBuilder.Append(stringBuilder1.ToString());
            stringBuilder.Append(stringBuilder2.ToString());
            if (idcount == 1)
            {
                Item2 = $"{BaseConstants.ParamPer}StrBuilder.Append(\";select @getautouid = SCOPE_IDENTITY()\"); ".AddPerTab(2);
            }
            stringBuilder.AppendLine(Item2);
            stringBuilder.AddLineStatement($"#endregion", 2);
            return(stringBuilder.ToString(), Item2);
        }
        public static string ParamInputDefault(IEnumerable <AzMetaCloumEntity> azMetaCloums, AzClassCreatProperty classPro)
        {
            if (classPro.ObjPresentation.ObjDataType < ObjDataTypeEnum.atk_FuncstoredProcedure)
            {
                return(string.Empty);
            }

            string result = string.Empty;

            foreach (var col in azMetaCloums)
            {
                string fn = GetCorrectType(col);
                if (string.IsNullOrWhiteSpace(result))
                {
                    result = $"default({fn})";
                }
                else
                {
                    result = $"{result},default({fn})";
                }
            }
            return(result);
        }
        public static (string models, string addId) ParamCreates(IEnumerable <AzMetaCloumEntity> azMetaCloums, AzClassCreatProperty classCreatProperty, AzOperateSqlModel azOperate)
        {
            bool          opm           = false;
            StringBuilder stringBuilder = new StringBuilder();
            string        item2         = "";

            foreach (var col in azMetaCloums)
            {
                opm = false;
                switch (azOperate)
                {
                case AzOperateSqlModel.atkInsert:
                    opm = (col.IsSelect == true) && (col.IsCreate == true) && (col.IsDataField == true);
                    break;

                case AzOperateSqlModel.atkUpdate:
                    opm = (col.IsSelect == true) && (col.IsUpdata == true) && (col.IsDataField == true);
                    break;

                case AzOperateSqlModel.atkSelect:
                    opm = (col.IsSelect == true) && (col.IsDataField == true);
                    break;
                }
                bool insertcmd = (azOperate == AzOperateSqlModel.atkInsert);
                if (insertcmd && (col.IsIdentity == true))
                {
                    stringBuilder.AddLineStatement(ParamIdentityCreate(col.FldType));
                    item2 = ParamIdentityPropertyCreate(col);
                }
                if (opm && (col.IsIdentity != true) && insertcmd)// || (opm && (col.IsIdentity != true)))
                {
                    stringBuilder.AddLineStatement(ParamCreate(col, classCreatProperty));
                }
            }

            return(stringBuilder.ToString(), item2);
        }
Exemple #10
0
        public static AzCreateItem GetAzCreateItem(AzClassCreatProperty creatProperty)
        {
            AzCreateItem createItem = new AzCreateItem();

            if (creatProperty == null)
            {
                return(createItem);
            }

            var azprojectinfo = GetProjectInformation();

            if (creatProperty.ObjPresentation.ObjDataType == ObjDataTypeEnum.atk_tables ||
                creatProperty.ObjPresentation.ObjDataType == ObjDataTypeEnum.atk_customTables)
            {
                createItem.AzthinkerDal_Interface      = azprojectinfo.HasDalInterface;
                createItem.AzthinkerDal_SQL            = azprojectinfo.HasDalLayer;
                createItem.AzthinkerBll_Class          = azprojectinfo.HasBll;
                createItem.AzthinkerBll_ListClass      = creatProperty.HasBussniesList && azprojectinfo.HasBllList;
                createItem.AzthinkerClass_WebUIDto     = azprojectinfo.HasWebUIDto;
                createItem.AzthinkerClass_WebListUIDto = azprojectinfo.HasWebListUIDto;
                createItem.AzthinkerClass_WebHandle    = azprojectinfo.HasWebListUIHandle;
                createItem.AzthinkerControllers        = true;
                createItem.AzthinkerView_Create        = creatProperty.HasControllerAdd;
                createItem.AzthinkerView_Delete        = creatProperty.HasControllerDelete;
                createItem.AzthinkerView_Details       = creatProperty.HasControllerDetail;
                createItem.AzthinkerView_Edit          = creatProperty.HasControllerEdit;

                createItem.AzthinkerView_Index            = creatProperty.HasControllerList && !creatProperty.HasControllerAsynPage;
                createItem.AzthinkerView_IndexPage        = creatProperty.HasControllerList && creatProperty.HasControllerAsynPage;
                createItem.AzthinkerView_IndexPageDetails = creatProperty.HasControllerList && creatProperty.HasControllerAsynPage;
            }
            else if ((creatProperty.ObjPresentation.ObjDataType == ObjDataTypeEnum.atk_views ||
                      creatProperty.ObjPresentation.ObjDataType == ObjDataTypeEnum.atk_customViews) && (!creatProperty.ObjPresentation.IsSchemaForOther))
            {
                createItem.AzthinkerDal_Interface      = azprojectinfo.HasDalInterface;
                createItem.AzthinkerDal_SQL            = azprojectinfo.HasDalLayer;
                createItem.AzthinkerBll_Class          = azprojectinfo.HasBll;
                createItem.AzthinkerBll_ListClass      = creatProperty.HasBussniesList && azprojectinfo.HasBllList;
                createItem.AzthinkerClass_WebUIDto     = azprojectinfo.HasWebUIDto;
                createItem.AzthinkerClass_WebListUIDto = azprojectinfo.HasWebListUIDto;
                createItem.AzthinkerClass_WebHandle    = azprojectinfo.HasWebListUIHandle;
                createItem.AzthinkerControllers        = true;
                createItem.AzthinkerView_Create        = creatProperty.HasControllerAdd && !(string.IsNullOrWhiteSpace(creatProperty.ObjPresentation.UpdateTableName));
                createItem.AzthinkerView_Delete        = creatProperty.HasControllerDelete && !(string.IsNullOrWhiteSpace(creatProperty.ObjPresentation.UpdateTableName));
                createItem.AzthinkerView_Details       = creatProperty.HasControllerDetail;
                createItem.AzthinkerView_Edit          = creatProperty.HasControllerEdit && !(string.IsNullOrWhiteSpace(creatProperty.ObjPresentation.UpdateTableName));

                createItem.AzthinkerView_Index            = creatProperty.HasControllerList && !creatProperty.HasControllerAsynPage;
                createItem.AzthinkerView_IndexPage        = creatProperty.HasControllerList && creatProperty.HasControllerAsynPage;
                createItem.AzthinkerView_IndexPageDetails = creatProperty.HasControllerList && creatProperty.HasControllerAsynPage;
            }
            else if (creatProperty.ObjPresentation.ObjDataType == ObjDataTypeEnum.atk_FuncstoredProcedure)
            {
                createItem.AzthinkerDal_Interface   = azprojectinfo.HasDalInterface;
                createItem.AzthinkerDal_SQL         = azprojectinfo.HasDalLayer;
                createItem.AzthinkerBll_Class       = azprojectinfo.HasBll;
                createItem.AzthinkerClass_WebUIDto  = azprojectinfo.HasWebUIDto;
                createItem.AzthinkerClass_WebHandle = azprojectinfo.HasWebListUIHandle;
            }
            else if (creatProperty.ObjPresentation.ObjDataType == ObjDataTypeEnum.atk_QuerystoredProcedure)
            {
                createItem.AzthinkerDal_Interface         = azprojectinfo.HasDalInterface;
                createItem.AzthinkerDal_SQL               = azprojectinfo.HasDalLayer;
                createItem.AzthinkerBll_Class             = azprojectinfo.HasBll;
                createItem.AzthinkerBll_ListClass         = azprojectinfo.HasBllList;
                createItem.AzthinkerClass_WebUIDto        = azprojectinfo.HasWebUIDto;
                createItem.AzthinkerClass_WebListUIDto    = azprojectinfo.HasWebListUIDto;
                createItem.AzthinkerClass_WebHandle       = azprojectinfo.HasWebListUIHandle;
                createItem.AzthinkerControllers           = true;
                createItem.AzthinkerView_Index            = creatProperty.HasControllerList && !creatProperty.HasControllerAsynPage;
                createItem.AzthinkerView_IndexPage        = creatProperty.HasControllerList && creatProperty.HasControllerAsynPage;
                createItem.AzthinkerView_IndexPageDetails = creatProperty.HasControllerList && creatProperty.HasControllerAsynPage;
            }
            return(createItem);
        }
Exemple #11
0
        private string CreateCodeHandle(string opCreate, AzMetaTableEntity item, AzClassCreatProperty itemproperty, IEnumerable <AzMetaCloumEntity> itemDetails)
        {
            if (!AzCreateItem.GetAzCreateItemEnable(opCreate, itemproperty))
            {
                return(string.Empty);
            }

            CodeHandle.HasSummary = azCdgnMasterDisplay1.GetHasSummary();

            string path     = string.Empty;
            string floder   = string.Empty;
            string filename = string.Empty;
            string codestr  = string.Empty;
            string ext      = ".cs";


            switch (opCreate)
            {
            case "AzthinkerDal_Interface":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.Dal.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"I{item.ClassName}Dal";
                codestr  = CodeHandle.AzInterfaceDal(item, itemproperty);
                break;

            case "AzthinkerDal_SQL":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.Dal.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"{item.ClassName}Dal";
                codestr  = CodeHandle.AzDalConcrete(item, itemproperty, itemDetails);
                break;

            case "AzthinkerBll_Class":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.BLL.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"{item.ClassName}Entity";
                codestr  = CodeHandle.AzBll_Class(item, itemproperty, itemDetails);
                break;

            case "AzthinkerBll_ListClass":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.BLL.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"{item.ClassName}ListEntity";
                codestr  = CodeHandle.AzBll_ListClass(item, itemproperty, itemDetails);
                break;

            case "AzthinkerClass_WebUIDto":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.UIServer.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"{item.ClassName}WebDto";
                codestr  = CodeHandle.AzWebUI_Dto(item, itemproperty, itemDetails);
                break;

            case "AzthinkerClass_WebListUIDto":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.UIServer.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"{item.ClassName}ListWebDto";
                codestr  = CodeHandle.AzWebUiList_Dto(item, itemproperty, itemDetails);
                break;

            case "AzthinkerClass_WebHandle":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.UIServer.{NormalSet.AzBase.AzProjectName}";
                floder   = item.ClassName;
                filename = $"{item.ClassName}WebHandle";
                codestr  = CodeHandle.AzWebUiHandle(item, itemproperty, itemDetails);
                break;

            case "AzthinkerControllers":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI";
                floder   = "Controllers";
                filename = $"{item.ClassName}Controller";
                codestr  = CodeHandle.AzMVC_Controllers(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_Create":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "Create";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_Create(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_Delete":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "Delete";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_Delete(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_Details":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "Details";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_Details(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_Edit":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "Edit";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_Edit(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_Index":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "Index";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_GetList(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_IndexPage":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "Index";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_GetListPage(item, itemproperty, itemDetails);
                break;

            case "AzthinkerView_IndexPageDetails":
                path     = $"{NormalSet.AzBase.AzProjectSpace}.WebUI\\View";
                floder   = item.ClassName;
                filename = "DetailsPage";
                ext      = ".cshtml";
                codestr  = CodeHandle.AzMvc_View_GetListPageDetails(item, itemproperty, itemDetails);
                break;
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                return("");
            }
            if (string.IsNullOrWhiteSpace(codestr))
            {
                return($"{item.ClassName}({item.ClassDisPlay}),无可生成代码");
            }
            FileHelper.SaveCodeToFile(path, floder, filename, codestr, ext);

            return(codestr);
        }