/// <summary> /// 繫結資料到畫面控制項 /// </summary> private void LoadData() { DataTable dt = new DataTable(); BCO.VAM15_BCO bco = new BCO.VAM15_BCO(ConntionDB); if (ViewState["Mode"].ToString() == "INSERT")//Model:新增 { ParameterList.Clear(); ParameterList.Add("XXXXXXXXXXXXXXXXXXXX"); dt = bco.QueryDetail(ParameterList); for (int i = 0; i < 5; i++) addRow(ref dt, i); gv_Detail.DataSource = dt; gv_Detail.DataBind(); } else if ((ViewState["Mode"].ToString() == "VIEW") || (ViewState["Mode"].ToString() == "EDIT"))//Model:檢視/編輯 { SLP_PROMOTE.Text = ViewState["PROMOTE_ID"].ToString(); ParameterList.Clear(); ParameterList.Add(ViewState["PROMOTE_ID"].ToString()); dt = bco.QueryDetail(ParameterList); if (dt.Rows.Count > 0) { txtUPDATEDATE.Text = dt.Rows[0]["UPDATEDATE"].ToString(); SLP_UPDATEUSER.Text = dt.Rows[0]["UPDATEUID"].ToString(); gv_Detail.DataSource = dt; gv_Detail.DataBind(); CheckReadOnly(dt); } else { ErrorMsgLabel.Text = "查無資料"; } } Session["VAM15_DTL_" + PageTimeStamp.Value] = dt; }
// Save 事件 protected void BtnSave_Click(object sender, EventArgs e) { gv_Detail_CacheUpdate(); DataTable NewDetail = null; string strCheckMsg = string.Empty; ErrorMsgLabel.Text = ""; try { BCO.VAM15_BCO bco = new BCO.VAM15_BCO(ConntionDB); if (this.SLP_PROMOTE.Text.Trim() == "") { ErrorMsgLabel.Text = "檔期編號必填!!"; return; } if (CheckExist_PROMOTE(this.SLP_PROMOTE.Text.Trim()) == false) { ErrorMsgLabel.Text = "此檔期編號不存在!!"; return; } if (ViewState["Mode"].ToString() == "INSERT") { ParameterList.Clear(); ParameterList.Add(SLP_PROMOTE.Text.Trim()); DataTable dtCheck = bco.QueryDetail(ParameterList); if (dtCheck.Rows.Count > 0) { ErrorMsgLabel.Text = "此檔期編號已有設定資料存在!!"; return; } } //1.同一個檔期,廠商,稅別 只允許一筆 //2.如果廠商未輸入要提示哪一行 //3.無明細不允許儲存 int iSaveRows = 0;//預計儲存的筆數 for (int i = 0; i < gv_Detail.Rows.Count; i++) { string strVendor = ((SLP_VendorBase)gv_Detail.Rows[i].FindControl("SLP_Vendor")).Text.Trim(); string strTAXTYPE = ((ASP.sys_slp_slp_enumbase_ascx)gv_Detail.Rows[i].FindControl("SLP_TAXTYPE")).Text.Trim(); string strSUM_AMT = ((TextBox)gv_Detail.Rows[i].FindControl("txtSUM_AMT")).Text.Trim(); if ((strVendor == "") && (strSUM_AMT != "0")) { strCheckMsg += "第 " + (i + 1) + " 列 資料輸入不完整<br />"; } else if (strVendor != "") { if (CheckExist_Vendor(strVendor) == false) { strCheckMsg += "第 " + (i + 1) + " 列 廠商編號不存在<br />"; } else { iSaveRows++; for (int j = 0; j < gv_Detail.Rows.Count; j++) { if (i != j) { if ((strVendor == ((SLP_VendorBase)gv_Detail.Rows[j].FindControl("SLP_Vendor")).Text.Trim()) && (strTAXTYPE == ((ASP.sys_slp_slp_enumbase_ascx)gv_Detail.Rows[j].FindControl("SLP_TAXTYPE")).Text.Trim())) { strCheckMsg += "第 " + (i + 1) + " 列 與第 " + (j + 1) + " 列 為相同的廠商和稅別資料 <br />"; break; } } } } } } if (strCheckMsg != "") { ErrorMsgLabel.Text = strCheckMsg; return; } if (iSaveRows == 0) { ErrorMsgLabel.Text = "明細資料未設定!!"; return; } ParameterList.Clear(); ParameterList.Add(SLP_PROMOTE.Text.Trim()); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(SLP_UPDATEUSER.Text.Trim()); ParameterList.Add(txtUPDATEDATE.Text.Trim()); bco.SaveData((DataTable)Session["VAM15_DTL_" + PageTimeStamp.Value], ParameterList); Response.Redirect("VAM152.aspx?PROMOTE_ID=" + this.SLP_PROMOTE.Text.Trim() + "&SSID=" + ViewState["SSID"].ToString() + "&mode=VIEW&Code=VAM15"); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
// 新增明細事件 protected void btnAddDetail_Click(object sender, EventArgs e) { ErrorMsgLabel.Text = ""; int iStartID = 0; if (ViewState["Mode"].ToString() == "INSERT" || ViewState["Mode"].ToString() == "EDIT") { gv_Detail_CacheUpdate(); DataTable dt = (DataTable)Session["VAM15_DTL_" + PageTimeStamp.Value]; if (dt == null || dt.Rows.Count == 0) { BCO.VAM15_BCO bco = new BCO.VAM15_BCO(ConntionDB); ParameterList.Clear(); ParameterList.Add("XXXXXXXXXXXXXXXXXXXX"); dt = bco.QueryDetail(ParameterList); //抓取SCHEMA而已 iStartID = 1; } else { iStartID = int.Parse(dt.Compute("MAX(ID)", null).ToString()) + 1; } addRow(ref dt, iStartID); GV_SHOW(); } }
private DataTable Get_MainData(string strPROMOTE_ID) { BCO.VAM15_BCO bco = new BCO.VAM15_BCO(ConntionDB); ParameterList.Clear(); ParameterList.Add(strPROMOTE_ID); DataTable dt = bco.QueryDetail(ParameterList); return dt; }