private void buttonAddPersonal_Click(object sender, EventArgs e) { if (textBoxLastName.Text.Length == 0 || textBoxFirstName.Text.Length == 0 || comboBoxGender.Text.Length == 0 || comboBoxFunction.Text.Length == 0 || (dateSelected == false && Form1.AddOrEdit == AddEditOrDelete.Add)) { MessageBox.Show("Вы ввели не все данные!"); return; } Functions funcCmb = (Functions)int.Parse(comboBoxFunction.SelectedValue.ToString()); if (emp == null) { emp = new Employee(textBoxINN.Text, textBoxFirstName.Text, textBoxSecondName.Text, textBoxLastName.Text, textBoxPassport.Text, textBoxAddress.Text, Convert.ToDateTime(date), Converter.ConvertSex(comboBoxGender.Text), textBoxNumbOfTel.Text, funcCmb); EmployeeMapper em = new EmployeeMapper(); try { emp = em.Insert(emp); } catch (Exception ex) { emp = null; MessageBox.Show("При добавлении данных произошла ошибка - " + $"{ex.Message}"); return; } } else { EmployeeMapper em = new EmployeeMapper(); emp.INN = textBoxINN.Text; emp.FirstName = textBoxFirstName.Text; emp.SecondName = textBoxSecondName.Text; emp.LastName = textBoxLastName.Text; emp.Passport = textBoxPassport.Text; emp.Address = textBoxAddress.Text; emp.BornDate = Convert.ToDateTime(date); emp.Gender = Converter.ConvertSex(comboBoxGender.Text); emp.Function = funcCmb; emp.PhoneNumb = textBoxNumbOfTel.Text; em.Update(emp); } Form1.AddListPersonalInGrid(mainForm.dataGridView, Queries.StaffView); this.Close(); mainForm.dataGridView.ClearSelection(); mainForm.dataGridView.Rows[Form1.SelectIndex].Selected = true; }
protected void ProceedButton_Click(object sender, EventArgs e) { EmployeeEntity entity = new EmployeeEntity(); entity.EmployeeNo = EmployeeNoTextBox.Text; entity.Firstname = FirstnameTextBox.Text; entity.Middlename = ""; entity.Middlename = MiddlenameTextBox.Text; entity.Lastname = LastnameTextBox.Text; DateTime dt; if (DateTime.TryParseExact(DateOfBirthTextBox.Text, ConfigurationManager.AppSettings["DateFormat"], null, System.Globalization.DateTimeStyles.None, out dt)) { entity.DateOfBirth = dt; } entity.Gender = (GenderEnum)Convert.ToInt32(GenderDropDownList.SelectedValue); entity.NationalityId = Convert.ToInt32(NationalityDropDownList.SelectedValue); entity.CountryId = Convert.ToInt32(CountryDropDownList.SelectedValue); entity.Address = AddressTextBox.Text; entity.PersonalNumber = PersonalNumberTextBox.Text; entity.WorkEmail = WorkEmailTextBox.Text; entity.MobilePhone = MobilePhoneTextBox.Text; entity.OtherEmail = OtherEmailTextBox.Text; entity.City = CityTextBox.Text; entity.BankId = Convert.ToInt32(BankDropDownList.SelectedValue); entity.AccountNumber = AccountNumberTextBox.Text; entity.MaritalStatus = (MaritalStatusEnum)Convert.ToInt32(MaritalStatusDropDownList.SelectedValue); if (Session["fileContents_"] != null) { byte[] fileContents = (byte[])Session["fileContents_"]; entity.Image = fileContents; } EmployeeMapper mapper = new EmployeeMapper(); try { if (Request.QueryString["action"] == "update" && Request.QueryString["EmployeeId"] != null) { entity.Id = Convert.ToInt32(Request.QueryString["EmployeeId"]); mapper.Update(entity); Response.Redirect("EducationAndExperience.aspx?action=update&EmployeeId=" + entity.Id); } else { ReminderEntity reminder = new ReminderEntity(); reminder.EntityPK = entity.Id.ToString(); reminder.EntityPKType = typeof(int).ToString(); reminder.ReminderType = ReminderEnum.EmployeeNoContract; reminder.Url = "/HRM/HR-Managment/Employee/EmployeesWithoutContract.aspx"; new EmployeeMapperTransaction().InsertWithReminder(entity, reminder); Response.Redirect("EducationAndExperience.aspx?EmployeeId=" + entity.Id); } } catch (SqlException ex) { StringBuilder sb = new StringBuilder(); sb.Append("<script language='javascript'>displayNoty('The Employee No { " + EmployeeNoTextBox.Text + " } has been used, plase write another number');</script>"); // if the script is not already registered if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "HeyPopup")) { ClientScript.RegisterClientScriptBlock(Page.GetType(), "HeyPopup", sb.ToString()); } } finally { } }