Esempio n. 1
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     if (departmentInput.Text.Length > 0)
     {
         try
         {
             context.floor.Add(new floor((byte)numberInput.Value, departmentInput.Text));
             context.SaveChanges();
             this.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show("Ошибка добавления: " + ex.Message);
         }
     }
     else
     {
         MessageBox.Show("Некорректные данные");
     }
 }
Esempio n. 2
0
 private void submitButton_Click(object sender, EventArgs e)
 {
     if (nameInput.Text.Length > 0 && contactFNInput.Text.Length > 0 && contactLNInput.Text.Length > 0 && contactMNInput.Text.Length > 0 && PhoneInput.Text.Length > 0)
     {
         if (!mode)
         {
             try
             {
                 context.firm.Find(id).Update(new firm(nameInput.Text, PhoneInput.Text, contactFNInput.Text, contactLNInput.Text, contactMNInput.Text));
                 context.SaveChanges();
                 Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка изменения: " + ex.Message);
             }
         }
         else
         {
             try
             {
                 context.firm.Add(new firm(nameInput.Text, PhoneInput.Text, contactFNInput.Text, contactLNInput.Text, contactMNInput.Text));
                 context.SaveChanges();
                 Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка добавления: " + ex.Message);
             }
         }
     }
     else
     {
         MessageBox.Show("Некорректные данные");
     }
 }
Esempio n. 3
0
 private void submitButton_Click(object sender, EventArgs e)
 {
     if (nameInput.Text.Length > 0 && lastNameInput.Text.Length > 0 && middleNameInput.Text.Length > 0 && phoneNumberInput.Text.Length > 0 && addressInput.Text.Length > 0)
     {
         if (!mode)
         {
             try
             {
                 context.person.Find(id).Update(new person(nameInput.Text, lastNameInput.Text, middleNameInput.Text, phoneNumberInput.Text, addressInput.Text));
                 context.SaveChanges();
                 Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка изменения: " + ex.Message);
             }
         }
         else
         {
             try
             {
                 context.person.Add(new person(nameInput.Text, lastNameInput.Text, middleNameInput.Text, phoneNumberInput.Text, addressInput.Text));
                 context.SaveChanges();
                 Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка добавления: " + ex.Message);
             }
         }
     }
     else
     {
         MessageBox.Show("Некорретные данные");
     }
 }
Esempio n. 4
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            switch (changeTable.SelectedIndex)
            {
            case 0:
            {
                if (DialogResult.Yes == MessageBox.Show("Вы уверены, что хотите удалить эту запись?", "Предупреждение", MessageBoxButtons.YesNo))
                {
                    for (int i = 0; i < infoDGV.SelectedRows.Count; i++)
                    {
                        short number = Convert.ToInt16(infoDGV.SelectedRows[i].Cells[0].Value);
                        byte  floor  = Convert.ToByte(infoDGV.SelectedRows[i].Cells[2].Value);
                        context.classroom.Remove(context.classroom.Find((from c in context.classroom
                                                                         where c.number == number &&
                                                                         c.floor_number == floor
                                                                         select c.id).FirstOrDefault()));
                    }
                }
                break;
            }

            case 1:
            {
                if (DialogResult.Yes == MessageBox.Show("Вы уверены, что хотите удалить эту запись?", "Предупреждение", MessageBoxButtons.YesNo))
                {
                    for (int i = 0; i < infoDGV.SelectedRows.Count; i++)
                    {
                        byte num = Convert.ToByte(infoDGV.SelectedRows[i].Cells[0].Value);
                        context.floor.Remove(context.floor.Find(num));
                    }
                }
                break;
            }

            case 2:
            {
                if (DialogResult.Yes == MessageBox.Show("Вы уверены, что хотите удалить эту запись?", "Предупреждение", MessageBoxButtons.YesNo))
                {
                    for (int i = 0; i < infoDGV.SelectedRows.Count; i++)
                    {
                        string name      = infoDGV.SelectedRows[i].Cells[0].Value.ToString();
                        string phone     = infoDGV.SelectedRows[i].Cells[1].Value.ToString();
                        string contactFN = infoDGV.SelectedRows[i].Cells[2].Value.ToString();
                        string contactLN = infoDGV.SelectedRows[i].Cells[3].Value.ToString();
                        string contactMN = infoDGV.SelectedRows[i].Cells[4].Value.ToString();
                        context.firm.Remove(context.firm.Find((from f in context.firm
                                                               where f.name == name &&
                                                               f.contact_phone_number == phone &&
                                                               f.contact_first_name == contactFN &&
                                                               f.contact_last_name == contactLN &&
                                                               f.contact_middle_name == contactMN
                                                               select f.id).FirstOrDefault()));
                    }
                }
                break;
            }

            case 3:
            {
                if (DialogResult.Yes == MessageBox.Show("Вы уверены, что хотите удалить эту(и) запись(и)?", "Предупреждение", MessageBoxButtons.YesNo))
                {
                    for (int i = 0; i < infoDGV.SelectedRows.Count; i++)
                    {
                        string firstName  = infoDGV.SelectedRows[i].Cells[0].Value.ToString();
                        string lastName   = infoDGV.SelectedRows[i].Cells[1].Value.ToString();
                        string middleName = infoDGV.SelectedRows[i].Cells[2].Value.ToString();
                        context.person.Remove(context.person.Find((from p in context.person
                                                                   where p.first_name == firstName &&
                                                                   p.last_name == lastName &&
                                                                   p.middle_name == middleName
                                                                   select p.id).FirstOrDefault()));
                    }
                }
                break;
            }

            case 4:
            {
                if (DialogResult.Yes == MessageBox.Show("Вы уверены, что хотите удалить эту запись?", "Предупреждение", MessageBoxButtons.YesNo))
                {
                    for (int i = 0; i < infoDGV.SelectedRows.Count; i++)
                    {
                        string   firmName    = infoDGV.SelectedRows[i].Cells[0].Value.ToString();
                        byte     floorNumber = Convert.ToByte(infoDGV.SelectedRows[i].Cells[1].Value);
                        DateTime startDate   = Convert.ToDateTime(infoDGV.SelectedRows[i].Cells[2].Value);
                        DateTime endDate     = Convert.ToDateTime(infoDGV.SelectedRows[i].Cells[3].Value);
                        decimal  sum         = Convert.ToDecimal(infoDGV.SelectedRows[i].Cells[4].Value);
                        context.act_of_renting.Remove(context.act_of_renting.Find((from aor in context.act_of_renting
                                                                                   join fr in context.firm on aor.firm_id equals fr.id
                                                                                   where fr.name == firmName &&
                                                                                   aor.floor_number == floorNumber &&
                                                                                   aor.start_date == startDate &&
                                                                                   aor.end_date == endDate &&
                                                                                   aor.sum_of_money == sum
                                                                                   select aor.id).FirstOrDefault()));
                    }
                }
                break;
            }

            default:
            {
                throw new Exception("Выход за предел выбора таблиц");
            }
            }
            context.SaveChanges();
            renderDGV();
        }
 private void submitButton_Click(object sender, EventArgs e)
 {
     if (firmCB.SelectedItem != null)
     {
         if (!mode)
         {
             try
             {
                 string[] name   = firmCB.SelectedItem.ToString().Split(';');
                 string   fname  = name[0];
                 string   phone  = name[1];
                 string   cnamef = name[2];
                 string   cnamel = name[3];
                 string   cnamem = name[4];
                 long     idFirm = (from f in context.firm
                                    where f.name == fname &&
                                    f.contact_phone_number == phone &&
                                    f.contact_first_name == cnamef &&
                                    f.contact_last_name == cnamel &&
                                    f.contact_middle_name == cnamem
                                    select f.id).FirstOrDefault();
                 context.act_of_renting.Find(id).Update(new act_of_renting(idFirm, (byte)floorInput.Value, startSateDTP.Value, endDateDTP.Value, sumInput.Value));
                 context.SaveChanges();
                 Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка изменения: " + ex.Message);
             }
         }
         else
         {
             try
             {
                 string[] name   = firmCB.SelectedItem.ToString().Split(';');
                 string   fname  = name[0];
                 string   phone  = name[1];
                 string   cnamef = name[2];
                 string   cnamel = name[3];
                 string   cnamem = name[4];
                 long     idFirm = (from f in context.firm
                                    where f.name == fname &&
                                    f.contact_phone_number == phone &&
                                    f.contact_first_name == cnamef &&
                                    f.contact_last_name == cnamel &&
                                    f.contact_middle_name == cnamem
                                    select f.id).FirstOrDefault();
                 context.act_of_renting.Add(new act_of_renting(idFirm, (byte)floorInput.Value, startSateDTP.Value, endDateDTP.Value, sumInput.Value));
                 context.SaveChanges();
                 Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка добавления: " + ex.Message);
             }
         }
     }
     else
     {
         MessageBox.Show("Некорректные данные");
     }
 }
Esempio n. 6
0
 private void submitButton_Click(object sender, EventArgs e)
 {
     if (responsibleP.SelectedItem != null)
     {
         if (!mode)
         {
             try
             {
                 string[] name     = responsibleP.SelectedItem.ToString().Split(';');
                 string   namef    = name[0];
                 string   namel    = name[1];
                 string   namem    = name[2];
                 string   phone    = name[3];
                 string   address  = name[4];
                 long     idPerson = (from p in context.person
                                      where p.first_name == namef &&
                                      p.last_name == namel &&
                                      p.middle_name == namem &&
                                      p.phone_number == phone &&
                                      p.address == address
                                      select p.id).FirstOrDefault();
                 context.classroom.Find(id).Update(new classroom((byte)floorInput.Value, idPerson, (short)numberInput.Value, (int)capacityInput.Value, safetyInput.Checked));
                 context.SaveChanges();
                 this.Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка изменения: " + ex.Message);
             }
         }
         else
         {
             try
             {
                 string[] name     = responsibleP.SelectedItem.ToString().Split(';');
                 string   namef    = name[0];
                 string   namel    = name[1];
                 string   namem    = name[2];
                 string   phone    = name[3];
                 string   address  = name[4];
                 long     idPerson = (from p in context.person
                                      where p.first_name == namef &&
                                      p.last_name == namel &&
                                      p.middle_name == namem &&
                                      p.phone_number == phone &&
                                      p.address == address
                                      select p.id).FirstOrDefault();
                 context.classroom.Add(new classroom((byte)floorInput.Value, idPerson, (short)numberInput.Value, (int)capacityInput.Value, safetyInput.Checked));
                 context.SaveChanges();
                 this.Close();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Ошибка добавления: " + ex.Message);
             }
         }
     }
     else
     {
         MessageBox.Show("Некорректные данные");
     }
 }