//добавляем начальные данные

        private void MainForm_Load(object sender, EventArgs e)
        {
            TypeBuilding type1 = new TypeBuilding("Shopping mall");
            TypeBuilding type2 = new TypeBuilding("Residential complex");
            TypeBuilding type3 = new TypeBuilding("Hotel");

            Building bild1 = new Building("Lavina", type1);
            Building bild2 = new Building("Millenium", type2);
            Building bild3 = new Building("Millenium State", type2);
            Building bild4 = new Building("Eleon", type3);
            Building bild5 = new Building("Hilton", type3);

            comp2.Add(bild2);
            comp2.Add(bild3);
            comp1.Add(bild1);
            comp3.Add(bild4);
            comp3.Add(bild5);

            Company.Load();
            TypeBuilding.Load();
            Building.Load();


            this.FormClosed += MainForm_FormClosed;
        }
 public void AddTyprBuilding(TypeBuilding g)
 {
     if (g != null)
     {
         TypeBuilding = g;
     }
 }
 private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     Company.Save();
     Building.Save();
     TypeBuilding.Save();
     Serialization(comp1);
     Serialization(comp2);
     Serialization(comp3);
 }
        public Building(string name, TypeBuilding g)
        {
            Name = name;

            if (g != null)
            {
                TypeBuilding = g;
            }
        }
        private void lbitems_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = 1;

            lbitems2.Items.Clear();
            //lbitems.Items.Clear();
            if (datchik == 1)
            {
                lbitems2.Items.Add("              Companies");
                try
                {
                    foreach (var s in p.GetByBuilding((Building)lbitems.SelectedItem))
                    {
                        lbitems2.Items.Add(i + ")" + s);
                        i++;
                    }
                }
                catch (Exception) { lbitems.SelectedItems.Clear(); }
            }
            if (datchik == 2)
            {
                i = 1;
                lbitems2.Items.Add("              Buildings");
                try
                {
                    foreach (var s in p.GetByOrganis((Company)lbitems.SelectedItem))
                    {
                        lbitems2.Items.Add(i + ")" + s);
                        i++;
                    }
                }
                catch (Exception) { lbitems.SelectedItems.Clear(); }
            }
            if (datchik == 3)
            {
                lbitems2.Items.Add("              Buildings");
                i = 1;
                try
                {
                    TypeBuilding t = (TypeBuilding)lbitems.SelectedItem;
                    foreach (var s in t.Buildings)
                    {
                        lbitems2.Items.Add(i + ")" + s);
                    }
                }
                catch (Exception) { lbitems.SelectedItems.Clear(); }
            }
        }
Ejemplo n.º 6
0
//список товаров

        private void lbBuildings_SelectedIndexChanged(object sender, EventArgs e)
        {
            Problems p = new Problems();
            Building t = (Building)lbBuildings.SelectedItem;

            if (rborg.Checked) //кнопочка компании
            {
                if ((Company)cbOrgs.SelectedItem != null && (Building)lbBuildings.SelectedItem != null)
                {
                    Company o = (Company)cbOrgs.SelectedItem;

                    bool b = true;
                    foreach (var s in p.GetByOrganis(o))
                    {
                        if (s.ToString().Equals(t.ToString()))
                        {
                            b = false;
                        }
                    }
                    if (b)
                    {
                        o.Add((Building)lbBuildings.SelectedItem);
                        MessageBox.Show(t.ToString() + " added to " + o.ToString(), " Massage");
                    }
                }
            }
            else if (rbtype.Checked) //кнопочка типа здания
            {
                TypeBuilding tt = (TypeBuilding)cbTupeBuilding.SelectedItem;
                bool         b  = true;
                if (tt != null && (Building)lbBuildings.SelectedItem != null)
                {
                    foreach (var s in tt.Buildings)
                    {
                        if (s.ToString().Equals(t.ToString()))
                        {
                            b = false;
                        }
                    }
                    if (b)
                    {
                        t.AddTyprBuilding(tt);
                        MessageBox.Show(t.ToString() + " added to " + tt.ToString(), " Massage");
                    }
                }
            }
        }
        private void btnDelet_Click(object sender, EventArgs e)
        {
            if (datchik == 1)
            {
                Building t = (Building)lbitems.SelectedItem;

                foreach (var s in p.GetByBuilding(t))
                {
                    s.list.Remove(t);
                }

                Building.Delete(t.ToString());
                Clear();
                lbitems.Items.Add("              Buildings");
                foreach (var s in Building.Items.Values.ToList())
                {
                    lbitems.Items.Add(s);
                }
            }

            if (datchik == 2)
            {
                Company o = (Company)lbitems.SelectedItem;
                Company.Delete(o.ToString());
                Clear();
                lbitems.Items.Add("              Companies");
                foreach (var s in Company.Items.Values.ToList())
                {
                    lbitems.Items.Add(s);
                }
            }

            if (datchik == 3)
            {
                TypeBuilding o = (TypeBuilding)lbitems.SelectedItem;
                TypeBuilding.Delete(o.ToString());
                Clear();
                lbitems.Items.Add("              Companies");
                foreach (var s in TypeBuilding.Items.Values.ToList())
                {
                    lbitems.Items.Add(s);
                }
            }
        }
Ejemplo n.º 8
0
        private void btnEditType_Click(object sender, EventArgs e)
        {
            if (tbtyp.Text != "")
            {
                TypeBuilding.Rename(lbTypeBuilding.SelectedItem.ToString(), tbtyp.Text);

                lbTypeBuilding.DataSource = null;
                lbTypeBuilding.DataSource = TypeBuilding.Items.Values.ToList();

                cbTupeBuilding.DataSource = null;
                cbTupeBuilding.DataSource = TypeBuilding.Items.Values.ToList();
            }
            else
            {
                MessageBox.Show("The field must not be empty", "Attention");
            }

            tbtyp.Text = null;
        }