示例#1
0
        /// <summary>
        /// 创建实体
        /// </summary>
        private void CreateModel()
        {
            //获取当前文件夹路径
            //string currPath = Application.StartupPath;
            //检查是否存在文件夹
            string subPath = subPathName + "\\Model";

            if (false == System.IO.Directory.Exists(subPath))
            {
                //创建pic文件夹
                System.IO.Directory.CreateDirectory(subPath);
            }
            DataTable     dt_Cloumns = this.dgvColumns.DataSource as DataTable;
            List <string> code_list  = new List <string>();

            code_list.Add("using System;");

            code_list.Add("public class  " + this.tvTables.SelectedNode.Text + "");
            code_list.Add("{");
            foreach (DataRow row in dt_Cloumns.Rows)
            {
                string c_type = FileOperate.SqlTypeTope(row["type"].ToString());
                string c_name = row["name"].ToString();
                code_list.Add("public " + c_type + " " + c_name.Substring(0, 1).ToUpper() + c_name.Substring(1) + "{get; set;}");
            }
            code_list.Add("}");
            FileOperate.FileWrite(code_list, "" + subPath + "\\" + this.tvTables.SelectedNode.Text + ".cs");
            //CreateManger();
        }
示例#2
0
        public void CreateModel(string strJson)
        {
            subPath = subPathName + "\\" + ModelName.Text + "";
            if (false == System.IO.Directory.Exists(subPath))
            {
                //创建pic文件夹
                System.IO.Directory.CreateDirectory(subPath);
            }
            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            Dictionary <string, Object> json       = (Dictionary <string, Object>)serializer.DeserializeObject(strJson);

            FileOperate.FWrite("using System;\r\nusing System.Collections.Generic;\r\nnamespace " + ModelName.Text.Trim() + "\r\n{\r\npublic class " + TableName + "\r\n{\r\n", "" + subPath + "\\" + TableName + ".cs");
            if (json != null)
            {
                List <string> keys = json.Keys.ToList();
                foreach (var s in keys)
                {
                    findNode(json[s], s, "test", true);
                }
            }


            DataRow[] Rowlist = IcreateType.GetColumns(TableName).Select("type <> 'jsonb' and type <>'json'");
            for (int i = 0; i < Rowlist.Length; i++)
            {
                string classType = FileOperate.SqlTypeTope(Rowlist[i][1].ToString());
                if (classType == "")
                {
                    classType = "string";
                }
                string className = Rowlist[i][0].ToString();
                FileOperate.FWrite("public  " + classType + "  " + className + "    {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
            }
            FileOperate.FWrite("}\r\n}\r\n", "" + subPath + "\\" + TableName + ".cs");
            CreateManger(TableName);
            CreateComponent((DataTable)dgvColumns.DataSource);
            CreateControllers((DataTable)dgvColumns.DataSource);
        }
示例#3
0
        public void CreateModel(string strJson)
        {
            lists.Clear();

            subPath = subPathName + "\\" + ModelName.Text + "";
            if (false == System.IO.Directory.Exists(subPath))
            {
                //创建pic文件夹
                System.IO.Directory.CreateDirectory(subPath);
            }

            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            Dictionary <string, Object> json       = (Dictionary <string, Object>)serializer.DeserializeObject(strJson);

            if (json != null)
            {
                List <string> keys  = json.Keys.ToList();
                List <string> fList = new List <string>();
                lists.Add(fList);
                fList.Add("[Serializable]");
                fList.Add("public class " + TableName);
                fList.Add("{");
                foreach (var s in keys)
                {
                    //findNode(json[s], s, "test", true);
                    findNode2(s, json[s], fList);
                }
                DataRow[] Rowlist = IcreateType.GetColumns(tableName).Select("type <> 'jsonb' and type <>'json'");
                for (int i = 0; i < Rowlist.Length; i++)
                {
                    string classType = FileOperate.SqlTypeTope(Rowlist[i][1].ToString());
                    if (classType == "")
                    {
                        classType = "string";
                    }
                    string className = Rowlist[i][0].ToString();
                    fList.Add("public  " + classType + "  " + className + "    {get;set;}");
                }
                fList.Add("}");
                List <string> header = new List <string>();
                header.Add("using System;");
                header.Add("using System.Collections.Generic;");
                header.Add("namespace " + ModelName.Text.Trim());
                header.Add("{");
                FileOperate.FileWrite(header, subPath + "\\" + TableName + ".cs");
                foreach (List <string> clist in lists)
                {
                    FileOperate.WriteAppendList(clist, subPath + "\\" + TableName + ".cs");
                }
                FileOperate.WriteAppendStr("\r\n}", subPath + "\\" + TableName + ".cs");
            }
            else
            {
                List <string> header = new List <string>();
                header.Add("using System;");
                header.Add("using System.Collections.Generic;");
                header.Add("namespace " + ModelName.Text.Trim());
                header.Add("{");
                header.Add("[Serializable]");
                header.Add("public class " + TableName);
                header.Add("{");
                FileOperate.FileWrite(header, subPath + "\\" + TableName + ".cs");

                DataRow[] Rowlist = IcreateType.GetColumns(tableName).Select("type <> 'jsonb' and type <>'json'");
                for (int i = 0; i < Rowlist.Length; i++)
                {
                    string classType = FileOperate.SqlTypeTope(Rowlist[i][1].ToString());
                    if (classType == "")
                    {
                        classType = "string";
                    }
                    string className = Rowlist[i][0].ToString();
                    header.Add("public  " + classType + "  " + className + "    {get;set;}");
                }
                header.Add("}");
                header.Add("}");
                FileOperate.FileWrite(header, subPath + "\\" + TableName + ".cs");
            }

            CreateManger(TableName);
            CreateComponent((DataTable)dgvColumns.DataSource);
            CreateControllers((DataTable)dgvColumns.DataSource);
            MessageBox.Show("生成成功,请查看!!", "提示");
        }