/// <summary>
        /// 更新通路(111使用)
        /// </summary>
        /// <param name="dtDisChanUpdateOld">更新的舊資料</param>
        /// <param name="dtDisChanUpdateNew">更新的新資料</param>
        /// <param name="dtDisChanAdd">新增的資料</param>
        /// <param name="dtDisChanDelete">刪除的資料</param>
        /// <param name="RootDBT">交易</param>
        /// <returns>回傳交易成功失敗</returns>
        public bool UpdateDisChanFor131(DataTable dtDisChanUpdateOld,
                                        DataTable dtDisChanUpdateNew,
                                        DataTable dtDisChanAdd,
                                        DataTable dtDisChanDelete,
                                        string ST_ACCEPT_DATE,
                                        DbTransaction RootDBT
                                        )
        {
            #region
            bool bResult = false;
            bool IsRootTranscation = false;

            try
            {
                //判斷是否有傳入Root Transcation 
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region 啟動交易或指定RootTranscation

                if (IsRootTranscation)
                {
                    //獨立呼叫啟動Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion

                ArrayList ParameterList = new ArrayList();
                ArrayList ParameterList2 = new ArrayList();
                MaintainDisStore DBO = new MaintainDisStore(ConnectionDB);


                //  處理刪除:dtDel
                if (dtDisChanDelete != null && dtDisChanDelete.Rows.Count > 0)
                {
                    #region
                    foreach (DataRow dr in dtDisChanDelete.Rows)
                    {
                        //a)呼叫MaintainDisStore.DeleteDisStoreByChan();
                        ParameterList.Clear();
                        ParameterList.Add(dr["DIS_NO"]);
                        ParameterList.Add(dr["CHAN_NO"]);
                        ParameterList.Add(dr["UPDATEUID"]);
                        bResult = DBO.DeleteDisStoreByChan(ParameterList, DBT);

                        //b)呼叫MaintainDisChan.DeleteDisChan();
                        ParameterList2.Clear();
                        ParameterList2.Add(dr["ID"]);
                        ParameterList2.Add(dr["CODE"]);
                        ParameterList2.Add(dr["CREATEDATE"]);
                        ParameterList2.Add(dr["CREATEUID"]);
                        ParameterList2.Add(dr["UPDATEDATE"]);
                        ParameterList2.Add(dr["UPDATEUID"]);
                        ParameterList2.Add(dr["DIS_NO"]);
                        ParameterList2.Add(dr["ITEM"]);
                        ParameterList2.Add(dr["PERIOD"]);
                        ParameterList2.Add(dr["CHAN_NO"]);
                        ParameterList2.Add(dr["DIS_TYPE"]);
                        ParameterList2.Add(dr["PATTERN_NO"]);
                        ParameterList2.Add(dr["DIS_TOT_QTY"]);
                        ParameterList2.Add(dr["IS_LOCK"]);
                        bResult = DeleteDisChan(ParameterList2, DBT);
                    }
                    #endregion
                }

                //  處理新增:dtAdd
                if (dtDisChanAdd != null && dtDisChanAdd.Rows.Count > 0)
                {
                    #region
                    foreach (DataRow dr in dtDisChanAdd.Rows)
                    {
                        ParameterList.Clear();
                        //ParameterList.Add(dr["DIS_NO"]);
                        //ParameterList.Add(dr["ITEM"]);
                        //ParameterList.Add(dr["PERIOD"]);
                        //ParameterList.Add(dr["ROOT_NO"]);
                        //ParameterList.Add(dr["PATTERN_NO"]);
                        //ParameterList.Add(dr["DIS_TYPE"]);
                        //ParameterList.Add(dr["CREATEDATE"]);
                        //ParameterList.Add(dr["CREATEUID"]);
                        //ParameterList.Add(dr["ST_ACCEPT_DATE"]);

                        ParameterList.Add(dr["DIS_NO"]);
                        ParameterList.Add(dr["ITEM"]);
                        ParameterList.Add(dr["PERIOD"]);
                        ParameterList.Add(dr["CHAN_NO"]);
                        ParameterList.Add(dr["DIS_TYPE"]);
                        ParameterList.Add(dr["CREATEDATE"]);
                        ParameterList.Add(dr["CREATEUID"]);
                        ParameterList.Add(dr["DIS_PRE_CQTY"]);
                        ParameterList.Add(ST_ACCEPT_DATE);
                        bResult = CreateDisChan(ParameterList, DBT);
                    }
                    #endregion
                }

                //  處理更新:dtUpdate
                if ( (dtDisChanUpdateOld != null) && 
                     (dtDisChanUpdateOld.Rows.Count > 0) &&
                     (dtDisChanUpdateNew != null) && 
                     (dtDisChanUpdateNew.Rows.Count > 0) 
                     )
                {
                    #region
                    for (int x = 0; x < dtDisChanUpdateNew.Rows.Count;x++ )
                    {
                        //new
                        ParameterList.Clear();                        
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["UPDATEDATE"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["UPDATEUID"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_NO"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["ITEM"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["PERIOD"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["CHAN_NO"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["PLAN_RETURN_DATE"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_TYPE"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["PATTERN_NO"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_BRATE"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_STO_CQTY"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_PRE_CQTY"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_TOT_QTY"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_TOT_OQTY"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["DIS_TOT_PQTY"]);
                        ParameterList.Add(dtDisChanUpdateNew.Rows[x]["IS_LOCK"]);
                        //old
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["ID"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["CODE"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["CREATEDATE"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["CREATEUID"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["UPDATEDATE"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["UPDATEUID"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_NO"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["ITEM"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["PERIOD"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["CHAN_NO"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["PLAN_RETURN_DATE"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_TYPE"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["PATTERN_NO"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_BRATE"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_STO_CQTY"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_PRE_CQTY"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_TOT_QTY"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_TOT_OQTY"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["DIS_TOT_PQTY"]);
                        ParameterList.Add(dtDisChanUpdateOld.Rows[x]["IS_LOCK"]);

                        bResult = UpdateDisChanFor111(ParameterList, DBT);
                    }
                    #endregion
                }


                #region 交易成功

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation成立
                    DBT.Commit();
                }

                #endregion
            }
            catch (Exception ex)
            {
                #region 交易失敗

                bResult = false;

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation失敗
                    DBT.Rollback();
                }

                #endregion

                throw GetNewException(ex);
            }
            finally
            {
                #region 判斷是否關閉交易連線

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation,關閉連線
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }

            return bResult;
            #endregion
        }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region
        ErrorMsgLabel.Text = "";
        RightMsgLabel.Text = "";

        if (!IsPostBack)
        {
            if (Request.QueryString["PageTimeStamp"] != null)
                PageTimeStamp.Value = Request.QueryString["PageTimeStamp"];
            else
                PageTimeStamp.Value = string.Format("{0}{1}{2}{3}{4}{5}",
                                                DateTime.Now.Year.ToString(),
                                                DateTime.Now.Month.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Day.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Minute.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Second.ToString().PadLeft(2, '0')
                                                );


            #region 取傳入參數
            //string s_DIS_NO, s_ITEM, s_PERIOD;
            try
            {
                s_DIS_NO = Request.QueryString["DIS_NO"];
            }
            catch
            {
                s_DIS_NO = null;
            }
            txt_DIS_NO_OLD.Text = s_DIS_NO;
            try
            {
                s_ITEM = Request.QueryString["ITEM"];
            }
            catch
            {
                s_ITEM = null;
            }
            try
            {
                s_PERIOD = Request.QueryString["PERIOD"];
            }
            catch
            {
                s_PERIOD = null;
            }

            if (s_DIS_NO == null || s_ITEM == null || s_PERIOD == null)
            {
                this.ErrorMsgLabel.Text = "傳入參數有誤,無法執行複製!請回前頁重新執行";
                return;
            }
            #endregion

            #region 設定Tabe index
            rb_ChanType.TabIndex = 1;
            SLP_StoreChain1.TextBox_Code.TabIndex = 2;
            rb_OrderType.TabIndex = 3;
            SLP_FrontCnt.TextBox_Code.TabIndex = 4;
            SLP_AdjustQty.TextBox_Code.TabIndex = 5;
            txt_AdjustSumQty.TabIndex = 6;
            btnExecute.TabIndex = 3;
            btnBack.TabIndex = 4;

            #endregion

            #region 取得可調整之有效配本門市數

            ArrayList ParameterList = new ArrayList();//20091113

            ParameterList.Clear();
            ParameterList.Add(s_DIS_NO);
            ParameterList.Add(s_ITEM);
            ParameterList.Add(s_PERIOD);

            ALOModel.MaintainDisStore bco_store = new ALOModel.MaintainDisStore(ConnectionDB);
            vNonLokcCnt = bco_store.QueryNonLockStoreCount(ParameterList);
            if (vNonLokcCnt <= 0)
            {
                this.ErrorMsgLabel.Text = "可調整之配本門市數=0, 無法進行升降冪調整, 請回前頁!";
                return;
            }

            #endregion

            this.btnExecute.Enabled = true;
            this.Form.DefaultButton = btnExecute.UniqueID;
        }


        ToolBarInit();

        AuthorityControls(this);
        #endregion
    }
        public bool UpdateDisCRMRecord(
            DataTable dtDisMain, 
            DataTable dtDisItemNew, DataTable dtDisItemOld,
            DataTable dtDisStoreNew, DataTable dtDisStoreOld,
            string strDIS_NO,
            DbTransaction RootDBT)
        {
            #region

            bool bResult = false;
            bool IsRootTranscation = false;
            ArrayList ParameterList = new ArrayList();
            DataCompare dc = new DataCompare();
            DataTable dtDisMainDiff = null;

            DataTable dtDisItemDiff = null;
            DataTable dtDisItemAdd = null;
            DataTable dtDisItemDelete = null;

            DataTable dtDisStoreDiff = null;
            DataTable dtDisStoreAdd = null;
            DataTable dtDisStoreDelete = null;

            try
            {
                //判斷是否有傳入Root Transcation 
                IsRootTranscation = (RootDBT == null) ? true : false;


                #region 啟動交易或指定RootTranscation

                //4.1) 控制 Begin Transaction
                if (IsRootTranscation)
                {
                    //獨立呼叫啟動Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion

                #region biz logical


                #region 4.2) 更新配本主檔並記

                if (dtDisMain != null && dtDisMain.Rows.Count > 0)
                {
                    MaintainDisMain BCODisMain = new MaintainDisMain(ConnectionDB);
                    bResult = BCODisMain.UpdateDisMainFor111(dtDisMain, DBT);
                }
                else
                {
                    bResult = true;
                }

                if (!bResult)
                    throw new Exception(string.Format("MaintainDisCRMRecord.UpdateDisMainFor111:Step{0} 發生錯誤", "4.2"));
                #endregion

                #region 4.3) 更新配本商品與配本通路

                #region 比較新舊值
                dc.Clear();
                dc.CompareA = dtDisItemNew;
                dc.CompareB = dtDisItemOld;
                dc.CompareField.AddCompareFieldRow("DIS_NO", "", true);
                dc.CompareField.AddCompareFieldRow("ITEM", "", true);
                dc.CompareField.AddCompareFieldRow("PERIOD", "", true);
                dc.CompareField.AddCompareFieldRow("INCLUDE_NON_EFF", "", false);
                dc.CompareData();

                dtDisItemDiff = dc.ADiff;
                dtDisItemAdd = dc.AOnly;
                dtDisItemDelete = dc.BOnly;

                #endregion

                //處理新增  
                if (dtDisItemAdd != null && dtDisItemAdd.Rows.Count > 0)
                {
                    #region
                    MaintainDisItem BCODisItem = new MaintainDisItem(ConnectionDB);
                    MaintainDisChan BCODisChan = new MaintainDisChan(ConnectionDB);

                    bResult = BCODisItem.CreateDisItem(dtDisItemAdd, strDIS_NO, DBT);
                    if (!bResult)
                        throw new Exception(string.Format("MaintainDisItem.CreateDisItem:Step{0} 發生錯誤", "4.3"));


                    foreach (DataRow dr in dtDisItemAdd.Rows)
                    {
                        ParameterList.Clear();
                        ParameterList.Add(strDIS_NO);
                        ParameterList.Add(dr["ITEM"]);
                        ParameterList.Add(dr["PERIOD"]);
                        ParameterList.Add(dtDisMain.Rows[0]["RCHAN_NO"]);
                        ParameterList.Add(DBNull.Value);
                        ParameterList.Add(dr["CREATEDATE"]);
                        ParameterList.Add(dr["CREATEUID"]);
                        ParameterList.Add(DBNull.Value);
                        ParameterList.Add(dtDisMain.Rows[0]["ST_ACCEPT_DATE"]);
                        bResult = BCODisChan.CreateDisChan(ParameterList, DBT);

                        if (!bResult)
                            throw new Exception(string.Format("MaintainDisChan.CreateDisChan:Step{0} 發生錯誤", "4.3"));
                    }
                }
                else
                {
                    bResult = true;
                    #endregion
                }

                //處理更新  
                if (dtDisItemDiff != null && dtDisItemDiff.Rows.Count > 0)
                {
                    #region
                    MaintainDisItem BCODisItem = new MaintainDisItem(ConnectionDB);
                    MaintainDisChan BCODisChan = new MaintainDisChan(ConnectionDB);

                    bResult = BCODisItem.UpdateDisItemFor111(dtDisItemDiff, DBT);

                    if (!bResult)
                        throw new Exception(string.Format("MaintainDisItem.UpdateDisItemFor111:Step{0} 發生錯誤", "4.3"));


                    foreach (DataRow dr in dtDisItemDiff.Rows)
                    {
                        ParameterList.Clear();
                        //new
                        ParameterList.Add(dr["CODE", DataRowVersion.Current]);
                        ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Current]);
                        ParameterList.Add(dr["UPDATEUID", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["ITEM", DataRowVersion.Current]);
                        ParameterList.Add(dr["PERIOD", DataRowVersion.Current]);
                        ParameterList.Add(dr["CHAN_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["PLAN_RETURN_DATE", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_TYPE", DataRowVersion.Current]);
                        ParameterList.Add(dr["PATTERN_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_BRATE", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_STO_CQTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_PRE_CQTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_TOT_QTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_TOT_OQTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_TOT_PQTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["IS_LOCK", DataRowVersion.Current]);
                        //old
                        ParameterList.Add(dr["ID", DataRowVersion.Original]);
                        ParameterList.Add(dr["CODE", DataRowVersion.Original]);
                        ParameterList.Add(dr["CREATEDATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["CREATEUID", DataRowVersion.Original]);
                        ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["UPDATEUID", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_NO", DataRowVersion.Original]);
                        ParameterList.Add(dr["ITEM", DataRowVersion.Original]);
                        ParameterList.Add(dr["PERIOD", DataRowVersion.Original]);
                        ParameterList.Add(dr["CHAN_NO", DataRowVersion.Original]);
                        ParameterList.Add(dr["PLAN_RETURN_DATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_TYPE", DataRowVersion.Original]);
                        ParameterList.Add(dr["PATTERN_NO", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_BRATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_STO_CQTY", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_PRE_CQTY", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_TOT_QTY", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_TOT_OQTY", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_TOT_PQTY", DataRowVersion.Original]);
                        ParameterList.Add(dr["IS_LOCK", DataRowVersion.Original]);

                        bResult = BCODisChan.UpdateDisChan(ParameterList, DBT);

                        if (!bResult)
                            throw new Exception(string.Format("MaintainDisChan.UpdateDisChan:Step{0} 發生錯誤", "4.3"));
                    }
                }
                else
                {
                    bResult = true;
                    #endregion
                }

                //處理刪除  
                if (dtDisItemDelete != null && dtDisItemDelete.Rows.Count > 0)
                {
                    #region
                    MaintainDisItem BCODisItem = new MaintainDisItem(ConnectionDB);

                    foreach (DataRow dr in dtDisItemDelete.Rows)
                    {
                        #region old
                        //ParameterList.Clear();
                        //ParameterList.Add(dr["ID", DataRowVersion.Original]);
                        //ParameterList.Add(dr["CODE", DataRowVersion.Original]);
                        //ParameterList.Add(dr["CREATEDATE", DataRowVersion.Original]);
                        //ParameterList.Add(dr["CREATEUID", DataRowVersion.Original]);
                        //ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Original]);
                        //ParameterList.Add(dr["UPDATEUID", DataRowVersion.Original]);
                        //ParameterList.Add(dr["DIS_NO", DataRowVersion.Original]);
                        //ParameterList.Add(dr["ITEM", DataRowVersion.Original]);
                        //ParameterList.Add(dr["PERIOD", DataRowVersion.Original]);
                        //ParameterList.Add(dtDisMain.Rows[0]["RCHAN_NO"]);
                        //ParameterList.Add(dr["MEMO", DataRowVersion.Original]);

                        //bResult = BCODisItem.DeleteDisCRMItem(ParameterList, DBT);

                        //if (!bResult)
                        //    throw new Exception(string.Format("MaintainDisItem.DeleteDisCRMItem:Step{0} 發生錯誤", "4.3"));
                        #endregion

                        //20090930 modified
                        ParameterList.Clear();
                        ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["UPDATEUID", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_NO", DataRowVersion.Original]);
                        ParameterList.Add(dr["ITEM", DataRowVersion.Original]);
                        ParameterList.Add(dr["PERIOD", DataRowVersion.Original]);
                        bResult = BCODisItem.DeleteDisItemFor111(ParameterList, DBT);

                        if (!bResult)
                            throw new Exception(string.Format("MaintainDisItem.DeleteDisItemFor111:Step{0} 發生錯誤", "4.3"));
                    }
                }
                else
                {
                    bResult = true;
                    #endregion
                }


                #endregion

                #region 4.4) 更新配本門市檔

                #region 比較新舊值
                dc.Clear();
                dc.CompareA = dtDisStoreNew;
                dc.CompareB = dtDisStoreOld;
                dc.CompareField.AddCompareFieldRow("CODE", "", true);
                dc.CompareField.AddCompareFieldRow("ROUTE", "", false);
                dc.CompareField.AddCompareFieldRow("STEP", "", false);
                dc.CompareField.AddCompareFieldRow("DIS_QTY", "", false);
                dc.CompareData();

                dtDisStoreDiff = dc.ADiff;
                dtDisStoreAdd = dc.AOnly;
                dtDisStoreDelete = dc.BOnly;

                #endregion

                //處理新增  
                if (dtDisStoreAdd != null && dtDisStoreAdd.Rows.Count > 0)
                {
                    #region
                    MaintainDisStore BCODisStore = new MaintainDisStore(ConnectionDB);

                    foreach (DataRow dr in dtDisStoreAdd.Rows)
                    {

                        ParameterList.Clear();
                        ParameterList.Add(dr["CODE", DataRowVersion.Current]);
                        ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Current]);
                        ParameterList.Add(dr["UPDATEUID", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["ITEM", DataRowVersion.Current]);
                        ParameterList.Add(dr["PERIOD", DataRowVersion.Current]);
                        ParameterList.Add(dr["CHAN_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["STORE", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_QTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["PO_SOURCE_NO", DataRowVersion.Current]);
                        ParameterList.Add(dtDisMain.Rows[0]["ST_ACCEPT_DATE"]);
                        bResult = BCODisStore.CreateDisCRMStore(ParameterList, DBT);

                        if (!bResult)
                            throw new Exception(string.Format("MaintainDisStore.CreateDisCRMStore:Step{0} 發生錯誤", "4.4"));
                    
                    }
                }
                else
                {
                    bResult = true;
                    #endregion
                }

                //處理更新  
                if (dtDisStoreDiff != null && dtDisStoreDiff.Rows.Count > 0)
                {
                    #region
                    MaintainDisStore BCODisStore = new MaintainDisStore(ConnectionDB);

                    foreach (DataRow dr in dtDisStoreDiff.Rows)
                    {

                        ParameterList.Clear();
                        ParameterList.Add(dr["CODE", DataRowVersion.Current]);
                        ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Current]);
                        ParameterList.Add(dr["UPDATEUID", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["ITEM", DataRowVersion.Current]);
                        ParameterList.Add(dr["PERIOD", DataRowVersion.Current]);
                        ParameterList.Add(dr["CHAN_NO", DataRowVersion.Current]);
                        ParameterList.Add(dr["STORE", DataRowVersion.Current]);
                        ParameterList.Add(dr["DIS_QTY", DataRowVersion.Current]);
                        ParameterList.Add(dr["PO_SOURCE_NO", DataRowVersion.Current]);
                        ParameterList.Add(dtDisMain.Rows[0]["ST_ACCEPT_DATE"]);
                        bResult = BCODisStore.CreateDisCRMStore(ParameterList, DBT);

                        if (!bResult)
                            throw new Exception(string.Format("MaintainDisStore.CreateDisCRMStore:Step{0} 發生錯誤", "4.4"));
                    
                    }
                }
                else
                {
                    bResult = true;
                    #endregion
                }

                //處理刪除  
                if (dtDisStoreDelete != null && dtDisStoreDelete.Rows.Count > 0)
                {
                    #region
                    MaintainDisStore BCODisStore = new MaintainDisStore(ConnectionDB);

                    foreach (DataRow dr in dtDisStoreDelete.Rows)
                    {
                        ParameterList.Clear();
                        ParameterList.Add(dr["ID", DataRowVersion.Original]);
                        ParameterList.Add(dr["CODE", DataRowVersion.Original]);
                        ParameterList.Add(dr["CREATEDATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["CREATEUID", DataRowVersion.Original]);
                        ParameterList.Add(dr["UPDATEDATE", DataRowVersion.Original]);
                        ParameterList.Add(dr["UPDATEUID", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_NO", DataRowVersion.Original]);
                        ParameterList.Add(dr["ITEM", DataRowVersion.Original]);
                        ParameterList.Add(dr["PERIOD", DataRowVersion.Original]);
                        ParameterList.Add(dr["CHAN_NO", DataRowVersion.Original]);
                        ParameterList.Add(dr["STORE", DataRowVersion.Original]);
                        ParameterList.Add(dr["DIS_QTY", DataRowVersion.Original]);
                        ParameterList.Add(dr["PO_SOURCE_NO", DataRowVersion.Original]);

                        bResult = BCODisStore.DeleteDisStore(ParameterList, DBT);

                        if (!bResult)
                            throw new Exception(string.Format("MaintainDisStore.DeleteDisStore:Step{0} 發生錯誤", "4.4"));
                    }
                }
                else
                {
                    bResult = true;
                    #endregion
                }

                #endregion


                #region  4.5) 呼叫 PKG_VDS_ALO_COMM.lf_area_qty

                if (dtDisItemOld != null && dtDisItemOld.Rows.Count > 0)
                {
                    ParameterList.Clear();
                    ParameterList.Add(strDIS_NO);
                    ParameterList.Add(dtDisItemOld.Rows[0]["ITEM"]);
                    ParameterList.Add(dtDisItemOld.Rows[0]["PERIOD"]);
                    ParameterList.Add(dtDisMain.Rows[0]["RCHAN_NO"]);
                    ParameterList.Add("X");
                    VDS_ALO_COMMON_DBO DBO_COMM = new VDS_ALO_COMMON_DBO(ref USEDB);
                    bResult = DBO_COMM.doLp_area_disqty(ParameterList, DBT);
                }

                if (!bResult)
                    throw new Exception(string.Format("{0} 發生失敗", "呼叫 PKG_VDS_ALO_COMM.lf_area_qty"));
                #endregion


                #region 4.6) 異動其他相關資料表

                if (dtDisItemOld != null && dtDisItemOld.Rows.Count > 0)
                {
                    ParameterList.Clear();
                    ParameterList.Add(strDIS_NO);
                    ParameterList.Add(dtDisItemOld.Rows[0]["ITEM"]);
                    ParameterList.Add(dtDisItemOld.Rows[0]["PERIOD"]);
                    ParameterList.Add(dtDisItemOld.Rows[0]["ROOT_NO"]);
                    ProcessALOCommon BCOProcessCommon = new ProcessALOCommon(ConnectionDB);
                    bResult = BCOProcessCommon.UpdateOtherTables(ParameterList, DBT);
                }

                if (!bResult)
                    throw new Exception(string.Format("ProcessALOCommon.UpdateOtherTables:Step{0} 發生錯誤", "4.6"));

                #endregion


                #endregion

                #region 交易成功

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation成立
                    DBT.Commit();
                }

                #endregion

            }
            catch (Exception ex)
            {
                #region 交易失敗

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation失敗
                    DBT.Rollback();
                }

                #endregion

                bResult = false;

                throw GetNewException(ex);
            }
            finally
            {
                #region 判斷是否關閉交易連線

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation,關閉連線
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }


            return bResult;

            #endregion
        }
Exemple #4
0
    private void QueryData()
    {
        #region
        try
        {
            if (s_DIS_NO == "") return;

            //if (CurrentPageMode == PageCurrentMode.Insert || CurrentPageMode == PageCurrentMode.Edit)
            //{
            #region

            CheckCurrentIndexAndSwitchNavigator(s_DIS_NO);

            ALOModel.MaintainDisMain BCO1 = new ALOModel.MaintainDisMain(ConnectionDB);
            ArrayList ParameterList = new ArrayList();
            ParameterList.Clear();
            ParameterList.Add(s_DIS_NO == "" ? null : s_DIS_NO);
            dtDisMain = BCO1.QueryByDisNo(ParameterList);

            ALOModel.MaintainDisCRMRecord BCO2 = new ALOModel.MaintainDisCRMRecord(ConnectionDB);
            ParameterList.Clear();
            ParameterList.Add(s_DIS_NO == "" ? null : s_DIS_NO);
            dtDisItem = BCO2.QueryDisCRMItemByDisNo(ParameterList);
            dtDisItemOld = dtDisItem.Copy();

            DataColumn[] PrimaryKeys21 = new DataColumn[3];
            PrimaryKeys21[0] = dtDisItemOld.Columns["DIS_NO"];
            PrimaryKeys21[1] = dtDisItemOld.Columns["ITEM"];
            PrimaryKeys21[2] = dtDisItemOld.Columns["PERIOD"];
            dtDisItemOld.PrimaryKey = PrimaryKeys21;

            DataColumn[] PrimaryKeys22 = new DataColumn[3];
            PrimaryKeys22[0] = dtDisItem.Columns["DIS_NO"];
            PrimaryKeys22[1] = dtDisItem.Columns["ITEM"];
            PrimaryKeys22[2] = dtDisItem.Columns["PERIOD"];
            dtDisItem.PrimaryKey = PrimaryKeys22;


            ALOModel.MaintainDisStore BCO3 = new ALOModel.MaintainDisStore(ConnectionDB);
            ParameterList.Clear();
            ParameterList.Add(s_DIS_NO == "" ? null : s_DIS_NO);

            dtDisStoreAll = BCO3.QueryDisStoreByDisNo(ParameterList);
            dtDisStore = dtDisStoreAll.Copy();
            dtDisStoreAllOld = dtDisStoreAll.Copy();

            DataColumn[] PrimaryKeys31 = new DataColumn[1];
            PrimaryKeys31[0] = dtDisStoreAllOld.Columns["CODE"];
            dtDisStoreAllOld.PrimaryKey = PrimaryKeys31;

            DataColumn[] PrimaryKeys32 = new DataColumn[1];
            PrimaryKeys32[0] = dtDisStoreAll.Columns["CODE"];
            dtDisStoreAll.PrimaryKey = PrimaryKeys32;

            #region Binding Data
            txt_DisNo.Text = s_DIS_NO;
            if (dtDisMain != null && dtDisMain.Rows.Count > 0)
            {
                SLP_StoreChain1.Text = dtDisMain.Rows[0]["RCHAN_NO"].ToString();
                SLP_SLPDate1_DisDate.Text = dtDisMain.Rows[0]["DIS_DATE"].ToString();
                SLP_SLPDate2_StAcceptDate.Text = dtDisMain.Rows[0]["ST_ACCEPT_DATE"].ToString();
                SLP_SLPDate3_TransStAcceptDate.Text = dtDisMain.Rows[0]["TRANS_ST_ACCEPT_DATE"].ToString();
                SLP_SLPDate4_ApproveDate.Text = dtDisMain.Rows[0]["APPROVE_DATE"].ToString();
                SLP_EnumBase1.Text = dtDisMain.Rows[0]["DATA_SOURCE"].ToString();
                txt_POSourceNo.Text = dtDisMain.Rows[0]["PO_SOURCE_NO"].ToString();
            }
            else
            {
                CurrentPageMode = PageCurrentMode.Query;
                throw new Exception("查無此筆資料或已被其他使用者刪除,請點選上一筆/下一筆鈕或回查詢頁重新查詢!");
            }

            currentGvModeDisItem = CurrentGridviewMode.ReadOnly;

            gv_DisItem.DataSource = dtDisItem;
            gv_DisItem.DataBind();

            if (dtDisItem != null && dtDisItem.Rows.Count > 0)
            {
                s_ITEM = dtDisItem.Rows[0]["ITEM"].ToString().Trim(); ;
                s_PERIOD = dtDisItem.Rows[0]["PERIOD"].ToString().Trim(); ;
                s_ITEM_NAME = dtDisItem.Rows[0]["ITEM_NAME"].ToString().Trim(); ;
                s_PMA = dtDisItem.Rows[0]["PMA"].ToString().Trim(); ;
                s_ROOT_NO = dtDisItem.Rows[0]["ROOT_NO"].ToString().Trim(); ;
                s_PATTERN = dtDisItem.Rows[0]["PATTERN_NO"].ToString().Trim(); ;
            }

            string strFilter = string.Format(" ITEM='{0}' and PERIOD='{1}' ", s_ITEM, s_PERIOD);
            DataView dv = dtDisStoreAll.DefaultView;
            dv.RowFilter = strFilter;

            dtDisStore = dv.ToTable().Copy();

            currentGvModeDisStore = CurrentGridviewMode.ReadOnly;

            gv_DisStore.DataSource = dtDisStore;
            gv_DisStore.DataBind();


            CountGvDisStoreInfo();
            #endregion

            #endregion
            //}

            if (CurrentPageMode == PageCurrentMode.Readonly)
            {
                CheckConfirmOrRemove();
            }

        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }

        #endregion
    }
Exemple #5
0
 private void MakeDataTableDisStoreAll()
 {
     #region
     try
     {
         ALOModel.MaintainDisStore BCO = new ALOModel.MaintainDisStore(ConnectionDB);
         dtDisStoreAll = BCO.GetDisStoreSchema();
     }
     catch (Exception ex)
     {
         ErrorMsgLabel.Text = ex.Message;
     }
     #endregion
 }
Exemple #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region
        ErrorMsgLabel.Text = "";
        RightMsgLabel.Text = "";

        if (!IsPostBack)
        {
            #region
            if (Request.QueryString["PageTimeStamp"] != null)
                PageTimeStamp.Value = Request.QueryString["PageTimeStamp"];
            else
                PageTimeStamp.Value = string.Format("{0}{1}{2}{3}{4}{5}",
                                                DateTime.Now.Year.ToString(),
                                                DateTime.Now.Month.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Day.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Minute.ToString().PadLeft(2, '0'),
                                                DateTime.Now.Second.ToString().PadLeft(2, '0')
                                                );


            #region 取傳入參數
            //string s_DIS_NO, s_ITEM, s_PERIOD;
            try
            {
                s_DIS_NO = Request.QueryString["DIS_NO"];
            }
            catch
            {
                s_DIS_NO = null;
            }

            try
            {
                s_ITEM = Request.QueryString["ITEM"];
            }
            catch
            {
                s_ITEM = null;
            }
            try
            {
                s_PERIOD = Request.QueryString["PERIOD"];
            }
            catch
            {
                s_PERIOD = null;
            }

            if (s_DIS_NO == null || s_ITEM == null || s_PERIOD == null)
            {
                this.ErrorMsgLabel.Text = "傳入參數(配本序號,品號,期別)有誤,無法執行計算!請回前頁重新執行";
                return;
            }
            s_SESSION_ID = this.PageTimeStamp.Value.ToString() + "_" + Session["UID"].ToString();
            #endregion

            #region 設定TextOnChange

            //TextBox txtChanCode = this.SLP_StoreChain1.TextBox_Code;
            //txtChanCode.TextChanged += new System.EventHandler(txtChanCode_TextChanged);
            //this.SLP_StoreChain1.TextBox_Code.Attributes["onchange"] += "__doPostBack(document.all['" + up_Slp_Chan.ClientID + "'].id,'txtChanCode_OnChange');";
            //txtChanCode.AutoPostBack = true;

            //AsyncPostBackTrigger trigger1 = new AsyncPostBackTrigger();
            //trigger1.EventName = "TextChanged";
            //trigger1.ControlID = SLP_StoreChain1.TextBox_Code.UniqueID;
            //this.up_Slp_Chan.Triggers.Add(trigger1);
            #endregion

            #region 取得可調整之有效配本門市數

            ArrayList ParameterList = new ArrayList();//20091113

            ParameterList.Clear();
            ParameterList.Add(s_DIS_NO);
            ParameterList.Add(s_ITEM);
            ParameterList.Add(s_PERIOD);
            ALOModel.MaintainDisStore bco_store = new ALOModel.MaintainDisStore(ConnectionDB);
            vNonLokcCnt = bco_store.QueryNonLockStoreCount(ParameterList);
            if (vNonLokcCnt <= 0)
            {
                this.ErrorMsgLabel.Text = "可調整之配本門市數=0, 無法進行計算比例, 請回前頁!";
                HasUpdateData = false;
                //return;
            }

            #endregion

            #region 取得待處理資訊

            #region 產生暫存檔資訊
            try
            {
                ALOModel.MaintainDisRecord BCO = new ALOModel.MaintainDisRecord(ConnectionDB);
                ParameterList.Clear();
                ParameterList.Add(s_DIS_NO);
                ParameterList.Add(s_ITEM);
                ParameterList.Add(s_PERIOD);
                ParameterList.Add(Session["UID"].ToString());
                ParameterList.Add(s_SESSION_ID);

                bool bResult = BCO.CreateALO116TMP(ParameterList);

                if (!bResult)
                {
                    throw new Exception("建立暫存檔失敗");
                }

            }
            catch (Exception ex)
            {
                this.ErrorMsgLabel.Text = ex.Message;
                return;
            }

            #endregion

            QueryAllChanData(); //取得通路資料

            QueryAllAreaData(); //取得區域資料

            #endregion

            this.btnExecute.Enabled = true;
            //this.Form.DefaultButton = btnExecute.UniqueID;

            rbtn_Chan.Attributes.Add("onclick", "CheckOPType(this);");
            rbtn_Area.Attributes.Add("onclick", "CheckOPType(this);");

            ScriptManager.RegisterStartupScript(this, this.GetType(), "",
                "LockOrUnLockButtonInGridviewControl(false,'gv_Chan','btn');LockOrUnLockButtonInGridviewControl(true,'gv_Area','btn');", true);

            #endregion
        }
        else
        {
            //if (Request.Form["__EVENTARGUMENT"] == "txtChanCode_OnChange")
            //    txtChanCode_OnChange();
        }

        ToolBarInit();
        #region 頁面狀態設定
        //SetPageControlStatus();
        if (Request.QueryString["APPROVE_DATE"] != null && Request.QueryString["APPROVE_DATE"].ToString().Trim() != "")
        {
            ConfirmData = true;
        }
        #endregion
        AuthorityControls(this);
        #endregion
    }