private void btnUpdate_Click(object sender, EventArgs e) { if (CheckBeforeSave() == true) { //get position number DTO.position c = (DTO.position)cboPosition.SelectedItem; string macv = c.PositionNumber.ToString(); MemoryStream mem = new MemoryStream(); try { Image ima = picImage.BackgroundImage; ima.Save(mem, ImageFormat.Jpeg); } catch { }; try { infoEmployeeBLL.UpdateEmployee(txtEmployeeID.Text, txtEmployeeName.Text, cboSex.Text, txtNumberID.Text, txtPhone.Text, dtmBirthDay.Value.ToString(), txtAddress.Text, txtPlaceBrith.Text, txtAge.Text, macv, txtSalary.Text, dtmDayWorking.Value.ToString(), txtPassword.Text, cboStatus.Text, mem); DisplayNotify("Cập nhật thành công", 1); } catch { DisplayNotify("Lỗi ghi dữ liệu xuống CSDL", -1); } } else { DisplayNotify("Lỗi nhập dữ liệu, có thể bạn đã nhập sai hoặc thiếu các trường được đánh dấu đỏ", -1); } }
public void SetSelectItemComboboxPosition(string ID) { for (int i = 0; i < cboPosition.Items.Count; i++) { DTO.position a = (DTO.position)(cboPosition.Items[i]); if (a.PositionNumber == ID) { cboPosition.SelectedIndex = i; break; } } }
private void btnEdit_Click(object sender, EventArgs e) { if (CheckBeforeSave(0) == true) { //get position number DTO.position c = (DTO.position)cboPosition.SelectedItem; string macv = c.PositionNumber.ToString(); //image MemoryStream mem = new MemoryStream(); if (txtImagelink.Text.Length == 0) { Image ima = picImage.BackgroundImage; ima.Save(mem, ImageFormat.Jpeg); } else { try { Image ima = Image.FromFile(txtImagelink.Text); ima.Save(mem, ImageFormat.Jpeg); } catch { Image ima = picImage.BackgroundImage; ima.Save(mem, ImageFormat.Jpeg); } } try { string KeyToSelect = txtEmployeeID.Text; employeeBLL.UpdateEmployee(txtEmployeeID.Text, txtEmployeeName.Text, cboSex.Text, txtNumberID.Text, txtPhone.Text, dtmBirthDay.Value.ToString(), txtAddress.Text, txtPlaceBrith.Text, txtAge.Text, macv, txtSalary.Text, dtmDayWorking.Value.ToString(), mem, txtPassword.Text, cboStatus.Text); DisplayNotify("Cập nhật thành công", 1); dgvData.DataSource = employeeBLL.GetAllEmployee(); SelectRow(dgvData, KeyToSelect); } catch { DisplayNotify("Lỗi ghi dữ liệu xuống CSDL", -1); } } else { DisplayNotify("Lỗi nhập dữ liệu, có thể bạn đã nhập sai hoặc thiếu các trường được đánh dấu đỏ", -1); } }
private void dgvData_SelectionChanged(object sender, EventArgs e) { if (dgvData.SelectedRows.Count == 1) { DTO.position p = (DTO.position)(dgvData.SelectedRows[0].DataBoundItem); txtPositionID.Text = p.PositionNumber; txtPositionName.Text = p.PositionName; txtSalary.Text = p.Salary; //btn btnSave.Enabled = false; btnEdit.Enabled = true; btnDelete.Enabled = true; // control try { } catch (Exception ex) { DisplayNotify("Lỗi không đọc được chức năng của Chức vụ này !", -1); } } }
private void btnDelete_Click(object sender, EventArgs e) { //get position number DTO.position c = (DTO.position)cboPosition.SelectedItem; string macv = c.PositionNumber.ToString(); //image MemoryStream mem = new MemoryStream(); try { if (txtImagelink.Text.Length == 0) { Image ima = picImage.BackgroundImage; ima.Save(mem, ImageFormat.Jpeg); } else { Image ima = Image.FromFile(txtImagelink.Text); ima.Save(mem, ImageFormat.Jpeg); } } catch { }; try { string KeyToSelect = txtEmployeeID.Text; employeeBLL.DeleteEmployee(txtEmployeeID.Text, txtEmployeeName.Text, cboSex.Text, txtNumberID.Text, txtPhone.Text, dtmBirthDay.Value.ToString(), txtAddress.Text, txtPlaceBrith.Text, txtAge.Text, macv, txtSalary.Text, dtmDayWorking.Value.ToString(), mem, txtPassword.Text, cboStatus.Text); DisplayNotify("Xoa thành công", 1); dgvData.DataSource = employeeBLL.GetAllEmployee(); SelectRow(dgvData, KeyToSelect); } catch { DisplayNotify("Lỗi xóa trong CSDL", -1); } }
private void btnSave_Click(object sender, EventArgs e) { if (CheckBeforeSave(1) == true) { //get position number DTO.position c = (DTO.position)cboPosition.SelectedItem; string macv = c.PositionNumber.ToString(); //images try { Image ima = Image.FromFile(openFileDialogImage.FileName); MemoryStream mem = new MemoryStream(); ima.Save(mem, ImageFormat.Jpeg); try { string KeyToSelect = txtEmployeeID.Text; employeeBLL.SaveEmployee(txtEmployeeID.Text, txtEmployeeName.Text, cboSex.Text, txtNumberID.Text, txtPhone.Text, dtmBirthDay.Value.ToString(), txtAddress.Text, txtPlaceBrith.Text, txtAge.Text, macv, txtSalary.Text, dtmDayWorking.Value.ToString(), mem, txtPassword.Text, cboStatus.Text); DisplayNotify("Lưu thành công", 1); dgvData.DataSource = employeeBLL.GetAllEmployee(); SelectRow(dgvData, KeyToSelect); } catch { DisplayNotify("Lỗi ghi dữ liệu xuống CSDL", -1); } } catch (Exception ex) { DisplayNotify("Lỗi load ảnh", -1); } } else { DisplayNotify("Lỗi nhập dữ liệu, có thể bạn đã nhập sai hoặc thiếu các trường được đánh dấu đỏ", -1); } }