private void save_data() { if (check_data_is_ok() == false) { return; } // Xử lý file đính kèm switch (m_e_file_mode) { case DataEntryFileMode.UploadFile: // Kiểm tra file đã tồn tại trên server hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Nếu đã chọn file if (m_lbl_file_name.Text != "") { // Upload server có sử dụng user và pass if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } // Upload không sử dụng user và pass else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.EditFile: // Nếu ko up lên file mới sẽ bỏ qua bước này if (m_str_link_old != m_lbl_file_name.Text) { // Kiểm tra file vừa upload đã tồn tại hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Xóa file cũ if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old)) { FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); } // Upload file mới lên if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.DeleteFile: // Kiểm tra file có tồn tại hay không if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old) == false) { BaseMessages.MsgBox_Infor("File không tồn tại!"); return; } FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); break; } // Xử lý quyết định switch (m_e_form_mode) { case DataEntryFormMode.UpdateDataState: if (check_data_is_ok() == false) { return; } else { form_2_us_object(); m_us.Update(); } break; case DataEntryFormMode.InsertDataState: if (check_trung_ma_quyet_dinh(m_txt_ma_quyet_dinh.Text)) { BaseMessages.MsgBox_Warning(216); m_txt_ma_quyet_dinh.BackColor = Color.Bisque; m_txt_ma_quyet_dinh.Focus(); m_txt_ma_quyet_dinh.SelectAll(); return; } else { m_txt_ma_quyet_dinh.BackColor = Color.White; if (check_data_is_ok() == false) { return; } else { form_2_us_object(); m_us.Insert(); } } break; default: break; } // Xử lý quyết định theo pháp nhân if (m_e_form_mode == DataEntryFormMode.InsertDataState) { form_to_us_quyet_dinh_phap_nhan(); m_us_quyet_dinh_phap_nhan.Insert(); } BaseMessages.MsgBox_Infor("Cập nhật dữ liệu thành công!"); this.Close(); }
private void save_data() { US_GD_QUYET_DINH_PHAP_NHAN v_us_gd_quyet_dinh_phap_nhan = new US_GD_QUYET_DINH_PHAP_NHAN(); if (confirm_save_data() && check_validate_data_is_ok()) { #region Xử lý file đính kèm // Xử lý file đính kèm switch (m_e_file_mode) { case DataEntryFileMode.UploadFile: // Kiểm tra file đã tồn tại trên server hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Nếu đã chọn file if (m_lbl_file_name.Text != "") { // Upload server có sử dụng user và pass if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } // Upload không sử dụng user và pass else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.EditFile: // Nếu ko up lên file mới sẽ bỏ qua bước này if (m_str_link_old != m_lbl_file_name.Text) { // Kiểm tra file vừa upload đã tồn tại hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Xóa file cũ if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old)) { FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); } // Upload file mới lên if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.DeleteFile: // Kiểm tra file có tồn tại hay không if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old) == false) { BaseMessages.MsgBox_Infor("File không tồn tại!"); return; } FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); break; } #endregion decimal v_dc_ty_le = 0; if (CIPConvert.is_valid_number(m_txt_ty_le_tham_gia.Text.Trim())) { v_dc_ty_le = CIPConvert.ToDecimal(m_txt_ty_le_tham_gia.Text.Trim()); } if (m_us_v_qua_trinh_lam_viec.Sum_ty_le_tham_gia(m_us_v_qua_trinh_lam_viec.strMA_NV, m_us_v_qua_trinh_lam_viec.strTRANG_THAI_CHUC_VU_YN, CAppContext_201.getCurrentIDPhapnhan()) + v_dc_ty_le > 100) { BaseMessages.MsgBox_Infor("Tỷ lệ tham gia đã đã vượt quá 100%."); return; } if (check_validate_data_is_ok() == false) { return; } else { if (m_txt_ma_quyet_dinh.Text != "") { form_to_us_object_quyet_dinh(); if (m_b_check_quyet_dinh_save) { m_us_quyet_dinh.Insert(); v_us_gd_quyet_dinh_phap_nhan = new US_GD_QUYET_DINH_PHAP_NHAN(); v_us_gd_quyet_dinh_phap_nhan.dcID_QUYET_DINH = m_us_quyet_dinh.dcID; v_us_gd_quyet_dinh_phap_nhan.dcID_PHAP_NHAN = CAppContext_201.getCurrentIDPhapnhan(); v_us_gd_quyet_dinh_phap_nhan.Insert(); } else { m_us_quyet_dinh.Update(); } } form_to_us_object_chi_tiet_chuc_vu(); m_us_chi_tiet_chuc_vu.Insert(); } BaseMessages.MsgBox_Infor("Dữ liệu đã được cập nhât!"); this.Close(); } }
private void save_data() { if (check_data_is_ok() == false) { return; } try { m_us.BeginTransaction(); #region Xử lý file đính kèm switch (m_e_file_mode) { case DataEntryFileMode.UploadFile: // Kiểm tra file đã tồn tại trên server hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Nếu đã chọn file if (m_lbl_file_name.Text != "") { // Upload server có sử dụng user và pass if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } // Upload không sử dụng user và pass else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.EditFile: // Nếu ko up lên file mới sẽ bỏ qua bước này if (m_str_link_old != m_lbl_file_name.Text) { // Kiểm tra file vừa upload đã tồn tại hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Xóa file cũ if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old)) { FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); } // Upload file mới lên if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.DeleteFile: // Kiểm tra file có tồn tại hay không if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old) == false) { BaseMessages.MsgBox_Infor("File không tồn tại!"); return; } FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); break; } #endregion #region Xử lý quyết định form_to_us_quyet_dinh(); switch (m_e_quyet_dinh_mode) { case DataEntryFormMode.InsertDataState: if (is_exist_quyet_dinh(m_txt_ma_quyet_dinh.Text)) { BaseMessages.MsgBox_Error("Mã quyết định đã tồn tại."); m_txt_ma_quyet_dinh.Focus(); return; } m_us.Insert(); break; case DataEntryFormMode.UpdateDataState: if (!m_txt_ma_quyet_dinh.Text.Equals(m_str_ma_quyet_dinh_old)) { if (is_exist_quyet_dinh(m_txt_ma_quyet_dinh.Text)) { BaseMessages.MsgBox_Error("Mã quyết định đã tồn tại hoặc đang được dùng cho dự án khác."); m_txt_ma_quyet_dinh.Focus(); return; } } m_us.Update(); break; } #endregion m_us.CommitTransaction(); } catch (Exception) { if (m_us.is_having_transaction()) { m_us.Rollback(); } } form_2_us_nhan_vien(); US_DM_QUYET_DINH v_us_qd = new US_DM_QUYET_DINH(); DS_DM_QUYET_DINH v_ds_qd = new DS_DM_QUYET_DINH(); switch (m_e_form_mode) { case DataEntryFormMode.InsertDataState: // Insert nhân sự chuyen_trang_thai_ve_no(m_us.dcID_NHAN_SU); m_us.strTRANG_THAI_HIEN_TAI = "Y"; // Quyết định if (m_b_check_quyet_dinh_save) { form_to_us_quyet_dinh(); if (m_b_check_quyet_dinh_null) { m_us_quyet_dinh.Insert(); US_DM_QUYET_DINH v_us = new US_DM_QUYET_DINH(); DS_DM_QUYET_DINH v_ds = new DS_DM_QUYET_DINH(); v_us.FillDataset_By_Ma_qd(v_ds, m_us_quyet_dinh.strMA_QUYET_DINH); if (v_ds.DM_QUYET_DINH.Rows.Count != 0) { US_GD_QUYET_DINH_PHAP_NHAN v_us_qd_pn = new US_GD_QUYET_DINH_PHAP_NHAN(); v_us_qd_pn.dcID_PHAP_NHAN = CAppContext_201.getCurrentIDPhapnhan(); v_us_qd_pn.dcID_QUYET_DINH = CIPConvert.ToDecimal(v_ds_qd.Tables[0].Rows[0]["ID"]); v_us_qd_pn.Insert(); } } else { m_us_quyet_dinh.Update(); } v_us_qd.FillDataset_By_Ma_qd(v_ds_qd, m_us_quyet_dinh.strMA_QUYET_DINH); if (v_ds_qd.Tables[0].Rows.Count != 0) { m_us.dcID_QUYET_DINH = CIPConvert.ToDecimal(v_ds_qd.Tables[0].Rows[0]["ID"]); } } m_us.Insert(); break; case DataEntryFormMode.UpdateDataState: if (m_txt_ma_quyet_dinh.Text != "") { form_to_us_quyet_dinh(); if (m_b_check_quyet_dinh_save) { m_us_quyet_dinh.Insert(); } else { m_us_quyet_dinh.Update(); } v_us_qd.FillDataset_By_Ma_qd(v_ds_qd, m_us_quyet_dinh.strMA_QUYET_DINH); if (v_ds_qd.Tables[0].Rows.Count != 0) { m_us.dcID_QUYET_DINH = CIPConvert.ToDecimal(v_ds_qd.Tables[0].Rows[0]["ID"]); } } m_us.Update(); break; } BaseMessages.MsgBox_Infor("Dữ liệu đã được cập nhật"); this.Close(); }
private void save_data() { if (check_data_is_ok() == false) { return; } #region Xử lý file đính kèm switch (m_e_file_mode) { case DataEntryFileMode.UploadFile: // Kiểm tra file đã tồn tại trên server hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Nếu đã chọn file if (m_lbl_file_name.Text != "") { // Upload server có sử dụng user và pass if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } // Upload không sử dụng user và pass else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.EditFile: // Nếu ko up lên file mới sẽ bỏ qua bước này if (m_str_link_old != m_lbl_file_name.Text) { // Kiểm tra file vừa upload đã tồn tại hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return; } // Xóa file cũ if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old)) { FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); } // Upload file mới lên if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.DeleteFile: // Kiểm tra file có tồn tại hay không if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_link_old)) { FileExplorer.DeleteFile(m_str_directory_to + m_str_link_old); } break; } #endregion form_2_us_object(); switch (m_e_form_mode) { case DataEntryFormMode.InsertDataState: if (check_trung_ma_hop_dong(m_txt_ma_hop_dong.Text)) { BaseMessages.MsgBox_Error("Mã hợp đồng đã tồn tại."); m_txt_ma_hop_dong.Focus(); return; } DS_GD_HOP_DONG ds_gd_hd = new DS_GD_HOP_DONG(); US_GD_HOP_DONG us_gd_hd = new US_GD_HOP_DONG(); us_gd_hd.FillDataSet_Search_by_trang_thai_hop_dong(ds_gd_hd, "Y", m_us.dcID_NHAN_SU); var v_i_total_record = ds_gd_hd.Tables[0].Rows.Count; if (v_i_total_record > 0) { foreach (var item in ds_gd_hd.GD_HOP_DONG) { us_gd_hd.dcID = item.ID; us_gd_hd.Upload_trang_thai_hop_dong(us_gd_hd); } } m_us.Insert(); break; case DataEntryFormMode.UpdateDataState: US_GD_HOP_DONG v_us_gd_hop_dong = new US_GD_HOP_DONG(m_str_id_hop_dong_old); if (!m_txt_ma_hop_dong.Text.Equals(v_us_gd_hop_dong.strMA_HOP_DONG)) { if (check_trung_ma_hop_dong(m_txt_ma_hop_dong.Text)) { BaseMessages.MsgBox_Error("Mã hợp đồng đã tồn tại."); m_txt_ma_hop_dong.Focus(); return; } } m_us.Update(); break; } f701_v_hop_dong_lao_dong.m_str_ma_hop_dong = m_txt_ma_hop_dong.Text; BaseMessages.MsgBox_Infor("Dữ liệu đã được cập nhật"); this.Close(); }
/// <summary> /// Insert/Update vào Table DM_QUYET_DINH trước, nếu thành công thì tiếp tục với GD_LUONG_THEO_QD. /// Nếu GD_LUONG_THEO_QD gặp exception thì Rollback() bản ghi DM_QUYET_DINH đã Insert/Update trước đó. /// </summary> /// <returns>Trả về True nếu thành công</returns> private bool save_data() { US_GD_QUYET_DINH_PHAP_NHAN v_us_qd_pn; try { #region Validate Data // Nếu validate có vấn đề if (!validate_data()) { return(false); } #endregion // Chưa hiểu rõ về xử lý file lắm #region Xử lý file đính kèm // Xử lý file đính kèm switch (m_e_file_mode) { case DataEntryFileMode.UploadFile: // Kiểm tra file đã tồn tại trên server hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return(false); } // Nếu đã chọn file if (m_lbl_file_name.Text != "") { // Upload server có sử dụng user và pass if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } // Upload không sử dụng user và pass else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.EditFile: // Nếu ko up lên file mới sẽ bỏ qua bước này if (m_str_previous_link != m_lbl_file_name.Text && m_lbl_file_name.Text != "") { // Kiểm tra file vừa upload đã tồn tại hay chưa if (FileExplorer.IsExistedFile(m_str_directory_to + FileExplorer.fileName)) { BaseMessages.MsgBox_Infor("Tên file đã tồn tại. Vui lòng đổi tên khác"); return(false); } // Xóa file cũ if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_previous_link)) { FileExplorer.DeleteFile(m_str_directory_to + m_str_previous_link); } // Upload file mới lên if (m_str_user_name != "") { FileExplorer.UploadFile(m_str_domain, m_str_directory_to, m_str_user_name, m_str_password); } else { FileExplorer.UploadFile(m_str_domain, m_str_directory_to); } } break; case DataEntryFileMode.DeleteFile: // Kiểm tra file có tồn tại hay không if (FileExplorer.IsExistedFile(m_str_directory_to + m_str_previous_link) == false) { BaseMessages.MsgBox_Infor("File không tồn tại!"); return(false); } FileExplorer.DeleteFile(m_str_directory_to + m_str_previous_link); break; } #endregion m_us_v_gd_luong_theo_qd.BeginTransaction(); #region Prepare for update // Bởi vì ở đây ta cần Update bảng DM_QUYET_DINH nhưng mà nó lại relate với GD_LUONG_THEO_QD theo MA_QD chứ không phải ID // Do đó ở đây ta cần Update cột MA_QD trong GD_LUONG_THEO_QD thành NULL để có thể Update ở DM_QUYET_DINH if (m_e_form_mode == DataEntryFormMode.UpdateDataState) { load_data_2_us_gd_luong_theo_qd(); m_us_v_gd_luong_theo_qd.strMA_QD = String.Empty; m_us_v_gd_luong_theo_qd.Update(); } #endregion #region Save Quyết định load_data_2_us_qd(); // Commit trans thông qua US m_us_gd_luong_theo_qd. // Việc này giúp Rollback() - ngừng connection tới DB nếu xảy ra lỗi. m_us_dm_quyet_dinh.UseTransOfUSObject(m_us_v_gd_luong_theo_qd); switch (m_e_form_mode) { case DataEntryFormMode.InsertDataState: m_us_dm_quyet_dinh.Insert(); // Trực tiếp thêm vào DataBase thành công ở bước này. // throw new Exception("DucVT: DEBUG"); // Đã Test OK. Nếu giả sử ở bước này xảy ra lỗi thì sẽ catch exception gọi RollBack() và // Xóa đi bản ghi vừa được m_us_dm_quyet_dinh.Insert() khỏi DataBase ở dòng trên đây. #region Save Gd quyết định, pháp nhân v_us_qd_pn = new US_GD_QUYET_DINH_PHAP_NHAN(); v_us_qd_pn.dcID_PHAP_NHAN = CAppContext_201.getCurrentIDPhapnhan(); // Lấy Id của bản ghi quyết định vừa được Insert ở trên vào Table DM_QUYET_DINH v_us_qd_pn.dcID_QUYET_DINH = CUtils.get_current_auto_id("DM_QUYET_DINH"); // Commit trans thông qua US m_us_gd_luong_theo_qd. v_us_qd_pn.UseTransOfUSObject(m_us_v_gd_luong_theo_qd); // Insert gd quyết định, pháp nhân v_us_qd_pn.Insert(); #endregion break; case DataEntryFormMode.SelectDataState: break; case DataEntryFormMode.UpdateDataState: m_us_dm_quyet_dinh.Update(); break; case DataEntryFormMode.ViewDataState: break; default: break; } #endregion #region Save Gd lương theo quyết định load_data_2_us_gd_luong_theo_qd(); switch (m_e_form_mode) { case DataEntryFormMode.InsertDataState: m_us_v_gd_luong_theo_qd.Insert(); // Refresh mới lại form để insert bản ghi mới CUtils.show_success_message("Thêm thành công Lương theo quyết định mới"); reset_form(); break; case DataEntryFormMode.SelectDataState: break; case DataEntryFormMode.UpdateDataState: m_us_v_gd_luong_theo_qd.Update(); this.Close(); break; case DataEntryFormMode.ViewDataState: break; default: break; } #endregion m_us_v_gd_luong_theo_qd.CommitTransaction(); if (m_e_form_mode == DataEntryFormMode.UpdateDataState) { this.Close(); } } catch (Exception v_e) { if (m_us_v_gd_luong_theo_qd.is_having_transaction()) { m_us_v_gd_luong_theo_qd.Rollback(); } CDBExceptionHandler v_objErrHandler = new CDBExceptionHandler(v_e, new CDBClientDBExceptionInterpret()); v_objErrHandler.showErrorMessage(); return(false); } return(true); }