protected void btnSave_Click(object sender, EventArgs e) { try { if (ValidateInput()) { if (cbEdit.Checked) { BranchBiz.UpdateData(txtBranchCodePopup.Text.Trim(), txtBranchNamePopup.Text.Trim(), txtWorkStartHourPopup.Text.Trim(), txtWorkStartMinPopup.Text.Trim(), txtWorkEndHourPopup.Text.Trim(), txtWorkEndMinPopup.Text.Trim(), cmbChannelPopup.SelectedItem.Value, rbActive.Checked, HttpContext.Current.User.Identity.Name); } else { BranchBiz.InsertData(txtBranchCodePopup.Text.Trim(), txtBranchNamePopup.Text.Trim(), txtWorkStartHourPopup.Text.Trim(), txtWorkStartMinPopup.Text.Trim(), txtWorkEndHourPopup.Text.Trim(), txtWorkEndMinPopup.Text.Trim(), cmbChannelPopup.SelectedItem.Value, rbActive.Checked, HttpContext.Current.User.Identity.Name); } AppUtil.ClientAlert(Page, "บันทึกข้อมูลเรียบร้อย"); ClearPopupControl(); mpePopup.Hide(); DoSearchBranch(0); } else { mpePopup.Show(); } } catch (Exception ex) { mpePopup.Show(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Debug(message); AppUtil.ClientAlert(Page, message); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (ValidateInput()) { var isConnectWsSuccess = false; var isShowException = false; //check recursive branch if (!BranchBiz.CheckRecurviceBranch(txtBranchCodeIdPopup.Text.Trim(), cmbUpperBranchPopup.SelectedItem.Value)) { isShowException = true; throw new Exception("SLM : การบันทึกข้อมูลไม่สำเร็จเนื่องจากพบ Recursive Upper Branch"); } //check duplicate name , code if (cbEdit.Checked) { //edit if (!BranchBiz.CheckDuplicateBranchNameForEdit(txtBranchCodeIdPopup.Text.Trim(), txtBranchNamePopup.Text.Trim())) { isShowException = true; throw new Exception(txtBranchNamePopup.Text.Trim() + " มีในระบบแล้ว"); } } else { if (!BranchBiz.CheckDuplicateBranchCode(txtBranchCodePopup.Text.Trim())) { isShowException = true; throw new Exception("SLM : รหัสสาขา " + txtBranchCodePopup.Text.Trim() + " มีในระบบแล้ว"); } if (!BranchBiz.CheckDuplicateBranchName(txtBranchNamePopup.Text.Trim())) { isShowException = true; throw new Exception("SLM : " + txtBranchNamePopup.Text.Trim() + " มีในระบบแล้ว"); } } if (AppConstant.CSMServiceEnableSyncBranch) { try { //send data to webservice var insertOrUpdateBranchRequest = new InsertOrUpdateBranchRequest(); insertOrUpdateBranchRequest.Header = new WebServiceHeader(); insertOrUpdateBranchRequest.Header.service_name = "CSMBranchService"; insertOrUpdateBranchRequest.Header.user_name = "SLM"; insertOrUpdateBranchRequest.Header.system_code = "SLM"; insertOrUpdateBranchRequest.Header.password = "******"; insertOrUpdateBranchRequest.Header.command = "InsertOrUpdateBranch"; insertOrUpdateBranchRequest.BranchCode = txtBranchCodePopup.Text.Trim(); insertOrUpdateBranchRequest.BranchName = txtBranchNamePopup.Text.Trim(); insertOrUpdateBranchRequest.Status = Convert.ToInt16(rbActive.Checked); insertOrUpdateBranchRequest.ChannelCode = cmbChannelPopup.SelectedItem.Value; // insertOrUpdateBranchRequest.UpperBranchCode = cmbUpperBranchPopup.SelectedItem.Value; insertOrUpdateBranchRequest.UpperBranchCode = BranchBiz.GetBranchCodeNew(cmbUpperBranchPopup.SelectedItem.Value); insertOrUpdateBranchRequest.StartTimeHour = Convert.ToInt32(txtWorkStartHourPopup.Text.Trim()); insertOrUpdateBranchRequest.StartTimeMinute = Convert.ToInt32(txtWorkStartMinPopup.Text.Trim()); insertOrUpdateBranchRequest.EndTimeHour = Convert.ToInt32(txtWorkEndHourPopup.Text.Trim()); insertOrUpdateBranchRequest.EndTimeMinute = Convert.ToInt32(txtWorkEndMinPopup.Text.Trim()); insertOrUpdateBranchRequest.ActionUsername = HttpContext.Current.User.Identity.Name; insertOrUpdateBranchRequest.HomeNo = txtAddressNo.Text; insertOrUpdateBranchRequest.Moo = txtMoo.Text; insertOrUpdateBranchRequest.Building = txtBuilding.Text; insertOrUpdateBranchRequest.Floor = txtFloor.Text; insertOrUpdateBranchRequest.Soi = txtLane.Text; insertOrUpdateBranchRequest.Street = txtStreet.Text; insertOrUpdateBranchRequest.Province = cmbProvince.SelectedValue; insertOrUpdateBranchRequest.Amphur = cmbAmphur.SelectedValue; insertOrUpdateBranchRequest.Tambol = cmbTambol.SelectedValue; insertOrUpdateBranchRequest.Zipcode = txtZipCode.Text; insertOrUpdateBranchRequest.Command = cbEdit.Checked; //Logging _log.Info("===== [Start] Call WS Submit Staff Data to CSM: InsertOrUpdateBranch ====="); _log.Debug("===== [START] Request Parameter ====="); _log.Debug("BranchCode=" + insertOrUpdateBranchRequest.BranchCode); _log.Debug("BranchName=" + insertOrUpdateBranchRequest.BranchName); _log.Debug("Status=" + insertOrUpdateBranchRequest.Status); _log.Debug("ChannelCode=" + insertOrUpdateBranchRequest.ChannelCode); _log.Debug("UpperBranchCode=" + insertOrUpdateBranchRequest.UpperBranchCode); _log.Debug("StartTimeHour=" + insertOrUpdateBranchRequest.StartTimeHour); _log.Debug("StartTimeMinute=" + insertOrUpdateBranchRequest.StartTimeMinute); _log.Debug("EndTimeHour=" + insertOrUpdateBranchRequest.EndTimeHour); _log.Debug("EndTimeMinute=" + insertOrUpdateBranchRequest.EndTimeMinute); _log.Debug("ActionUsername="******"HomeNo=" + insertOrUpdateBranchRequest.HomeNo); _log.Debug("Moo=" + insertOrUpdateBranchRequest.Moo); _log.Debug("Building=" + insertOrUpdateBranchRequest.Building); _log.Debug("Floor=" + insertOrUpdateBranchRequest.Floor); _log.Debug("Soi=" + insertOrUpdateBranchRequest.Soi); _log.Debug("Street=" + insertOrUpdateBranchRequest.Street); _log.Debug("Province=" + insertOrUpdateBranchRequest.Province); _log.Debug("Amphur=" + insertOrUpdateBranchRequest.Amphur); _log.Debug("Tambol=" + insertOrUpdateBranchRequest.Tambol); _log.Debug("Zipcode=" + insertOrUpdateBranchRequest.Zipcode); _log.Debug("===== [END] Request Parameter ====="); var start = DateTime.Now; _log.DebugFormat("Start Call InsertOrUpdateBranch at {0:dd/MM/yyyy HH:mm:ss}", start); var csmBranchService = new CSMBranchServiceClient(); var response = csmBranchService.InsertOrUpdateBranch(insertOrUpdateBranchRequest); isConnectWsSuccess = true; var stop = DateTime.Now; _log.DebugFormat("End Call InsertOrUpdateBranch at {0:dd/MM/yyyy HH:mm:ss} (Elapsed Time={1} seconds)", stop, stop.Subtract(start).TotalSeconds); if (response.StatusResponse.Status == "SUCCESS") { _log.Info("===== [End] Call WS Submit Staff Data to CSM: InsertOrUpdateBranch (SUCCESS) ====="); _log.Debug("===== [START] Response Data ====="); _log.Debug("IsSuccess=" + response.StatusResponse.Status); _log.Debug("ErrorCode=" + response.StatusResponse.ErrorCode); _log.Debug("ErrorMessage=" + response.StatusResponse.Description); _log.Debug("===== [END] Response Data ====="); } else if (response.StatusResponse.Status == "FAILED") { _log.Error("===== [End] Call WS Submit Staff Data to CSM: InsertOrUpdateBranch (FAIL) ====="); _log.Error("===== [START] Response Data ====="); _log.Error("IsSuccess=" + response.StatusResponse.Status); _log.Error("ErrorCode=" + response.StatusResponse.ErrorCode); _log.Error("ErrorMessage=" + response.StatusResponse.Description); _log.Error("===== [END] Response Data ====="); } if (response.StatusResponse.Status == "FAILED") { throw new Exception(string.Format("{0} \r\nError Message : {1}", "การบันทึกข้อมูลไม่สำเร็จที่ ระบบ CSM", !string.IsNullOrEmpty(response.StatusResponse.Description) ? response.StatusResponse.Description : string.Empty)); } } catch (Exception wsex) { _log.Error("===== [End] Call WS Submit Staff Data to CSM: InsertOrUpdateBranch (FAIL with Exception) =====", wsex); _log.Error("===== [START] FAIL with Exception ====="); _log.Error("ErrorMessage=" + (!string.IsNullOrEmpty(wsex.ToString()) ? wsex.ToString() : "การบันทึกข้อมูลไม่สำเร็จเนื่องจากไม่สามารถเชื่อมต่อระบบ CSM")); _log.Error("===== [END] FAIL with Exception ====="); if (isShowException) { throw wsex; } if (!isConnectWsSuccess) { throw new Exception("การบันทึกข้อมูลไม่สำเร็จเนื่องจากไม่สามารถเชื่อมต่อระบบ CSM"); } else { throw wsex; } } } if (cbEdit.Checked) { BranchBiz.UpdateData(txtBranchCodeOldPopup.Text.Trim(), txtBranchCodePopup.Text.Trim(), txtBranchNamePopup.Text.Trim(), txtWorkStartHourPopup.Text.Trim(), txtWorkStartMinPopup.Text.Trim(), txtWorkEndHourPopup.Text.Trim(), txtWorkEndMinPopup.Text.Trim(), cmbUpperBranchPopup.SelectedItem.Value, cmbChannelPopup.SelectedItem.Value, rbActive.Checked, HttpContext.Current.User.Identity.Name , txtAddressNo.Text, txtMoo.Text, txtBuilding.Text, txtFloor.Text, txtLane.Text, txtStreet.Text, AppUtil.SafeInt(cmbTambol.SelectedValue), AppUtil.SafeInt(cmbAmphur.SelectedValue), AppUtil.SafeInt(cmbProvince.SelectedValue), txtZipCode.Text); } else { string internalBranchCode = BranchBiz.InsertData(txtBranchCodePopup.Text.Trim(), txtBranchNamePopup.Text.Trim(), txtWorkStartHourPopup.Text.Trim(), txtWorkStartMinPopup.Text.Trim(), txtWorkEndHourPopup.Text.Trim(), txtWorkEndMinPopup.Text.Trim(), cmbUpperBranchPopup.SelectedItem.Value, cmbChannelPopup.SelectedItem.Value, rbActive.Checked, HttpContext.Current.User.Identity.Name , txtAddressNo.Text, txtMoo.Text, txtBuilding.Text, txtFloor.Text, txtLane.Text, txtStreet.Text, AppUtil.SafeInt(cmbTambol.SelectedValue), AppUtil.SafeInt(cmbAmphur.SelectedValue), AppUtil.SafeInt(cmbProvince.SelectedValue), txtZipCode.Text); InsertBranchRole(internalBranchCode); } AppUtil.ClientAlert(Page, "บันทึกข้อมูลเรียบร้อย"); ClearPopupControl(); mpePopup.Hide(); DoSearchBranch(0); } else { mpePopup.Show(); } } catch (Exception ex) { mpePopup.Show(); string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Error(message); AppUtil.ClientAlert(Page, message); } }