public void AddCleanWorks() { try { _connect.cleaning_works.Load(); if (VerifyDate(_dateTimePicker.Value.ToShortDateString().ToString()) == null) { cleaning_works obj = new cleaning_works(); if (_maskedTextBox.Text == "") { _maskedTextBox.Text = "0"; } obj.cost = int.Parse(_maskedTextBox.Text); obj.date = _dateTimePicker.Value.ToShortDateString().ToString(); obj.note = _textBox.Text; obj.fk = (_comboBox.SelectedIndex + 1); _connect.cleaning_works.Add(obj); _connect.SaveChanges(); Summ(); CreateTableAdapter(); MessageBox.Show("Запись успешно добавлена."); _maskedTextBox.Text = "0"; _textBox.Clear(); } else { MessageBox.Show("Ошибка. На дату " + _dateTimePicker.Value.ToShortDateString().ToString() + " уже есть запись."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void AddInfoPerson(TextBox name, TextBox surname, MaskedTextBox phone, MaskedTextBox number, TextBox info, MaskedTextBox pay) { if (name.Text != "" && surname.Text != "") { using (WG_db connect = new WG_db()) { var obj = connect.people.Where((x) => x.name == name.Text && x.surname == surname.Text).FirstOrDefault(); if (obj == null) { people people = new people(); people.name = name.Text; people.surname = surname.Text; people.phone = phone.Text; people.namber = number.Text; people.note = info.Text; people.summa = int.Parse(pay.Text); people.payment_date = DateTime.Now.ToShortDateString(); connect.people.Add(people); connect.SaveChanges(); } else { MessageBox.Show("Запись есть в базе!!!"); } } } else { MessageBox.Show("Поля Имя и Фамилия обязательны к заполнению"); } }
public void EditInfo() { EditPersonWorm ePerson = new EditPersonWorm(); try { int index = _dataGridView.SelectedRows[0].Index + 1; using (WG_db connect = new WG_db()) { people people = connect.people.Find(index); if (people != null) { ePerson.textBox1.Text = people.name; ePerson.textBox2.Text = people.surname; ePerson.textBox3.Text = people.note; ePerson.maskedTextBox1.Text = people.phone; ePerson.maskedTextBox2.Text = people.namber; ePerson.maskedTextBox3.Text = people.summa.ToString(); if (ePerson.ShowDialog() == DialogResult.Cancel) { return; } if (VerifyDate(ePerson.textBox1.Text, ePerson.textBox2.Text) == null || VerifyDate(ePerson.textBox1.Text, ePerson.textBox2.Text).id == people.id) { people.name = ePerson.textBox1.Text; people.surname = ePerson.textBox2.Text; people.note = ePerson.textBox3.Text; people.phone = ePerson.maskedTextBox1.Text; people.namber = ePerson.maskedTextBox2.Text; people.summa = int.Parse(ePerson.maskedTextBox3.Text); connect.SaveChanges(); ShowAll(); MessageBox.Show("Запись успешно обновлена."); } else { MessageBox.Show("Ошибка. Такая запись уже есть в базе!!!."); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }