Exemplo n.º 1
0
        private void toolStripButtonLishkaAdd_Click(object sender, EventArgs e)
        {
            FormLishka   formLishka = new FormLishka();
            DialogResult result     = formLishka.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Lishkat_Mana lishka = new Lishkat_Mana();
            int          lishkat_mana_code;
            bool         converted = Int32.TryParse(formLishka.textBoxLishkaCode.Text, out lishkat_mana_code);

            if (converted == false)
            {
                return;
            }
            lishka.Lishkat_Mana_Code = lishkat_mana_code;
            lishka.Lishkat_Mana_Name = formLishka.textBoxLishkaName.Text;

            db.Lishkot_Mana.Add(lishka);
            db.SaveChanges();

            MessageBox.Show("New object added");
        }
Exemplo n.º 2
0
        private void toolStripButtonLishkaEdit_Click(object sender, EventArgs e)
        {
            if (dataGridViewLishkot.SelectedRows.Count > 0)
            {
                int  index = dataGridViewLishkot.SelectedRows[0].Index;
                int  lishkat_mana_code;
                bool converted = Int32.TryParse(dataGridViewLishkot[0, index].Value.ToString(), out lishkat_mana_code);
                if (converted == false)
                {
                    return;
                }

                Lishkat_Mana lishka = db.Lishkot_Mana.Find(lishkat_mana_code);

                FormLishka formLishka = new FormLishka();
                formLishka.textBoxLishkaCode.Text    = lishka.Lishkat_Mana_Code.ToString();
                formLishka.textBoxLishkaName.Text    = lishka.Lishkat_Mana_Name;
                formLishka.textBoxLishkaCode.Enabled = false;

                DialogResult result = formLishka.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                lishka.Lishkat_Mana_Name = formLishka.textBoxLishkaName.Text;

                db.SaveChanges();

                dataGridViewLishkot.Refresh(); // обновляем грид

                MessageBox.Show("Object updated");
            }
        }
Exemplo n.º 3
0
        private void toolStripButtonLishkaRemove_Click(object sender, EventArgs e)
        {
            if (dataGridViewLishkot.SelectedRows.Count > 0)
            {
                int  index             = dataGridViewLishkot.SelectedRows[0].Index;
                int  lishkat_mana_code = 0;
                bool converted         = Int32.TryParse(dataGridViewLishkot[0, index].Value.ToString(), out lishkat_mana_code);
                if (converted == false)
                {
                    return;
                }

                Lishkat_Mana lishka = db.Lishkot_Mana.Find(lishkat_mana_code);
                db.Lishkot_Mana.Remove(lishka);
                db.SaveChanges();

                MessageBox.Show("Object removed");
            }
        }
Exemplo n.º 4
0
        private static void LoadCitiesFromXmlByXmlDocument(string fileName)
        {
            XmlDocument xmlDocument = new XmlDocument();

            List <Country_Region>   regions = new List <Country_Region>();
            List <Lishkat_Mana>     lishkot = new List <Lishkat_Mana>();
            List <Regional_Council> muacot  = new List <Regional_Council>();
            List <City>             cities  = new List <City>();

            SplashScreen.SetStatus("Loading XML " + fileName);
            xmlDocument.Load(fileName);
            SplashScreen.SetStatus(fileName + " XML Loaded");

            SplashScreen.SetStatus("Parsing XML");
            foreach (XmlNode node in xmlDocument.DocumentElement)
            {
                //foreach (XmlNode child in node.ChildNodes)
                //{
                //
                //}

                Country_Region region = new Country_Region
                {
                    Country_Region_Code = int.Parse(node.ChildNodes[4].InnerText),
                    Country_Region_Name = node.ChildNodes[5].InnerText.Trim()
                };
                if (!regions.Exists(x => x.Country_Region_Code == region.Country_Region_Code))
                {
                    regions.Add(region);
                }

                Lishkat_Mana lishka = new Lishkat_Mana
                {
                    Lishkat_Mana_Code = int.Parse(node.ChildNodes[6].InnerText),
                    Lishkat_Mana_Name = node.ChildNodes[7].InnerText.Trim()
                };
                if (!lishkot.Exists(x => x.Lishkat_Mana_Code == lishka.Lishkat_Mana_Code))
                {
                    lishkot.Add(lishka);
                }

                Regional_Council muaca = new Regional_Council
                {
                    Regional_Council_Code = int.Parse(node.ChildNodes[8].InnerText),
                    Regional_Council_Name = node.ChildNodes[9].InnerText.Trim()
                };
                if (!muacot.Exists(x => x.Regional_Council_Code == muaca.Regional_Council_Code))
                {
                    muacot.Add(muaca);
                }

                City city = new City
                {
                    //Table = node.ChildNodes[0].InnerText,
                    City_Code           = int.Parse(node.ChildNodes[1].InnerText),
                    City_Name           = node.ChildNodes[2].InnerText.Trim(),
                    City_Name_En        = node.ChildNodes[3].InnerText.Trim(),
                    Country_Region_Code = int.Parse(node.ChildNodes[4].InnerText),
                    //Region_name = node.ChildNodes[5].InnerText,
                    Lishkat_Mana_Code = int.Parse(node.ChildNodes[6].InnerText),
                    //Lishka_Name = node.ChildNodes[7].InnerText,
                    Regional_Council_Code = int.Parse(node.ChildNodes[8].InnerText),
                    //Muaca_Izorit_Name = node.ChildNodes[9].InnerText
                };
                if (!cities.Exists(x => x.City_Code == city.City_Code))
                {
                    cities.Add(city);
                }

                /*
                 * if (db.Country_Regions.Find(region.Country_Region_Code) == null)
                 *  db.Country_Regions.Add(region);
                 * //db.SaveChanges();
                 *
                 * if (db.Lishkot_Mana.Find(lishka.Lishkat_Mana_Code) == null)
                 *  db.Lishkot_Mana.Add(lishka);
                 * //db.SaveChanges();
                 *
                 * if (muaca.Regional_Council_Code != 0 || db.Regional_Councils.Find(muaca.Regional_Council_Code) == null)
                 *  db.Regional_Councils.Add(muaca);
                 * //db.SaveChanges();
                 *
                 * if (db.Cities.Find(city.City_Code) == null)
                 *  db.Cities.Add(city);
                 * //db.SaveChanges();
                 */
            }
            SplashScreen.SetStatus("XML Parsed");

            SplashScreen.SetStatus("Conecting to db");
            using (WorldGeoDataDB db = new WorldGeoDataDB())
            {
                SplashScreen.SetStatus("Ading data to DB");

                SplashScreen.SetStatus("Ading regions");
                db.Country_Regions.AddRange(regions);
                db.SaveChanges();
                SplashScreen.SetStatus("Country_Regions Added");

                SplashScreen.SetStatus("Ading lishkot");
                db.Lishkot_Mana.AddRange(lishkot);
                db.SaveChanges();
                SplashScreen.SetStatus("Lishkot_Mana Added");

                SplashScreen.SetStatus("Ading muacot");
                db.Regional_Councils.AddRange(muacot);
                db.SaveChanges();
                SplashScreen.SetStatus("Muacot Added");

                SplashScreen.SetStatus("Ading cities");
                db.Cities.AddRange(cities);
                db.SaveChanges();
                SplashScreen.SetStatus("Cities Added");
            }
        }