private DataSet QueryData(string CNT_NO, string EDIT_NO, bool isToolBar) { //處理若使用者刪除資料,於另一Tab頁按上、下筆時會查不到資料,此時將以下按鈕Disable btnAdd_Mode.Enabled = true; btnDel.Enabled = true; btnModify_Mode.Enabled = true; btnCopy_Mode.Enabled = true; btnStoreGroup.Enabled = true; btnSingleBook.Enabled = true; btnSetLvel.Enabled = true; ClearAllField(); ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); DataSet ds = new DataSet(); string SessionIDName = "VDM022_" + PageTimeStamp.Value; ds = (DataSet)Session[SessionIDName]; DataTable dt = new DataTable(); BCO.MaintainVendorAgm bco = new BCO.MaintainVendorAgm(ConntionDB); dt = bco.QueryAgmByEdit(ParameterList); dt.TableName = "Table_0"; //VDS_VDM_CONTRACT_MST ds.Tables.Add(dt.Copy()); if (dt.Rows.Count > 0) { txtVENDOR_CODE.Text = dt.Rows[0]["VENDOR_CODE"].ToString(); txtEDIT_NO.Text = dt.Rows[0]["EDIT_NO"].ToString(); ddlPAY_TYPE.Text = dt.Rows[0]["PAY_TYPE"].ToString(); txtCOL_DAYS.Text = dt.Rows[0]["COL_DAYS"].ToString(); slpCNT_VALID_DATE.Text = dt.Rows[0]["CNT_VALID_DATE"].ToString(); slpCNT_END_DATE.Text = dt.Rows[0]["CNT_END_DATE"].ToString(); foreach (ListItem li in slpCNT_CONFIRM_CODE.Items) li.Selected = (li.Value == dt.Rows[0]["CNT_CONFIRM_CODE"].ToString() ? true : false); slpCNT_CONFIRM_DATE.Text = dt.Rows[0]["CNT_CONFIRM_DATE"].ToString(); txtCNT_NO.Text = dt.Rows[0]["CNT_NO"].ToString(); slpTRACE_DATE_B.Text = dt.Rows[0]["TRACE_DATE_B"].ToString(); slpTRACE_DATE_E.Text = dt.Rows[0]["TRACE_DATE_E"].ToString(); txtYEAR_MONTH.Text = dt.Rows[0]["TRACING_CHECK_MONTH"].ToString(); slpSTOP_DATE.Text = dt.Rows[0]["STOP_DATE"].ToString(); slpRESUME_DATE_B.Text = dt.Rows[0]["RESUME_DATE_B"].ToString(); slpRESUME_DATE_E.Text = dt.Rows[0]["RESUME_DATE_E"].ToString(); slpBELOW_SUBVEN.Text = dt.Rows[0]["BELOW_SUBVEN"].ToString(); slpBELOW_SUBVEN_PAY_TYPE.Text = dt.Rows[0]["BELOW_SUBVEN_PAY_TYPE"].ToString(); slpBELOW_SUBVEN_TYPE.Text = dt.Rows[0]["BELOW_SUBVEN_TYPE"].ToString(); slpBELOW_SUBVEN_RATE.Text = dt.Rows[0]["BELOW_SUBVEN_RATE"].ToString(); SLP_SLPDate1.Text = dt.Rows[0]["CREATEDATE"].ToString();//建立日期 SLP_User1.Text = dt.Rows[0]["CREATEUID"].ToString();//建立人員 SLP_SLPDate2.Text = dt.Rows[0]["UPDATEDATE"].ToString();//異動日期 SLP_User2.Text = dt.Rows[0]["UPDATEUID"].ToString();//異動人員 ViewState["EDIT_NO"] = dt.Rows[0]["EDIT_NO"].ToString(); ViewState["STOP_DATE"] = dt.Rows[0]["STOP_DATE"].ToString(); //該份合約已終止往來,無法新增履歷 dt = bco.QueryAnnualByEdit(ParameterList); dt.TableName = "Table_7"; //VDS_VDM_CONTRACT_ANNUAL ds.Tables.Add(dt.Copy()); if (dt.Rows.Count > 0) { rdoCOUNT_TYPE1.Checked = dt.Rows[0]["COUNT_TYPE"].ToString() == "1" ? true : false; rdoCOUNT_TYPE2.Checked = dt.Rows[0]["COUNT_TYPE"].ToString() == "2" ? true : false; SLP_CodeFile4.Text = dt.Rows[0]["PAY_TYPE"].ToString(); foreach (ListItem li in SLP_CodeFile3.Items) li.Selected = (li.Value == dt.Rows[0]["ANNUAL_RULE"].ToString() ? true : false); //部分店群 if (rdoCOUNT_TYPE1.Checked) { btnSetCountStore.Enabled = false; } else { if (((DropDownList)SLP_CodeFile4.FindControl("D1")).SelectedValue != "1") { btnSetCountStore.Enabled = true; } else { btnSetCountStore.Enabled = false; } } } dt = bco.QueryTargetByEdit(ParameterList); if (dt.Rows.Count > 0) { if (ViewState["ROWNUM"] != null)//取得最大筆數值,以便以後可以新增Detail資料 ViewState["ROWNUM"] = Int32.Parse(ViewState["ROWNUM"].ToString()) + dt.Rows.Count; else ViewState["ROWNUM"] = dt.Rows.Count; //DataRow[] drs = dt.Select("VENDOR_CODE like '%'", "ROW_ID desc"); //ViewState["ROW_ID"] = drs[0]["ROW_ID"]; ds = FillDataSet(ds, null, dt, "Table_3"); Session["VDM022_" + PageTimeStamp.Value] = ds; GridView_3.DataSource = ds.Tables["Table_3"]; g = 1; GridView_3.DataBind(); } dt = bco.QueryStoreByEdit(ParameterList); if (dt.Rows.Count > 0) { ViewState["ROWNUM"] = dt.Rows.Count; DataRow[] drs = dt.Select("COUNT_TYPE='1'"); //COUNT_TYPE 設定類別:1.未達銷售補貼(排除)2.獎勵金(排除)3.年度獎勵金 4.油價補貼 if (drs.Length > 0) ds = FillDataSet(ds, drs, null, "Table_1"); GridView_1.DataSource = ds.Tables["Table_1"]; g = 1; GridView_1.DataBind(); drs = dt.Select("COUNT_TYPE='2'"); if (drs.Length > 0) ds = FillDataSet(ds, drs, null, "Table_4"); //GridView_4.DataSource = ds.Tables["Table_4"]; GridView_4.DataSource = null; g = 1; GridView_4.DataBind(); drs = dt.Select("COUNT_TYPE='3'"); if (drs.Length > 0) ds = FillDataSet(ds, drs, null, "Table_6"); GridView_6.DataSource = ds.Tables["Table_6"]; g = 1; GridView_6.DataBind(); //油價補貼 drs = dt.Select("COUNT_TYPE='4'"); if (drs.Length > 0) ds = FillDataSet(ds, drs, null, "Table_SUBSIDY2"); GridView_SUBSIDY2.DataSource = ds.Tables["Table_SUBSIDY2"]; g = 1; GridView_SUBSIDY2.DataBind(); } dt = bco.QueryItemByEdit(ParameterList); if (dt.Rows.Count > 0) { if (ViewState["ROWNUM"] != null) ViewState["ROWNUM"] = Int32.Parse(ViewState["ROWNUM"].ToString()) + dt.Rows.Count; else ViewState["ROWNUM"] = dt.Rows.Count; ds = FillDataSet(ds, null, dt, "Table_2"); GridView_2.DataSource = ds.Tables["Table_2"]; g = 1; GridView_2.DataBind(); } ParameterList.Clear(); if (ds.Tables["Table_7"].Rows.Count > 0) { ParameterList.Add(ds.Tables["Table_7"].Rows[0]["ID"].ToString()); dt = bco.QueryRangeByEdit(ParameterList); if (dt.Rows.Count > 0) { if (ViewState["ROWNUM"] != null) ViewState["ROWNUM"] = Int32.Parse(ViewState["ROWNUM"].ToString()) + dt.Rows.Count; else ViewState["ROWNUM"] = dt.Rows.Count; ds = FillDataSet(ds, null, dt, "Table_5"); // GridView_5.DataSource = ds.Tables["Table_5"]; DataView dv_Table_5 = ds.Tables["Table_5"].DefaultView; dv_Table_5.Sort = "TARGET_AMT"; GridView_5.DataSource = dv_Table_5; g = 1; GridView_5.DataBind(); } } //載入預設值 //油價補貼 rblSUBSIDY2_TYPE.SelectedValue = "2"; rblSUBSIDY2_COUNT_TYPE.SelectedValue = "0"; ddlSUBSIDY2_PAY_TYPE.SelectedValue = "4"; ddlSUBSIDY2_RULE.SelectedValue = "6"; ViewState["Temp_SUBSIDY2_RULE_Selected_OLD"] = ddlSUBSIDY2_RULE.SelectedValue; slpSUBSIDY2_RATE.Text = ""; btnSUBSIDY2_StoreGroup.Enabled = false; //離島配送費 rblSUBSIDY1_COUNT_TYPE.SelectedValue = "0"; ddlSUBSIDY1_PAY_TYPE.SelectedValue = "4"; ddlSUBSIDY1_RULE.SelectedValue = "6"; slpSUBSIDY1_RATE.Text = ""; //轉運費 rblSUBSIDY4_COUNT_TYPE.SelectedValue = "0"; #region 油價補貼 ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(2); dt = bco.QuerySUBSIDYByEdit(ParameterList); ds = FillDataSet(ds, null, dt, "Table_SUBSIDY_DATA_2"); if (dt.Rows.Count > 0) { rblSUBSIDY2_TYPE.SelectedValue = "2"; rblSUBSIDY2_COUNT_TYPE.SelectedValue = dt.Rows[0]["COUNT_TYPE"].ToString(); slpSUBSIDY2_RATE.Text = dt.Rows[0]["SUBSIDY_RATE"].ToString(); ddlSUBSIDY2_PAY_TYPE.SelectedValue = dt.Rows[0]["PAY_TYPE"].ToString(); ddlSUBSIDY2_RULE.SelectedValue = dt.Rows[0]["SUBSIDY_RULE"].ToString(); ViewState["Temp_SUBSIDY2_RULE_Selected_OLD"] = ddlSUBSIDY2_RULE.SelectedValue; } ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(3); dt = bco.QuerySUBSIDYByEdit(ParameterList); ds = FillDataSet(ds, null, dt, "Table_SUBSIDY_DATA_3"); if (dt.Rows.Count > 0) { rblSUBSIDY2_TYPE.SelectedValue = "3"; rblSUBSIDY2_COUNT_TYPE.SelectedValue = dt.Rows[0]["COUNT_TYPE"].ToString(); slpSUBSIDY2_RATE.Text = dt.Rows[0]["SUBSIDY_RATE"].ToString(); ddlSUBSIDY2_PAY_TYPE.SelectedValue = dt.Rows[0]["PAY_TYPE"].ToString(); ddlSUBSIDY2_RULE.SelectedValue = dt.Rows[0]["SUBSIDY_RULE"].ToString(); ViewState["Temp_SUBSIDY2_RULE_Selected_OLD"] = ddlSUBSIDY2_RULE.SelectedValue; //油價補貼的店群設定讀取在上方已先執行 } if (rblSUBSIDY2_COUNT_TYPE.SelectedValue == "2") { btnSUBSIDY2_StoreGroup.Enabled = true; } else { btnSUBSIDY2_StoreGroup.Enabled = false; } #endregion #region 離島配送費 ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(1); dt = bco.QuerySUBSIDYByEdit(ParameterList); ds = FillDataSet(ds, null, dt, "Table_SUBSIDY_DATA_1"); if (dt.Rows.Count > 0) { rblSUBSIDY1_COUNT_TYPE.SelectedValue = dt.Rows[0]["COUNT_TYPE"].ToString(); slpSUBSIDY1_RATE.Text = dt.Rows[0]["SUBSIDY_RATE"].ToString(); ddlSUBSIDY1_PAY_TYPE.SelectedValue = dt.Rows[0]["PAY_TYPE"].ToString(); ddlSUBSIDY1_RULE.SelectedValue = dt.Rows[0]["SUBSIDY_RULE"].ToString(); } #endregion #region 轉運費 ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(4); dt = bco.QuerySUBSIDYByEdit(ParameterList); ds = FillDataSet(ds, null, dt, "Table_SUBSIDY_DATA_4"); if (dt.Rows.Count > 0) { rblSUBSIDY4_COUNT_TYPE.SelectedValue = dt.Rows[0]["COUNT_TYPE"].ToString(); } #endregion ds.AcceptChanges(); Session["VDM022_" + PageTimeStamp.Value] = ds; return ds; } else { if (isToolBar) //lblErrMsg.Text = "此筆資料已被其他使用者刪除,請點選上一筆/下一筆鈕繼續查詢"; ScriptManager.RegisterStartupScript(Page, this.GetType(), "VDM022_alert", "alert('此筆資料已被其他使用者刪除,請點選上一筆/下一筆鈕繼續查詢');", true); else ScriptManager.RegisterStartupScript(Page, this.GetType(), "VDM022_alert", "alert('無法取得資料');", true); //lblErrMsg.Text = "無法取得資料"; ClearAllField(); ReadOnlyMode(); DisableForm(true); btnAdd_Mode.Enabled = false; btnDel.Enabled = false; btnModify_Mode.Enabled = false; btnCopy_Mode.Enabled = false; btnStoreGroup.Enabled = false; btnSingleBook.Enabled = false; btnSetLvel.Enabled = false; return null; } }
private void QueryData(string CNT_NO, string EDIT_NO, bool isToolBar) { DataTable dtTemp; ClearAllField(); ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); string SessionIDName = "VDM081_" + PageTimeStamp.Value; BCO.MaintainVendorAgm bco = new BCO.MaintainVendorAgm(ConntionDB); DataTable dt1 = bco.QueryAgmByEdit(ParameterList); if (dt1.Rows.Count > 0) { Panel2.Visible = false; Panel3.Visible = false; Panel4.Visible = false; Panel5.Visible = false; Panel6.Visible = false; Panel7.Visible = false; Panel8.Visible = false; Panel9.Visible = false; Panel10.Visible = false; Panel11.Visible = false; Panel12.Visible = false; //1. Session["VDM081_DT1_" + PageTimeStamp.Value] = dt1; txtVENDOR_CODE.Text = dt1.Rows[0]["VENDOR_CODE"].ToString(); txtEDIT_NO.Text = dt1.Rows[0]["EDIT_NO"].ToString(); ddlPAY_TYPE.Text = dt1.Rows[0]["PAY_TYPE"].ToString(); txtCOL_DAYS.Text = dt1.Rows[0]["COL_DAYS"].ToString(); slpCNT_VALID_DATE.Text = dt1.Rows[0]["CNT_VALID_DATE"].ToString(); slpCNT_END_DATE.Text = dt1.Rows[0]["CNT_END_DATE"].ToString(); foreach (ListItem li in slpCNT_CONFIRM_CODE.Items) li.Selected = (li.Value == dt1.Rows[0]["CNT_CONFIRM_CODE"].ToString() ? true : false); slpCNT_CONFIRM_DATE.Text = dt1.Rows[0]["CNT_CONFIRM_DATE"].ToString(); txtCNT_NO.Text = dt1.Rows[0]["CNT_NO"].ToString(); //2. BELOW_SUBVEN is not null AND ! = 0 才顯示 if ((dt1.Rows[0]["BELOW_SUBVEN"].ToString() != "0") && (dt1.Rows[0]["BELOW_SUBVEN"].ToString() != "")) { Panel2.Visible = true; slpBELOW_SUBVEN.Text = dt1.Rows[0]["BELOW_SUBVEN"].ToString(); slpBELOW_SUBVEN_PAY_TYPE.Text = dt1.Rows[0]["BELOW_SUBVEN_PAY_TYPE"].ToString(); slpBELOW_SUBVEN_TYPE.Text = dt1.Rows[0]["BELOW_SUBVEN_TYPE"].ToString(); slpBELOW_SUBVEN_RATE.Text = dt1.Rows[0]["BELOW_SUBVEN_RATE"].ToString(); } //3 & 7 DataTable dt2 = bco.QueryStoreByEdit(ParameterList); if (dt2.Rows.Count > 0) { Session["VDM081_DT2_" + PageTimeStamp.Value] = dt2; dtTemp = Fill_DataTable(dt2, "COUNT_TYPE='1'"); GridView_1.DataSource = dtTemp; ////COUNT_TYPE 設定類別:1.未達銷售補貼(排除)2.獎勵金(排除)3.年度獎勵金 GridView_1.DataBind(); if (dtTemp.Rows.Count > 0) Panel3.Visible = true; dtTemp = Fill_DataTable(dt2, "COUNT_TYPE='3'"); GridView_6.DataSource = dtTemp; GridView_6.DataBind(); if (dtTemp.Rows.Count > 0) Panel7.Visible = true; } //4 DataTable dt3 = bco.QueryItemByEdit(ParameterList); if (dt3.Rows.Count > 0) { Session["VDM081_DT3_" + PageTimeStamp.Value] = dt3; GridView_2.DataSource = dt3; GridView_2.DataBind(); if (dt3.Rows.Count > 0) Panel4.Visible = true; } //5.1 DataTable dt4 = bco.QueryTargetByEdit(ParameterList); if (dt4.Rows.Count > 0) { iGV3_NO = 0; Session["VDM081_DT4_" + PageTimeStamp.Value] = dt4; Repeater1.DataSource = dt4; Repeater1.DataBind(); if (dt4.Rows.Count > 0) Panel5.Visible = true; } //6 & 8 DataTable dt5 = bco.QueryAnnualByEdit(ParameterList); if (dt5.Rows.Count > 0) { Session["VDM081_DT5_" + PageTimeStamp.Value] = dt5; rdoCOUNT_TYPE1.Checked = dt5.Rows[0]["COUNT_TYPE"].ToString() == "1" ? true : false; rdoCOUNT_TYPE2.Checked = dt5.Rows[0]["COUNT_TYPE"].ToString() == "2" ? true : false; SLP_CodeFile4.Text = dt5.Rows[0]["PAY_TYPE"].ToString(); foreach (ListItem li in SLP_CodeFile3.Items) li.Selected = (li.Value == dt5.Rows[0]["ANNUAL_RULE"].ToString() ? true : false); ParameterList.Clear(); ParameterList.Add(dt5.Rows[0]["ID"].ToString()); DataTable dt6 = bco.QueryRangeByEdit(ParameterList); if (dt6.Rows.Count > 0) { Panel6.Visible = true; Session["VDM081_DT6_" + PageTimeStamp.Value] = dt6; DataView dv6 = dt6.DefaultView; dv6.Sort = "TARGET_AMT"; GridView_5.DataSource = dv6; GridView_5.DataBind(); if (dt6.Rows.Count > 0) Panel8.Visible = true; } } #region 油價補貼 ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(2); DataTable dt7 = bco.QuerySUBSIDYByEdit(ParameterList); if (dt7.Rows.Count > 0) { Panel9.Visible = true; Session["VDM081_DT7_" + PageTimeStamp.Value] = dt7; rblSUBSIDY2_TYPE.SelectedValue = "2"; rblSUBSIDY2_COUNT_TYPE.SelectedValue = dt7.Rows[0]["COUNT_TYPE"].ToString(); slpSUBSIDY2_RATE.Text = dt7.Rows[0]["SUBSIDY_RATE"].ToString(); ddlSUBSIDY2_PAY_TYPE.SelectedValue = dt7.Rows[0]["PAY_TYPE"].ToString(); ddlSUBSIDY2_RULE.SelectedValue = dt7.Rows[0]["SUBSIDY_RULE"].ToString(); } ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(3); dt7 = bco.QuerySUBSIDYByEdit(ParameterList); if (dt7.Rows.Count > 0) { Panel9.Visible = true; Session["VDM081_DT7_" + PageTimeStamp.Value] = dt7; rblSUBSIDY2_TYPE.SelectedValue = "3"; rblSUBSIDY2_COUNT_TYPE.SelectedValue = dt7.Rows[0]["COUNT_TYPE"].ToString(); slpSUBSIDY2_RATE.Text = dt7.Rows[0]["SUBSIDY_RATE"].ToString(); ddlSUBSIDY2_PAY_TYPE.SelectedValue = dt7.Rows[0]["PAY_TYPE"].ToString(); ddlSUBSIDY2_RULE.SelectedValue = dt7.Rows[0]["SUBSIDY_RULE"].ToString(); } ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); DataTable dt8 = bco.QueryStoreByEdit(ParameterList); if (dt8.Rows.Count > 0) { Session["VDM081_DT8_" + PageTimeStamp.Value] = dt8; dtTemp = Fill_DataTable(dt8, "COUNT_TYPE='4'"); GridView_7.DataSource = dtTemp; GridView_7.DataBind(); if (dtTemp.Rows.Count > 0) Panel10.Visible = true; } #endregion #region 離島配送費 ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(1); DataTable dt9 = bco.QuerySUBSIDYByEdit(ParameterList); if (dt9.Rows.Count > 0) { Panel11.Visible = true; Session["VDM081_DT9_" + PageTimeStamp.Value] = dt9; rblSUBSIDY1_COUNT_TYPE.SelectedValue = dt9.Rows[0]["COUNT_TYPE"].ToString(); slpSUBSIDY1_RATE.Text = dt9.Rows[0]["SUBSIDY_RATE"].ToString(); ddlSUBSIDY1_PAY_TYPE.SelectedValue = dt9.Rows[0]["PAY_TYPE"].ToString(); ddlSUBSIDY1_RULE.SelectedValue = dt9.Rows[0]["SUBSIDY_RULE"].ToString(); } #endregion #region 轉運費 ParameterList.Clear(); ParameterList.Add(CNT_NO); ParameterList.Add(Int16.Parse(EDIT_NO)); ParameterList.Add(4); DataTable dt10 = bco.QuerySUBSIDYByEdit(ParameterList); if (dt10.Rows.Count > 0) { Panel12.Visible = true; Session["VDM081_DT10_" + PageTimeStamp.Value] = dt10; rblSUBSIDY4_COUNT_TYPE.SelectedValue = dt10.Rows[0]["COUNT_TYPE"].ToString(); } #endregion } if (slpCNT_CONFIRM_CODE.Text == "1") //已審核 { btnUpdate.Enabled = false; btnDelete.Enabled = true; } else { btnUpdate.Enabled = true; btnDelete.Enabled = false; } }