Esempio n. 1
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);
        }
Esempio n. 2
0
        public void findNode(object obj, string fileName, string fastName, bool IsF)
        {
            if (null == obj)
            {
                if (IsF)
                {
                    FileOperate.FWrite("public string " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
                }
                else
                {
                    FileOperate.FWrite("public string " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + fastName + "Content.cs");
                }
                return;
            }
            var type = obj.GetType();

            if (type == typeof(int))
            {
                if (IsF)
                {
                    FileOperate.FWrite("public int " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
                }
                else
                {
                    FileOperate.FWrite("public int " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + fastName + "Content.cs");
                }

                return;
            }
            else if (type == typeof(string))
            {
                if (IsF)
                {
                    FileOperate.FWrite("public string " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
                }
                else
                {
                    FileOperate.FWrite("public string " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + fastName + "Content.cs");
                }

                return;
            }
            else if (type == typeof(bool))
            {
                if (IsF)
                {
                    FileOperate.FWrite("public bool " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
                }
                else
                {
                    FileOperate.FWrite("public bool " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + fastName + "Content.cs");
                }

                return;
            }
            else if (type == typeof(Dictionary <string, Object>))//键值对
            {
                Dictionary <string, Object> chi = obj as Dictionary <string, Object>;
                List <string> keys = chi.Keys.ToList();
                if (IsF)
                {
                    FileOperate.FWrite("public " + fileName + "Content  " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
                }
                else
                {
                    FileOperate.FWrite("public " + fileName + "Content  " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + fastName + "Content.cs");
                }
                FileOperate.FWrite("using System;\r\nusing System.Collections.Generic;\r\nnamespace " + ModelName.Text.Trim() + "\r\n{\r\npublic class " + fileName + "Content\r\n{\r\n", "" + subPath + "\\" + fileName + "Content.cs");
                int i = 0;
                foreach (var s in keys)
                {
                    i++;
                    findNode(chi[s], s, fileName, false);
                    if (i == keys.Count)
                    {
                        FileOperate.FWrite("}\r\n}\r\n", "" + subPath + "\\" + fileName + "Content.cs");
                    }
                }
            }
            else //集合
            {
                Object[] objArr = obj as Object[];
                Dictionary <string, Object> chi = objArr[0] as Dictionary <string, Object>;
                List <string> keys = chi.Keys.ToList();
                if (IsF)
                {
                    FileOperate.FWrite("public List<" + fileName + "Content>  " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + TableName + ".cs");
                }
                else
                {
                    FileOperate.FWrite("public List<" + fileName + "Content>  " + fileName + "  {get;set;}\r\n", "" + subPath + "\\" + fastName + "Content.cs");
                }
                FileOperate.FWrite("using System;\r\nusing System.Collections.Generic;\r\nnamespace " + ModelName.Text.Trim() + "\r\n{\r\npublic class " + fileName + "Content\r\n{\r\n", "" + subPath + "\\" + fileName + "Content.cs");
                int i = 0;
                foreach (var s in keys)
                {
                    i++;

                    findNode(chi[s], s, fileName, false);
                    if (i == keys.Count)
                    {
                        FileOperate.FWrite("}\r\n}\r\n", "" + subPath + "\\" + fileName + "Content.cs");
                    }
                }
            }
        }