//--於編輯模式按下保存鈕 protected void EditSaveButton_Click(object sender, EventArgs e) { #region if (FormView1.CurrentMode == FormViewMode.Edit) { #region int UpdateRecord = 0; try { ALOModel.MaintainDisParameter BCO = new ALOModel.MaintainDisParameter(ConntionDB); #region 取得畫面元件的值 string v_CODE = ((TextBox)FormView1.FindControl("txtCODE")).Text.Trim(); string v_NAME = ((TextBox)FormView1.FindControl("txtNAME")).Text.Trim(); string v_SELECT_SW = (((CheckBox)FormView1.FindControl("chk_SELECT_SW")).Checked) ? "1" : "0"; string v_REFER_SW = (((CheckBox)FormView1.FindControl("chk_REFER_SW")).Checked) ? "1" : "0"; string v_SORT_SW = (((CheckBox)FormView1.FindControl("chk_SORT_SW")).Checked) ? "1" : "0"; string v_POS_SW = (((CheckBox)FormView1.FindControl("chk_POS_SW")).Checked) ? "1" : "0"; string v_RANK_SW = (((CheckBox)FormView1.FindControl("chk_RANK_SW")).Checked) ? "1" : "0";//20090106 added DateTime v_UPDATEDATE = Convert.ToDateTime(((WUI.SLP.SLPDate)FormView1.FindControl("SLP_SLPDate1")).Text.Trim()); string v_UPDATEUID = ((WUI.SLP.User)FormView1.FindControl("txtUser")).Text.Trim(); string v_SELECT_CHANGE = (((CheckBox)FormView1.FindControl("chk_SELECT_CHANGE")).Checked) ? "1" : "0"; int v_SELECT_PERIOD = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtPeriod")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtPeriod")).Text.Trim()); int v_SELECT_ITEM = 0; if (((WUI.SLP.SLPNumber)FormView1.FindControl("txtItemCount")).Text.Trim() != "") { v_SELECT_ITEM = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtItemCount")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtItemCount")).Text.Trim()); } int v_SELECT_P_FROM = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtPFrom")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtPFrom")).Text.Trim()); int v_SELECT_P_TO = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtPTo")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtPTo")).Text.Trim()); string v_REFER_CHANGE = (((CheckBox)FormView1.FindControl("chk_REFER_CHANGE")).Checked) ? "1" : "0"; int v_REFER_OTHER = 0; if (((WUI.SLP.SLPNumber)FormView1.FindControl("txtRateOther")).Text.Trim() != "") { v_REFER_OTHER = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtRateOther")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtRateOther")).Text.Trim()); } int v_REFER_RATE1 = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate1")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate1")).Text.Trim()); int v_REFER_RATE2 = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate2")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate2")).Text.Trim()); int v_REFER_RATE3 = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate3")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate3")).Text.Trim()); int v_REFER_RATE4 = Convert.ToInt32((((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate4")).Text.Trim() == "") ? "0" : ((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate4")).Text.Trim()); string v_SORT_KEY1 = ((TextBox)FormView1.FindControl("txtSort1")).Text.Trim(); string v_SORT_KEY2 = ((TextBox)FormView1.FindControl("txtSort2")).Text.Trim(); string v_SORT_KEY3 = ((TextBox)FormView1.FindControl("txtSort3")).Text.Trim(); #endregion #region 檢查輸入值 if (GetStringLen(v_NAME) > 20) { ErrorMsgLabel.Text = "參數名稱限制20個字元"; return; } //20090106 marked //if (v_SELECT_P_TO != (v_SELECT_PERIOD + v_SELECT_P_FROM - 1)) //{ // ScriptManager.RegisterStartupScript(Page, this.GetType(), "ALO022.aspx", "alert(' [前幾期To] 須等於 [往前取幾期] + [前幾期From] - 1 ');", true); // return; //} //if ((v_REFER_RATE1 + v_REFER_RATE2 + v_REFER_RATE3 + v_REFER_RATE4) != 100) //{ // ScriptManager.RegisterStartupScript(Page, this.GetType(), "ALO022.aspx", "alert(' 比率1 + 比率2 + 比率3 + 比率4 的總合須為100 ');", true); // return; //} #endregion #region 取得更新前舊值 #region 使用XML轉回DataSet //if ( MasterOLDData.InnerHtml //DataSet Ds = new DataSet(); //System.IO.StringReader sr = new System.IO.StringReader(MasterOLDData.InnerHtml); //Ds.ReadXml(sr); //DataTable Dt = Ds.Tables[0]; #endregion //if (Ds.Tables[0].Rows.Count == 0) //{ // throw new Exception("抓取不到舊值,更新失敗!"); //} #endregion #region 加入更新條件 ArrayList ParameterList = new ArrayList();//20091112 ParameterList.Clear(); //舊值 ParameterList.Add(v_CODE); ParameterList.Add(v_UPDATEDATE); ParameterList.Add(v_UPDATEUID); //需要更新值 ParameterList.Add(v_CODE); ParameterList.Add(v_NAME); ParameterList.Add(v_SELECT_SW); ParameterList.Add(v_REFER_SW); ParameterList.Add(v_SORT_SW); ParameterList.Add(v_POS_SW); ParameterList.Add(DateTime.Now); if (Session["UID"] == null) throw new Exception("Session Time Out"); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(v_SELECT_CHANGE); ParameterList.Add(v_SELECT_PERIOD); ParameterList.Add(v_SELECT_ITEM); ParameterList.Add(v_SELECT_P_FROM); ParameterList.Add(v_SELECT_P_TO); ParameterList.Add(v_REFER_CHANGE); ParameterList.Add(v_REFER_OTHER); ParameterList.Add(v_REFER_RATE1); ParameterList.Add(v_REFER_RATE2); ParameterList.Add(v_REFER_RATE3); ParameterList.Add(v_REFER_RATE4); ParameterList.Add(v_SORT_KEY1); ParameterList.Add(v_SORT_KEY2); ParameterList.Add(v_SORT_KEY3); ParameterList.Add("1");//ENABLE ParameterList.Add(v_RANK_SW);//200901016 added #endregion UpdateRecord = BCO.UpdateDisParameter(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("更新0筆資料!"); } else { //Response.Write(string.Format("<script>alert('更改完成');location.replace('ALO022.aspx?CODE=ALO02&PARAMCODE={0}&CurrentMode=readonly');</script>", v_CODE)); //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", string.Format("alert('更改完成');location.replace('ALO022.aspx?Code=ALO02&PARAMCODE={0}&CurrentMode=readonly');", v_CODE), true); ResultMsgLabel.Text = "更新完成"; SwitchFormviewMode(FormViewMode.ReadOnly); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion } #endregion }
//--於檢視模式按下刪除鈕 protected void ReadonlyDeleteButton_Click(object sender, EventArgs e) { #region int UpdateRecord = 0; try { #region 取得畫面元件的值 string v_CODE = ((TextBox)FormView1.FindControl("txtCODE")).Text.Trim(); string v_NAME = ((TextBox)FormView1.FindControl("txtNAME")).Text.Trim(); string v_SELECT_SW = (((CheckBox)FormView1.FindControl("chk_SELECT_SW")).Checked) ? "1" : "0"; string v_REFER_SW = (((CheckBox)FormView1.FindControl("chk_REFER_SW")).Checked) ? "1" : "0"; string v_SORT_SW = (((CheckBox)FormView1.FindControl("chk_SORT_SW")).Checked) ? "1" : "0"; string v_POS_SW = (((CheckBox)FormView1.FindControl("chk_POS_SW")).Checked) ? "1" : "0"; string v_RANK_SW = (((CheckBox)FormView1.FindControl("chk_RANK_SW")).Checked) ? "1" : "0";//20090106 added DateTime v_UPDATEDATE = Convert.ToDateTime(((WUI.SLP.SLPDate)FormView1.FindControl("SLP_SLPDate1")).Text.Trim()); string v_UPDATEUID = ((WUI.SLP.User)FormView1.FindControl("txtUser")).Text.Trim(); string v_SELECT_CHANGE = (((CheckBox)FormView1.FindControl("chk_SELECT_CHANGE")).Checked) ? "1" : "0"; int v_SELECT_PERIOD = 0; int v_SELECT_ITEM = 0; int v_SELECT_P_FROM = 0; int v_SELECT_P_TO = 0; Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtPeriod")).Text.Trim(), out v_SELECT_PERIOD); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtItemCount")).Text.Trim(), out v_SELECT_ITEM); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtPFrom")).Text.Trim(), out v_SELECT_P_FROM); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtPTo")).Text.Trim(), out v_SELECT_P_TO); string v_REFER_CHANGE = (((CheckBox)FormView1.FindControl("chk_REFER_CHANGE")).Checked) ? "1" : "0"; int v_REFER_OTHER = 0; int v_REFER_RATE1 = 0; int v_REFER_RATE2 = 0; int v_REFER_RATE3 = 0; int v_REFER_RATE4 = 0; Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtRateOther")).Text.Trim(), out v_REFER_OTHER); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate1")).Text.Trim(), out v_REFER_RATE1); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate2")).Text.Trim(), out v_REFER_RATE2); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate3")).Text.Trim(), out v_REFER_RATE3); Int32.TryParse(((WUI.SLP.SLPNumber)FormView1.FindControl("txtRate4")).Text.Trim(), out v_REFER_RATE4); string v_SORT_KEY1 = ((TextBox)FormView1.FindControl("txtSort1")).Text.Trim(); string v_SORT_KEY2 = ((TextBox)FormView1.FindControl("txtSort2")).Text.Trim(); string v_SORT_KEY3 = ((TextBox)FormView1.FindControl("txtSort3")).Text.Trim(); #endregion #region 取得更新前舊值 #region 使用XML轉回DataSet DataSet Ds = new DataSet(); System.IO.StringReader sr = new System.IO.StringReader(MasterOLDData.InnerHtml); Ds.ReadXml(sr); DataTable Dt = Ds.Tables[0]; #endregion if (Ds.Tables[0].Rows.Count == 0) { throw new Exception("抓取不到舊值,更新失敗!"); } #endregion #region 加入更新條件 ArrayList ParameterList = new ArrayList();//20091112 ParameterList.Clear(); //舊值 ParameterList.Add(v_CODE); ParameterList.Add(v_UPDATEDATE); ParameterList.Add(v_UPDATEUID); #region deleted //ParameterList.Add(Dt.Rows[0]["NAME"]); //ParameterList.Add(Dt.Rows[0]["SELECT_SW"]); //ParameterList.Add(Dt.Rows[0]["REFER_SW"]); //ParameterList.Add(Dt.Rows[0]["SORT_SW"]); //ParameterList.Add(Dt.Rows[0]["POS_SW"]); //ParameterList.Add(Dt.Rows[0]["UPDATEDATE"]); //ParameterList.Add(Dt.Rows[0]["UPDATEUID"]); //ParameterList.Add(Dt.Rows[0]["SELECT_CHANGE"]); //ParameterList.Add(Dt.Rows[0]["SELECT_PERIOD"]); //ParameterList.Add(Dt.Rows[0]["SELECT_ITEM"]); //ParameterList.Add(Dt.Rows[0]["SELECT_P_FROM"]); //ParameterList.Add(Dt.Rows[0]["SELECT_P_TO"]); //ParameterList.Add(Dt.Rows[0]["REFER_CHANGE"]); //ParameterList.Add(Dt.Rows[0]["REFER_OTHER"]); //ParameterList.Add(Dt.Rows[0]["REFER_RATE1"]); //ParameterList.Add(Dt.Rows[0]["REFER_RATE2"]); //ParameterList.Add(Dt.Rows[0]["REFER_RATE3"]); //ParameterList.Add(Dt.Rows[0]["REFER_RATE4"]); //ParameterList.Add(Dt.Rows[0]["SORT_KEY1"]); //ParameterList.Add(Dt.Rows[0]["SORT_KEY2"]); //ParameterList.Add(Dt.Rows[0]["SORT_KEY3"]); #endregion //需要更新值 ParameterList.Add(v_CODE); ParameterList.Add(v_NAME); ParameterList.Add(v_SELECT_SW); ParameterList.Add(v_REFER_SW); ParameterList.Add(v_SORT_SW); ParameterList.Add(v_POS_SW); ParameterList.Add(DateTime.Now); if (Session["UID"] == null) throw new Exception("Session Time Out"); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(v_SELECT_CHANGE); ParameterList.Add(v_SELECT_PERIOD); ParameterList.Add(v_SELECT_ITEM); ParameterList.Add(v_SELECT_P_FROM); ParameterList.Add(v_SELECT_P_TO); ParameterList.Add(v_REFER_CHANGE); ParameterList.Add(v_REFER_OTHER); ParameterList.Add(v_REFER_RATE1); ParameterList.Add(v_REFER_RATE2); ParameterList.Add(v_REFER_RATE3); ParameterList.Add(v_REFER_RATE4); ParameterList.Add(v_SORT_KEY1); ParameterList.Add(v_SORT_KEY2); ParameterList.Add(v_SORT_KEY3); ParameterList.Add("0");//ENABLE ParameterList.Add(v_RANK_SW);//200901016 added #endregion ALOModel.MaintainDisParameter BCO = new ALOModel.MaintainDisParameter(ConntionDB); UpdateRecord = BCO.UpdateDisParameter(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("刪除0筆資料!"); } else { ResultMsgLabel.Text = "刪除完成"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", string.Format("location.replace('ALO021.aspx?Code=ALO02');"), true);//alert('刪除完成'); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }