Пример #1
0
    protected void btn_Exec_Click(object sender, EventArgs e)
    {
        #region
        try
        {
            if (CheckInputValuesNotNull())
            {
                ALOModel.MaintainStoreSpec BCO = new PIC.VDS2G.BSM.ALO.MaintainStoreSpec(ConnectionDB);
                bool bResult = BCO.CopyToNewItem(GetInputValues(), null);
                if (bResult)
                {
                    ResultMsgLabel.Text = "複製成功";
                }
                else
                {
                    ResultMsgLabel.Text = "複製失敗, 無資料可複製, 請確認複製品號對應期別與商品主檔均已正確建立";
                }
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
        finally
        {
            fmStatus = FormStatus.fmBrowse;
        }
        #endregion

    }
Пример #2
0
        /// <summary>
        ///1.目的:將上傳檔案內容,存入暫存檔

        ///2.傳入參數:@處理檔名、@使用者
        ///  回傳參數:@處理筆數、@正確筆數、@錯誤筆數、@錯誤訊息

        ///3.處理表格:VDS_ALO_STORESPEC_TMP(T)

        ///4.處理邏輯:

        ///  4.1) 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊。
        ///       相關Table:VDS_ALO_STORESPEC_TM
        ///  4.2) 讀取匯入檔案到暫存資料集。
        ///  4.3) 檢查匯入檔案格式內容是否正確,如有任何錯誤,則停止上傳流程,並回傳錯誤訊息。
        ///       『XX檔案,檔案內容錯誤:@錯誤說明』 (格式請參考資料庫Table Shcema)
        ///         * 日期:檢查日期格式。
        ///         * 數字:檢查內容是否為數字。
        ///         * 文字:檢查長度是否溢位。
        ///         * 檔案欄位數是否不足。
        ///         * 檢查必填欄位是否有值:通路、店號、品號、數量、原因代碼、設定類別
        ///         * 工作表匯入內容有任一筆錯,皆視為錯誤,整批放棄。
        ///         * 匯入表格細節說明請參考:Excel文件
        ///  4.4) 格式檢查正確無誤後
        ///       a) 暫存檔中的[狀態]欄位調整為1:FILE TO TMP
        ///       b) 呼叫 [CheckData] ,檢查資料內容邏輯正確性 
        ///  4.5) 無論CheckData()檢查結果是否為True,
        ///       皆將上傳檔案內容新增到資料庫Tmp Table:,
        ///       並記錄錯誤原因、匯入者、匯入日期、處理檔案名稱=上傳檔名。

        ///5. 回傳處理結果(@處理筆數、@正確筆數、@錯誤筆數、@錯誤訊息(無錯誤時=null) )   
        /// </summary>
        public ArrayList FileToTmp(DataSet ds_Excel, DateTime d_CreateDate, string s_LoginUser, string s_AP_FileName, string V_SESSION_ID)
        {
            #region
            int i_newTable_Count = 0;
            ArrayList arl_Return = new ArrayList();
            ArrayList arr_CheckData_Table = new ArrayList();
            ArrayList arr_CheckData = new ArrayList();
            int i_FileToTemp_Total_count = 0;
            int i_FileToTemp_Right_count = 0;
            int i_FileToTemp_Wrong_count = 0;
            bool b_Check_Logic = true;
            ArrayList paramTemp = new ArrayList();
            Hashtable htTemp = new Hashtable();

            DataTable dtTemp = new DataTable();
            string strErrMsg = "";
            string strErrMsgDataFormat = "";

            Int32 iErrCount = 0;

            string strTemp = "";
            bool bResultTemp = false;

            try
            {
                ParameterList.Clear();
                DataTable dt_ALO_IMPORT_TMP = QuerySwitch(QueryType.GetStoreSpec_TmpSchema, ParameterList);
                VDS_ALO_DIS_PATTERN_DBO ALO_DIS_PATTERN = new VDS_ALO_DIS_PATTERN_DBO(ref USEDB);
                VDS_ALO_STORESPEC_TMP_DBO ALO_STORESPEC_TMP = new VDS_ALO_STORESPEC_TMP_DBO(ref USEDB);
                VDS_ALO_STORESPEC_DETL_DBO ALO_STORESPEC_DETL = new VDS_ALO_STORESPEC_DETL_DBO(ref USEDB);
                MaintainStoreSpec ALO_STORESPEC_MAIN = new MaintainStoreSpec(ConnectionDB);
                QueryALOCommon BCOCommon = new QueryALOCommon(ConnectionDB);


                //20090626 added
                VDS_ALO_STORESPEC_TMP_DBO DBO = new VDS_ALO_STORESPEC_TMP_DBO(ref USEDB);
                ParameterList.Clear();
                ParameterList.Add(s_LoginUser);
                ParameterList.Add(V_SESSION_ID);
                DBO.doDelete_STORESPEC_TMP(ParameterList, null);


                foreach (System.Data.DataRow dRow in ds_Excel.Tables[0].Rows)
                {
                    #region
                    iErrCount = 0;
                    strErrMsg = "";

                    if (!CheckRequiredField(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查必填欄位
                    {
                        #region 檢查資料格式正確性
                        arl_Return.Add("FALSE");
                        arl_Return.Add(strErrMsgDataFormat);
                        return arl_Return;
                    }
                    else if (!CheckOverFlow(dRow, iAryOverflowColumnsCheck, out strErrMsgDataFormat))//檢查是否為溢位
                    {
                        arl_Return.Add("FALSE");
                        arl_Return.Add(strErrMsgDataFormat);
                        return arl_Return;
                    }
                    else if (!CheckInputValueIsInt32_2(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查是否為數值
                    {   //2009-06-26 cyhsu 改用 CheckInputValueIsInt32_2 
                        //因為數值欄位部分條件下可輸入負值,所以在格式檢查時不檢查正負號
                        arl_Return.Add("FALSE");
                        arl_Return.Add(strErrMsgDataFormat);
                        return arl_Return;
                        #endregion
                    }
                    else
                    {
                        #region 檢查資料邏輯正確性

                        #region 將資料寫入 TEMP TABLE

                        DataRow dRow_Temp = dt_ALO_IMPORT_TMP.NewRow();

                        dRow_Temp["CREATEDATE"] = d_CreateDate;
                        dRow_Temp["CREATEUID"] = s_LoginUser;
                        dRow_Temp["ID"] = i_newTable_Count;
                        dRow_Temp["UPDATEDATE"] = d_CreateDate;
                        dRow_Temp["UPDATEUID"] = s_LoginUser;
                        dRow_Temp["CHAN_NO"] = dRow[1].ToString().Trim();
                        dRow_Temp["STORE"] = dRow[2].ToString().Trim();
                        dRow_Temp["ITEM"] = dRow[3].ToString().Trim();
                        dRow_Temp["SPEC_QTY"] = Int32.Parse(dRow[5].ToString().Trim());
                        dRow_Temp["REASON"] = dRow[6].ToString().Trim();
                        dRow_Temp["SPEC_TYPE"] = dRow[7].ToString().Trim();
                        dRow_Temp["SESSION_ID"] = V_SESSION_ID;

                        #endregion

                        #region 4.1 判斷是否可新增
                        htTemp.Clear();
                        strTemp = "";
                        htTemp.Add("ChanNo", dRow[1].ToString().Trim());
                        htTemp.Add("Store", dRow[2].ToString().Trim());
                        htTemp.Add("Item", dRow[3].ToString().Trim());

                        htTemp.Add("StartDate", DateTime.Now.ToString("yyyy/MM/dd"));
                        htTemp.Add("EndDate", DateTime.Now.AddDays(90).ToString("yyyy/MM/dd"));


                        bResultTemp = ALO_STORESPEC_MAIN.CheckStoreSpecCanAdd(htTemp, ref strTemp);

                        if (!bResultTemp)
                        {
                            strErrMsg += string.Format("{0},", strTemp);
                        }

                        ParameterList.Clear();
                        ParameterList.Add(dRow[1].ToString().Trim());
                        ParameterList.Add(dRow[2].ToString().Trim());
                        strTemp = BCOCommon.CheckCurrentStoreState(ParameterList);

                        if (strTemp != "")
                        {
                            strErrMsg += string.Format("{0},", strTemp);
                        }

                        #endregion

                        #region
                        switch (dRow[7].ToString().Trim())
                        {
                            case "1"://加減本數
                                strErrMsg += "不可匯入控制類別[加減本數],";
                                dRow_Temp["S_START_DATE"] = DateTime.Now;
                                dRow_Temp["S_END_DATE"] = DateTime.Now.AddDays(90);
                                break;
                            case "3"://停配
                                dRow_Temp["S_START_DATE"] = DateTime.Now;
                                dRow_Temp["S_END_DATE"] = DateTime.Parse("9999/12/31");
                                dRow_Temp["SPEC_QTY"] = "0";
                                break;
                            case "2":
                            case "4":
                            case "5":
                            case "6":
                                dRow_Temp["S_START_DATE"] = DateTime.Now;
                                dRow_Temp["S_END_DATE"] = DateTime.Now.AddDays(90);
                                break;
                            default:
                                strErrMsg += "無此控制類別,";
                                dRow_Temp["S_START_DATE"] = DateTime.Now;
                                dRow_Temp["S_END_DATE"] = DateTime.Now.AddDays(90);
                                break;

                        }


                        #endregion


                        #region 控制類別 = 2 時,可輸入負值,其他不可 2009-060-26 cyhsu add
                        if ((dRow_Temp["SPEC_TYPE"].ToString().Trim() != "2") &&
                            (int.Parse(dRow_Temp["SPEC_QTY"].ToString()) < 0)
                           )
                        {
                            strErrMsg += "此控制類別非加減比例,對應之設定值不可小於0,";
                        }

                        #endregion


                        #region 4.4 針對MEMO是否為空字串做檢查

                        if (strErrMsg.Trim() == string.Empty)
                        {
                            dRow_Temp["MEMO"] = System.DBNull.Value;
                            dRow_Temp["DATASOURCE"] = s_AP_FileName;
                        }
                        else
                        {
                            if (strErrMsg.Trim().Length > 0)
                            {
                                if (strErrMsg.Trim().Substring(strErrMsg.Trim().Length - 1) == ",")
                                {
                                    strErrMsg = strErrMsg.Trim().Substring(0, strErrMsg.Trim().Length - 1);
                                }

                            }

                            dRow_Temp["MEMO"] = strErrMsg;
                            dRow_Temp["DATASOURCE"] = s_AP_FileName;
                            iErrCount++;
                        }


                        if (iErrCount != 0)
                        {
                            i_FileToTemp_Wrong_count += 1;
                            dRow_Temp["DATATYPE"] = 2;
                            b_Check_Logic = false;
                        }
                        else
                        {
                            i_FileToTemp_Right_count += 1;
                            dRow_Temp["DATATYPE"] = 1;
                        }


                        #endregion

                        dt_ALO_IMPORT_TMP.Rows.Add(dRow_Temp);
                        i_newTable_Count += 1;

                        #endregion
                    }

                    i_FileToTemp_Total_count += 1;
                    #endregion
                }

                #region 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊,並將 Excel 資料匯入 TEMP TABLE

                ParameterList.Clear();
                ParameterList.Add(s_LoginUser);
                ParameterList.Add(V_SESSION_ID);

                DELETE_AND_INSERT_TEMP_TABLE(ParameterList, null, dt_ALO_IMPORT_TMP);

                #endregion

                arl_Return.Add("TRUE");
                arl_Return.Add(b_Check_Logic);
                arl_Return.Add(i_FileToTemp_Total_count);
                arl_Return.Add(i_FileToTemp_Right_count);
                arl_Return.Add(i_FileToTemp_Wrong_count);
            }
            catch (Exception ex)
            {
                arl_Return.Add("FALSE");
                arl_Return.Add(GetNewException(ex).Message);
            }

            return arl_Return;
            #endregion
        }
Пример #3
0
    private bool CheckStoreSpecCanEdit(Hashtable htTemp)
    {
        #region
        bool bResult = false;

        try
        {
            ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);
            string strErrMsg = "";
            bResult = BCO.CheckStoreSpecCanEdit(htTemp, ref strErrMsg);

            if (strErrMsg.Trim().Length > 0)
            {
                if (strErrMsg.Substring(strErrMsg.Length - 1, 1) == ",")
                {
                    strErrMsg = strErrMsg.Substring(0, strErrMsg.Length - 1);
                }
            }

            if (!bResult && strErrMsg != "")
            {
                ErrorMsgLabel.Text = strErrMsg;
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", string.Format("alert('{0}');", strErrMsg), true);
            }

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

        return bResult;

        #endregion
    }
Пример #4
0
    private bool CheckStoreSpecExist(Hashtable htTemp)
    {
        #region
        bool bResult = false;

        try
        {
            ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);
            string strErrMsg = "";
            bResult = BCO.CheckStoreSpecExist(htTemp);

            if (!bResult)
            {

                strErrMsg = string.Format("該門市已設定品號={0}的控制檔", htTemp["Item"].ToString());
                ErrorMsgLabel.Text = strErrMsg;
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", string.Format("alert('{0}');", strErrMsg), true);
            }

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

        return bResult;

        #endregion
    }
Пример #5
0
    /// <summary>
    /// 繫結資料到控制項
    /// </summary>
    /// <param name="vdb"></param>
    private void QueryData()
    {
        #region
        LabelQueryRecordCount.Text = "";

        string SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value);

        ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);

        //2010/04/15 modified: for performance  DataTable Dt = BCO.QueryStorSpecByFind(GetInputValues());
        DataTable Dt = BCO.QueryStorSpecByFind2(GetInputValues());

        Session[SessionIDName] = Dt;
        
        SmartGridView1.DataSource = Dt;

        SmartGridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) <= 0) ? 10 : int.Parse(TextBoxPagesize.Text);

        if (!(CurrentPageMode == PageCurrentMode.Query || CurrentPageMode == PageCurrentMode.Readonly))
        {
            SmartGridView1.PageIndex = GetPageIndexByParam(SLP_SKU3.Text.Trim());
        }
        else 
        {
            SmartGridView1.PageIndex = 0;
        }

        SmartGridView1.DataBind();

        LabelQueryRecordCount.Text = string.Format(" {0} Rows ", Dt.Rows.Count.ToString());

        if (Dt == null || (Dt != null && Dt.Rows.Count <= 0))
        {
            if (btn_Export.Visible == true)
            {
                btn_Export.Enabled = false;
            }

            //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('查無資料');", true);
            ResultMsgLabel.Text = "查無資料";
            CurrentPageMode = PageCurrentMode.Query;
        }
        else
        {

            if (btn_Export.Visible == true)
            {
                btn_Export.Enabled = true;
            }

            LastPageMode = PageCurrentMode.Query;
            CurrentPageMode = PageCurrentMode.Readonly;
        }

        btn_EditComment.Enabled = true;

        #endregion
    }
Пример #6
0
    protected void SmartGridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        #region
        Label lbl_ID = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_ID");
        Label lbl_item = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_item");
        Label lbl_spec_qty = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_spec_qty");
        Label lbl_reason = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_reason");
        Label lbl_s_start_date = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_s_start_date");
        Label lbl_s_end_date = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_s_end_date");
        Label lbl_spec_type = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_spec_type");
        Label lbl_chan_no = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_chan_no");
        Label lbl_store = (Label)SmartGridView1.Rows[e.NewEditIndex].FindControl("lbl_store");
        #region
        ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);
        Hashtable ht = new Hashtable();
        ht.Add("PID", lbl_ID.Text);

        DataTable dtDetl = BCO.QueryDetlByPID(ht);

        if (dtDetl != null && dtDetl.Rows.Count > 0)
        {
            dtDetailData = dtDetl;
            gv_Detail.DataSource = dtDetl;
            Panel_Detail.Visible = true;
            btn_AddDetail.Visible = true;
            btn_CopyDetail.Visible = true;
            dtForDetailDeleted.Clear();

        }
        else
        {
            dtDetailData = null;
            Panel_Detail.Visible = false;
        }

        gv_Detail.DataBind();

        SLP_StoreChain2.Text = lbl_chan_no.Text;
        SLP_Store2.Text = lbl_store.Text;
        SLP_SKU3.Text = lbl_item.Text;
        SLP_SLPDate2.Text = lbl_s_start_date.Text;
        SLP_SLPDate3.Text = lbl_s_end_date.Text;
        SLP_Number1.Text = lbl_spec_qty.Text;
        SLP_Number1.ReadOnly = false;

        DropDownList ddl = (DropDownList)SLP_CodeFile1.FindControl("D1");
        ddl.SelectedValue = lbl_reason.Text;

        SetRadioButtonClear();

        switch (lbl_spec_type.Text)
        {
            case "1":
                rBtn_SpecType1.Checked = true;
                btn_Setting.Enabled = true;
                hiddenCurrentSpecType.Value = "1";
                SLP_Number1.ReadOnly = true;
                break;
            case "2":
                rBtn_SpecType2.Checked = true;
                btn_Setting.Enabled = false;
                hiddenCurrentSpecType.Value = "2";
                SLP_Number1.ReadOnly = false;
                break;
            case "3":
                rBtn_SpecType3.Checked = true;
                btn_Setting.Enabled = false;
                hiddenCurrentSpecType.Value = "3";
                SLP_Number1.ReadOnly = true;
                break;
            case "4":
                rBtn_SpecType4.Checked = true;
                btn_Setting.Enabled = false;
                hiddenCurrentSpecType.Value = "4";
                SLP_Number1.ReadOnly = false;
                break;
            case "5":
                rBtn_SpecType5.Checked = true;
                btn_Setting.Enabled = false;
                hiddenCurrentSpecType.Value = "5";
                SLP_Number1.ReadOnly = false;
                break;
            case "6":
                rBtn_SpecType6.Checked = true;
                btn_Setting.Enabled = false;
                hiddenCurrentSpecType.Value = "6";
                SLP_Number1.ReadOnly = false;
                break;
        }

        #endregion

        SetTmpDataForMaster(lbl_ID.Text.Trim());


        LastPageMode = PageCurrentMode.Readonly;
        CurrentPageMode = PageCurrentMode.Edit;





        #endregion
    }
Пример #7
0
    protected void SmartGridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        #region
        try
        {
            bool bResult = false;
            #region 取得畫面元件的值

            DateTime processtime = DateTime.Now;

            #endregion

            #region 取得刪除前舊值

            Label lbl_ID = (Label)SmartGridView1.Rows[e.RowIndex].FindControl("lbl_ID");
            SetTmpDataForMaster(lbl_ID.Text.Trim());//將CurrentRow的值塞入暫存master
            DataTable dtTemp = dtForMaster;

            if (dtTemp == null || dtTemp.Rows.Count == 0)
            {
                throw new Exception("抓取不到舊值,更新失敗!");
            }

            #endregion

            #region 加入更新條件

            //master
            htParams.Clear();
            //舊值
            htParams.Add("ID", dtTemp.Rows[0]["ID"]);
            htParams.Add("CODE", dtTemp.Rows[0]["CODE"]);
            htParams.Add("CREATEDATE", dtTemp.Rows[0]["CREATEDATE"]);
            htParams.Add("CREATEUID", dtTemp.Rows[0]["CREATEUID"]);
            htParams.Add("UPDATEDATE", dtTemp.Rows[0]["UPDATEDATE"]);
            htParams.Add("UPDATEUID", dtTemp.Rows[0]["UPDATEUID"]);
            htParams.Add("ENABLE", dtTemp.Rows[0]["ENABLE"]);
            htParams.Add("ChanN0", dtTemp.Rows[0]["CHAN_NO"]);
            htParams.Add("STORE", dtTemp.Rows[0]["STORE"]);
            htParams.Add("ITEM", dtTemp.Rows[0]["ITEM"]);
            htParams.Add("SPEC_TYPE", dtTemp.Rows[0]["SPEC_TYPE"]);
            htParams.Add("SPEC_QTY", dtTemp.Rows[0]["SPEC_QTY"]);
            htParams.Add("S_START_DATE", dtTemp.Rows[0]["S_START_DATE"]);
            htParams.Add("S_END_DATE", dtTemp.Rows[0]["S_END_DATE"]);
            htParams.Add("REASON", dtTemp.Rows[0]["REASON"]);
            //需要更新值
            htParams.Add("NEW_UPDATEDATE", processtime);
            htParams.Add("NEW_UPDATEUID", Session["UID"].ToString());


            //detail
            htParams2.Clear();
            htParams2.Add("PIDForLog", dtTemp.Rows[0]["ID"]);
            htParams2.Add("UIDForLog", dtTemp.Rows[0]["CREATEUID"]);

            #endregion

            ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);

            bResult = BCO.DeleteMasterAndDetail(htParams, htParams2, null);
            //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('刪除完成');", true);
            ResultMsgLabel.Text = "刪除完成";
            QueryData();
            CurrentPageMode = PageCurrentMode.Readonly;
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
        #endregion

    }
Пример #8
0
    protected void btn_CopyDetail_Click(object sender, EventArgs e)
    {
        #region

        ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);

        htParams.Clear();
        htParams.Add("ChanNo", SLP_StoreChain2.Text.Trim());
        htParams.Add("STORE", SLP_Store2.Text.Trim());

        DataTable dtDetl = BCO.QueryLastStoreSpecDetail(htParams);

        if (dtDetl != null && dtDetl.Rows.Count > 0)
        {
            dtDetailData = dtDetl;
            gv_Detail.DataSource = dtDetl;
            gv_Detail.DataBind();
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", "alert('此門市無前筆有效明細設定資訊,請手動新增');", true);
        }

        Panel_AddDetail.Visible = false;


        #endregion
    }
Пример #9
0
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        #region
        if (CurrentPageMode == PageCurrentMode.Edit)
        {
            #region
            bool bResult = false;

            try
            {
                htTemp.Clear();
                htTemp.Add("Item", SLP_SKU3.Text.Trim());
                htTemp.Add("StartDate", SLP_SLPDate2.Text.Trim());
                htTemp.Add("EndDate", SLP_SLPDate3.Text.Trim());

                if (CheckSpecTypeAndValue() && CheckDetailDataIsNotNull() && CheckStoreSpecCanEdit(htTemp))
                {
                    #region 取得畫面元件的值


                    DateTime processtime = DateTime.Now;
                    #endregion

                    #region 取得更新前舊值

                    if (dtForMaster == null || dtForMaster.Rows.Count == 0)
                    {
                        throw new Exception("抓取不到舊值,更新失敗!");
                    }


                    #endregion

                    DataTable dtForUpdate = dtDetailData.GetChanges();

                    DataTable dtMaster = dtForMaster;
                    string strUID = Session["UID"].ToString();

                    #region Master
                    htParams.Clear();
                    for (Int32 i = 0; i <= dtMaster.Rows.Count - 1; i++)
                    {
                        if (dtMaster.Rows[i].RowState != DataRowState.Deleted)
                        {
                            htParams.Add("ID", dtMaster.Rows[i]["ID"]);
                            htParams.Add("CODE", dtMaster.Rows[i]["CODE"]);
                            htParams.Add("CREATEDATE", dtMaster.Rows[i]["CREATEDATE"]);
                            htParams.Add("CREATEUID", dtMaster.Rows[i]["CREATEUID"]);
                            htParams.Add("UPDATEDATE", dtMaster.Rows[i]["UPDATEDATE"]);
                            htParams.Add("UPDATEUID", dtMaster.Rows[i]["UPDATEUID"]);
                            htParams.Add("ENABLE", dtMaster.Rows[i]["ENABLE"]);
                            htParams.Add("ChanN0", dtMaster.Rows[i]["CHAN_NO"]);
                            htParams.Add("STORE", dtMaster.Rows[i]["STORE"]);
                            htParams.Add("ITEM", dtMaster.Rows[i]["ITEM"]);
                            htParams.Add("SPEC_TYPE", dtMaster.Rows[i]["SPEC_TYPE"]);
                            htParams.Add("SPEC_QTY", dtMaster.Rows[i]["SPEC_QTY"]);
                            htParams.Add("S_START_DATE", dtMaster.Rows[i]["S_START_DATE"]);
                            htParams.Add("S_END_DATE", dtMaster.Rows[i]["S_END_DATE"]);
                            htParams.Add("REASON", dtMaster.Rows[i]["REASON"]);
                            //新的資料                
                            htParams.Add("NEW_UPDATEDATE", processtime);
                            htParams.Add("NEW_UPDATEUID", strUID);
                            htParams.Add("NEW_SPEC_TYPE", getSpecTypeChecked());
                            htParams.Add("NEW_SPEC_QTY", SLP_Number1.Text.Trim());
                            htParams.Add("NEW_S_START_DATE", SLP_SLPDate2.Text.Trim());
                            htParams.Add("NEW_S_END_DATE", SLP_SLPDate3.Text.Trim());
                            htParams.Add("NEW_REASON", strReason.Trim());

                            break;
                        }
                    }


                    htParams.Add("PIDForLog", dtMaster.Rows[0]["ID"]);
                    htParams.Add("UIDForLog", dtMaster.Rows[0]["CREATEUID"]);


                    #endregion

                    ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);

                    bResult = BCO.UpdateMasterAndDetail(htParams, dtForUpdate, strUID, dtForDetailDeleted, null);

                    if (!bResult)
                    {
                        throw new Exception("更新0筆資料!");
                    }
                    else
                    {
                        dtDetailData.AcceptChanges();
                        dtForDetailDeleted.Clear();
                        //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('更改完成');", true);
                        ResultMsgLabel.Text = "更改完成";
                        QueryData();
                        CurrentPageMode = PageCurrentMode.Readonly;
                    }

                }
            }
            catch (Exception ex)
            {
                ErrorMsgLabel.Text = ex.Message;
            }
            #endregion
        }
        else if (CurrentPageMode == PageCurrentMode.Insert)
        {
            #region
            Int32 iResult = 0;

            try
            {
                htTemp.Clear();
                htTemp.Add("ChanNo", SLP_StoreChain2.Text.Trim());
                htTemp.Add("Store", SLP_Store2.Text.Trim());
                htTemp.Add("Item", SLP_SKU3.Text.Trim());
                htTemp.Add("StartDate", SLP_SLPDate2.Text.Trim());
                htTemp.Add("EndDate", SLP_SLPDate3.Text.Trim());

                if (CheckSpecTypeAndValue() && CheckDetailDataIsNotNull() && CheckStoreSpecCanAdd(htTemp) && CheckStoreSpecExist(htTemp))
                {
                    #region
                    DataTable dtForUpdate = dtDetailData;//.GetChanges(DataRowState.Added);

                    #region Master
                    string strCode = string.Format("{0}_{1}_{2}",
                                                    SLP_StoreChain2.Text.Trim(), SLP_Store2.Text.Trim(), SLP_SKU3.Text.Trim());

                    htParams.Clear();
                    htParams.Add("CODE", strCode);
                    htParams.Add("UserID", Session["UID"].ToString());
                    htParams.Add("ChanNO", SLP_StoreChain2.Text.Trim());
                    htParams.Add("STORE", SLP_Store2.Text.Trim());
                    htParams.Add("ITEM", SLP_SKU3.Text.Trim());
                    htParams.Add("SPEC_TYPE", getSpecTypeChecked());
                    htParams.Add("SPEC_QTY", SLP_Number1.Text.Trim());
                    htParams.Add("S_START_DATE", SLP_SLPDate2.Text.Trim());
                    htParams.Add("S_END_DATE", SLP_SLPDate3.Text.Trim());
                    htParams.Add("REASON", strReason.Trim());

                    #endregion

                    ALOModel.MaintainStoreSpec BCO = new ALOModel.MaintainStoreSpec(ConnectionDB);

                    iResult = BCO.CreateMasterAndDetail(htParams, dtForUpdate, null);

                    if (iResult == 0)
                    {
                        throw new Exception("新增0筆資料!");
                    }
                    else
                    {
                        if (dtForUpdate != null)
                            dtForUpdate.AcceptChanges();

                        dtDetailData = dtForUpdate;
                        dtForDetailDeleted.Clear();

                        //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('新增完成');", true);
                        ResultMsgLabel.Text = "新增完成";
                        QueryData();
                        CurrentPageMode = PageCurrentMode.Readonly;
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                ErrorMsgLabel.Text = ex.Message;
            }
            #endregion
        }

        txt_Comment.Text = GetMemoByChanAndStore();
        #endregion
    }