private void btnDelete_Click(object sender, EventArgs e) { if (index < 0) { return; } DialogResult dr = TailorMessage.Show("តើអ្នកចង់លុបទិន្នន័យមែនទេ?", "លុបទិន្នន័យ", TailorMessageIcon.Warning); if (dr == DialogResult.Yes) { using (var context = new TailorEntities()) { var staff = context.Staffs.SingleOrDefault(s => s.Code == code); staff.IsActive = false; int action = context.SaveChanges(); { if (action >= 1) { LoadData(); LoadInfo(); } } } } }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNameKh.Text.Trim())) { txtNameKh.Focus(); error.SetError(txtNameKh, null); return; } if (cboGender.SelectedIndex < 0) { cboGender.Focus(); error.SetError(cboGender, null); return; } if (cboSkill.SelectedIndex < 0) { cboSkill.Focus(); error.SetError(cboSkill, null); return; } if (string.IsNullOrEmpty(txtNationalId.Text.Trim())) { txtNationalId.Focus(); error.SetError(txtNationalId, null); return; } if (string.IsNullOrEmpty(txtPhone.Text)) { txtPhone.Focus(); error.SetError(txtPhone, null); return; } if (string.IsNullOrEmpty(txtBasicSalary.Text.Trim())) { txtBasicSalary.Focus(); error.SetError(txtBasicSalary, null); return; } if (edit) { using (var db = new TailorEntities()) { DialogResult dr = TailorMessage.Show("Are you sure you want to update data?", "Update", TailorMessageIcon.Question); if (dr == DialogResult.Yes) { var staff = db.Staffs.SingleOrDefault(s => s.Code == code); staff.NameKh = txtNameKh.Text; staff.NameEn = txtNameEn.Text; staff.GenderId = int.Parse(cboGender.SelectedValue.ToString()); staff.NationalId = txtNationalId.Text; staff.DateOfBirth = dtpBirthDate.Value; staff.PlaceOfBirth = txtBirthPlace.Text; staff.CurrentAddress = txtCurrentAddress.Text; staff.Phone = txtPhone.Text; staff.PositionId = int.Parse(cboSkill.SelectedValue.ToString()); staff.BasicSalary = decimal.Parse(txtBasicSalary.Text); staff.IsActive = true; int action = db.SaveChanges(); if (action >= 1) { lblFinished.Visible = true; lblFinished.Visible = true; } } } } else { id = int.Parse(cboSkill.SelectedValue.ToString()); using (var db = new TailorEntities()) { var position = db.Positions.FirstOrDefault(p => p.Id == id); code = position.Abbreviation; var staff = db.Staffs.Count(); countRow = staff; countRow++; } using (var db = new TailorEntities()) { DialogResult dr = TailorMessage.Show("Are you sure you want to add data?", "Save", TailorMessageIcon.Question); if (dr == DialogResult.Yes) { Staff staff = new Staff() { Code = code + countRow, NameKh = txtNameKh.Text, NameEn = txtNameEn.Text, GenderId = int.Parse(cboGender.SelectedValue.ToString()), NationalId = txtNationalId.Text, DateOfBirth = dtpBirthDate.Value, PlaceOfBirth = txtBirthPlace.Text, CurrentAddress = txtCurrentAddress.Text, Phone = txtPhone.Text, PositionId = int.Parse(cboSkill.SelectedValue.ToString()), BasicSalary = decimal.Parse(txtBasicSalary.Text), IsActive = true }; staff = db.Staffs.Add(staff); int action = db.SaveChanges(); if (action >= 1) { lblFinished.Visible = true; lblCode.Text += " " + staff.Code; lblCode.Visible = true; code = staff.Code; edit = true; } } } } if (staffView != null) { staffView.LoadData(); staffView.LoadInfo(); } }