private void btnAddQueryExist_Click(object sender, EventArgs e) { DateTime dt = new DateTime(dtpDateBExist.Value.Year, dtpDateBExist.Value.Month, dtpDateBExist.Value.Day); string clientfio = txtFioExist.Text.Trim(); int carID = Convert.ToInt32(cmbCarsExist.SelectedValue); string carinfo = General.context.Cars .Where(x => x.ID == carID).Select(x => new { name = x.ModelCars.NameCar.Trim() + " " + x.RegisterSign.Trim() + " | Цвет: " + x.color.Trim() + " | Номер двигателя: " + x.EnNumber.Trim() + " | Номер тех паспорта: " + x.pts.Trim() }).Select(x => x.name).First().ToString().Trim(); int masterID = Convert.ToInt32(cmdmasterExist.SelectedValue); string masterfio = General.context.Masters .Where(x => x.ID == masterID).Select(x => new { name = x.SurName.Trim() + " " + x.Name.Trim() + " " + x.Patronymic.Trim() }).Select(x => x.name).First().ToString().Trim(); var result = General.context.Clients.Where(x => x.CarID == carID && (x.SurName.Trim() + " " + x.Name.Trim() + " " + x.Patronymic.Trim()) == clientfio && x.Birthday == dt ).Select(x => x.ID).ToList(); if (result.Count != 0) { int clientID = result.First(); int i_row = dtgQuery.SelectedRows[0].Index; using (SettingsAllQueryForm sett = new SettingsAllQueryForm()) { AllQuerySettings.ClientFIO = clientfio; AllQuerySettings.ClientID = clientID; AllQuerySettings.CarInfo = carinfo; AllQuerySettings.Birthday = dt; AllQuerySettings.MasterID = masterID; AllQuerySettings.MasterFIO = masterfio; AllQuerySettings.DateVisit = DateTime.Now; AllQuerySettings.DateForReady = null; AllQuerySettings.Done = false; sett.ShowDialog(); RefreshDataGrid(); dtgQuery.Rows[i_row].Cells[0].Selected = true; txtFioExist.Text = ""; GetInfoCount(); } } else { MessageBox.Show("Клиента с такими данными не существует", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); txtFioExist.Text = ""; } }
private void btnSettingsQuery_Click(object sender, EventArgs e) { if (dtgQuery.SelectedRows.Count > 0) { if (dtgQuery.SelectedRows[0].Index != -1) { int i_row = dtgQuery.SelectedRows[0].Index; if (!Convert.ToBoolean(dtgQuery.Rows[i_row].Cells[8].FormattedValue.ToString().Trim())) { using (SettingsAllQueryForm sett = new SettingsAllQueryForm()) { AllQuerySettings.ClientFIO = dtgQuery.Rows[i_row].Cells[0].FormattedValue.ToString().Trim(); AllQuerySettings.ClientID = Convert.ToInt32(dtgQuery.Rows[i_row].Cells[9].Value); AllQuerySettings.CarInfo = dtgQuery.Rows[i_row].Cells[1].FormattedValue.ToString().Trim(); AllQuerySettings.Birthday = Convert.ToDateTime(dtgQuery.Rows[i_row].Cells[2].Value); AllQuerySettings.MasterID = Convert.ToInt32(dtgQuery.Rows[i_row].Cells[3].Value); AllQuerySettings.MasterFIO = dtgQuery.Rows[i_row].Cells[4].FormattedValue.ToString().Trim(); AllQuerySettings.DateVisit = Convert.ToDateTime(dtgQuery.Rows[i_row].Cells[5].Value); if (dtgQuery.Rows[i_row].Cells[6].FormattedValue.ToString().Trim() != "") { AllQuerySettings.DateForReady = Convert.ToDateTime(dtgQuery.Rows[i_row].Cells[6].FormattedValue); } AllQuerySettings.Done = Convert.ToBoolean(dtgQuery.Rows[i_row].Cells[8].FormattedValue.ToString().Trim()); sett.ShowDialog(); RefreshDataGrid(); dtgQuery.Rows[i_row].Cells[0].Selected = true; GetInfoCount(); } } else { MessageBox.Show("Данная заявка уже выполнена и не подлежит редактированию!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Выделите строку в таблице заявок!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAddQueryNew_Click(object sender, EventArgs e) { try { int carID = -1; int clientID = -1; DateTime dt = new DateTime(dtpDateBNew.Value.Year, dtpDateBNew.Value.Month, dtpDateBNew.Value.Day); string clientfio = txtFioNew.Text.Trim(); bool is_car = false, is_client = false; int amount = new Regex(" ").Matches(clientfio).Count; string[] fio = clientfio.Split(' '); // surname, name, patron var temp_client = General.context.Clients .Where(x => (x.SurName.Trim() + x.Name.Trim() + x.Patronymic.Trim()) == clientfio.Replace(" ", "") && x.Birthday == dt) .ToList(); if (temp_client.Count == 0) { if (amount >= 1) { string carinfo = ""; #region Car int modelcarID = Convert.ToInt32(cmbCarsNew.SelectedValue); var cars = General.context.Cars .Where(x => x.ModelCarID == modelcarID && x.RegisterSign.Trim() == txtGRSNew.Text.Trim() && x.color.Trim() == txtCOLORNew.Text.Trim() && x.EnNumber.Trim() == txtEnNumberNew.Text.Trim() && x.pts.Trim() == txtPTSNew.Text.Trim()) .ToList(); Cars car = new Cars() { ModelCarID = modelcarID, RegisterSign = txtGRSNew.Text.Trim(), color = txtCOLORNew.Text.Trim(), EnNumber = txtEnNumberNew.Text.Trim(), pts = txtPTSNew.Text.Trim() }; if (cars.Count == 0) { try { General.context.Cars.Add(car); General.context.SaveChanges(); carID = car.ID; carinfo = General.context.ModelCars.Where(z => z.ID == modelcarID).Select(x => x.NameCar).First().ToString().Trim() + " " + car.RegisterSign.Trim() + " | Цвет: " + car.color.Trim() + " | Номер двигателя: " + car.EnNumber.Trim() + " | Номер тех паспорта: " + car.pts.Trim(); is_car = true; } catch (Exception) { General.context.Cars.Remove(car); General.context.SaveChanges(); } } else { carID = cars.Select(x => x.ID).First(); carinfo = General.context.ModelCars.Where(z => z.ID == modelcarID).Select(x => x.NameCar).First().ToString().Trim() + " " + car.RegisterSign.Trim() + " | Цвет: " + car.color.Trim() + " | Номер двигателя: " + car.EnNumber.Trim() + " | Номер тех паспорта: " + car.pts.Trim(); is_car = true; } #endregion Car #region Master int masterID = Convert.ToInt32(cmdmasterNew.SelectedValue); string masterfio = General.context.Masters .Where(x => x.ID == masterID).Select(x => new { name = x.SurName.Trim() + " " + x.Name.Trim() + " " + x.Patronymic.Trim() }).Select(x => x.name).First().ToString(); #endregion Master #region Client var clients = General.context.Clients.Where(x => (x.SurName.Trim() + " " + x.Name.Trim() + " " + x.Patronymic.Trim()) == clientfio && x.Birthday == dt && x.Phone.Trim() == txtPhoneNew.Text.Trim() ).Select(x => x.ID).ToList(); #endregion Clien if (clients.Count == 0) { Clients client = new Clients(); client.SurName = fio[0]; client.Name = fio[1]; if (amount == 2) { client.Patronymic = fio[2]; } client.Birthday = dt; client.Phone = txtPhoneNew.Text.Trim(); client.CarID = carID; client.imagename = "noimage.png"; try { General.context.Clients.Add(client); General.context.SaveChanges(); clientID = client.ID; is_client = true; } catch (Exception) { General.context.Clients.Remove(client); General.context.SaveChanges(); } if (is_client && is_car) { using (SettingsAllQueryForm sett = new SettingsAllQueryForm()) { int i_row = dtgQuery.SelectedRows[0].Index; AllQuerySettings.ClientFIO = clientfio; AllQuerySettings.ClientID = clientID; AllQuerySettings.CarInfo = carinfo; AllQuerySettings.Birthday = dt; AllQuerySettings.MasterID = masterID; AllQuerySettings.MasterFIO = masterfio; AllQuerySettings.DateVisit = DateTime.Now; AllQuerySettings.DateForReady = null; AllQuerySettings.Done = false; sett.ShowDialog(); RefreshDataGrid(); dtgQuery.Rows[i_row].Cells[0].Selected = true; txtFioNew.Text = ""; GetInfoCount(); } } } else { MessageBox.Show("Клиента с такими данными уже существует", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); txtFioNew.Text = ""; } } else { MessageBox.Show("Клиент обязательно должен иметь Имя и Фамилию", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Клиент с таким Ф.И.О и датой рождения уже существует!\n" + "Перейдите во вкладку \"Существующие\".", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception exp) { MessageBox.Show(exp.Message.ToString()); } }