protected void Btn_Execute_Click(object sender, EventArgs e) { try { ErrorMsgLabel.Text = ""; string strZ_O = this.SLP_CodeFile1.Text; string strOldChanNo = this.SLP_StoreChain_OLD.Text; string strOldStore = this.SLP_Store_OLD.Text; string strSurveyDate = this.txtSURVEY_DATE.Text; string strNewChanNo = this.SLP_StoreChain_NEW.Text; string strNewStore = this.SLP_Store_NEW.Text; #region 門市 營業所Check if (SLP_CodeFile1.Text != "") { #region 原門市 營業所Check ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(strOldStore, "string")); BCO.MaintainMarketSurveyRecords bcoOldZ_O = new BCO.MaintainMarketSurveyRecords(ConnectionDB); DataTable dtZ_O = bcoOldZ_O.QueryZ_OByStore(ParameterList); if (dtZ_O == null || dtZ_O.Rows.Count == 0 || dtZ_O.Rows[0][0].ToString() != strZ_O) { ErrorMsgLabel.Text = "原門市不屬於此營業所範圍"; return; } #endregion #region 新門市 營業所Check ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(strNewStore, "string")); BCO.MaintainMarketSurveyRecords bcoNewZ_O = new BCO.MaintainMarketSurveyRecords(ConnectionDB); DataTable dtZ_ONew = bcoNewZ_O.QueryZ_OByStore(ParameterList); if (dtZ_ONew == null || dtZ_ONew.Rows.Count == 0 || dtZ_ONew.Rows[0][0].ToString() != strZ_O) { ErrorMsgLabel.Text = "新門市不屬於此營業所範圍"; return; } #endregion } #endregion #region 檢查原門市資料是否已存在市調計畫 ParameterList.Clear(); ParameterList.Add(""); ParameterList.Add(""); ParameterList.Add(GetValueSetParameter(strOldChanNo, "string")); ParameterList.Add(GetValueSetParameter(strOldStore, "string")); ParameterList.Add(GetValueSetParameter(strSurveyDate, "date")); ParameterList.Add(GetValueSetParameter(Session["UID"].ToString(), "string")); ParameterList.Add(GetValueSetParameter(SLP_CodeFile1.Text, "string")); //營業所 BCO.MaintainMarketSurveyRecords bcoMainOld = new BCO.MaintainMarketSurveyRecords(ConnectionDB); DataTable dtExistMainOld = bcoMainOld.QueryExistPk(ParameterList); if (dtExistMainOld == null || dtExistMainOld.Rows.Count == 0) { ErrorMsgLabel.Text = "原門市資料不存在市調計畫,無法複製"; return; } #endregion #region 組合複製市調計畫條件至ArrayList ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(strOldChanNo, "string")); ParameterList.Add(GetValueSetParameter(strOldStore, "string")); ParameterList.Add(GetValueSetParameter(strNewChanNo, "string")); ParameterList.Add(GetValueSetParameter(strNewStore, "string")); ParameterList.Add(GetValueSetParameter(strSurveyDate, "date")); ParameterList.Add(GetValueSetParameter(Session["UID"].ToString(), "string")); ParameterList.Add(GetValueSetParameter(SLP_CodeFile1.Text, "string")); //營業所 #endregion #region 新門市必需存在於市調門市檔 BCO.MaintainMarketSurveyStore bco = new BCO.MaintainMarketSurveyStore(ConnectionDB); DataTable dtExist = bco.QueryExistPk(ParameterList); if (dtExist == null || dtExist.Rows.Count == 0) { ErrorMsgLabel.Text = "新門市不存在於市調門市檔"; return; } #endregion #region 檢查新門市資料是否已存在市調計畫 BCO.MaintainMarketSurveyRecords bcoMain = new BCO.MaintainMarketSurveyRecords(ConnectionDB); DataTable dtExistMain = bcoMain.QueryExistPk(ParameterList); if (dtExistMain != null && dtExistMain.Rows.Count > 0) { ErrorMsgLabel.Text = "複製市調計畫至新門市失敗, 新門市資料已存在市調計畫"; return; } #endregion #region 複製市調計畫至新門市 BCO.MaintainMarketSurveyRecords bcoCopy = new BCO.MaintainMarketSurveyRecords(ConnectionDB); // 執行複製市調計畫至新門市的動作 bcoCopy.CopyToNewStore(ParameterList, null); #endregion this.ErrorMsgLabel.Text = "複製市調計畫成功"; #region 關掉POP視窗 //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Window", "alert('儲存成功');window.close();", true); #endregion } catch (Exception ex) { this.ErrorMsgLabel.Text = ex.ToString(); } finally { } }
protected void Btn_Save_Click(object sender, EventArgs e) { try { SLP_User1.Text = Page.Request.Form[SLP_User1.TextBox_Code.UniqueID]; #region 資料儲存 if (txtInvestigator.Text.Trim() == "") { ErrorMsgLabel.Text = "請輸入「市調人員」"; return; } BCO.MaintainMarketSurveyStore bco = new BCO.MaintainMarketSurveyStore(ConnectionDB); { switch (this.hid_PageStatus.Value) { case "INSERT": #region 處理新增作業 { DataTable dtExist = new DataTable(); dtExist = bco.QueryExistPk(this.getParameterList()); if (dtExist != null && dtExist.Rows.Count > 0) { ErrorMsgLabel.Text = "新增失敗, 門市(" + this.SLP_Store1.Text + ")資料已存在"; return; } #region 儲存新增資料 string strMsg = ""; // 做資料儲存的動作 int vPID = bco.CreateSurveyStore(this.getParameterList(), null, out strMsg); if (strMsg != "") { //資料儲存異常 this.ErrorMsgLabel.Text = strMsg; return; } this.hiddenID.Value = Convert.ToString(vPID); #endregion } #endregion break; case "EDIT": { #region 使用XML轉回DataSet DataTable MasterOldDt = null; if (MasterOLDData.InnerHtml != "" && MasterOLDData.InnerHtml != "<NewDataSet />") { DataSet Ds = new DataSet(); System.IO.StringReader sr = new System.IO.StringReader(MasterOLDData.InnerHtml); Ds.ReadXml(sr); MasterOldDt = Ds.Tables[0]; } #endregion string strMsg = ""; // 做資料儲存的動作 bco.UpdateSurveyStore(this.getParameterList(), MasterOldDt.Rows[0], null, out strMsg); if (strMsg != "") { //資料儲存異常 this.ErrorMsgLabel.Text = strMsg; return; } break; } break; } #region 存檔後資料重新讀取 databind_Mst(); #endregion #region 存檔後狀態設定 this.hid_PageStatus.Value = "VIEW"; this.txt_PageStatus.Text = "VIEW"; #endregion } #endregion } catch (Exception ex) { this.ErrorMsgLabel.Text = ex.ToString(); } finally { SetPageStatus(); SetDefaultValue(); } }