}//Page_Load private void QueryData() { #region DataTable dt = null; string SessionIDName = string.Format("{0}_{1}", strPrefixed, PageTimeStamp.Value); if (dtTransPayRoute != null) { DataView dv = dtTransPayRoute.DefaultView; dv.RowFilter = string.Format("TRANS_NO = '{0}' and PAY_NO ='{1}'", s_TRANS_NO, s_PAY_NO); dt = dv.ToTable(); } if (dt == null) { TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); ArrayList ParameterList = new ArrayList(); ParameterList.Clear(); ParameterList.Add(s_TRANS_NO); ParameterList.Add(s_PAY_NO); dt = BCO.QUERY_TRANS_PAY_ROUTE(ParameterList); } bAfterQueryDataBinding = true; if (!dt.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可 dt.Columns.Add("CHECKED"); if (!dt.Columns.Contains("ROWID"))//增加欄位以判別勾選與否 dt.Columns.Add("ROWID"); if (!dt.Columns.Contains("CODE"))//增加欄位以判別勾選與否 dt.Columns.Add("CODE"); if (!dt.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否 dt.Columns.Add("ROWNUM"); hidden_RowID_MaxID.Value = dt == null ? "-1" : (dt.Rows.Count - 1).ToString();//記錄最大ROWID hidden_RowID_Selected.Value = "";//清空已選ROWID Session[SessionIDName] = dt; SetRowIDToDataTable(true);//設定ROWID GridView1.DataSource = dt; GridView1.PageSize = 20; GridView1.DataBind(); GridView1.SelectedIndex = -1; bAfterQueryDataBinding = false; if (dt == null || (dt != null && dt.Rows.Count <= 0)) { ErrorMsgLabel.Text = "查無資料"; } #endregion }
/// <summary> /// 繫結資料到控制項 /// </summary> /// <param name="vdb"></param> private void QueryData() { #region try { string SessionIDName_ROUTE = string.Format("{0}_{1}_ROUTE", PAGE_DT_01, PageTimeStamp.Value); string SessionIDName_PAY = string.Format("{0}_{1}_PAY", PAGE_DT_01, PageTimeStamp.Value); TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); DataSet ds = null; DataTable dt_ROUTE = null, dt_PAY = null; ds = BCO.QUERY_TRANS_ROUTE_MAIN(GetQueryParams()); dt_ROUTE = ds.Tables[0].Copy(); dt_PAY = ds.Tables[1].Copy(); dtRoute = ds.Tables[0].Copy(); dtPay = ds.Tables[1].Copy(); bAfterQueryDataBinding = true; #region ROUTE #region original if (!dt_ROUTE.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可 dt_ROUTE.Columns.Add("CHECKED"); if (!dt_ROUTE.Columns.Contains("ROWID"))//增加欄位以判別勾選與否 dt_ROUTE.Columns.Add("ROWID"); if (!dt_ROUTE.Columns.Contains("CODE"))//增加欄位以判別勾選與否 dt_ROUTE.Columns.Add("CODE"); if (!dt_ROUTE.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否 dt_ROUTE.Columns.Add("ROWNUM"); #endregion #region editing if (!dtRoute.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可 dtRoute.Columns.Add("CHECKED"); if (!dtRoute.Columns.Contains("ROWID"))//增加欄位以判別勾選與否 dtRoute.Columns.Add("ROWID"); if (!dtRoute.Columns.Contains("CODE"))//增加欄位以判別勾選與否 dtRoute.Columns.Add("CODE"); if (!dtRoute.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否 dtRoute.Columns.Add("ROWNUM"); #endregion #endregion #region PAY #region original if (!dt_PAY.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可 dt_PAY.Columns.Add("CHECKED"); if (!dt_PAY.Columns.Contains("ROWID"))//增加欄位以判別勾選與否 dt_PAY.Columns.Add("ROWID"); if (!dt_PAY.Columns.Contains("CODE"))//增加欄位以判別勾選與否 dt_PAY.Columns.Add("CODE"); if (!dt_PAY.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否 dt_PAY.Columns.Add("ROWNUM"); #endregion #region editing if (!dtPay.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可 dtPay.Columns.Add("CHECKED"); if (!dtPay.Columns.Contains("ROWID"))//增加欄位以判別勾選與否 dtPay.Columns.Add("ROWID"); if (!dtPay.Columns.Contains("CODE"))//增加欄位以判別勾選與否 dtPay.Columns.Add("CODE"); if (!dtPay.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否 dtPay.Columns.Add("ROWNUM"); #endregion #endregion #region PAY ROUTE ArrayList ParameterList = new ArrayList(); ParameterList.Add(SLP_TRN_TransNo1.Text); ParameterList.Add(null); dtTransPayRoute = BCO.QUERY_TRANS_PAY_ROUTE(ParameterList); #endregion if (ds == null || ds.Tables.Count <= 0 || (ds.Tables[0].Rows.Count <= 0 && ds.Tables[1].Rows.Count <= 0)) { gv_Route.DataBind(); gv_Pay.DataBind(); Panel_ROUTE.Visible = false; Panel_PAY.Visible = false; if (CurrentPageMode != PageCurrentMode.Insert) { ErrorMsgLabel.Text = "查無資料"; } } else { Panel_ROUTE.Visible = true; Panel_PAY.Visible = true; if (CurrentPageMode == PageCurrentMode.Insert) { CurrentPageMode = PageCurrentMode.Edit; } else { CurrentPageMode = PageCurrentMode.Readonly; SetControlsByCurrentPageMode(); } #region //ROUTE hidden_RowID_MaxID_ROUTE.Value = dt_ROUTE == null ? "-1" : (dt_ROUTE.Rows.Count - 1).ToString();//記錄最大ROWID hidden_RowID_Selected_ROUTE.Value = "";//清空已選ROWID_ROUTE hidden_RowID_Selected_STATUS.Value = "";//清空已選ROWID_STATUS Session[SessionIDName_ROUTE] = dt_ROUTE; SetRowIDToDataTable(false, EditingGridview.ROUTE);//設定ROWID_ROUTE gv_Route.DataSource = dt_ROUTE; gv_Route.PageIndex = 0; gv_Route.DataBind(); gv_Route.SelectedIndex = -1; //PAY hidden_RowID_MaxID_PAY.Value = dt_PAY == null ? "-1" : (dt_PAY.Rows.Count - 1).ToString();//記錄最大ROWID hidden_RowID_Selected_PAY.Value = "";//清空已選ROWID_PAY Session[SessionIDName_PAY] = dt_PAY; SetRowIDToDataTable(false, EditingGridview.PAY);//設定ROWID_PAY gv_Pay.DataSource = dt_PAY; gv_Pay.PageIndex = 0; gv_Pay.DataBind(); gv_Pay.SelectedIndex = -1; #endregion } bAfterQueryDataBinding = false; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }
private string GetStoreCountByRoute(string strRoute, string strROWID, string strPageTimeStamp, string strTRANS_NO) { #region string strResult = ""; try { #region Check Duplicated DataTable dtTemp = (DataTable)Session[string.Format("dtRoute_{0}", strPageTimeStamp)]; DataRow[] drAry = dtTemp.Select(string.Format("ROUTE ='{0}'", strRoute)); if (drAry != null && drAry.Length > 0 && drAry[0]["ROWID"].ToString() != strROWID) { strResult = "DUPLICATED";//"路線資料維護之路線重複"; } #endregion #region Check USED if (strResult == "") { TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); ArrayList ParameterList = new ArrayList(); ParameterList.Clear(); ParameterList.Add(strTRANS_NO); ParameterList.Add(strRoute); DataTable dtUse = BCO.CHECK_ROUTE_USE(ParameterList); if (dtUse.Rows.Count > 0) { //此路線已存在路線運費歸屬檔,運輸代碼= XXX中,請確認! strResult = string.Format("{0}||{1}||{2}||{3}", "USED", dtUse.Rows[0]["TRANS_NO"].ToString(), "", ""); } } #endregion #region Get Data if (strResult == "") { TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); ArrayList ParameterList = new ArrayList(); ParameterList.Clear(); ParameterList.Add(strRoute); DataTable dt = BCO.QUERY_STORE_COUNT_DSIR(ParameterList); if (dt != null && dt.Rows.Count > 0) { strResult = string.Format("{0}||{1}||{2}||{3}", dt.Rows[0]["EFF_START"].ToString(), dt.Rows[0]["EFF_END"].ToString(), dt.Rows[0]["D_SIR_NAME"].ToString(), dt.Rows[0]["STORE_CNT"].ToString()); } else { strResult = "INVALID";//"路線未生效"; } } #endregion } catch (Exception ex) { throw ex; } return strResult; #endregion }
private Int32 GetStoreCountByTransNo(string strTransNo) { #region try { TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); ArrayList ParameterList = new ArrayList(); ParameterList.Clear(); ParameterList.Add(strTransNo); return BCO.QUERY_STORE_COUNT(ParameterList); } catch (Exception ex) { throw ex; } #endregion }
}//btn_Edit_Click protected void btn_Delete_Click(object sender, EventArgs e) { #region try { TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); ArrayList ParameterList = new ArrayList(); ParameterList.Clear(); ParameterList.Add(SLP_TRN_TransNo1.Text.Trim()); ParameterList.Add(Session["UID"].ToString()); BCO.DEL_ALL(ParameterList, null); CurrentPageMode = PageCurrentMode.Query; QueryData(); SetControlsByCurrentPageMode(); ErrorMsgLabel.Text = "刪除成功"; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }//btn_Delete_Click
}//btn_Add_Click protected void btn_Save_Click(object sender, EventArgs e) { #region try { #region CurrentEditingGridview = EditingGridview.None; SaveCurrentGridviewValue(); if (CheckDetailIsExisted() && CheckDetailDataIntervalIsValid())//2011/04/29 add CheckDetailDataIntervalIsValid() for Checking Interval { TRNModel.VDS_TRN13_BCO BCO = new TRNModel.VDS_TRN13_BCO(ConnectionDB); string strErrMsg = ""; ArrayList ParameterList = new ArrayList(); for (int i = 0; i <= dtRoute.Rows.Count - 1; i++) { if (dtRoute.Rows[i].RowState != DataRowState.Deleted) { ParameterList.Clear(); ParameterList.Add(dtRoute.Rows[i]["TRANS_NO"].ToString()); ParameterList.Add(dtRoute.Rows[i]["ROUTE"].ToString()); DataTable dtUse = BCO.CHECK_ROUTE_USE(ParameterList); if (dtUse.Rows.Count > 0) { strErrMsg += "[" + dtRoute.Rows[i]["ROUTE"].ToString() + "]路線已存在路線運費歸屬檔,運輸代碼= " + dtUse.Rows[0]["TRANS_NO"].ToString() + "中<BR>"; } } } if (strErrMsg != "") { ErrorMsgLabel.Text = strErrMsg; return; } string strPK = ""; DataRow[] drAry = null; bool bResult = false; Int32 i32PID, i32PID_C; TRNModel.TRNCommon BCOCommon = new TRNModel.TRNCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); if (CurrentPageMode == PageCurrentMode.Insert) { #region try { #region 新增 for (Int32 i = 0; i <= dtRoute.Rows.Count - 1; i++) { if (dtRoute.Rows[i].RowState != DataRowState.Deleted) { if (strErrMsg == "") { //TRNAS_ROUTE_MAIN ParameterList.Clear(); ParameterList.Add(dtRoute.Rows[i]["TRANS_NO"].ToString()); ParameterList.Add(dtRoute.Rows[i]["ROUTE"].ToString()); ParameterList.Add(dtRoute.Rows[i]["STATUS"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_TRANS_ROUTE_MAIN(ParameterList, DBT, out i32PID, out strErrMsg); for (Int32 k = 0; k <= dtPay.Rows.Count - 1; k++) { if (dtPay.Rows[k].RowState != DataRowState.Deleted) { //PAY_CODE ParameterList.Clear(); ParameterList.Add(i32PID); ParameterList.Add(dtPay.Rows[k]["TRANS_NO"].ToString()); ParameterList.Add(dtPay.Rows[k]["PAY_NO"].ToString()); ParameterList.Add(dtPay.Rows[k]["PAY_MEMO"].ToString()); ParameterList.Add(dtPay.Rows[k]["START_DATE"].ToString()); ParameterList.Add(dtPay.Rows[k]["END_DATE"].ToString()); ParameterList.Add(dtPay.Rows[k]["PRICE"].ToString()); ParameterList.Add(dtPay.Rows[k]["UNIT"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_PAY_CODE(ParameterList, DBT, out i32PID_C, out strErrMsg); if (dtTransPayRoute != null) { strPK = string.Format("TRANS_NO = '{0}' and PAY_NO = '{1}'", dtRoute.Rows[i]["TRANS_NO"].ToString(), dtPay.Rows[k]["PAY_NO"].ToString()); drAry = dtTransPayRoute.Select(strPK); if (drAry != null) { for (Int32 m = 0; m <= drAry.GetUpperBound(0); m++) { //PAY_ROUTE ParameterList.Clear(); ParameterList.Add(i32PID_C); ParameterList.Add(drAry[m]["TRANS_NO"].ToString()); ParameterList.Add(drAry[m]["PAY_NO"].ToString()); ParameterList.Add(drAry[m]["ROUTE"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_PAY_ROUTE(ParameterList, DBT, out strErrMsg); } } } } } } else { break; DBT.Rollback();//交易失敗 } } } #endregion DBT.Commit();//交易成功 } catch (Exception ex) { DBT.Rollback();//交易失敗 throw ex; } if (bResult && strErrMsg == "") { CurrentPageMode = PageCurrentMode.Readonly; SetControlsByCurrentPageMode(); QueryData(); ErrorMsgLabel.Text = "新增成功"; } else { ErrorMsgLabel.Text = strErrMsg; } #endregion } else if (CurrentPageMode == PageCurrentMode.Edit) { #region try { bResult = true; #region 刪除 DataTable dtDeleted_ROUTE = dtRoute.GetChanges(DataRowState.Deleted); ; DataTable dtDeleted_PAY = dtPay.GetChanges(DataRowState.Deleted); ; DataTable dtDeleted_PAY_ROUTE = dtTransPayRoute.GetChanges(DataRowState.Deleted); ; if (dtDeleted_PAY_ROUTE != null) { for (Int32 j = 0; j <= dtDeleted_PAY_ROUTE.Rows.Count - 1; j++) { if (bResult) { ParameterList.Clear(); ParameterList.Add(dtDeleted_PAY_ROUTE.Rows[j]["TRANS_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_PAY_ROUTE.Rows[j]["PAY_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_PAY_ROUTE.Rows[j]["ROUTE", DataRowVersion.Original].ToString()); ParameterList.Add(Session["UID"].ToString()); BCO.DEL_PAY_ROUTE(ParameterList, DBT); } else { break; DBT.Rollback();//交易失敗 } } } if (dtDeleted_PAY != null) { for (Int32 j = 0; j <= dtDeleted_PAY.Rows.Count - 1; j++) { if (bResult) { ParameterList.Clear(); ParameterList.Add(dtDeleted_PAY.Rows[j]["TRANS_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_PAY.Rows[j]["PAY_NO", DataRowVersion.Original].ToString()); ParameterList.Add(Session["UID"].ToString()); BCO.DEL_PAY_CODE(ParameterList, DBT); } else { break; DBT.Rollback();//交易失敗 } } } if (dtDeleted_ROUTE != null) { for (Int32 j = 0; j <= dtDeleted_ROUTE.Rows.Count - 1; j++) { if (bResult) { ParameterList.Clear(); ParameterList.Add(dtDeleted_ROUTE.Rows[j]["TRANS_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_ROUTE.Rows[j]["ROUTE", DataRowVersion.Original].ToString()); ParameterList.Add(Session["UID"].ToString()); BCO.DEL_TRANS_ROUTE_MAIN(ParameterList, DBT); } else { break; DBT.Rollback();//交易失敗 } } } #endregion #region 修改 for (Int32 i = 0; i <= dtRoute.Rows.Count - 1; i++) { if (dtRoute.Rows[i].RowState != DataRowState.Deleted) { if (strErrMsg == "") { //TRNAS_ROUTE_MAIN ParameterList.Clear(); ParameterList.Add(dtRoute.Rows[i]["TRANS_NO"].ToString()); ParameterList.Add(dtRoute.Rows[i]["ROUTE"].ToString()); ParameterList.Add(dtRoute.Rows[i]["STATUS"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_TRANS_ROUTE_MAIN(ParameterList, DBT, out i32PID, out strErrMsg); for (Int32 k = 0; k <= dtPay.Rows.Count - 1; k++) { if (dtPay.Rows[k].RowState != DataRowState.Deleted) { //PAY_CODE ParameterList.Clear(); ParameterList.Add(i32PID); ParameterList.Add(dtPay.Rows[k]["TRANS_NO"].ToString()); ParameterList.Add(dtPay.Rows[k]["PAY_NO"].ToString()); ParameterList.Add(dtPay.Rows[k]["PAY_MEMO"].ToString()); ParameterList.Add(dtPay.Rows[k]["START_DATE"].ToString()); ParameterList.Add(dtPay.Rows[k]["END_DATE"].ToString()); ParameterList.Add(dtPay.Rows[k]["PRICE"].ToString()); ParameterList.Add(dtPay.Rows[k]["UNIT"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_PAY_CODE(ParameterList, DBT, out i32PID_C, out strErrMsg); if (dtTransPayRoute != null) { strPK = string.Format("TRANS_NO = '{0}' and PAY_NO = '{1}'", dtRoute.Rows[i]["TRANS_NO"].ToString(), dtPay.Rows[k]["PAY_NO"].ToString()); drAry = dtTransPayRoute.Select(strPK); if (drAry != null) { for (Int32 m = 0; m <= drAry.GetUpperBound(0); m++) { //PAY_ROUTE ParameterList.Clear(); ParameterList.Add(i32PID_C); ParameterList.Add(drAry[m]["TRANS_NO"].ToString()); ParameterList.Add(drAry[m]["PAY_NO"].ToString()); ParameterList.Add(drAry[m]["ROUTE"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_PAY_ROUTE(ParameterList, DBT, out strErrMsg); } } } } } } else { break; DBT.Rollback();//交易失敗 } } } #endregion DBT.Commit();//交易成功 } catch (Exception ex) { DBT.Rollback();//交易失敗 throw ex; } if (bResult && strErrMsg == "") { CurrentPageMode = PageCurrentMode.Readonly; SetControlsByCurrentPageMode(); QueryData(); ErrorMsgLabel.Text = "更新成功"; } else { ErrorMsgLabel.Text = strErrMsg; } #endregion } //} } #endregion } catch (Exception ex) { gv_Pay.DataSource = dtPay; gv_Pay.DataBind(); gv_Route.DataSource = dtRoute; gv_Route.DataBind(); ErrorMsgLabel.Text = ex.Message; UpdatePanel_ALL.Update(); } #endregion }//btn_Save_Click