Esempio n. 1
0
        protected override void Act()
        {
            if (!Checker.IsNumber(textBox1.Text))
            {
                MessageBox.Show("Неверный номер квартиры");
                return;
            }
            int  ind = dataGridView1.SelectedRows[0].Index;
            int  id  = 0;
            bool ok  = int.TryParse(dataGridView1[Program.FindTitle(dataGridView1, "Id"), ind].Value.ToString(), out id);

            if (!ok)
            {
                return;
            }
            if (ActionMode == ActionMode.Add)
            {
                if (Operations.AddAddress(int.Parse(textBox1.Text), Operations.FindHouse(id), out string Res))
                {
                    Close();
                }
                MessageBox.Show(Res);
            }
            else
            {
                if (Operations.ChangeAddress(Id, int.Parse(textBox1.Text), Operations.FindHouse(id), out string Res))
                {
                    Close();
                }
                MessageBox.Show(Res);
            }
        }
Esempio n. 2
0
        public void Update()
        {
            Operations.InicializeNextId();
            int idx = Operations.NextId[EntityTypes.City];
            Dictionary <int, int> CityIndices = new Dictionary <int, int>();

            foreach (_City c in CitySet)
            {
                if (Operations.AddCity(c.Name, out string Res))
                {
                    CityIndices.Add(c.Id, ++idx);
                }
                else
                {
                    CityIndices.Add(c.Id, (from p in Operations.cont.CitySet where p.Name == c.Name select p.Id).First());
                }
            }
            Dictionary <int, int> StreetIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Street];
            foreach (_Street s in StreetSet)
            {
                int cid = CityIndices[s.CityId];
                if (Operations.AddStreet(s.Name, Operations.FindCity(cid), out string Res))
                {
                    StreetIndices.Add(s.Id, ++idx);
                }
                else
                {
                    StreetIndices.Add(s.Id, (from p in Operations.cont.StreetSet where p.Name == s.Name && p.City.Id == cid select p.Id).First());
                }
            }
            Dictionary <int, int> HouseIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.House];
            foreach (_House h in HouseSet)
            {
                int sid = StreetIndices[h.StreetId];
                if (Operations.AddHouse(h.Number, Operations.FindStreet(sid), out string Res))
                {
                    HouseIndices.Add(h.Id, ++idx);
                }
                else
                {
                    HouseIndices.Add(h.Id, (from p in Operations.cont.HouseSet where p.Number == h.Number && p.Street.Id == sid select p.Id).First());
                }
            }
            Dictionary <int, int> AddressesIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Address];
            foreach (_Address a in AddressSet)
            {
                int hid = HouseIndices[a.HouseId];
                if (Operations.AddAddress(a.Flat, Operations.FindHouse(hid), out string Res))
                {
                    AddressesIndices.Add(a.Id, ++idx);
                }
                else
                {
                    AddressesIndices.Add(a.Id, (from p in Operations.cont.AddressSet where p.Flat == a.Flat && p.House.Id == hid select p.Id).First());
                }
            }
            Dictionary <int, int> UserIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.User];
            foreach (_User u in UserSet)
            {
                if (Operations.AddUser(u.UserType, u.Login, u.Password, out string Res))
                {
                    UserIndices.Add(u.Id, ++idx);
                }
                else
                {
                    UserIndices.Add(u.Id, (from p in Operations.cont.UserSet where p.Login == u.Login select p.Id).First());
                }
            }
            Dictionary <int, int> MeterTypeindices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.MeterType];
            foreach (_MeterType m in MeterTypeSet)
            {
                if (Operations.AddMeterType(m.Name, out string Res))
                {
                    MeterTypeindices.Add(m.Id, ++idx);
                }
                else
                {
                    MeterTypeindices.Add(m.Id, (from p in Operations.cont.MeterTypeSet where p.Name == m.Name select p.Id).First());
                }
            }
            Dictionary <int, int> MeterIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Meter];
            foreach (_Meter m in MeterSet)
            {
                int mt = MeterTypeindices[m.MeterTypeId];
                if (Operations.AddMeter(m.Name, Operations.FindMeterType(mt), out string Res))
                {
                    MeterIndices.Add(m.Id, ++idx);
                }
                else
                {
                    MeterIndices.Add(m.Id, (from p in Operations.cont.MeterSet where p.Name == m.Name && p.MeterType.Id == mt select p.Id).First());
                }
            }
            Dictionary <int, int> PersonIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Person];
            foreach (_Person p in PersonSet)
            {
                if (Operations.AddPerson(p.FIO, out string Res))
                {
                    PersonIndices.Add(p.Id, ++idx);
                }
                else
                {
                    PersonIndices.Add(p.Id, (from q in Operations.cont.PersonSet where q.FIO == p.FIO select q.Id).First());
                }
            }
            Dictionary <int, int> StavkaIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Stavka];
            foreach (_Stavka s in StavkaSet)
            {
                int mt  = MeterTypeindices[s.MeterTypeId];
                int pid = PersonIndices[s.PersonId];
                if (Operations.AddStavka(Operations.FindMeterType(mt), Operations.FindPerson(pid), out string Res))
                {
                    StavkaIndices.Add(s.Id, ++idx);
                }
                else
                {
                    StavkaIndices.Add(s.Id, (from p in Operations.cont.StavkaSet where p.MeterType.Id == mt && p.Person.Id == pid select p.Id).First());
                }
            }
            Dictionary <int, int> CustomerIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Customer];
            foreach (_Customer c in CustomerSet)
            {
                if (c is _Company m)
                {
                    if (Operations.AddCompany(m.FIO, m.Passport, m.PhoneNumber, m.CompanyName, m.INN, out string Res))
                    {
                        CustomerIndices.Add(m.Id, ++idx);
                    }
                    else
                    {
                        CustomerIndices.Add(m.Id, (from p in Operations.cont.CustomerSet where p is Company && (p as Company).INN == m.INN select p.Id).First());
                    }
                }
                else
                {
                    if (Operations.AddCustomer(c.FIO, c.Passport, c.PhoneNumber, out string Res))
                    {
                        CustomerIndices.Add(c.Id, ++idx);
                    }
                    else
                    {
                        CustomerIndices.Add(c.Id, (from p in Operations.cont.CustomerSet where !(p is Company) && p.Passport == c.Passport select p.Id).First());
                    }
                }
            }
            Dictionary <int, int> OrderIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Order];
            foreach (_Order o in OrderSet)
            {
                int uid = UserIndices[o.UserId];
                int cid = CustomerIndices[o.CustomerId];
                int aid = AddressesIndices[o.AddressId];
                Operations.AddOrder(Operations.FindUser(uid), Operations.FindCustomer(cid),
                                    Operations.FindAddress(aid), out string Res, out int id, ++idx);
                OrderIndices.Add(o.Id, idx);
            }
            Dictionary <int, int> StatusIndices = new Dictionary <int, int>();

            idx = Operations.NextId[EntityTypes.Status];
            foreach (_Status s in StatusSet)
            {
                if (Operations.AddStatus(s.Name, out string res))
                {
                    StatusIndices[s.Id] = ++idx;
                }
                else
                {
                    StatusIndices[s.Id] = (from p in Operations.cont.StatusSet where p.Name == s.Name select p.Id).First();
                }
            }
            foreach (_OrderEntry o in OrderEntrySet)
            {
                int oid = OrderIndices[o.OrderId];
                int mid = MeterIndices[o.MeterId];
                int pid = o.PersonId != null ? PersonIndices[(int)o.PersonId] : -1;
                int sid = StatusIndices[o.StatusId];
                Operations.AddOrderEntry(Operations.FindOrder(oid), o.startTime, o.endTime, o.RegNum, Operations.FindMeter(mid),
                                         o.PersonId != null ? Operations.FindPerson(pid) : null, Operations.FindStatus(sid), out string Res);
            }
        }
Esempio n. 3
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (address1 != null)
     {
         Operations.cont.AddressSet.Load();
         Operations.cont.HouseSet.Load();
         Operations.cont.StreetSet.Load();
         Operations.cont.CitySet.Load();
         Operations.cont.CustomerSet.Load();
         int cityid;
         if (!Operations.SelectCitys((s) => s.Name == city1.Name).Any())
         {
             if (!Operations.AddCity(city1.Name, out string Res))
             {
                 MessageBox.Show(Res);
                 return;
             }
         }
         cityid = Operations.SelectCitys((s) => s.Name == city1.Name).First().Id;
         int streetid;
         if (!Operations.SelectStreets((s) => s.Name == street1.Name && s.City.Id == cityid).Any())
         {
             if (!Operations.AddStreet(street1.Name, Operations.FindCity(cityid), out string Res))
             {
                 MessageBox.Show(Res);
                 return;
             }
         }
         streetid = Operations.SelectStreets((s) => s.Name == street1.Name && s.City.Id == cityid).First().Id;
         int houseid;
         if (!Operations.SelectHouses((s) => s.Number == house1.Number && s.Street.Id == streetid).Any())
         {
             if (!Operations.AddHouse(house1.Number, Operations.FindStreet(streetid), out string Res))
             {
                 MessageBox.Show(Res);
                 return;
             }
         }
         houseid = Operations.SelectHouses((s) => s.Number == house1.Number && s.Street.Id == streetid).First().Id;
         int addressid;
         if (!Operations.SelectAddresss((s) => s.Flat == address1.Flat && s.House.Id == houseid).Any())
         {
             if (!Operations.AddAddress(address1.Flat, Operations.FindHouse(houseid), out string Res))
             {
                 MessageBox.Show(Res);
                 return;
             }
         }
         addressid = Operations.SelectAddresss((s) => s.Flat == address1.Flat && s.House.Id == houseid).First().Id;
         int customerid;
         if (customer1 is _Company comp)
         {
             if (!Operations.SelectCustomers((s) => (s is Company) && (s as Company).INN == (comp.INN)).Any())
             {
                 if (!Operations.AddCompany(comp.FIO, comp.Passport, comp.PhoneNumber, comp.CompanyName, comp.INN, out string Res))
                 {
                     MessageBox.Show(Res);
                     return;
                 }
             }
             customerid = Operations.SelectCustomers((s) => (s is Company) && (s as Company).INN == (comp.INN)).First().Id;
         }
         else
         {
             if (!Operations.SelectCustomers((s) => !(s is Company) && s.Passport == customer1.Passport).Any())
             {
                 if (!Operations.AddCustomer(customer1.FIO, customer1.Passport, customer1.PhoneNumber, out string Res))
                 {
                     MessageBox.Show(Res);
                     return;
                 }
             }
             customerid = Operations.SelectCustomers((s) => !(s is Company) && s.Passport == customer1.Passport).First().Id;
         }
         if (!Operations.AddOrder(CurrentUser, Operations.FindCustomer(customerid), Operations.FindAddress(addressid), out string Res1, out int orderid))
         {
             MessageBox.Show(Res1);
             return;
         }
         List <_OrderEntry> list = dataGridView1.DataSource as List <_OrderEntry>;
         if (list == null)
         {
             MessageBox.Show("Не удалось загрузить список заказных позиций");
             return;
         }
         foreach (_OrderEntry ord in list)
         {
             Meter meter = Operations.FindMeter(ord.MeterId);
             if (meter == null)
             {
                 MessageBox.Show("Не удалось найти счётчик");
                 break;
             }
             if (!Operations.AddOrderEntry(Operations.FindOrder(orderid), ord.startTime, ord.endTime, null, meter, null, Operations.FindStatus(1), out string Res))
             {
                 MessageBox.Show(Res);
                 break;
             }
         }
         MessageBox.Show("Добавлен заказ номер" + orderid);
     }
 }
Esempio n. 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            Customer customer;

            if (radioButton2.Checked)
            {
                if (!Checker.IsFIO(NameTextBox.Text))
                {
                    MessageBox.Show("Неверное ФИО заказчика");
                    return;
                }
                if (!Checker.IsPhoneNumber(PhoneNumberTextBox.Text))
                {
                    MessageBox.Show("Неверный номер телефона");
                    return;
                }
                if (!Checker.IsPassportNumber(PassportTextBox.Text))
                {
                    MessageBox.Show("Неверный номер пасспорта");
                    return;
                }
                if (!BCompany)
                {
                    if (!Operations.AddCustomer(NameTextBox.Text, PassportTextBox.Text, PhoneNumberTextBox.Text, out string Res))
                    {
                        MessageBox.Show(Res);
                        return;
                    }
                    customer = (from c in Operations.cont.CustomerSet where !(c is Company) && c.Passport == PassportTextBox.Text select c).First();
                }
                else
                {
                    if (!Checker.IsName(CompanyNameTextBox.Text))
                    {
                        MessageBox.Show("Неверная строка названия компании");
                        return;
                    }
                    if (!Checker.IsINN(INNTextBox.Text))
                    {
                        MessageBox.Show("Неверный ИНН компании");
                        return;
                    }
                    if (!Operations.AddCompany(NameTextBox.Text, PassportTextBox.Text, PhoneNumberTextBox.Text, CompanyNameTextBox.Text, INNTextBox.Text, out string Res))
                    {
                        MessageBox.Show(Res);
                        return;
                    }
                    customer = (from c in Operations.cont.CustomerSet where c is Company && (c as Company).INN == INNTextBox.Text select c).First();
                }
            }
            else
            {
                int id = int.Parse(CustomerDataGridView[Program.FindTitle(CustomerDataGridView, "Id"), CustomerDataGridView.SelectedRows[0].Index].Value.ToString());
                if (!BCompany)
                {
                    customer = Operations.FindCustomer(id);
                }
                else
                {
                    customer = Operations.FindCompany(id);
                }
            }
            if (city == null)
            {
                if (!Checker.IsName(CityTextBox.Text))
                {
                    MessageBox.Show("Неверное название города");
                    return;
                }
                if (!Operations.AddCity(CityTextBox.Text, out string Res))
                {
                    MessageBox.Show(Res);
                    return;
                }
                city = (from p in Operations.cont.CitySet where p.Name == CityTextBox.Text select p).First();
            }
            if (street == null)
            {
                if (!Checker.IsName(StreetTextBox.Text))
                {
                    MessageBox.Show("Неверное название улицы");
                    return;
                }
                if (!Operations.AddStreet(StreetTextBox.Text, city, out string Res1))
                {
                    MessageBox.Show(Res1);
                    return;
                }
                street = (from p in city.Street where p.Name == StreetTextBox.Text select p).First();
            }
            if (house == null)
            {
                if (!Checker.IsHouseNumber(HouseTextBox.Text))
                {
                    MessageBox.Show("Неверный номер дома");
                    return;
                }
                if (!Operations.AddHouse(HouseTextBox.Text, street, out string res2))
                {
                    MessageBox.Show(res2);
                    return;
                }
                house = (from p in street.House where p.Number == HouseTextBox.Text select p).First();
            }
            if (address == null)
            {
                if (!Checker.IsNumber(AddressTextBox.Text))
                {
                    MessageBox.Show("Неверный номер квартиры");
                    return;
                }
                if (!Operations.AddAddress(int.Parse(AddressTextBox.Text), house, out string Res4))
                {
                    MessageBox.Show(Res4);
                    return;
                }
                address = (from p in house.Address where p.Flat == int.Parse(AddressTextBox.Text) select p).First();
            }
            if (!Operations.AddOrder(CurrentUser, customer, address, out string res, out int order))
            {
                MessageBox.Show(res);
                return;
            }
            foreach (_OrderEntry o in OrderEntryList)
            {
                if (!Operations.AddOrderEntry(Operations.FindOrder(order), o.startTime, o.endTime, o.RegNum, Operations.FindMeter(o.MeterId), null, Operations.FindStatus(1), out string Res2))
                {
                    MessageBox.Show(Res2);
                    return;
                }
            }
            MessageBox.Show("Успешно добавлен заказ №" + order);
        }