private void update_click(object sender, RoutedEventArgs e) { string id_edit_employee = this.id_employee; login_er.Visibility = Visibility.Hidden; surname_er.Visibility = Visibility.Hidden; first_name_er.Visibility = Visibility.Hidden; middle_name_er.Visibility = Visibility.Hidden; phone_er.Visibility = Visibility.Hidden; passport_er.Visibility = Visibility.Hidden; email_er.Visibility = Visibility.Hidden; bool er = false; string error_msg = ""; if ((error_msg = AddEmployee.check_login(login_text.Text)) != "") { er = true; login_er.Content = error_msg; login_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_surname(surname.Text)) != "") { er = true; surname_er.Content = error_msg; surname_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_name(first_name.Text)) != "") { er = true; first_name_er.Content = error_msg; first_name_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_name(middle_name.Text)) != "") { er = true; middle_name_er.Content = error_msg; middle_name_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_phone(phone.Text)) != "") { er = true; phone_er.Content = error_msg; phone_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_passport(passport.Text)) != "") { er = true; passport_er.Content = error_msg; passport_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_email(email.Text)) != "") { er = true; email_er.Content = error_msg; email_er.Visibility = Visibility.Visible; } if (!er) { string login_trm = login_text.Text.Trim(); string surname_trm = surname.Text.Trim(); string name_trm = first_name.Text.Trim(); string middle_name_trm = middle_name.Text.Trim(); string phone_trm = phone.Text.Trim(); string passport_trm = passport.Text.Trim(); string email_trm = email.Text.Trim(); try { string sqlExpression = " UPDATE dbo.EMPLOYEES SET dbo.EMPLOYEES.id_employee = @login_value, dbo.EMPLOYEES.last_name_employee = @surname_value, dbo.EMPLOYEES.first_name_employee = @name_value, " + " dbo.EMPLOYEES.middle_name_employee = @middle_name_value, dbo.EMPLOYEES.phone_employee = @phone_value, dbo.EMPLOYEES.passport_employee = @passport_value, " + " dbo.EMPLOYEES.email_employee = @email_value " + " FROM dbo.EMPLOYEES" + " WHERE(id_employee = '" + id_edit_employee + "') "; SqlCommand command = new SqlCommand(sqlExpression, connection); SqlParameter login_param = new SqlParameter("@login_value", login_trm); command.Parameters.Add(login_param); SqlParameter surname_param = new SqlParameter("@surname_value", surname_trm); command.Parameters.Add(surname_param); SqlParameter name_param = new SqlParameter("@name_value", name_trm); command.Parameters.Add(name_param); SqlParameter middle_name_param = new SqlParameter("@middle_name_value", middle_name_trm); command.Parameters.Add(middle_name_param); SqlParameter phone_param = new SqlParameter("@phone_value", phone_trm); command.Parameters.Add(phone_param); SqlParameter passport_param = new SqlParameter("@passport_value", passport_trm); command.Parameters.Add(passport_param); SqlParameter email_param = new SqlParameter("@email_value", email_trm); command.Parameters.Add(email_param); command.ExecuteNonQuery(); ((EditAllProfiles)parent_window).update_employees(); MessageBox.Show("Данные обновлены!"); } catch (SqlException en) { MessageBox.Show((en.Number).ToString() + " " + en.Message); } } }
private void sell(object sender, RoutedEventArgs e) { string id_client; DateTime local_time = DateTime.Now; string order = local_time.ToString("yyyyMMddhhmm") + this.id_sell_car; int vehicle = this.id_sell_car; string employee = Manager.ID_SELLER; DateTime date = DateTime.Now; if ((bool)exist_client.IsChecked) { clients buyer = (clients)grid_clients.SelectedItem; if (buyer == null) { return; } id_client = buyer.LOGIN; } else { login_er.Visibility = Visibility.Hidden; surname_er.Visibility = Visibility.Hidden; first_name_er.Visibility = Visibility.Hidden; middle_name_er.Visibility = Visibility.Hidden; dob_er.Visibility = Visibility.Hidden; phone_er.Visibility = Visibility.Hidden; passport_er.Visibility = Visibility.Hidden; email_er.Visibility = Visibility.Hidden; bool er = false; string error_msg = ""; if ((error_msg = AddEmployee.check_login(login.Text)) != "") { er = true; login_er.Content = error_msg; login_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_surname(surname.Text)) != "") { er = true; surname_er.Content = error_msg; surname_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_name(first_name.Text)) != "") { er = true; first_name_er.Content = error_msg; first_name_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_name(middle_name.Text)) != "") { er = true; middle_name_er.Content = error_msg; middle_name_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_phone(phone.Text)) != "") { er = true; phone_er.Content = error_msg; phone_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_dob(dob.DisplayDate)) != "") { er = true; dob_er.Content = error_msg; dob_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_passport(passport.Text)) != "") { er = true; passport_er.Content = error_msg; passport_er.Visibility = Visibility.Visible; } if ((error_msg = AddEmployee.check_email(email.Text)) != "") { er = true; email_er.Content = error_msg; email_er.Visibility = Visibility.Visible; } if (!er) { string login_trm = login.Text.Trim(); string surname_trm = surname.Text.Trim(); string name_trm = first_name.Text.Trim(); string middle_name_trm = middle_name.Text.Trim(); DateTime dob_trm = dob.DisplayDate; string phone_trm = phone.Text.Trim(); string passport_trm = passport.Text.Trim(); string email_trm = email.Text.Trim(); char gender = ((bool)m_gender.IsChecked) ? 'м' : 'ж'; id_client = login_trm; try { string sqlExpression = " INSERT INTO CLIENTS VALUES (@login_value, @surname_value, @name_value, @middle_name_value, @dob_value, @phone_value, @passport_value, @email_value, @gender_value) "; SqlCommand command = new SqlCommand(sqlExpression, connection); SqlParameter login_param = new SqlParameter("@login_value", login_trm); command.Parameters.Add(login_param); SqlParameter surname_param = new SqlParameter("@surname_value", surname_trm); command.Parameters.Add(surname_param); SqlParameter name_param = new SqlParameter("@name_value", name_trm); command.Parameters.Add(name_param); SqlParameter middle_name_param = new SqlParameter("@middle_name_value", middle_name_trm); command.Parameters.Add(middle_name_param); SqlParameter dob_param = new SqlParameter("@dob_value", dob_trm); command.Parameters.Add(dob_param); SqlParameter phone_param = new SqlParameter("@phone_value", phone_trm); command.Parameters.Add(phone_param); SqlParameter passport_param = new SqlParameter("@passport_value", passport_trm); command.Parameters.Add(passport_param); SqlParameter email_param = new SqlParameter("@email_value", email_trm); command.Parameters.Add(email_param); SqlParameter gender_param = new SqlParameter("@gender_value", gender); command.Parameters.Add(gender_param); command.ExecuteNonQuery(); sqlExpression = " INSERT INTO ORDERS VALUES (@id_order, @id_vehicle, @id_client, @id_employee, @current_date) "; command = new SqlCommand(sqlExpression, connection); SqlParameter id_order_par = new SqlParameter("@id_order", order); command.Parameters.Add(id_order_par); SqlParameter id_vehicle_par = new SqlParameter("@id_vehicle", vehicle); command.Parameters.Add(id_vehicle_par); SqlParameter id_client_par = new SqlParameter("@id_client", id_client); command.Parameters.Add(id_client_par); SqlParameter id_employee_par = new SqlParameter("@id_employee", employee); command.Parameters.Add(id_employee_par); SqlParameter current_date_par = new SqlParameter("@current_date", date); command.Parameters.Add(current_date_par); command.ExecuteNonQuery(); sqlExpression = " UPDATE VEHICLES SET id_status = @id_status WHERE id_vehicle = @id_vehicle; "; command = new SqlCommand(sqlExpression, connection); SqlParameter id_status_par = new SqlParameter("@id_status", 'S'); command.Parameters.Add(id_status_par); id_vehicle_par = new SqlParameter("@id_vehicle", vehicle); command.Parameters.Add(id_vehicle_par); command.ExecuteNonQuery(); MessageBox.Show("Автомобиль продан!"); ((SellCar)parent_window).update_sell_car(); parent_window.Visibility = Visibility.Visible; this.Close(); } catch (SqlException en) { MessageBox.Show((en.Number).ToString() + " " + en.Message); } } return; } try { string sqlExpression = " INSERT INTO ORDERS VALUES (@id_order, @id_vehicle, @id_client, @id_employee, @current_date) "; SqlCommand command = new SqlCommand(sqlExpression, connection); SqlParameter id_order_par = new SqlParameter("@id_order", order); command.Parameters.Add(id_order_par); SqlParameter id_vehicle_par = new SqlParameter("@id_vehicle", vehicle); command.Parameters.Add(id_vehicle_par); SqlParameter id_client_par = new SqlParameter("@id_client", id_client); command.Parameters.Add(id_client_par); SqlParameter id_employee_par = new SqlParameter("@id_employee", employee); command.Parameters.Add(id_employee_par); SqlParameter current_date_par = new SqlParameter("@current_date", date); command.Parameters.Add(current_date_par); command.ExecuteNonQuery(); sqlExpression = " UPDATE VEHICLES SET id_status = @id_status WHERE id_vehicle = @id_vehicle; "; command = new SqlCommand(sqlExpression, connection); SqlParameter id_status_par = new SqlParameter("@id_status", 'S'); command.Parameters.Add(id_status_par); id_vehicle_par = new SqlParameter("@id_vehicle", vehicle); command.Parameters.Add(id_vehicle_par); command.ExecuteNonQuery(); MessageBox.Show("Автомобиль продан!"); string file_name = order + ".txt"; StreamWriter file = new StreamWriter(order); file.WriteLine("Номер заказа: " + order); file.WriteLine("Дата заказа: " + date); file.Close(); ((SellCar)parent_window).update_sell_car(); parent_window.Visibility = Visibility.Visible; this.Close(); } catch (SqlException en) { MessageBox.Show((en.Number).ToString() + " " + en.Message); } }