示例#1
0
        public static string CreateControllersCode(List <object> CreateInfo)
        {
            string        TableName       = CreateInfo[0].ToString();                //表名 即类名
            List <string> FeildName       = CreateInfo[1] as List <string>;          //表字段名称
            List <string> FeildType       = CreateInfo[2] as List <string>;          //表字段类型
            List <string> FeildLength     = CreateInfo[3] as List <string>;          //表字段长度
            List <string> FeildIsNullable = CreateInfo[4] as List <string>;          //表字段可空
            List <string> FeildMark       = CreateInfo[5] as List <string>;          //表字段说明
            List <string> FeildIsPK       = CreateInfo[6] as List <string>;          //表字段是否主键
            List <string> FeildIsIdentity = CreateInfo[7] as List <string>;          //表字段是否自增

            Boolean[] MethodInfo   = CreateInfo[8] as Boolean[];                     //checkbox选项
            string    BLLclassName = CreateInfo[9].ToString();                       //获得BLL层的类名


            StringBuilder str = new StringBuilder();


            #region 版权信息
            //版权信息
            str.Append(Info.CopyRight);
            str.Append("\r\n");
            #endregion


            //判断是否需要 实例化对象 getForm
            if (MethodInfo[0])
            {
                str.Append("\t" + TableName + " " + TableName + "Object = new " + TableName + "();" + "\r\n");//添加方法介绍
                for (int i = 0; i < FeildName.Count; i++)
                {
                    if (TypeConvert.RT_Type(FeildType[i].Trim()) == "Int32")
                    {
                        str.Append("\t" + TableName + "Object." + FeildName[i].Trim() + "=Convert.ToInt32(Request[\"" + FeildName[i].Trim() + "\"]);" + "\r\n");
                    }
                    else
                    {
                        str.Append("\t" + TableName + "Object." + FeildName[i].Trim() + "=(" + TypeConvert.RT_Type(FeildType[i].Trim()) + ")Request[\"" + FeildName[i].Trim() + "\"];" + "\r\n");
                    }
                }
                str.Append("\r\n");
                str.Append("\t" + "//time=DateTime.Now.ToString();" + "\r\n");
                str.Append("\r\n");
            }
            //判断是否需要 实例化对象自定义
            if (MethodInfo[1])
            {
                str.Append("\t" + TableName + " " + TableName + "Object = new " + TableName + "();" + "\r\n");
                for (int i = 0; i < FeildName.Count; i++)
                {
                    str.Append("\t" + TableName + "Object." + FeildName[i].Trim() + "=\"\";" + "\r\n");
                }
                str.Append("\r\n");
                str.Append("\t" + "//time=DateTime.Now.ToString();" + "\r\n");
                str.Append("\r\n");
            }

            //判断是否需要JsonResult
            if (MethodInfo[2])
            {
                str.Append("\t" + "if (true)" + "\r\n");
                str.Append("\t" + "{" + "\r\n");
                str.Append("\t\t" + "return Json(new { TFMark = true, Msg = \"操作成功!\"/*,result=*/ }, JsonRequestBehavior.AllowGet);" + "\r\n");
                str.Append("\t" + "}" + "\r\n");
                str.Append("\t" + "else" + "\r\n");
                str.Append("\t" + "{" + "\r\n");
                str.Append("\t\t" + "return Json(new { TFMark = false, Msg = \"操作失败,请检查信息!\" }, JsonRequestBehavior.AllowGet);" + "\r\n");
                str.Append("\t" + "}" + "\r\n");
                str.Append("\r\n");
            }
            //判断是否需要带Try Catch 的JsonResult
            if (MethodInfo[3])
            {
                str.Append("\t" + "try" + "\r\n");
                str.Append("\t" + "{" + "\r\n");
                str.Append("\t\t" + "if (true)" + "\r\n");
                str.Append("\t\t" + "{" + "\r\n");
                str.Append("\t\t\t" + "return Json(new { TFMark = true, Msg = \"操作成功!\"/*,result=*/ }, JsonRequestBehavior.AllowGet);" + "\r\n");
                str.Append("\t\t" + "}" + "\r\n");
                str.Append("\t\t" + "else" + "\r\n");
                str.Append("\t\t" + "{" + "\r\n");
                str.Append("\t\t\t" + "return Json(new { TFMark = false, Msg = \"操作失败,请检查信息!\" }, JsonRequestBehavior.AllowGet);" + "\r\n");
                str.Append("\t\t" + "}" + "\r\n");
                str.Append("\t" + "}" + "\r\n");
                str.Append("\t" + "catch(Exception)" + "\r\n");
                str.Append("\t" + "{" + "\r\n");
                str.Append("\t\t" + "return Json(new { TFMark = false, Msg = \"操作失败,请检查信息!\" }, JsonRequestBehavior.AllowGet);" + "\r\n");
                str.Append("\t" + "}" + "\r\n");
            }

            return(str.ToString());
        }
示例#2
0
        public static string CreateModelsCode(List <object> CreateInfo)
        {
            string        NameSpace       = CreateInfo[0].ToString();                //命名空间
            string        TableName       = CreateInfo[1].ToString();                //表名
            List <string> FeildName       = CreateInfo[2] as List <string>;          //表字段名称
            List <string> FeildType       = CreateInfo[3] as List <string>;          //表字段类型
            List <string> FeildLength     = CreateInfo[4] as List <string>;          //表字段长度
            List <string> FeildIsNullable = CreateInfo[5] as List <string>;          //表字段可空
            List <string> FeildMark       = CreateInfo[6] as List <string>;          //表字段说明
            List <string> FeildIsPK       = CreateInfo[7] as List <string>;          //表字段是否主键
            List <string> FeildIsIdentity = CreateInfo[8] as List <string>;          //表字段是否自增
            string        className       = CreateInfo[9].ToString();                //获得类名


            StringBuilder str = new StringBuilder();

            str.Append("using System;" + "\r\n");
            str.Append("\r\n");                                                     //空间引用结束换行
            //添加命名空间
            str.Append("namespace " + NameSpace + "\r\n");
            str.Append("{" + "\r\n");
            #region 版权信息
            //版权信息
            str.Append(Info.CopyRight);
            str.Append("\r\n");
            #endregion
            //添加实体类
            str.Append("\t" + "/// <summary>" + "\r\n");
            str.Append("\t" + "/// 实体类" + TableName + "(可添加属性说明)" + "\r\n");
            str.Append("\t" + "/// </summary>" + "\r\n");
            str.Append("\t" + "[Serializable]" + "\r\n");
            str.Append("\t" + "public class " + className + "\r\n");
            str.Append("\t" + "{" + "\r\n");
            //添加构造方法
            str.Append("\t\t" + "/// <summary>" + "\r\n");
            str.Append("\t\t" + "/// 构造方法" + "\r\n");
            str.Append("\t\t" + "/// </summary>" + "\r\n");
            str.Append("\t\t" + "public " + className + "()" + "\r\n");
            str.Append("\t\t" + "{}" + "\r\n" + "\r\n");
            //添加私有属性行
            for (int i = 0; i < FeildName.Count; i++)
            {
                str.Append("\t\t" + "private " + TypeConvert.RT_Type(FeildType[i]) + TypeConvert.RT_Nullable(FeildIsNullable[i]) + " _" + FeildName[i].ToLower() + ";\t\t//" + TypeConvert.RT_PK(FeildIsPK[i]) + FeildMark[i] + "\r\n");
            }
            str.Append("\r\n");//换行
            //添加私有属性的公有方法
            for (int i = 0; i < FeildName.Count; i++)
            {
                str.Append("\t\t" + "/// <summary>" + "\r\n" + "\t\t" + "///" + FeildMark[i] + "\r\n" + "\t\t" + "/// </summary>" + "\r\n");//添加方法介绍
                str.Append("\t\t" + "public " + TypeConvert.RT_Type(FeildType[i]) + TypeConvert.RT_Nullable(FeildIsNullable[i]) + " " + FeildName[i] + "\r\n");
                str.Append("\t\t" + "{" + "\r\n");
                str.Append("\t\t\t" + "set{_" + FeildName[i].ToLower() + "=value;}" + "\r\n");
                str.Append("\t\t\t" + "get{return _" + FeildName[i].ToLower() + ";}" + "\r\n");
                str.Append("\t\t}" + "\r\n");
            }
            str.Append("\t" + "}" + "\r\n"); //public class }
            str.Append("}" + "\r\n");        //namespace class }

            return(str.ToString());
        }