Exemple #1
0
    /// <summary>
    /// 繫結資料到控制項
    /// </summary>
    /// <param name="vdb"></param>
    private void QueryData()
    {
        #region
        try
        {
            string SessionIDName_FEE = string.Format("{0}_{1}_FEE", PAGE_DT_01, PageTimeStamp.Value);

            TRNModel.VDS_TRN15_BCO BCO = new TRNModel.VDS_TRN15_BCO(ConnectionDB);
            DataTable dt_FEE = null;
            dt_FEE = BCO.QUERY_TRN_OTHER_FEE(GetQueryParams());

            if (dt_FEE != null)
                dtFee = dt_FEE.Copy();

            bAfterQueryDataBinding = true;

            #region FEE

            #region original
            if (dt_FEE != null)
            {
                if (!dt_FEE.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可
                    dt_FEE.Columns.Add("CHECKED");

                if (!dt_FEE.Columns.Contains("ROWID"))//增加欄位以判別勾選與否
                    dt_FEE.Columns.Add("ROWID");

                if (!dt_FEE.Columns.Contains("CODE"))//增加欄位以判別勾選與否
                    dt_FEE.Columns.Add("CODE");

                if (!dt_FEE.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否
                    dt_FEE.Columns.Add("ROWNUM");
            }
            #endregion

            #region editing
            if (!dtFee.Columns.Contains("CHECKED"))//增加欄位以方便判別是否可
                dtFee.Columns.Add("CHECKED");

            if (!dtFee.Columns.Contains("ROWID"))//增加欄位以判別勾選與否
                dtFee.Columns.Add("ROWID");

            if (!dtFee.Columns.Contains("CODE"))//增加欄位以判別勾選與否
                dtFee.Columns.Add("CODE");

            if (!dtFee.Columns.Contains("ROWNUM"))//增加欄位以判別勾選與否
                dtFee.Columns.Add("ROWNUM");
            #endregion

            #endregion

            if (dt_FEE == null || dt_FEE.Rows.Count <= 0)
            {
                if (CurrentPageMode != PageCurrentMode.Insert)
                {
                    ErrorMsgLabel.Text = "查無資料";
                }
            }
            else
            {
                Panel_FEE.Visible = true;

                if (CurrentPageMode == PageCurrentMode.Insert)
                {
                    CurrentPageMode = PageCurrentMode.Edit;
                }
                else
                {
                    CurrentPageMode = PageCurrentMode.Readonly;
                    SetControlsByCurrentPageMode();
                }

                #region
                hidden_RowID_MaxID_FEE.Value = dt_FEE == null ? "-1" : (dt_FEE.Rows.Count - 1).ToString();//記錄最大ROWID
                hidden_RowID_Selected_FEE.Value = "";//清空已選ROWID_FEE

                Session[SessionIDName_FEE] = dt_FEE;
                SetRowIDToDataTable(false, EditingGridview.FEE);//設定ROWID_FEE

                gv_Fee.DataSource = dt_FEE;
                gv_Fee.PageIndex = 0;
                gv_Fee.DataBind();
                gv_Fee.SelectedIndex = -1;
                #endregion
            }

            bAfterQueryDataBinding = false;

        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
        #endregion
    }
Exemple #2
0
    }//btn_Add_Click

    protected void btn_Save_Click(object sender, EventArgs e)
    {
        #region
        try
        {
            SaveCurrentGridviewValue();
            try
            {
                #region



                if (CheckDetailIsExisted())
                {
                    //if (CheckDetailIsDuplicated())
                    //{
                    #region Variables
                    TRNModel.VDS_TRN15_BCO BCO = new TRNModel.VDS_TRN15_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_OTHER_FEE
                                        ParameterList.Clear();
                                        ParameterList.Add(dtFee.Rows[i]["TRANS_NO"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["CAL_MONTH"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["BUS_DATE"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["ROUTE"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["SUBSIDY_NO"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["SUBSIDY_MONEY"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["MEMO"].ToString());
                                        ParameterList.Add(Session["UID"].ToString());
                                        bResult = BCO.ADD_TRN_OTHER_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]["TRANS_NO", DataRowVersion.Original].ToString());
                                        ParameterList.Add(dtDeleted_FEE.Rows[j]["CAL_MONTH", DataRowVersion.Original].ToString());
                                        ParameterList.Add(dtDeleted_FEE.Rows[j]["BUS_DATE", DataRowVersion.Original].ToString());
                                        ParameterList.Add(dtDeleted_FEE.Rows[j]["ROUTE", DataRowVersion.Original].ToString());
                                        ParameterList.Add(dtDeleted_FEE.Rows[j]["SUBSIDY_NO", DataRowVersion.Original].ToString());
                                        ParameterList.Add(Session["UID"].ToString());
                                        BCO.DEL_TRN_OTHER_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_OTHER_FEE
                                        ParameterList.Clear();
                                        ParameterList.Add(dtFee.Rows[i]["TRANS_NO"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["CAL_MONTH"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["BUS_DATE"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["ROUTE"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["SUBSIDY_NO"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["SUBSIDY_MONEY"].ToString());
                                        ParameterList.Add(dtFee.Rows[i]["MEMO"].ToString());
                                        ParameterList.Add(Session["UID"].ToString());
                                        bResult = BCO.ADD_TRN_OTHER_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();
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
            UpdatePanel_ALL.Update();
        }
        #endregion
    }//btn_Save_Click