Exemple #1
0
        public static void BuildDb()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("Enum.xml");
            using (SqlConnection con = new SqlConnection(Properties.Settings.Default.bds13396338_dbConnectionString))
            {
                con.Open();
                var cmd = con.CreateCommand();
                cmd.CommandText = "truncate table tableEnum;truncate table tableEnumValue;";
                cmd.ExecuteNonQuery();
                StringBuilder sb = new StringBuilder("using System;\r\n");
                sb.AppendLine("using ZXModel.Models");
                sb.AppendLine("namespace ZXModel.NSEnum {");
                using (whateverDataContext dc = new whateverDataContext(con))
                {
                    XmlNodeList xmlNodeList = doc.SelectNodes("//root/enum");
                    List<TableEnumValue> values = new List<TableEnumValue>();
                    if (xmlNodeList != null)
                    {
                        foreach (XmlNode node in xmlNodeList)
                        {
                            foreach (XmlNode node2 in node.SelectNodes("values"))
                            {
                                TableEnum en = new TableEnum();
                                en.TabelName = node.Attributes["tableName"].Value;
                                en.FieldName = node2.Attributes["tableFiled"].Value;
                                dc.TableEnum.InsertOnSubmit(en);
                                dc.SubmitChanges();
                                sb.AppendLine("public partial class" + en.TabelName + " {");
                                sb.AppendLine("public enum Enum" + en.TabelName + en.FieldName + " {");

                                foreach (XmlNode node3 in node2.SelectNodes("value"))
                                {
                                    TableEnumValue vl = new TableEnumValue();
                                    vl.EnumId = en.Id;
                                    vl.EnumValue = int.Parse(node3.Attributes["value"].Value);
                                    vl.EnumDespValue = node3.Attributes["despValue"].Value;
                                    values.Add(vl);
                                    sb.AppendLine(vl.EnumDespValue + "=" + vl.EnumValue + ",");
                                }
                                sb.AppendLine("}");
                                sb.AppendLine("}");
                            }
                        }
                    }
                    if (values.Count > 0)
                        dc.TableEnumValue.InsertAllOnSubmit(values);
                    dc.SubmitChanges();
                }
                sb.AppendLine("}");
                File.WriteAllText(@"C:\Users\zhaoxin-pc\Documents\Visual Studio 2013\Projects\zxlovejyl\ZXModel\Common\EnumNS.cs", sb.ToString());
            }
        }
Exemple #2
0
        public static void BuildCode()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("Enum.xml");
            using (SqlConnection con = new SqlConnection(Properties.Settings.Default.bds13396338_dbConnectionString))
            {
                StringBuilder sb = new StringBuilder("using System;\r\n");
                sb.AppendLine("namespace ZXModel.Models {");
                XmlNodeList xmlNodeList = doc.SelectNodes("//root/enum");
                List<TableEnumValue> values = new List<TableEnumValue>();
                if (xmlNodeList != null)
                {
                    foreach (XmlNode node in xmlNodeList)
                    {
                        sb.AppendLine("public partial class " + node.Attributes["tableName"].Value + " { ");
                        foreach (XmlNode node2 in node.SelectNodes("values"))
                        {
                            TableEnum en = new TableEnum();
                            en.TabelName = node.Attributes["tableName"].Value;
                            en.FieldName = node2.Attributes["tableFiled"].Value;
                            sb.AppendLine("public enum Enum" + en.TabelName + en.FieldName + " {");

                            foreach (XmlNode node3 in node2.SelectNodes("value"))
                            {
                                TableEnumValue vl = new TableEnumValue();
                                vl.EnumId = en.Id;
                                vl.EnumValue = int.Parse(node3.Attributes["value"].Value);
                                vl.EnumDespValue = node3.Attributes["despValue"].Value;
                                values.Add(vl);
                                sb.AppendLine(vl.EnumDespValue + "=" + vl.EnumValue + ",");
                            }
                            sb.AppendLine("}");
                        }

                        sb.AppendLine("}");
                    }
                }
                sb.AppendLine("}");
                File.WriteAllText(@"C:\Users\zhaoxin-pc\Documents\Visual Studio 2013\Projects\zxlovejyl\ZXModel\Common\EnumNS.cs", sb.ToString());
            }
        }
 partial void UpdateTableEnum(TableEnum instance);
 partial void DeleteTableEnum(TableEnum instance);
 partial void InsertTableEnum(TableEnum instance);