Esempio n. 1
0
        public static string CreateModel(string name_space, string table_name, List <SqlColumnInfo> colList, string model_name)
        {
            StringBuilder content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using System.Collections.Generic;");
            content.AppendLine("using System.Text;");
            content.AppendLine("namespace " + (string.IsNullOrEmpty(name_space) ? "命名空间" : name_space));
            content.AppendLine("{");
            if (!string.IsNullOrEmpty(table_name))
            {
                content.Append(CommentTool.CreateComment(table_name, 1));
            }

            content.AppendFormat("\tpublic class {0}\r\n", model_name);
            content.AppendLine("\t{");

            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tprivate {0} _{1} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));

                content.AppendLine();
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1}\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name);
                content.AppendLine("\t\t{");
                content.AppendLine("\t\t\tget { return this._" + item.Name + "; }");
                content.AppendLine("\t\t\tset { this._" + item.Name + " = value; }");
                content.AppendLine("\t\t}\r\n");
            }

            content.AppendLine("\t}");
            content.AppendLine("}");

            return(content.ToString());
        }
Esempio n. 2
0
        public static string CreateModel(string name_space, string table_name, List <SqlColumnInfo> colList, string model_name)
        {
            StringBuilder content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using System.Collections.Generic;");
            content.AppendLine("using System.ComponentModel;");
            content.AppendLine("using System.Text;");
            content.AppendLine("namespace " + (string.IsNullOrEmpty(name_space) ? "命名空间" : name_space));
            content.AppendLine("{");
            if (!string.IsNullOrEmpty(table_name))
            {
                content.Append(CommentTool.CreateComment(table_name, 1));
            }

            content.AppendFormat("\tpublic class {0}\r\n", model_name);
            content.AppendLine("\t{");

            bool isCodeSplit = false;

            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    isCodeSplit = true;
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));
                if (isCodeSplit && i < (colList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t}");
            content.AppendLine("}");

            return(content.ToString());
        }
        public static string CreateModel()
        {
            StringBuilder content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using System.Collections.Generic;");
            content.AppendLine("using System.ComponentModel;");
            content.AppendLine("using System.Text;");
            content.AppendLine("namespace " + (string.IsNullOrEmpty(PageCache.NameSpaceStr) ? "命名空间" : PageCache.NameSpaceStr));
            content.AppendLine("{");
            if (!string.IsNullOrEmpty(PageCache.TableName))
            {
                content.Append(CommentTool.CreateComment(PageCache.TableName, 1));
            }

            content.AppendFormat("\tpublic class {0}\r\n", PageCache.TableName_Model);
            content.AppendLine("\t{");

            var colList = PageCache.GetColumnList();

            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                content.AppendLine();
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\t[DefaultValue(typeof({0}), \"{1}\")]\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     SqlTool.GetDefaultValueAttributeStr(item.DbType));
                content.AppendFormat("\t\tpublic {0} {1}\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name);
                content.AppendLine("\t\t{");
                content.AppendLine("\t\t\tget { return this._" + item.Name + "; }");
                content.AppendLine("\t\t\tset { this._" + item.Name + " = value; }");
                content.AppendLine("\t\t}\r\n");
            }

            var extendList = PageCache.GetExtendList();

            for (int i = 0; i < extendList.Count; i++)
            {
                var item = extendList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1}\r\n",
                                     item.AttributeType,
                                     item.NewAttName);
                content.AppendLine("\t\t{");
                content.AppendLine("\t\t\tget");
                content.AppendLine("\t\t\t{");
                if (item.FormatType == 0)
                {
                    string formatStr = item.FormatStr.Replace("{c1}", item.DependColumn);
                    content.AppendLine("\t\t\treturn " + formatStr + ";");
                }
                else if (item.FormatType == 1)
                {
                    content.AppendLine("\t\t\t\treturn " + item.DependColumn.ToString() + ".ToString(\"" + item.FormatStr + "\");");
                }
                else if (item.FormatType == 2)
                {
                    string   formatStr = item.FormatStr;
                    string[] lineArray = item.FormatStr.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    content.AppendLine("\t\t\t\tswitch (" + item.DependColumn + ")");
                    content.AppendLine("\t\t\t\t{");
                    foreach (var line in lineArray)
                    {
                        var lineItemArray = line.Split(new string[] { "---" }, StringSplitOptions.None);
                        if (lineItemArray[0] != StaticVariable.Switch_Default_Key)
                        {
                            content.AppendLine("\t\t\t\t\tcase " + lineItemArray[0] + ":");
                            content.AppendLine("\t\t\t\t\t\treturn \"" + lineItemArray[1] + "\";");
                        }
                    }

                    foreach (var line in lineArray)
                    {
                        var lineItemArray = line.Split(new string[] { "---" }, StringSplitOptions.None);
                        if (lineItemArray[0] == StaticVariable.Switch_Default_Key)
                        {
                            content.AppendLine("\t\t\t\t\tdefault:");
                            content.AppendLine("\t\t\t\t\t\treturn \"" + lineItemArray[1] + "\";");
                        }
                    }



                    content.AppendLine("\t\t\t\t}");
                }

                content.AppendLine("\t\t\t}");

                if (extendList.Count == i - 1)
                {
                    content.AppendLine("\t\t}");
                }
                else
                {
                    content.AppendLine("\t\t}\r\n");
                }
            }

            content.AppendLine("\t}");
            content.AppendLine("}");

            return(content.ToString());
        }
Esempio n. 4
0
        public string CreateModel(string table_name, List <SqlColumnInfo> colList, bool add_display_model = false)
        {
            this.model_name = table_name + model_suffix;

            StringBuilder content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using System.Collections.Generic;");
            content.AppendLine("using System.Linq;");
            content.AppendLine("using System.Threading.Tasks;");
            content.AppendLine();
            content.AppendLine("namespace " + (string.IsNullOrEmpty(name_space) ? "命名空间" : name_space));
            content.AppendLine("{");
            if (!string.IsNullOrEmpty(table_name))
            {
                content.Append(CommentTool.CreateComment(table_name, 1));
            }

            content.AppendFormat("\tpublic class {0}\r\n", model_name);
            content.AppendLine("\t{");
            bool isCodeSplit = false;

            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    isCodeSplit = true;
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));
                if (isCodeSplit && i < (colList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t}");
            if (add_display_model)
            {
                content.AppendLine();
                content.AppendFormat("\tpublic class batedit_{0}\r\n", model_name);
                content.AppendLine("\t{");
                for (int i = 0; i < colList.Count; i++)
                {
                    var item = colList[i];
                    if (!string.IsNullOrEmpty(item.Comment))
                    {
                        content.Append(CommentTool.CreateComment(item.Comment, 2));
                    }

                    content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                         SqlTool.GetFormatString(item.DbType),
                                         item.Name,
                                         SqlTool.GetDefaultValueStr(item.DbType));

                    if (isCodeSplit && i < (colList.Count - 1))
                    {
                        content.AppendLine();
                    }
                }

                content.AppendLine("\t\tpublic string ids { get; set; } = string.Empty;");
                content.AppendLine("\t}");

                content.AppendLine();
                content.AppendFormat("\tpublic class query_{0}\r\n", model_name);
                content.AppendLine("\t{");
                for (int i = 0; i < colList.Count; i++)
                {
                    var item = colList[i];
                    if (!string.IsNullOrEmpty(item.Comment))
                    {
                        content.Append(CommentTool.CreateComment(item.Comment, 2));
                    }

                    content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                         SqlTool.GetFormatString(item.DbType),
                                         item.Name,
                                         SqlTool.GetDefaultValueStr(item.DbType));

                    if (isCodeSplit && i < (colList.Count - 1))
                    {
                        content.AppendLine();
                    }
                }

                content.AppendLine("\t\tpublic int page { get; set; } = 0;");
                content.AppendLine("\t\tpublic int pageSize { get; set; } = 0;");
                content.AppendLine("\t}");

                content.AppendLine();
                content.AppendFormat("\tpublic class display_{0}\r\n", model_name);
                content.AppendLine("\t{");
                content.AppendLine("\t\tpublic int item_count { get; set; } = 0;");
                content.AppendLine("\t\tpublic int page_count { get; set; } = 0;");
                content.AppendFormat("\t\tpublic List<{0}> list {{ get; set; }} = new List<{0}>();\r\n", model_name);
                content.AppendLine("\t}");
            }

            content.AppendLine("}");

            return(content.ToString());
        }
        public string CreateModel(string table_name, List <SqlColumnInfo> colList)
        {
            this.model_name = table_name + model_suffix;

            StringBuilder content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using System.Collections.Generic;");
            content.AppendLine("using System.Linq;");
            content.AppendLine("using System.Threading.Tasks;");
            content.AppendLine();
            content.AppendLine("namespace " + (string.IsNullOrEmpty(name_space) ? "命名空间" : name_space));
            content.AppendLine("{");
            if (!string.IsNullOrEmpty(table_name))
            {
                content.Append(CommentTool.CreateComment(table_name, 1));
            }

            content.AppendFormat("\tpublic class {0}\r\n", model_name);
            content.AppendLine("\t{");
            bool isCodeSplit = false;

            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    isCodeSplit = true;
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));
                if (isCodeSplit && i < (colList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t}");
            content.AppendLine();

            var addList = Cache_VMData.GetVMList(table_name, VMType.Add, colList);

            content.AppendFormat("\tpublic class add_{0}\r\n", model_name);
            content.AppendLine("\t{");
            for (int i = 0; i < addList.Count; i++)
            {
                var item = addList[i];
                if (item.IsMainKey)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));

                if (isCodeSplit && i < (addList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t}");
            content.AppendLine();

            var editList = Cache_VMData.GetVMList(table_name, VMType.Edit, colList);

            content.AppendFormat("\tpublic class edit_{0}\r\n", model_name);
            content.AppendLine("\t{");
            for (int i = 0; i < editList.Count; i++)
            {
                var item = editList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));

                if (isCodeSplit && i < (editList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t}");
            content.AppendLine();
            content.AppendFormat("\tpublic class delete_{0}\r\n", model_name);
            content.AppendLine("\t{");
            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                if (!item.IsMainKey)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));

                if (isCodeSplit && i < (colList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t}");
            content.AppendLine();

            var queryList = Cache_VMData.GetVMList(table_name, VMType.Query, colList);

            content.AppendFormat("\tpublic class query_{0}\r\n", model_name);
            content.AppendLine("\t{");
            for (int i = 0; i < queryList.Count; i++)
            {
                var item = queryList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1} {{ get; set; }} = {2};\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name,
                                     SqlTool.GetDefaultValueStr(item.DbType));

                if (isCodeSplit && i < (queryList.Count - 1))
                {
                    content.AppendLine();
                }
            }

            content.AppendLine("\t\tpublic int page { get; set; } = 0;");
            content.AppendLine("\t\tpublic int pageSize { get; set; } = 0;");
            content.AppendLine("\t}");

            content.AppendLine();
            content.AppendFormat("\tpublic class display_{0}\r\n", model_name);
            content.AppendLine("\t{");
            content.AppendLine("\t\tpublic int item_count { get; set; } = 0;");
            content.AppendLine("\t\tpublic int page_count { get; set; } = 0;");
            content.AppendFormat("\t\tpublic List<{0}> list {{ get; set; }} = new List<{0}>();\r\n", model_name);
            content.AppendLine("\t}");
            content.AppendLine("}");

            return(content.ToString());
        }