private void btnDelete_Click(object sender, EventArgs e) { try { DialogResult dr; dr = MessageBox.Show("Do you want to delete?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { int Index = dgvList.CurrentRow.Index; int Id = int.Parse(dgvList.Rows[Index].Cells[1].Value.ToString()); using (var context = new TailorEntities()) { var remove = context.StaffDeductions.Find(Id); if (remove != null) { //remove.Status = false; context.SaveChanges(); this.LoadData(); MessageBox.Show("Removed..."); } } } } catch (Exception ex) { MessageBox.Show("There is no value to delete"); } }
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) { //description can't be null if (string.IsNullOrEmpty(txtDescription.Text.Trim())) { MessageBox.Show("Input description..."); txtDescription.Focus(); return; } //Save clothes Kind var clothes = new ClothesKind() { Description = txtDescription.Text }; db.ClothesKinds.Add(clothes); db.SaveChanges(); this.LoadData(); MessageBox.Show("Saved..."); }
private void btnSave_Click(object sender, EventArgs e) { //Update Staff if (editFlag) { var staff = db.StaffDeductions.Find(editId); staff.StaffCode = cboStaff.SelectedValue.ToString(); staff.Date = dtpDate.Value; staff.Amount = (txtAmount.Text != null) ? decimal.Parse(txtAmount.Text) : 0; staff.Reason = txtReason.Text; staff.ComputerCode = Entities.TailorSetting.GetComputerCode(); staff.ComputeTime = Entities.TailorSetting.GetComputerTime(); editId = 0; editFlag = false; db.SaveChanges(); return; } else { //Insert Staff Deduction var staff = new StaffDeduction() { StaffCode = cboStaff.SelectedValue.ToString(), Date = dtpDate.Value, Amount = (!string.IsNullOrEmpty(txtAmount.Text.Trim()) ? decimal.Parse(txtAmount.Text) : 0), Reason = txtReason.Text, ComputerCode = Entities.TailorSetting.GetComputerCode(), ComputeTime = Entities.TailorSetting.GetComputerTime() }; db.StaffDeductions.Add(staff); int re = db.SaveChanges(); if (re >= 0) { MessageBox.Show("Saved..."); } } }
private void btnSave_Click(object sender, EventArgs e) { using (var db = new TailorEntities()) { var query = db.Staffs.Where(s => s.IsActive).ToList(); var attendances = db.StaffAttendances.Where(a => a.Date.Month == dtpAttendanceDate.Value.Month).ToList(); foreach (var s in query) { int isExist = 0; foreach (var a in attendances) { if (s.Code == a.Staff.Code && a.Date == dtpAttendanceDate.Value.Date) { isExist = 1; } } if (isExist == 0) { var attendance = new StaffAttendance() { StaffCode = s.Code, Date = dtpAttendanceDate.Value, Status = "W", ComputerCode = TailorService.GetComputerCode(), ComputeTime = TailorService.GetComputerTime() }; db.StaffAttendances.Add(attendance); } } int action = db.SaveChanges(); if (action >= 1) { progressBar1.Value = 100; lblFinished.Visible = true; } } if (view != null) { view.LoadStaffAttendance(); } }
private void btnSave_Click(object sender, EventArgs e) { if (cboCode.SelectedIndex < 0) { cboCode.Focus(); error.SetError(cboCode, null); return; } if (cboStaff.SelectedIndex < 0) { cboStaff.Focus(); error.SetError(cboStaff, null); return; } if (string.IsNullOrEmpty(txtAmount.Text.Trim())) { txtAmount.Focus(); error.SetError(txtAmount, null); return; } using (var db = new TailorEntities()) { StaffBonu bonus = new StaffBonu() { StaffCode = cboStaff.SelectedValue.ToString(), Date = dtpDate.Value, Amount = decimal.Parse(txtAmount.Text), Remark = txtReason.Text, ComputerCode = TailorService.GetComputerCode(), ComputeTime = TailorService.GetComputerTime() }; db.StaffBonus.Add(bonus); int action = db.SaveChanges(); if (action >= 1) { lblFinished.Visible = true; } } }
private void btnRemove_Click(object sender, EventArgs e) { //to remove measurement DialogResult dr; dr = MessageBox.Show("Do you want to delete?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { int Index = dgvList.CurrentRow.Index; int Id = int.Parse(dgvList.Rows[Index].Cells[1].Value.ToString()); var remove = db.Measurements.Find(Id); if (remove != null) { remove.IsActive = false; db.SaveChanges(); this.LoadData(); MessageBox.Show("Removed..."); } } }
private void btnSave_Click(object sender, EventArgs e) { if (cboCode.SelectedIndex < 0) { error.SetError(cboCode, null); cboCode.Focus(); return; } if (cboStaff.SelectedIndex < 0) { error.SetError(cboStaff, null); cboStaff.Focus(); return; } if (dtpUntillDate.Value < dtpFromDate.Value) { error.SetError(dtpUntillDate, null); dtpUntillDate.Focus(); return; } string status = rbtnA.Checked ? "A" : "P"; DateTime startDate = dtpFromDate.Value; DateTime endDate = dtpUntillDate.Value; if (edit) { using (var db = new TailorEntities()) { var query = db.StaffAttendances.SingleOrDefault(a => a.StaffCode == code && a.Date == date); query.Status = status; query.Remark = txtReason.Text; int action = db.SaveChanges(); if (action >= 1) { lblFinished.Visible = true; } } } else { using (var db = new TailorEntities()) { var query = db.StaffAttendances.Where(a => a.Date.Month == dtpFromDate.Value.Month || a.Date.Month == dtpUntillDate.Value.Month).ToList(); for (DateTime date = startDate.Date; date <= endDate.Date; date = date.AddDays(1)) { int isExist = 0; foreach (var a in query) { if (a.StaffCode == cboCode.SelectedValue.ToString() && a.Date.Date == date) { isExist = 1; } } if (isExist == 0) { StaffAttendance attendance = new StaffAttendance() { StaffCode = cboCode.SelectedValue.ToString(), Date = date, Status = status, Remark = txtReason.Text, ComputerCode = TailorService.GetComputerCode(), ComputeTime = TailorService.GetComputerTime() }; db.StaffAttendances.Add(attendance); } } int action = db.SaveChanges(); if (action >= 1) { lblFinished.Visible = true; } } } if (AttendanceView != null) { AttendanceView.LoadStaffAttendance(); AttendanceView.LoadAttendanceInfo(); } }
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(); } }