}//btn_Add_Click protected void btn_Save_Click(object sender, EventArgs e) { #region try { #region SaveCurrentGridviewValue(); if (CheckDetailIsExisted()) { //if (CheckDetailIsDuplicated()) //{ #region Variables TRNModel.VDS_TRN16_BCO BCO = new TRNModel.VDS_TRN16_BCO(ConnectionDB); string strErrMsg = ""; string strPK = ""; DataRow[] drAry = null; bool bResult = false; Int32 i32ID, i32ID_C; ArrayList ParameterList = new ArrayList(); TRNModel.TRNCommon BCOCommon = new TRNModel.TRNCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); #endregion if (CurrentPageMode == PageCurrentMode.Insert) { #region try { #region 新增 for (Int32 i = 0; i <= dtFee.Rows.Count - 1; i++) { if (dtFee.Rows[i].RowState != DataRowState.Deleted) { if (strErrMsg == "") { //TRN_DRIVER_FEE ParameterList.Clear(); ParameterList.Add(dtFee.Rows[i]["CAL_MONTH"].ToString()); ParameterList.Add(dtFee.Rows[i]["TYPE_NO"].ToString()); ParameterList.Add(dtFee.Rows[i]["TRANS_NO"].ToString()); ParameterList.Add(dtFee.Rows[i]["DRIVER_NAME"].ToString()); ParameterList.Add(dtFee.Rows[i]["ST_ACCEPT_DATE"].ToString()); ParameterList.Add(dtFee.Rows[i]["STORE"].ToString()); ParameterList.Add(dtFee.Rows[i]["ITEM"].ToString()); ParameterList.Add(dtFee.Rows[i]["PERIOD"].ToString()); ParameterList.Add(dtFee.Rows[i]["PRICE"].ToString()); ParameterList.Add(dtFee.Rows[i]["DIFF_QTY"].ToString()); ParameterList.Add(dtFee.Rows[i]["MEMO"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_TRN_DRIVER_FEE(ParameterList, DBT, out i32ID, 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_FEE = dtFee.GetChanges(DataRowState.Deleted); ; if (dtDeleted_FEE != null) { for (Int32 j = 0; j <= dtDeleted_FEE.Rows.Count - 1; j++) { if (bResult) { ParameterList.Clear(); ParameterList.Add(dtDeleted_FEE.Rows[j]["CAL_MONTH", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["TYPE_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["TRANS_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["DRIVER_NAME", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["ST_ACCEPT_DATE", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["STORE", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["ITEM", DataRowVersion.Original].ToString()); ParameterList.Add(dtDeleted_FEE.Rows[j]["PERIOD", DataRowVersion.Original].ToString()); ParameterList.Add(Session["UID"].ToString()); BCO.DEL_TRN_DRIVER_FEE(ParameterList, DBT); } else { break; DBT.Rollback();//交易失敗 } } } #endregion #region 修改 for (Int32 i = 0; i <= dtFee.Rows.Count - 1; i++) { if (dtFee.Rows[i].RowState != DataRowState.Deleted) { if (strErrMsg == "") { //TRN_DRIVER_FEE ParameterList.Clear(); ParameterList.Add(dtFee.Rows[i]["CAL_MONTH"].ToString()); ParameterList.Add(dtFee.Rows[i]["TYPE_NO"].ToString()); ParameterList.Add(dtFee.Rows[i]["TRANS_NO"].ToString()); ParameterList.Add(dtFee.Rows[i]["DRIVER_NAME"].ToString()); ParameterList.Add(dtFee.Rows[i]["ST_ACCEPT_DATE"].ToString()); ParameterList.Add(dtFee.Rows[i]["STORE"].ToString()); ParameterList.Add(dtFee.Rows[i]["ITEM"].ToString()); ParameterList.Add(dtFee.Rows[i]["PERIOD"].ToString()); ParameterList.Add(dtFee.Rows[i]["PRICE"].ToString()); ParameterList.Add(dtFee.Rows[i]["DIFF_QTY"].ToString()); ParameterList.Add(dtFee.Rows[i]["MEMO"].ToString()); ParameterList.Add(Session["UID"].ToString()); bResult = BCO.ADD_TRN_DRIVER_FEE(ParameterList, DBT, out i32ID, 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_Fee.DataSource = dtFee; gv_Fee.DataBind(); ErrorMsgLabel.Text = ex.Message; UpdatePanel_ALL.Update(); } #endregion }//btn_Save_Click