예제 #1
0
    /// <summary>
    /// 新增模式下,取得路線運費歸屬維護主檔
    /// </summary>
    private void GetTransRouteMain()
    {
        #region
        try
        {
            string SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value);

            TRNModel.VDS_TRN14_BCO BCO = new TRNModel.VDS_TRN14_BCO(ConnectionDB);
            DataTable dt = null;
            ArrayList ParameterList = new ArrayList();
            ParameterList.Clear();
            ParameterList = GetQueryParams();
            ParameterList.Add(string.Format("{0}/{1}/10", SLP_YearMonth1.Text.Substring(0, 4), SLP_YearMonth1.Text.Substring(4, 2)));
            ParameterList.Add(Session["UID"].ToString());
            dt = BCO.QUERY_CAL_MONTH_ROUTE_ADD(ParameterList);
            Session[SessionIDName] = dt;

            if (dt == null || dt.Rows.Count <= 0)
            {
                ErrorMsgLabel.Text = "查無資料,請先至TRN13維護主檔";
            }

            GridView1.DataSource = dt;
            GridView1.PageIndex = 0;
            GridView1.DataBind();


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

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

            if (CheckDetailIsExisted())
            {
                if (CurrentPageMode == PageCurrentMode.Insert || CurrentPageMode == PageCurrentMode.Edit)
                {
                    SaveCurrentGridviewValue();
                }

                //if (CheckDetailIsDuplicated())
                //{
                #region Variables
                string SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value);
                DataTable dtTemp = (DataTable)Session[SessionIDName];

                TRNModel.VDS_TRN14_BCO BCO = new TRNModel.VDS_TRN14_BCO(ConnectionDB);
                string strErrMsg = "";
                bool bResult = false;

                //WUI.SLP.SLP_Route SLP_Route1;
                //WUI.SLP.SLPNumber SLP_SLPNumber1;
                //WUI.SLP.SLPNumber SLP_SLPNumber2;
                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
                    {
                        //先把舊資料都刪除
                        ParameterList.Clear();
                        ParameterList = GetQueryParams();
                        ParameterList.Add(DBNull.Value);
                        ParameterList.Add(Session["UID"].ToString());
                        BCO.DEL_CAL_MONTH_ROUTE(ParameterList, DBT);

                        #region 新增
                        for (Int32 i = 0; i <= dtTemp.Rows.Count - 1; i++)
                        {
                            if (dtTemp.Rows[i].RowState != DataRowState.Deleted)
                            {
                                if (strErrMsg == "")
                                {
                                    //SLP_Route1 = (WUI.SLP.SLP_Route)GridView1.Rows[i].FindControl("SLP_Route1");
                                    //SLP_SLPNumber1 = (WUI.SLP.SLPNumber)GridView1.Rows[i].FindControl("SLP_SLPNumber1");
                                    //SLP_SLPNumber2 = (WUI.SLP.SLPNumber)GridView1.Rows[i].FindControl("SLP_SLPNumber2");
                                    ParameterList.Clear();
                                    ParameterList = GetQueryParams();
                                    //ParameterList.Add(SLP_Route1.Text);
                                    //ParameterList.Add(SLP_SLPNumber1.Text);
                                    //ParameterList.Add(SLP_SLPNumber2.Text);
                                    ParameterList.Add(dtTemp.Rows[i]["ROUTE"].ToString());
                                    ParameterList.Add(dtTemp.Rows[i]["ADD_STORE_CNT"].ToString());
                                    ParameterList.Add(dtTemp.Rows[i]["STORE_CNT"].ToString());
                                    ParameterList.Add(Session["UID"].ToString());
                                    bResult = BCO.ADD_CAL_MONTH_ROUTE(ParameterList, DBT, out strErrMsg);
                                }
                                else
                                {
                                    break;
                                    DBT.Rollback();//交易失敗
                                }
                            }
                        }
                        #endregion

                        #region 刪除
                        //DataTable dtDeleted = dtTemp.GetChanges(DataRowState.Deleted); ;

                        //if (dtDeleted != null)
                        //{
                        //    for (Int32 j = 0; j <= dtDeleted.Rows.Count - 1; j++)
                        //    {
                        //        if (bResult)
                        //        {
                        //            ParameterList.Clear();
                        //            ParameterList = GetQueryParams();
                        //            ParameterList.Add(dtDeleted.Rows[j]["ROUTE", DataRowVersion.Original].ToString());
                        //            ParameterList.Add(Session["UID"].ToString());
                        //            BCO.DEL_CAL_MONTH_ROUTE(ParameterList, DBT);
                        //        }
                        //        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
                    {
                        #region 修改
                        for (Int32 i = 0; i <= dtTemp.Rows.Count - 1; i++)
                        {
                            if (dtTemp.Rows[i].RowState != DataRowState.Deleted)
                            {
                                if (strErrMsg == "")
                                {
                                    //SLP_Route1 = (WUI.SLP.SLP_Route)GridView1.Rows[i].FindControl("SLP_Route1");
                                    //SLP_SLPNumber1 = (WUI.SLP.SLPNumber)GridView1.Rows[i].FindControl("SLP_SLPNumber1");
                                    //SLP_SLPNumber2 = (WUI.SLP.SLPNumber)GridView1.Rows[i].FindControl("SLP_SLPNumber2");
                                    ParameterList.Clear();
                                    ParameterList = GetQueryParams();
                                    //ParameterList.Add(SLP_Route1.Text);
                                    //ParameterList.Add(SLP_SLPNumber1.Text);
                                    //ParameterList.Add(SLP_SLPNumber2.Text);
                                    ParameterList.Add(dtTemp.Rows[i]["ROUTE"].ToString());
                                    ParameterList.Add(dtTemp.Rows[i]["ADD_STORE_CNT"].ToString());
                                    ParameterList.Add(dtTemp.Rows[i]["STORE_CNT"].ToString());
                                    ParameterList.Add(Session["UID"].ToString());
                                    bResult = BCO.UPDATE_CAL_MONTH_ROUTE(ParameterList, DBT, out strErrMsg);
                                }
                                else
                                {
                                    break;
                                    DBT.Rollback();//交易失敗
                                }
                            }
                        }
                        #endregion

                        #region 刪除
                        DataTable dtDeleted = dtTemp.GetChanges(DataRowState.Deleted); ;

                        if (dtDeleted != null)
                        {
                            for (Int32 j = 0; j <= dtDeleted.Rows.Count - 1; j++)
                            {
                                if (bResult)
                                {
                                    ParameterList.Clear();
                                    ParameterList = GetQueryParams();
                                    ParameterList.Add(dtDeleted.Rows[j]["ROUTE", DataRowVersion.Original].ToString());
                                    ParameterList.Add(Session["UID"].ToString());
                                    BCO.DEL_CAL_MONTH_ROUTE(ParameterList, DBT);
                                }
                                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)
        {
            ErrorMsgLabel.Text = ex.Message;
            UpdatePanel1.Update();
        }
        #endregion
    }//btn_Save_Click
예제 #3
0
    /// <summary>
    /// 繫結資料到控制項
    /// </summary>
    /// <param name="vdb"></param>
    private void QueryData()
    {
        #region
        try
        {
            string SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value);

            TRNModel.VDS_TRN14_BCO BCO = new TRNModel.VDS_TRN14_BCO(ConnectionDB);
            DataTable dt = null;
            dt = BCO.QUERY_CAL_MONTH_ROUTE(GetQueryParams());
            Session[SessionIDName] = dt;

            GridView1.DataSource = dt;
            GridView1.PageIndex = 0;
            GridView1.DataBind();

            if (dt == null || dt.Rows.Count <= 0)
            {
                if (CurrentPageMode == PageCurrentMode.Insert)
                {
                    GetTransRouteMain();
                }
                else
                {
                    ErrorMsgLabel.Text = "查無資料";
                }
            }
            else
            {
                if (CurrentPageMode == PageCurrentMode.Insert)
                {
                    CurrentPageMode = PageCurrentMode.Edit;
                }
                else
                {
                    CurrentPageMode = PageCurrentMode.Readonly;
                    SetControlsByCurrentPageMode();
                }
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
        #endregion
    }