예제 #1
0
        public bool Connect(String pass, out bool ConnToDbSuccess, out bool ConnToXmlSuccess)
        {
            xp = new XmlParser(path);

            db = new DataBase();

            this.dbPass = pass;
            if (!db.ConnectToDb(dbName, dbPass))
            {
                ConnToDbSuccess  = false;
                ConnToXmlSuccess = true;
                return(false);
            }
            else
            {
                ConnToDbSuccess = true;
            }


            if (xp.getFile())
            {
                TotalInfo ti = xp.ParseFile();

                db.CreateTables();
                db.FillTables(ti);

                ConnToXmlSuccess = true;
            }
            else
            {
                ConnToXmlSuccess = false;
            }
            return(true);
        }
예제 #2
0
        public bool Update()
        {
            if (xp.getFile())
            {
                TotalInfo ti = xp.ParseFile();

                db.CreateTables();
                db.FillTables(ti);
                return(true);
            }
            return(false);
        }
예제 #3
0
        public void FillTables(TotalInfo totalInfo)
        {
            // fill date
            this.InsertIntoWithValues("date",
                                      new List <String> {
                "date"
            },
                                      new List <String> {
                totalInfo.Date
            });

            // fill org_type
            foreach (OrgType ot in totalInfo.orgTypes)
            {
                this.InsertIntoWithValues("org_type",
                                          new List <String> {
                    "org_type_id", "org_type_title"
                },
                                          new List <String> {
                    ot.id.ToString(), ot.title
                });
            }

            // fill region
            foreach (Region r in totalInfo.regions)
            {
                this.InsertIntoWithValues("region",
                                          new List <String> {
                    "region_id", "region_title"
                },
                                          new List <String> {
                    r.region_id, r.title
                });
            }

            // fill city
            foreach (City c in totalInfo.cities)
            {
                this.InsertIntoWithValues("city",
                                          new List <String> {
                    "city_id", "city_title"
                },
                                          new List <string> {
                    c.city_id, c.title
                });
            }

            // fill curr_info
            foreach (CurrInfo ci in totalInfo.currenciesInfo)
            {
                this.InsertIntoWithValues("curr_info",
                                          new List <String> {
                    "eng_title", "rus_title"
                },
                                          new List <String> {
                    ci.eng_id, ci.title
                });
            }

            // fill organization

            foreach (Organisation org in totalInfo.organisations)
            {
                int org_id = this.InsertIntoWithValues("organization",
                                                       new List <String> {
                    "org_type_id",
                    "title",
                    "phone",
                    "address",
                    "region_id",
                    "city_id",
                },

                                                       new List <String> {
                    org.org_type.ToString(),
                    org.title,
                    org.phone,
                    org.address,
                    org.region_id,
                    org.city_id,
                });

                Console.WriteLine("ID - " + org_id);

                foreach (Currency curr in org.currencies)
                {
                    int curr_id = this.InsertIntoWithValues("currency",
                                                            new List <String> {
                        "curr_id",
                        "purchase",
                        "sale"
                    },
                                                            new List <string> {
                        curr.eng_id,
                        curr.purchase,
                        curr.sale
                    });

                    String update = "UPDATE currency SET org_id = " + org_id + " WHERE id = " + curr_id + ";";

                    Console.WriteLine(update);

                    cmd.CommandText = update;
                    cmd.ExecuteNonQuery();
                }
            }
        }
예제 #4
0
        public TotalInfo ParseFile()
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(filePath);

            TotalInfo totalInfo = new TotalInfo();

            // получим корневой элемент
            XmlElement xRoot = xDoc.DocumentElement;

            totalInfo.Date = xRoot.GetAttribute("date");
            // обход всех узлов в корневом элементе
            foreach (XmlNode xnode in xRoot)
            {
                // go through organosations
                if (xnode.Name == "organizations")
                {
                    List <Organisation> orgList = new List <Organisation>(0);

                    foreach (XmlNode organisation in xnode)
                    {
                        Organisation org = new Organisation();

                        XmlNode org_id   = organisation.Attributes.GetNamedItem("id");
                        XmlNode org_type = organisation.Attributes.GetNamedItem("org_type");

                        XmlNode title     = organisation["title"].Attributes.GetNamedItem("value");
                        XmlNode region_id = organisation["region"].Attributes.GetNamedItem("id");
                        XmlNode city_id   = organisation["city"].Attributes.GetNamedItem("id");
                        XmlNode phone     = organisation["phone"].Attributes.GetNamedItem("value");
                        XmlNode address   = organisation["address"].Attributes.GetNamedItem("value");


                        if (org_id != null && org_type != null && title != null &&
                            region_id != null && city_id != null && phone != null && address != null)
                        {
                            org.org_id    = org_id.Value;
                            org.org_type  = int.Parse(org_type.Value);
                            org.title     = title.Value;
                            org.region_id = region_id.Value;
                            org.city_id   = city_id.Value;
                            org.phone     = phone.Value;
                            org.address   = address.Value;
                        }

                        List <Currency> currList = new List <Currency>(0);

                        foreach (XmlNode currencies in organisation)
                        {
                            if (currencies.Name == "currencies")
                            {
                                Currency curr = new Currency();
                                foreach (XmlNode c in currencies)
                                {
                                    XmlNode eng_id   = c.Attributes.GetNamedItem("id");
                                    XmlNode purchase = c.Attributes.GetNamedItem("br");
                                    XmlNode sale     = c.Attributes.GetNamedItem("ar");

                                    if (eng_id != null &&
                                        purchase != null &&
                                        sale != null)
                                    {
                                        curr.eng_id   = eng_id.Value;
                                        curr.purchase = purchase.Value;
                                        curr.sale     = sale.Value;
                                    }
                                    currList.Add(curr);
                                }
                            }
                        }

                        org.currencies = currList;
                        orgList.Add(org);
                    }
                    totalInfo.organisations = orgList;
                }

                if (xnode.Name == "org_types")
                {
                    List <OrgType> orgTypeList = new List <OrgType>(0);

                    foreach (XmlNode orgType in xnode)
                    {
                        OrgType orgTypeStruct = new OrgType();

                        XmlNode id    = orgType.Attributes.GetNamedItem("id");
                        XmlNode title = orgType.Attributes.GetNamedItem("title");

                        if (id != null && title != null)
                        {
                            orgTypeStruct.id    = int.Parse(id.Value);
                            orgTypeStruct.title = title.Value;
                        }

                        orgTypeList.Add(orgTypeStruct);
                    }

                    totalInfo.orgTypes = orgTypeList;
                }

                if (xnode.Name == "currencies")
                {
                    List <CurrInfo> currInfoList = new List <CurrInfo>(0);

                    foreach (XmlNode curr in xnode)
                    {
                        CurrInfo currInfo = new CurrInfo();

                        XmlNode eng_id = curr.Attributes.GetNamedItem("id");
                        XmlNode title  = curr.Attributes.GetNamedItem("title");

                        if (eng_id != null && title != null)
                        {
                            currInfo.eng_id = eng_id.Value;
                            currInfo.title  = title.Value;

                            //db.InsertIntoWithValues("curr_info", new List<String> { "eng_title", "rus_title" },
                            //                                    new List<String> { eng_id.Value, title.Value });
                        }

                        currInfoList.Add(currInfo);
                    }

                    totalInfo.currenciesInfo = currInfoList;
                }

                if (xnode.Name == "regions")
                {
                    List <Region> regList = new List <Region>(0);

                    foreach (XmlNode reg in xnode)
                    {
                        Region regStruct = new Region();

                        XmlNode region_id = reg.Attributes.GetNamedItem("id");
                        XmlNode title     = reg.Attributes.GetNamedItem("title");

                        if (region_id != null && title != null)
                        {
                            regStruct.region_id = region_id.Value;
                            regStruct.title     = title.Value;

                            //db.InsertIntoWithValues("region",
                            //    new List<String> { "region_id" , "title" },
                            //    new List<String> { region_id.Value, title.Value });
                        }

                        regList.Add(regStruct);
                    }

                    totalInfo.regions = regList;
                }

                if (xnode.Name == "cities")
                {
                    List <City> cityList = new List <City>(0);

                    foreach (XmlNode city in xnode)
                    {
                        City cityStruct = new City();

                        XmlNode city_id = city.Attributes.GetNamedItem("id");
                        XmlNode title   = city.Attributes.GetNamedItem("title");

                        if (city_id != null && title != null)
                        {
                            cityStruct.city_id = city_id.Value;
                            cityStruct.title   = title.Value;

                            //db.InsertIntoWithValues("city",
                            //    new List<String> { "city_id", "title" },
                            //    new List<String> { city_id.Value, title.Value });
                        }

                        cityList.Add(cityStruct);
                    }

                    totalInfo.cities = cityList;
                }
            }

            return(totalInfo);
        }