Ejemplo n.º 1
0
    //期別主檔、期別屬性檔、期別帳務資料 -> EditItemTemplate -> 儲存<編輯模式>
    protected void btnPeriodEditCommit_Click(object sender, EventArgs e)
    {
        #region 檢查欄位[期別結束日]

        //20100208新增條件,編輯模式下,欄位[期別結束日]如有異動,必須大於或等於生活日(sysdate)
        if (((ASP.wui_slp_slp_slpdate_ascx)this.FormView1.FindControl("txtPERIOD_END_DATE")).Text != ((ASP.wui_slp_slp_slpdate_ascx)this.FormView1.FindControl("txtPERIOD_END_DATE_Original")).Text)
        {
            if (((ASP.wui_slp_slp_slpdate_ascx)this.FormView1.FindControl("txtPERIOD_END_DATE")).Text != string.Empty)
            {
                DateTime d_PERIOD_END_DATE = DateTime.Parse(((ASP.wui_slp_slp_slpdate_ascx)this.FormView1.FindControl("txtPERIOD_END_DATE")).Text);
                if (d_PERIOD_END_DATE < DateTime.Now.Date)
                {
                    Alert("欄位[期別結束日]必須大於或等於生活日");
                    return;
                }
            }
        }

        #endregion

        #region 檢查[品號][供應商]是否輸入正確的值

        #region 設定變數

        int i_ITEM_Count = 0;
        int i_VENDOR_Count = 0;
        string s_ErrorMsg = string.Empty;

        TextBox txt_ITEM = ((WUI.SLP.SLP_SKU)this.FormView1.FindControl("txtITEM")).TextBox_Code;//商品
        TextBox txt_VENDOR = ((WUI.SLP.SLP_VendorBase)this.FormView1.FindControl("txtVENDOR")).TextBox_Code;//供應商

        STMModel.ITMPublic BCO_Public = new STMModel.ITMPublic(ConntionDB);

        #endregion

        #region 檢查[品號]

        ParameterList.Clear();
        ParameterList.Add(txt_ITEM.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_ITEM_Count = BCO_Public.QUERY_ITME_COUNT(ParameterList);

        #endregion

        #region 檢查[供應商]

        ParameterList.Clear();
        ParameterList.Add(txt_VENDOR.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_VENDOR_Count = BCO_Public.QUERY_VENDOR_COUNT(ParameterList);

        #endregion

        #region 檢查回傳資料

        if (i_ITEM_Count != 1)
        { s_ErrorMsg += "期別主檔頁籤的品號欄位,輸入正確的品號\\r\\n"; }

        if (i_VENDOR_Count != 1)
        { s_ErrorMsg += "期別主檔頁籤的供應商欄位,請輸入正確的供應商\\r\\n"; }

        if (s_ErrorMsg != string.Empty)
        {
            Alert(s_ErrorMsg);
            return;
        }

        #endregion

        #endregion

        DbConnection con;
        DbTransaction transaction = bco.GetTransaction(out con);
        if (Save_Data(true, DateTime.Now, ((TextBox)FormView1.FindControl("txtEDIT_NO")).Text.Trim(), transaction, con) == true) //因「產生異動序號」也會用到同樣的程序,所以另寫一個Save_Data函式共用
        {
            Response.Redirect(string.Format("ITM022.aspx?Code=ITM02&arl_Key={0}&isToolBar=N&ID={1}&mode={2}&finish={3}", Request.QueryString["arl_Key"], ViewState["PID"].ToString(), "readonly", "Y"), false);
        }
    }
Ejemplo n.º 2
0
    private string Check_Condition()
    {
        string s_ReturnMsg = string.Empty;

        #region 設定變數

        int i_VENDOR_Count = 0;//[供應商]筆數
        int i_ROOT_NO_Count = 0;//[群分類]筆數
        int i_PMA_Count = 0;//[大分類]筆數
        int i_CATEGORY_Count = 0;//[中分類]筆數
        int i_SORTOUT_Count = 0;//[小分類]筆數

        TextBox txt_VENDOR = ((WUI.SLP.SLP_VendorBase)this.FormView1.FindControl("txtMANUFACTURE")).TextBox_Code;//供應商
        TextBox txt_ROOT_NO = ((WUI.SLP.SLP_RootNo)this.FormView1.FindControl("ddlROOT_NO")).TextBox_Code;//群分類
        TextBox txt_PMA = ((WUI.SLP.SLP_PMA)this.FormView1.FindControl("txtPMA")).TextBox_Code;//大分類
        TextBox txt_CATEGORY = ((WUI.SLP.SLP_Category)this.FormView1.FindControl("txtCATEGORY")).TextBox_Code;//中分類
        TextBox txt_SORT_OUT = ((WUI.SLP.SLP_SortOut)this.FormView1.FindControl("txtSORT_OUT")).TextBox_Code;//小分類

        PIC.VDS2G.GFM.ITM.ITMPublic BCO_Public = new PIC.VDS2G.GFM.ITM.ITMPublic(ConntionDB);

        #endregion

        #region 檢查[供應商]

        ParameterList.Clear();
        ParameterList.Add(txt_VENDOR.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_VENDOR_Count = BCO_Public.QUERY_VENDOR_COUNT(ParameterList);

        #endregion

        #region 檢查[群分類]

        ParameterList.Clear();
        ParameterList.Add(txt_ROOT_NO.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_ROOT_NO_Count = BCO_Public.QUERY_ROOT_NO_COUNT(ParameterList);

        #endregion

        #region 檢查[大分類]

        ParameterList.Clear();
        ParameterList.Add(txt_ROOT_NO.Text.Trim());
        ParameterList.Add(txt_PMA.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_PMA_Count = BCO_Public.QUERY_PMA_COUNT(ParameterList);

        #endregion

        #region 檢查[中分類]

        ParameterList.Clear();
        ParameterList.Add(txt_ROOT_NO.Text.Trim());
        ParameterList.Add(txt_PMA.Text.Trim());
        ParameterList.Add(txt_CATEGORY.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_CATEGORY_Count = BCO_Public.QUERY_CATEGORY_COUNT(ParameterList);

        #endregion

        #region 檢查[小分類]

        ParameterList.Clear();
        ParameterList.Add(txt_ROOT_NO.Text.Trim());
        ParameterList.Add(txt_PMA.Text.Trim());
        ParameterList.Add(txt_CATEGORY.Text.Trim());
        ParameterList.Add(txt_SORT_OUT.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_SORTOUT_Count = BCO_Public.QUERY_SORTOUT_COUNT(ParameterList);

        #endregion

        #region 檢查回傳資料

        if (i_VENDOR_Count != 1)
        { s_ReturnMsg += "新品主檔頁籤的供應商欄位,請輸入正確的供應商\\r\\n"; }

        if (i_ROOT_NO_Count != 1)
        { s_ReturnMsg += "新品主檔頁籤的群分類欄位,請輸入正確的群分類\\r\\n"; }

        if (i_PMA_Count != 1)
        { s_ReturnMsg += "新品主檔頁籤的大分類欄位,請輸入正確的大分類\\r\\n"; }

        if (i_CATEGORY_Count != 1)
        { s_ReturnMsg += "新品主檔頁籤的中分類欄位,請輸入正確的中分類\\r\\n"; }

        if (i_SORTOUT_Count != 1)
        { s_ReturnMsg += "新品主檔頁籤的小分類欄位,請輸入正確的小分類\\r\\n"; }

        #endregion

        return s_ReturnMsg;
    }
Ejemplo n.º 3
0
    //期別主檔、期別屬性檔、期別帳務資料 -> InsertItemTemplate -> 儲存<新增模式>
    protected void btnPeriodInsertButton_Click(object sender, EventArgs e)
    {
        #region 檢查欄位[期別結束日]

        //20100208新增條件,新增模式下,欄位[期別結束日]必須大於或等於生活日(sysdate)
        if (((ASP.wui_slp_slp_slpdate_ascx)this.FormView1.FindControl("txtPERIOD_END_DATE")).Text != string.Empty)
        {
            DateTime d_PERIOD_END_DATE = DateTime.Parse(((ASP.wui_slp_slp_slpdate_ascx)this.FormView1.FindControl("txtPERIOD_END_DATE")).Text);
            if (d_PERIOD_END_DATE < DateTime.Now.Date)
            {
                Alert("欄位[期別結束日]必須大於或等於生活日");
                return;
            }
        }

        #endregion

        #region 檢查[品號][供應商]是否輸入正確的值

        #region 設定變數

        int i_ITEM_Count = 0;
        int i_VENDOR_Count = 0;
        string s_ErrorMsg = string.Empty;

        TextBox txt_ITEM = ((WUI.SLP.SLP_SKU)this.FormView1.FindControl("txtITEM")).TextBox_Code;//商品
        TextBox txt_VENDOR = ((WUI.SLP.SLP_VendorBase)this.FormView1.FindControl("txtVENDOR")).TextBox_Code;//供應商

        STMModel.ITMPublic BCO_Public = new STMModel.ITMPublic(ConntionDB);

        #endregion

        #region 檢查[品號]

        ParameterList.Clear();
        ParameterList.Add(txt_ITEM.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_ITEM_Count = BCO_Public.QUERY_ITME_COUNT(ParameterList);

        #endregion

        #region 檢查[供應商]

        ParameterList.Clear();
        ParameterList.Add(txt_VENDOR.Text.Trim());
        ParameterList.Add(Session["UID"].ToString());

        i_VENDOR_Count = BCO_Public.QUERY_VENDOR_COUNT(ParameterList);

        #endregion

        #region 檢查回傳資料

        if (i_ITEM_Count != 1)
        { s_ErrorMsg += "期別主檔頁籤的品號欄位,輸入正確的品號\\r\\n"; }

        if (i_VENDOR_Count != 1)
        { s_ErrorMsg += "期別主檔頁籤的供應商欄位,請輸入正確的供應商\\r\\n"; }

        if (s_ErrorMsg != string.Empty)
        {
            Alert(s_ErrorMsg);
            return;
        }

        #endregion

        #endregion

        if (!chkItemPeriod('1'))
        {
            Alert("品號、期別重複,請重新輸入");
            return;
        }

        if (chkFieldEmpty()) return;
        DbConnection con;
        DbTransaction transaction = bco.GetTransaction(out con);
        DateTime TimeNow = DateTime.Now;

        int v_ID = 0;
        try
        {
            #region 畫面取值

            FormView fv = FormView1;
            string v_ITEM = ((WUI.SLP.SLP_SKU)fv.FindControl("txtITEM")).Text.Trim();
            string v_PERIOD = ((TextBox)fv.FindControl("txtPERIOD")).Text.Trim();
            //string v_EDIT_NO = string.Format("{0}001", DateTime.Today.ToString("yyyyMMdd"));
            string v_EDIT_NO = "0";
            string v_PERIOD_START_DATE = ((WUI.SLP.SLPDate)fv.FindControl("txtPERIOD_START_DATE")).Text.Trim();
            string v_PERIOD_END_DATE = ((WUI.SLP.SLPDate)fv.FindControl("txtPERIOD_END_DATE")).Text.Trim();
            string v_CATEGORY = ((WUI.SLP.SLP_Category)fv.FindControl("txtCATEGORY")).Text.Trim();
            string v_PUBLISH_TYPE = ((WUI.SLP.CodeFile)fv.FindControl("txtPUBLISH_TYPE")).Text.Trim();
            string v_TAX_TYPE = ((WUI.SLP.EnumBase)fv.FindControl("txtTAX_TYPE")).Text.Trim();
            string v_SPECIAL_TEXT = ((TextBox)fv.FindControl("txtSPECIAL_TEXT")).Text.Trim();
            string v_ATTRIBUTE = ((((TextBox)fv.FindControl("txtACCT_VALIDATE")).Text.Trim() == "已審核") ? "1" : "0");
            string v_VENDOR = ((WUI.SLP.SLP_VendorBase)fv.FindControl("txtVENDOR")).Text.Trim();
            string v_BARCODE = ((TextBox)fv.FindControl("txtBARCODE")).Text.Trim();
            string v_PERIOD_BARCODE = ((TextBox)fv.FindControl("txtPERIOD_BARCODE")).Text.Trim();
            string v_COST = ((WUI.SLP.SLPNumber)fv.FindControl("txtCOST")).Text.Trim();
            string v_PRICE = ((WUI.SLP.SLPNumber)fv.FindControl("txtPRICE")).Text.Trim();
            string v_DISCOUNT_RATE;
            if (v_PRICE == "0")
                v_DISCOUNT_RATE = "0";
            else
                v_DISCOUNT_RATE = Math.Round(Convert.ToDecimal(decimal.Parse(v_COST) / decimal.Parse(v_PRICE)), 2).ToString();
            string v_PRINT_CNTY = ((WUI.SLP.CodeFile)fv.FindControl("txtPRINT_CNTY")).Text.Trim();
            string v_LANGUAGE = ((WUI.SLP.CodeFile)fv.FindControl("txtLANGUAGE")).Text.Trim();
            //string v_COVER_FILE = ((TextBox)fv.FindControl("txtCOVER_FILE")).Text.Trim();
            string v_COVER_FILE = Page.Request.Form[((TextBox)fv.FindControl("txtCOVER_FILE")).UniqueID];//新增畫面,該欄位在前端組合產生
            if (v_COVER_FILE == null) v_COVER_FILE = v_ITEM + "/" + v_ITEM + v_PERIOD + ".jpg";//預防畫面欄位未被javascript寫入
            string v_DIS_RULE = ((WUI.SLP.CodeFile)fv.FindControl("txtDIS_RULE")).Text.Trim();
            string v_DIS_ACCEPT_RATE = ((WUI.SLP.SLPNumber)fv.FindControl("txtDIS_ACCEPT_RATE")).Text.Trim();
            string v_DIS_RETURN_RATE = ((WUI.SLP.SLPNumber)fv.FindControl("txtDIS_RETURN_RATE")).Text.Trim();
            string v_DIS_ACCEPT_DOLLAR = ((WUI.SLP.SLPNumber)fv.FindControl("txtDIS_ACCEPT_DOLLAR")).Text.Trim();
            string v_DIS_RETURN_DOLLAR = ((WUI.SLP.SLPNumber)fv.FindControl("txtDIS_RETURN_DOLLAR")).Text.Trim();
            string v_EDIT_REASON = ((TextBox)fv.FindControl("txtEDIT_REASON")).Text.Trim();
            string v_CODE = string.Format("{0}{1}{2}", v_ITEM, v_PERIOD, v_EDIT_NO);
            #endregion 畫面取值

            #region 更新編輯後的資料
            ParameterList.Clear();
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vCODE", v_CODE); //vCODE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vITEM", v_ITEM); //vITEM
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vPERIOD", v_PERIOD); //vPERIOD
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vEDIT_NO", v_EDIT_NO); //vEDIT_NO
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vSPECIAL_TEXT", v_SPECIAL_TEXT); //vSPECIAL_TEXT
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vTAX_TYPE", v_TAX_TYPE); //vTAX_TYPE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vVENDOR", v_VENDOR); //vVENDOR
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vCOST", v_COST); //vCOST
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vPRICE", v_PRICE); //vPRICE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vFRONT_PERIOD", ""); //vFRONT_PERIOD
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vBARCODE", v_BARCODE); //vBARCODE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vPUBLISH_TYPE", v_PUBLISH_TYPE); //vPUBLISH_TYPE
            SQLHelper.SQLWhere(ref ParameterList, DbType.DateTime, "vRETURN_DATE", null); //vRETURN_DATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vCOVER_FILE", v_COVER_FILE); //vCOVER_FILE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vPERIOD_BARCODE", v_PERIOD_BARCODE); //vPERIOD_BARCODE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vDIS_BASE", ""); //vDIS_BASE
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vDIS_ACCEPT_DOLLAR", v_DIS_ACCEPT_DOLLAR); //vDIS_ACCEPT_DOLLAR
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vDIS_RETURN_DOLLAR", v_DIS_RETURN_DOLLAR); //vDIS_RETURN_DOLLAR
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vDIS_RULE", v_DIS_RULE); //vDIS_RULE
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vDIS_ACCEPT_RATE", v_DIS_ACCEPT_RATE); //vDIS_ACCEPT_RATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vDIS_RETURN_RATE", v_DIS_RETURN_RATE); //vDIS_RETURN_RATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vACCT_VALIDATE", "0"); //vACCT_VALIDATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.DateTime, "vPERIOD_START_DATE", v_PERIOD_START_DATE); //vPERIOD_START_DATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.DateTime, "vPERIOD_END_DATE", v_PERIOD_END_DATE); //vPERIOD_END_DATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vRESEARCH_FREQUENCY", ""); //vRESEARCH_FREQUENCY
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vRESEARCH_INTERVAL", ""); //vRESEARCH_INTERVAL
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vMARKET_RESEARCH", null); //vMARKET_RESEARCH
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vPRINT_CNTY", v_PRINT_CNTY); //vPRINT_CNTY
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vLANGUAGE", v_LANGUAGE); //vLANGUAGE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vRESEARCH_INTERVAL2", ""); //vRESEARCH_INTERVAL2
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vRESEARCH_INTERVAL3", ""); //vRESEARCH_INTERVAL3
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vEDIT_REASON", v_EDIT_REASON); //vEDIT_REASON
            SQLHelper.SQLWhere(ref ParameterList, DbType.VarNumeric, "vDISCOUNT_RATE", v_DISCOUNT_RATE); //vDISCOUNT_RATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.DateTime, "vCREATEDATE", TimeNow); //vCREATEDATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vCREATEUID", Session["UID"].ToString()); //vCREATEUID
            SQLHelper.SQLWhere(ref ParameterList, DbType.DateTime, "vUPDATEDATE", TimeNow); //vUPDATEDATE
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vUPDATEUID", Session["UID"].ToString()); //vUPDATEUID       
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vSOURCE_PERIOD", "X");
            SQLHelper.SQLWhere(ref ParameterList, DbType.String, "vSOURCE_EDIT_NO", "X");
            #endregion

            //新增儲存期別屬性檔資料
            #region 畫面取值
            FormView fv2 = FormView2;
            string v_ISSUANCE_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtISSUANCE_DATE")).Text.Trim();
            string v_PLAN_ACCEPT_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtPLAN_ACCEPT_DATE")).Text.Trim();
            object v_PACKAGE_UNIT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtPACKAGE_UNIT")).Text.Trim();
            string v_ACCEPT_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtACCEPT_DATE")).Text.Trim();
            string v_FRONT_ACCEPT_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtFRONT_ACCEPT_DATE")).Text.Trim();
            string v_EOS_NO = ((TextBox)fv2.FindControl("txtEOS_NO")).Text.Trim();
            string v_DIS_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtDIS_DATE")).Text.Trim();
            string v_DIS_NO = ((TextBox)fv2.FindControl("txtDIS_NO")).Text.Trim();
            string v_PURCHASE_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtPURCHASE_DATE")).Text.Trim();
            object v_PURCHASE_QTY = ((WUI.SLP.SLPNumber)fv2.FindControl("txtPURCHASE_QTY")).Text.Trim();
            string v_PURCHASE_NO = ((TextBox)fv2.FindControl("txtPURCHASE_NO")).Text.Trim();
            string v_OUT_ST_ACCEPT_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtOUT_ST_ACCEPT_DATE")).Text.Trim();
            string v_ST_ACCEPT_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtST_ACCEPT_DATE")).Text.Trim();
            string v_RETURN_DATE = ((WUI.SLP.SLPDate)fv2.FindControl("txtRETURN_DATE")).Text.Trim();
            object v_ACCEPT_QTY = ((WUI.SLP.SLPNumber)fv2.FindControl("txtACCEPT_QTY")).Text.Trim();
            object v_ONWAY_QTY = ((WUI.SLP.SLPNumber)fv2.FindControl("txtONWAY_QTY")).Text.Trim();
            object v_DIS_QTY = ((WUI.SLP.SLPNumber)fv2.FindControl("txtDIS_QTY")).Text.Trim();
            object v_ACCEPT_DAYS = ((WUI.SLP.SLPNumber)fv2.FindControl("txtACCEPT_DAYS")).Text.Trim();
            object v_OUT_DAYS = ((WUI.SLP.SLPNumber)fv2.FindControl("txtOUT_DAYS")).Text.Trim();
            object v_S_WEIGHT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtS_WEIGHT")).Text.Trim();
            object v_S_WIDTH = ((WUI.SLP.SLPNumber)fv2.FindControl("txtS_WIDTH")).Text.Trim();
            object v_S_LENGHT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtS_LENGHT")).Text.Trim();
            object v_S_HEIGHT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtS_HEIGHT")).Text.Trim();
            object v_W_WEIGHT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtW_WEIGHT")).Text.Trim();
            object v_W_WIDTH = ((WUI.SLP.SLPNumber)fv2.FindControl("txtW_WIDTH")).Text.Trim();
            object v_W_LENGHT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtW_LENGHT")).Text.Trim();
            object v_W_HEIGHT = ((WUI.SLP.SLPNumber)fv2.FindControl("txtW_HEIGHT")).Text.Trim();

            v_CODE = string.Format("{0}{1}{2}", v_ITEM, v_PERIOD, v_EDIT_NO);
            #endregion 畫面取值

            #region 更新編輯後的資料
            Array_List.Clear();
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vCODE", v_CODE); //vCODE
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vITEM", v_ITEM); //vITEM
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vPERIOD", v_PERIOD); //vPERIOD
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vEDIT_NO", v_EDIT_NO); //vEDIT_NO
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vPACKAGE_UNIT", v_PACKAGE_UNIT); //vPACKAGE_UNIT
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vS_WEIGHT", v_S_WEIGHT); //vS_WEIGHT
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vS_LENGTH", v_S_LENGHT); //vS_LENGTH
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vS_WIDTH", v_S_WIDTH); //vS_WIDTH
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vS_HEIGHT", v_S_HEIGHT); //vS_HEIGHT
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vP_WEIGHT", v_W_WEIGHT); //vP_WEIGHT
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vP_LENGTH", v_W_LENGHT); //vP_LENGTH
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vP_WIDTH", v_W_WIDTH); //vP_WIDTH
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vP_HEIGHT", v_W_HEIGHT); //vP_HEIGHT
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vISSUANCE_DATE", v_ISSUANCE_DATE); //vISSUANCE_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vPURCHASE_DATE", v_PURCHASE_DATE); //vPURCHASE_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vPLAN_ACCEPT_DATE", v_PLAN_ACCEPT_DATE); //vPLAN_ACCEPT_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vFRONT_ACCEPT_DATE", v_FRONT_ACCEPT_DATE); //vFRONT_ACCEPT_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vACCEPT_DATE", v_ACCEPT_DATE); //vACCEPT_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vDIS_DATE", v_DIS_DATE); //vDIS_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vOUT_ST_ACCEPT_DATE", v_OUT_ST_ACCEPT_DATE); //vOUT_ST_ACCEPT_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vST_ACCEPT_DATE", v_ST_ACCEPT_DATE); //vST_ACCEPT_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vPICK_DATE", null); //vPICK_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vRETURN_DATE", v_RETURN_DATE); //vRETURN_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vEOS_NO", v_EOS_NO); //vEOS_NO
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vPURCHASE_QTY", v_PURCHASE_QTY); //vPURCHASE_QTY
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vPURCHASE_NO", v_PURCHASE_NO); //vPURCHASE_NO
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vDIS_NO", v_DIS_NO); //vDIS_NO
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vACCEPT_QTY", v_ACCEPT_QTY); //vACCEPT_QTY
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vONWAY_QTY", v_ONWAY_QTY); //vONWAY_QTY
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vDIS_QTY", v_DIS_QTY); //vDIS_QTY
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vACCETP_DAYS", v_ACCEPT_DAYS); //vACCETP_DAYS
            SQLHelper.SQLWhere(ref Array_List, DbType.VarNumeric, "vOUT_DAYS", v_OUT_DAYS); //vOUT_DAYS
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vFIRST_VENDOR_RETURN_DATE", null); //vFIRST_VENDOR_RETURN_DATE
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vCREATEUID", Session["UID"].ToString()); //vCREATEUID
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vCREATEDATE", TimeNow); //vCREATEDATE
            SQLHelper.SQLWhere(ref Array_List, DbType.DateTime, "vUPDATEDATE", TimeNow); //vUPDATEDATE
            SQLHelper.SQLWhere(ref Array_List, DbType.String, "vUPDATEUID", Session["UID"].ToString()); //vUPDATEUID
            #endregion

            //新增儲存期別屬性檔資料
            #region 期別帳務資料
            DataTable dtSubsidy_New = bcoSubsidy.ConvertXMLToDataTable(VDS_ITM_CHAN_SUBSIDY_NEW.InnerHtml);
            DataTable dtSubsidy_Old = bcoSubsidy.ConvertXMLToDataTable(VDS_ITM_CHAN_SUBSIDY.InnerHtml);

            string SessionIDName = "ITM022_" + PageTimeStamp.Value;
            DataTable dtOld = (DataTable)Session[SessionIDName + "_0"]; //店群門市原始資料
            DataTable dtNew = (DataTable)Session[SessionIDName];

            #region 掃瞄期別帳務資料並做檢核
            ArrayList Array_L = new ArrayList();
            for (int i = 0; i < ((Repeater)FormView4.FindControl("repTarget")).Items.Count; i++)
            {
                DataRow nRow = dtSubsidy_New.Rows[i];
                RepeaterItem nItem = ((Repeater)FormView4.FindControl("repTarget")).Items[i];

                TextBox Accept_Amt = (TextBox)nItem.FindControl("txtACCEPT_AMT");
                TextBox Retrun_Amt = (TextBox)nItem.FindControl("txtRETURN_AMT");
                TextBox Accept_Rate = (TextBox)nItem.FindControl("txtACCEPT_RATE");
                TextBox Retrun_Rate = (TextBox)nItem.FindControl("txtRETURN_RATE");
                TextBox Discount = (TextBox)nItem.FindControl("txtDISCOUNT_RATE");
                TextBox Min_Amt = (TextBox)nItem.FindControl("txtMIN_AMT");
                DropDownList SLP_NOTES = (DropDownList)((ASP.sys_slp_slp_codefile_ascx)nItem.FindControl("SLP_NOTES")).FindControl("D1");
                Page currentPage = (Page)HttpContext.Current.Handler;
                string script = "";
                string name = "PayTypeAlert";
                if (Accept_Amt.Text.Length > 0)
                {
                    if (decimal.Parse(Accept_Amt.Text) > 99999)
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定進貨金額欄位整數位數不可大於5位');", true);

                        checkFormMode();

                        return;
                    }

                    //只有折扣補貼(VOTES=3)的資料才可輸入負數 20120529 rika 
                    if (decimal.Parse(Accept_Amt.Text) < 0 && SLP_NOTES.SelectedItem.Value != "3")
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + SLP_NOTES.SelectedItem.Text + "」固定進貨金額欄位不可為負數');", true);

                        checkFormMode();

                        return;
                    }

                    if (Accept_Amt.Text.IndexOf('.') != -1)
                        if (Accept_Amt.Text.Length - Accept_Amt.Text.IndexOf('.') - 1 > 2)
                        {
                            ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定進貨金額欄位小數位數不可大於2位');", true);

                            checkFormMode();

                            return;
                        }
                }
                if (Retrun_Amt.Text.Length > 0)
                {
                    if (decimal.Parse(Retrun_Amt.Text) > 99999)
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定退貨金額欄位整數位數不可大於5位');", true);

                        checkFormMode();

                        return;
                    }


                    //只有折扣補貼(VOTES=3)的資料才可輸入負數 20120529 rika 
                    if (decimal.Parse(Retrun_Amt.Text) < 0 && SLP_NOTES.SelectedItem.Value != "3")
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + SLP_NOTES.SelectedItem.Text + "」固定退貨金額欄位不可為負數');", true);

                        checkFormMode();

                        return;
                    }

                    if (Retrun_Amt.Text.IndexOf('.') != -1)
                        if (Retrun_Amt.Text.Length - Retrun_Amt.Text.IndexOf('.') - 1 > 2)
                        {
                            ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定退貨金額欄位小數位數不可大於2位');", true);

                            checkFormMode();

                            return;
                        }
                }
                if (Accept_Rate.Text.Length > 0)
                {
                    if (decimal.Parse(Accept_Rate.Text) > 999)
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定進貨%欄位整數位數不可大於3位');", true);

                        checkFormMode();

                        return;
                    }

                    //只有折扣補貼(VOTES=3)的資料才可輸入負數 20120529 rika 
                    if (decimal.Parse(Accept_Rate.Text) < 0 && SLP_NOTES.SelectedItem.Value != "3")
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + SLP_NOTES.SelectedItem.Text + "」固定進貨%欄位不可為負數');", true);

                        checkFormMode();

                        return;
                    }

                    if (Accept_Rate.Text.IndexOf('.') != -1)
                        if (Accept_Rate.Text.Length - Accept_Rate.Text.IndexOf('.') - 1 > 3)
                        {
                            ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定進貨%欄位小數位數不可大於3位');", true);

                            checkFormMode();

                            return;
                        }
                }
                if (Retrun_Rate.Text.Length > 0)
                {
                    if (decimal.Parse(Retrun_Rate.Text) > 999)
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定退貨%欄位整數位數不可大於3位');", true);

                        checkFormMode();

                        return;
                    }

                    //只有折扣補貼(VOTES=3)的資料才可輸入負數 20120529 rika 
                    if (decimal.Parse(Retrun_Rate.Text) < 0 && SLP_NOTES.SelectedItem.Value != "3")
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + SLP_NOTES.SelectedItem.Text + "」固定退貨%欄位不可為負數');", true);

                        checkFormMode();

                        return;
                    }

                    if (Retrun_Rate.Text.IndexOf('.') != -1)
                        if (Retrun_Rate.Text.Length - Retrun_Rate.Text.IndexOf('.') - 1 > 3)
                        {
                            ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定退貨%欄位小數位數不可大於3位');", true);

                            checkFormMode();

                            return;
                        }
                }
                if (Discount.Text.Length > 0)
                {
                    if (decimal.Parse(Discount.Text) > 999)
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」費率%欄位整數位數不可大於3位');", true);

                        checkFormMode();

                        return;
                    }


                    //只有折扣補貼(VOTES=3)的資料才可輸入負數 20120529 rika 
                    if (decimal.Parse(Discount.Text) < 0 && SLP_NOTES.SelectedItem.Value != "3")
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + SLP_NOTES.SelectedItem.Text + "」費率%欄位不可為負數');", true);

                        checkFormMode();

                        return;
                    }

                    if (Discount.Text.IndexOf('.') != -1)
                        if (Discount.Text.Length - Discount.Text.IndexOf('.') - 1 > 3)
                        {
                            ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」費率%欄位小數位數不可大於3位');", true);

                            checkFormMode();

                            return;
                        }
                }
                if (Discount.Text.Length == 0 && Retrun_Rate.Text.Length == 0 && Accept_Rate.Text.Length == 0 &&
                    Retrun_Amt.Text.Length == 0 && Accept_Amt.Text.Length == 0)
                {

                    ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('固定金額、固定%、費率%必須擇一輸入值');", true);

                    checkFormMode();

                    return ;

                }

                if (Min_Amt.Text.Length > 0)
                {
                    if (decimal.Parse(Min_Amt.Text) > 9999)
                    {
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」最低金額欄位整數位數不可大於7位');", true);

                        checkFormMode();

                        return;
                    }
                    if (Min_Amt.Text.IndexOf('.') != -1)
                        if (Min_Amt.Text.Length - Min_Amt.Text.IndexOf('.') - 1 > 3)
                        {
                            ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, "alert('「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」最低金額欄位小數位數不可大於3位');", true);

                            checkFormMode();

                            return;
                        }
                }
                //nRow["SUBSIDY_TYPE"] = Convert.ToString(i + 1);
                if ((Accept_Amt.Text != "")) { if (decimal.Parse(Accept_Amt.Text) == 0)nRow["ACCEPT_AMT"] = System.DBNull.Value; else nRow["ACCEPT_AMT"] = Convert.ToDecimal(Accept_Amt.Text); } else nRow["ACCEPT_AMT"] = System.DBNull.Value;
                if ((Retrun_Amt.Text != "")) { if (decimal.Parse(Retrun_Amt.Text) == 0)nRow["RETURN_AMT"] = System.DBNull.Value; else nRow["RETURN_AMT"] = Convert.ToDecimal(Retrun_Amt.Text); } else nRow["RETURN_AMT"] = System.DBNull.Value;
                if ((Accept_Rate.Text != "")) { if (decimal.Parse(Accept_Rate.Text) == 0)nRow["ACCEPT_RATE"] = System.DBNull.Value; else nRow["ACCEPT_RATE"] = Convert.ToDecimal(Accept_Rate.Text); } else nRow["ACCEPT_RATE"] = System.DBNull.Value;
                if ((Retrun_Rate.Text != "")) { if (decimal.Parse(Retrun_Rate.Text) == 0)nRow["RETURN_RATE"] = System.DBNull.Value; else nRow["RETURN_RATE"] = Convert.ToDecimal(Retrun_Rate.Text); } else nRow["RETURN_RATE"] = System.DBNull.Value;
                if ((Discount.Text != "")) { if (decimal.Parse(Discount.Text) == 0)nRow["DISCOUNT_RATE"] = System.DBNull.Value; else nRow["DISCOUNT_RATE"] = Convert.ToDecimal(Discount.Text); } else nRow["DISCOUNT_RATE"] = System.DBNull.Value;
                if ((((WUI.SLP.CodeFile)nItem.FindControl("txtPAY_TYPE")).Text != "")) nRow["PAY_TYPE"] = Convert.ToDecimal(((WUI.SLP.CodeFile)nItem.FindControl("txtPAY_TYPE")).Text);
                //固定金額、固定%、費率%只能擇一輸入值
                script = string.Format("alert('{0}');", "「" + ((TextBox)nItem.FindControl("txtSUBSIDY_TYPE")).Text + "」固定金額、固定%、費率%只能擇一輸入值,請重新輸入");
                if (((Accept_Amt.Text.Trim() != "" && Accept_Amt.Text.Replace(".", "").Trim('0') != "") || (Retrun_Amt.Text.Trim() != "" && Retrun_Amt.Text.Replace(".", "").Trim('0') != "")) && ((Accept_Rate.Text.Trim() != "" && Accept_Rate.Text.Replace(".", "").Trim('0') != "") || (Retrun_Rate.Text.Trim() != "" && Retrun_Rate.Text.Replace(".", "").Trim('0') != "")))
                {
                    script += @"window.setTimeout(function set_focus(){document.getElementById('" + Accept_Amt.ClientID + @"').focus();document.getElementById('" + Accept_Amt.ClientID + @"').select();}, 1800);";
                    ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, script, true);

                    checkFormMode();

                    return;
                }
                if (((Accept_Amt.Text.Trim() != "" && Accept_Amt.Text.Replace(".", "").Trim('0') != "") || (Retrun_Amt.Text.Trim() != "" && Retrun_Amt.Text.Replace(".", "").Trim('0') != "")) && (Discount.Text.Trim() != "" && Discount.Text.Replace(".", "").Trim('0') != ""))
                {
                    script += @"window.setTimeout(function set_focus(){document.getElementById('" + Accept_Amt.ClientID + @"').focus();document.getElementById('" + Accept_Amt.ClientID + @"').select();}, 1800);";
                    ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, script, true);

                    checkFormMode();

                    return;
                }
                if (((Accept_Rate.Text != "" && Accept_Rate.Text.Replace(".", "").Trim('0') != "") || (Retrun_Rate.Text != "" && Retrun_Rate.Text.Replace(".", "").Trim('0') != "")) && (Discount.Text != "" && Discount.Text.Replace(".", "").Trim('0') != ""))
                {
                    script += @"window.setTimeout(function set_focus(){document.getElementById('" + Accept_Rate.ClientID + @"').focus();document.getElementById('" + Accept_Rate.ClientID + @"').select();}, 1800);";
                    ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, script, true);

                    checkFormMode();

                    return;
                }
                //收取方式=牌價,卻沒有設定店群門市資料,顯示提醒《沒有設定店群,收取方式不能選擇牌價,請重新設定》
                WUI.SLP.CodeFile txtPAY_TYPE = ((WUI.SLP.CodeFile)nItem.FindControl("txtPAY_TYPE"));
                if (txtPAY_TYPE.Text == "4") //收取方式=牌價
                {
                    //Array_L.Clear();
                    //SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "PID", nRow["ID"].ToString(), "=", "and");
                    //DataTable dtSubsidyStore = bcoSubsidyStore.QueryPeriodStoreGroupByFind_1(Array_L);
                    //if (dtSubsidyStore.Rows.Count == 0)
                    DataRow[] drs = dtNew.Select(string.Format("PID='{0}'", nRow["NEWID"].ToString()));
                    if (drs.Length == 0)
                    {
                        script = string.Format("alert('{0}');", "沒有設定店群,收取方式不能選擇牌價,請重新設定");
                        DropDownList txt_PAY_TYPE = (DropDownList)((ASP.sys_slp_slp_codefile_ascx)nItem.FindControl("txtPAY_TYPE")).FindControl("D1");
                        //須加時間延遲,待該物件生成後才給focus()
                        script += @"window.setTimeout(function set_focus(){document.getElementById('" + txt_PAY_TYPE.ClientID + @"').focus();}, 1800);";
                        ScriptManager.RegisterStartupScript(currentPage, currentPage.GetType(), name, script, true);

                        checkFormMode();

                        return;
                    }
                }
                nRow["TARGET_RULE"] = 0;
                if ((((WUI.SLP.CodeFile)nItem.FindControl("txtTARGET_RULE")).Text != "")) nRow["TARGET_RULE"] = Convert.ToDecimal(((WUI.SLP.CodeFile)nItem.FindControl("txtTARGET_RULE")).Text);
                nRow["NOTES"] = ((ASP.sys_slp_slp_codefile_ascx)nItem.FindControl("SLP_NOTES")).Text;
                if ((((TextBox)nItem.FindControl("txtMIN_AMT")).Text != "")) nRow["MIN_AMT"] = Convert.ToDecimal(((TextBox)nItem.FindControl("txtMIN_AMT")).Text);
                nRow["MONTHCOUNT_YN"] = int.Parse(((WUI.SLP.SLP_Boolean)nItem.FindControl("txtMONTHCOUNT_YN")).Text.Trim());
                nRow["DISTRIBUTE_YN"] = int.Parse(((DropDownList)nItem.FindControl("txtDISTRIBUTE_YN")).Text.Trim());
                nRow["CODE"] = string.Format("{0}{1}{2}", v_ITEM, v_PERIOD, v_EDIT_NO);
                nRow["ITEM"] = v_ITEM;
                nRow["PERIOD"] = v_PERIOD;
                nRow["EDIT_NO"] = v_EDIT_NO;
            }
            #endregion
            //Find Deleted Data

            foreach (DataRow dr1 in dtSubsidy_Old.Rows)
            {
                //準備刪除畫面上不存在的資料
                DataRow[] drs = dtSubsidy_New.Select(string.Format("ID='{0}'", dr1["ID"].ToString()));
                //準備刪除畫面上固定金額、固定%、費率都為0或空值的資料
                DataRow[] Drs = dtSubsidy_New.Select(string.Format("ID='{0}' and ((ACCEPT_AMT=0 or ACCEPT_AMT is null) and (RETURN_AMT=0 or RETURN_AMT is null) and (ACCEPT_RATE=0 or ACCEPT_RATE is null) and (RETURN_RATE=0 or RETURN_RATE is null) and (DISCOUNT_RATE=0 or DISCOUNT_RATE is null))", dr1["ID"].ToString()));
                if (drs.Length == 0 || Drs.Length == 1)
                {
                    #region 參數
                    Array_L.Clear();
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_ID", dr1["ID"].ToString()); //OLD_ID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_CODE", dr1["CODE"].ToString()); //OLD_CODE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_ITEM", dr1["ITEM"].ToString()); //OLD_ITEM
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_PERIOD", dr1["PERIOD"].ToString()); //OLD_PERIOD
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_EDIT_NO", dr1["EDIT_NO"].ToString()); //OLD_EDIT_NO
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_SUBSIDY_TYPE", dr1["SUBSIDY_TYPE"].ToString()); //OLD_SUBSIDY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_ACCEPT_AMT", dr1["ACCEPT_AMT"].ToString()); //OLD_ACCEPT_AMT
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_RETURN_AMT", dr1["RETURN_AMT"].ToString()); //OLD_RETURN_AMT
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_ACCEPT_RATE", dr1["ACCEPT_RATE"].ToString()); //OLD_ACCEPT_RATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_RETURN_RATE", dr1["RETURN_RATE"].ToString()); //OLD_RETURN_RATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_DISCOUNT_RATE", dr1["DISCOUNT_RATE"].ToString()); //OLD_DISCOUNT_RATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_PAY_TYPE", dr1["PAY_TYPE"].ToString()); //OLD_PAY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_TARGET_RULE", dr1["TARGET_RULE"].ToString()); //OLD_TARGET_RULE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_NOTES", dr1["NOTES"].ToString()); //OLD_NOTES
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_MIN_AMT", dr1["MIN_AMT"].ToString()); //OLD_MIN_AMT
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_IN_STORE_FLAG", dr1["IN_STORE_FLAG"].ToString()); //OLD_IN_STORE_FLAG
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_PERIOD_PAY_TYPE", dr1["PERIOD_PAY_TYPE"].ToString()); //OLD_PERIOD_PAY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_MONTHCOUNT_YN", dr1["MONTHCOUNT_YN"].ToString()); //OLD_MONTHCOUNT_YN
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_DISTRIBUTE_YN", dr1["DISTRIBUTE_YN"].ToString()); //OLD_DISTRIBUTE_YN
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "OLD_CREATEDATE", dr1["CREATEDATE"].ToString()); //OLD_CREATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_CREATEUID", dr1["CREATEUID"].ToString()); //OLD_CREATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_UPDATEUID", dr1["UPDATEUID"].ToString()); //OLD_UPDATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "OLD_UPDATEDATE", dr1["UPDATEDATE"].ToString()); //OLD_UPDATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "OLD_ENABLE", dr1["ENABLE"].ToString()); //OLD_ENABLE
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "NEW_UPDATEDATE", TimeNow); //NEW_UPDATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "NEW_UPDATEUID", Session["UID"].ToString()); //NEW_UPDATEUID
                    #endregion
                    bcoSubsidy.DeletePeriodSubsidy(Array_L, transaction);

                    //同步刪除VDS_ITM_CHAN_SUBSIDY_STORE的DataTable裏的資料(因為上一步的Package已刪除VDS_ITM_CHAN_SUBSIDY_STORE裏的資料了)
                    DataRow[] DrsS = dtOld.Select("PID='" + dr1["ID"].ToString() + "'");
                    if (DrsS.Length > 0)
                        foreach (DataRow DDR in DrsS)
                            dtOld.Rows.Remove(DDR);
                    DataRow[] DrsS1 = dtNew.Select("PID='" + dr1["ID"].ToString() + "'");
                    if (DrsS1.Length > 0)
                        foreach (DataRow DDR in DrsS1)
                            dtNew.Rows.Remove(DDR);
                }
            }
            //Find New Data
            foreach (DataRow dr1 in dtSubsidy_New.Rows)
            {
                if (dr1["ID"].ToString() == "" || dr1["ID"].ToString() == "0")
                {
                    if ((dr1["ACCEPT_AMT"].ToString() == "" || dr1["ACCEPT_AMT"].ToString() == "0") && (dr1["RETURN_AMT"].ToString() == "" || dr1["RETURN_AMT"].ToString() == "0") && (dr1["ACCEPT_RATE"].ToString() == "" || dr1["ACCEPT_RATE"].ToString() == "0") && (dr1["RETURN_RATE"].ToString() == "" || dr1["RETURN_RATE"].ToString() == "0") && (dr1["DISCOUNT_RATE"].ToString() == "" || dr1["DISCOUNT_RATE"].ToString() == "0"))
                        continue;
                    #region 參數
                    Array_L.Clear();
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "vID", dr1["NEWID"].ToString()); //vID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vCODE", dr1["CODE"].ToString()); //vCODE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vITEM", dr1["ITEM"].ToString()); //vITEM
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vPERIOD", dr1["PERIOD"].ToString()); //vPERIOD
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vEDIT_NO", dr1["EDIT_NO"].ToString()); //vEDIT_NO
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vSUBSIDY_TYPE", dr1["SUBSIDY_TYPE"].ToString()); //vSUBSIDY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vACCEPT_AMT", dr1["ACCEPT_AMT"].ToString()); //vACCEPT_AMT
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vRETURN_AMT", dr1["RETURN_AMT"].ToString()); //vRETURN_AMT
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vACCEPT_RATE", dr1["ACCEPT_RATE"].ToString()); //vACCEPT_RATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vRETURN_RATE", dr1["RETURN_RATE"].ToString()); //vRETURN_RATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vDISCOUNT_RATE", dr1["DISCOUNT_RATE"].ToString()); //vDISCOUNT_RATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vPAY_TYPE", dr1["PAY_TYPE"].ToString()); //vPAY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vTARGET_RULE", dr1["TARGET_RULE"].ToString()); //vTARGET_RULE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vNOTES", dr1["NOTES"].ToString()); //vNOTES
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vMIN_AMT", dr1["MIN_AMT"].ToString()); //vMIN_AMT
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vIN_STORE_FLAG", dr1["IN_STORE_FLAG"].ToString()); //vIN_STORE_FLAG
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vPERIOD_PAY_TYPE", dr1["PERIOD_PAY_TYPE"].ToString()); //vPERIOD_PAY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vMONTHCOUNT_YN", dr1["MONTHCOUNT_YN"].ToString()); //vMONTHCOUNT_YN
                    SQLHelper.SQLWhere(ref Array_L, DbType.Decimal, "vDISTRIBUTE_YN", dr1["DISTRIBUTE_YN"].ToString()); //vDISTRIBUTE_YN
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "vCREATEDATE", TimeNow); //vCREATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vCREATEUID", Session["UID"].ToString()); //vCREATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vUPDATEUID", Session["UID"].ToString()); //vUPDATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "vUPDATEDATE", TimeNow); //vUPDATEDATE
                    #endregion
                    bcoSubsidy.CreatePeriodSubsidyWidthID(Array_L, transaction);
                }
            }
            if (((Repeater)FormView4.FindControl("repTarget")).Items.Count > 0)
            {
                //針對VDS_ITM_CHAN_SUBSIDY的SUBSIDY_TYPE在DB重新排序
                Array_L.Clear();
                Array_L.Add(v_ITEM);
                Array_L.Add(v_PERIOD);
                Array_L.Add(v_EDIT_NO);
                bcoSubsidy.ResortSubsidyType(Array_L, transaction);
            }
            #endregion

            #region 店群門市資料
            foreach (DataRow Dr1 in dtOld.Rows)//刪除資料
            {
                DataRow[] drs = dtNew.Select(string.Format("ID={0}", Dr1["ID"].ToString()));
                if (drs.Length == 0)
                {
                    Array_L.Clear();
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_ID", Dr1["ID"].ToString()); //OLD_ID
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_PID", Dr1["PID"].ToString()); //OLD_PID
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_SUBSIDY_TYPE", Dr1["SUBSIDY_TYPE"].ToString()); //OLD_SUBSIDY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_STORE_GROUP", Dr1["STORE_GROUP"].ToString()); //OLD_STORE_GROUP
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_STORE", Dr1["STORE"].ToString()); //OLD_STORE
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "OLD_CREATEDATE", Dr1["CREATEDATE"].ToString()); //OLD_CREATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_CREATEUID", Dr1["CREATEUID"].ToString()); //OLD_CREATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_UPDATEUID", Dr1["UPDATEUID"].ToString()); //OLD_UPDATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "OLD_UPDATEDATE", Dr1["UPDATEDATE"].ToString()); //OLD_UPDATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "NEW_UPDATEDATE", TimeNow); //NEW_UPDATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "NEW_UPDATEUID", Session["UID"].ToString()); //NEW_UPDATEUID
                    bcoSubsidyStore.DeletePeriodStoreGroup(Array_L, transaction);
                }
            }
            foreach (DataRow drNew in dtNew.Rows)//新增資料
            {
                if (drNew["ID"].ToString() == "" || drNew["ID"].ToString() == "0")
                {
                    Array_L.Clear();
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "vPID", drNew["PID"].ToString()); //vPID
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "vSUBSIDY_TYPE", drNew["SUBSIDY_TYPE"].ToString()); //vSUBSIDY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vSTORE_GROUP", drNew["STORE_GROUP"].ToString()); //vSTORE_GROUP
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vSTORE", drNew["STORE"].ToString()); //vSTORE
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "vCREATEDATE", TimeNow); //vCREATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vCREATEUID", Session["UID"].ToString()); //vCREATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "vUPDATEUID", Session["UID"].ToString()); //vUPDATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "vUPDATEDATE", TimeNow); //vUPDATEUID
                    bcoSubsidyStore.CreatePeriodStoreGroup(Array_L, transaction);
                }
            }
            foreach (DataRow drOld in dtOld.Rows)//修改資料
            {
                DataRow[] drs = dtNew.Select(string.Format("ID={0}", drOld["ID"].ToString()));
                if (drs.Length > 0)
                {
                    DataRow drNew = drs[0];
                    Array_L.Clear();
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_ID", drOld["ID"].ToString()); //OLD_ID
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_PID", drOld["PID"].ToString()); //OLD_PID
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "OLD_SUBSIDY_TYPE", drOld["SUBSIDY_TYPE"].ToString()); //OLD_SUBSIDY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_STORE_GROUP", drOld["STORE_GROUP"].ToString()); //OLD_STORE_GROUP
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_STORE", drOld["STORE"].ToString()); //OLD_STORE
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "OLD_CREATEDATE", drOld["CREATEDATE"].ToString()); //OLD_CREATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_CREATEUID", drOld["CREATEUID"].ToString()); //OLD_CREATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "OLD_UPDATEUID", drOld["UPDATEUID"].ToString()); //OLD_UPDATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "OLD_UPDATEDATE", drOld["UPDATEDATE"].ToString()); //OLD_UPDATEDATE
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "NEW_PID", drNew["PID"].ToString()); //NEW_PID
                    SQLHelper.SQLWhere(ref Array_L, DbType.VarNumeric, "NEW_SUBSIDY_TYPE", drNew["SUBSIDY_TYPE"].ToString()); //NEW_SUBSIDY_TYPE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "NEW_STORE_GROUP", drNew["STORE_GROUP"].ToString()); //NEW_STORE_GROUP
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "NEW_STORE", drNew["STORE"].ToString()); //NEW_STORE
                    SQLHelper.SQLWhere(ref Array_L, DbType.String, "NEW_UPDATEUID", Session["UID"].ToString()); //NEW_UPDATEUID
                    SQLHelper.SQLWhere(ref Array_L, DbType.DateTime, "NEW_UPDATEDATE", TimeNow); //NEW_UPDATEDATE
                    bcoSubsidyStore.UpdatePeriodStoreGroup(Array_L, transaction);
                }
            }
            #endregion

            v_ID = bco.CreateSKUPeriod(ParameterList, Array_List, transaction, true, con);

            ArrayList AL = (ArrayList)Session[Request.QueryString["arl_Key"]];
            if (AL == null) AL = new ArrayList();
            AL.Add(v_ID);

            Session[Request.QueryString["arl_Key"]] = AL;

            //Response.Write("<script>alert('新增完成');location.replace('ITM022.aspx?arl_Key=" + Request.QueryString["arl_Key"] + "&ID=" + v_ID.ToString() + "&mode=readonly');</script>");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "AddComplete", "alert('新增完成');location.replace('ITM022.aspx?Code=ITM02&arl_Key=" + Request.QueryString["arl_Key"] + "&isToolBar=N&ID=" + v_ID.ToString() + "&mode=readonly');", true);
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
            if (transaction.Connection != null)
                transaction.Rollback();
        }
        finally { }

    }//end InsertButton_Click