Пример #1
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            string SessionIDName = "STM381_GridView1" + PageTimeStamp.Value;
            string V_Result = "0";

            //同步GRIDVIEW至DT
            if(!DoUPD_DT())
                return;

            #region UPDATE
            bool bResult = true;

            this.btnUpdate.Enabled = false;
            this.btnCancel.Enabled = false;
            this.btn_UPDATE_BATCH.Enabled = false;
            this.ErrorMsgLabel.Text = "";

            DataTable dt = ((DataTable)Session[SessionIDName]);
            STMModel.VDS_STM38_BCO BCO = new STMModel.VDS_STM38_BCO(ConntionDB);
            DbTransaction DBT = null;

            //初始化DBT            
            BCO.StartDBT(out DBT);

            if (hid_EdType.Value == "S")
            {
                DataTable dt1 = dt.Copy();

                for (int i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    if (dt.Rows[i]["PROOF_FLG"].ToString() == "1" && bResult)
                    {
                        DataRow[] dr = dt1.Select(string.Format("PROMOTE_ID ='{0}' and PROOF_FLG ='0'",
                                                    dt.Rows[i]["PROMOTE_ID"].ToString()
                                                    ));

                        if (dr.Length > 0)
                        {
                            this.ErrorMsgLabel.Text += "書展編號" + dt.Rows[i]["PROMOTE_ID"] + "書展折讓已回狀態應一致;";
                            bResult = false;
                        }

                    }

                    if (rbl_proType.SelectedValue == "2" && dt.Rows[i]["SALE_QTY"].ToString().Trim() != "" && bResult)
                    {
                        DataRow[] dr = dt1.Select(string.Format("PROMOTE_ID ='{0}' and SALE_QTY is null ",
                                                    dt.Rows[i]["PROMOTE_ID"].ToString()
                                                    ));

                        if (dr.Length > 0)
                        {
                            this.ErrorMsgLabel.Text += "書展編號" + dt.Rows[i]["PROMOTE_ID"] + "實銷數不可有空白資料;";
                            bResult = false;
                        }

                    }

                    if (rbl_proType.SelectedValue == "1" && dt.Rows[i]["PRICE_SUM"].ToString().Trim() != string.Empty && bResult)
                    {
                        DataRow[] dr = dt1.Select(string.Format("PROMOTE_ID ='{0}' and PRICE_SUM is null ",
                                                    dt.Rows[i]["PROMOTE_ID"].ToString()
                                                    ));

                        if (dr.Length > 0)
                        {
                            this.ErrorMsgLabel.Text += "書展編號" + dt.Rows[i]["PROMOTE_ID"] + "零售價小計不可有空白資料;";
                            bResult = false;
                        }

                    }

                    if (bResult)
                    {
                        ParameterList.Clear();
                        ParameterList.Add(GetValueSetParameter(dt.Rows[i]["ID"].ToString(), "int", false));//0
                        ParameterList.Add(GetValueSetParameter(hid_ProType.Value, "int", false));//1
                        ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_DT"].ToString(), "string", false));//2
                        ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_ID"].ToString(), "string", false));//3
                        ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROOF_FLG"].ToString(), "int", false));//4

                        if (hid_ProType.Value == "1")
                        {
                            ParameterList.Add(DBNull.Value);//5
                            if (dt.Rows[i]["PRICE_SUM"].ToString() != "")
                            {
                                ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PRICE_SUM"].ToString(), "int", false));//6 
                            }
                            else
                            {
                                ParameterList.Add(DBNull.Value);//6
                            }
                        }
                        else
                        {
                            if (dt.Rows[i]["SALE_QTY"].ToString() != "")
                            {
                                ParameterList.Add(GetValueSetParameter(dt.Rows[i]["SALE_QTY"].ToString(), "int", false));//5
                            }
                            else
                            {
                                ParameterList.Add(DBNull.Value);//5
                            }
                            ParameterList.Add(DBNull.Value);//6                
                        }

                        if (dt.Rows[i]["ADJUST_AMT"].ToString() != "")
                        {
                            ParameterList.Add(GetValueSetParameter(dt.Rows[i]["ADJUST_AMT"].ToString(), "float", false));//7
                        }
                        else
                        {
                            ParameterList.Add(DBNull.Value);//7                
                        }

                        ParameterList.Add(GetValueSetParameter(Session["UID"].ToString(), "string", false));//8

                        V_Result = BCO.doUpdate_S(ParameterList, DBT);

                        if (V_Result == "0")
                        {
                            if (hid_ProType.Value == "1")
                            {
                                this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" +
                                                          dt.Rows[i]["STORE"].ToString() + "供應商編號" + dt.Rows[i]["VENDOR"]  + "發生錯誤!";
                            }
                            else
                            {
                                this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" +
                                                          dt.Rows[i]["STORE"].ToString() + "品號" + dt.Rows[i]["ITEM"] + "期別" +
                                                          dt.Rows[i]["PERIOD"] + "發生錯誤!";
                            }
                            break;
                        }
                    }
                    else
                    {
                        V_Result = "0";
                        break;
                    }
                }

            }
            else
            {
                for (int i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    ParameterList.Clear();
                    ParameterList.Add(GetValueSetParameter(dt.Rows[i]["ID"].ToString(), "int", false));//0
                    ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_TYPE"].ToString(), "int", false));//1
                    ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_DT"].ToString(), "string", false));//2
                    ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_ID"].ToString(), "string", false));//3
                    ParameterList.Add(GetValueSetParameter(dt.Rows[i]["CHECK_MONTH"].ToString(), "string", false));//4

                    if (dt.Rows[i]["COST_SUBSIDY_PERCENT"].ToString() != "")
                    {
                        ParameterList.Add(GetValueSetParameter(dt.Rows[i]["COST_SUBSIDY_PERCENT"].ToString(), "float", false));//5
                    }
                    else
                    {
                        V_Result = "0";
                        break;
                    }

                    ParameterList.Add(GetValueSetParameter(Session["UID"].ToString(), "string", false));//6

                    V_Result = BCO.doUpdate_V(ParameterList, DBT);

                    if (V_Result == "0")
                    {
                        if (dt.Rows[i]["PROMOTE_TYPE"].ToString() == "1")
                        {
                            this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" +
                                                      dt.Rows[i]["STORE"].ToString() + "供應商編號" + dt.Rows[i]["VENDOR"] + "發生錯誤!";
                        }
                        else
                        {
                            this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" +
                                                          dt.Rows[i]["STORE"].ToString() + "品號" + dt.Rows[i]["ITEM"] + "期別" +
                                                          dt.Rows[i]["PERIOD"] + "發生錯誤!";
                        }
                        break;
                    }
                }
            }

            if (V_Result != "0")
            {
                //完成交易
                BCO.CommitDBT(DBT);
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "STM381", "alert('更新完成');location.replace('STM381.aspx?Code=STM38');", true);
            }
            else
            {
                if (DBT != null)
                    DBT.Rollback();
                
                ParameterList.Clear();

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

                this.btnUpdate.Enabled = true;
                this.btnCancel.Enabled = true;
            }

            #endregion
        }
        catch (Exception ex)
        {
            WaringLogProcess(ex.Message);
            this.ErrorMsgLabel.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0];  //直接取第一個
        }
        finally 
        {
            Finally_Function(); 
        
        }
    }
Пример #2
0
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        try
        {
            ErrorMsgLabel.Text = "";
            hidCHECK_FLG_ALL.Value = "X";
            this.hidPROOF_FLG_ALL.Value = "2";
            slp_CheckMonth.Text = "";
            #region 呼叫BCO查詢

            STMModel.VDS_STM38_BCO bco = new STMModel.VDS_STM38_BCO(ConntionDB);

            ParameterList.Clear();

            if (rbl_EdType.SelectedValue=="S")
            {
                ParameterList.Add(GetValueSetParameter(rbl_proType.SelectedValue, "int", false));//0
                ParameterList.Add(GetValueSetParameter(rbl_discType.SelectedValue, "string", false));//1
                ParameterList.Add(GetValueSetParameter(slp_YearMonthS.Text, "string", false));//2
                ParameterList.Add(GetValueSetParameter(slp_YearMonthE.Text, "string", false));//3
                ParameterList.Add(GetValueSetParameter(txt_ProID_S.Text, "string", false));//4
                ParameterList.Add(GetValueSetParameter(txt_ProID_E.Text, "string", false));//5
                ParameterList.Add(GetValueSetParameter(slp_GROUP_NO_S.Text, "string", false));//6
                ParameterList.Add(GetValueSetParameter(slp_GROUP_NO_E.Text, "string", false));//7
                ParameterList.Add(GetValueSetParameter(slp_Store_S.Text, "string", false));//8
                ParameterList.Add(GetValueSetParameter(slp_Store_E.Text, "string", false));//9
                ParameterList.Add(GetValueSetParameter(SLP_AC_ID.Text, "string", false));//10
                ParameterList.Add(GetValueSetParameter(rbl_discStatus.SelectedValue, "int", false));//11
                ParameterList.Add(GetValueSetParameter(TextBoxRowCountLimit.Text, "int", false));//12
                ParameterList.Add(GetValueSetParameter(rbl_EdType.SelectedValue, "string", false));//13
                ParameterList.Add(GetValueSetParameter(rbl_Checkmonth.SelectedValue, "int", false));//14
            }
            else
            {
                ParameterList.Add(0);//0
                ParameterList.Add(GetValueSetParameter(rbl_discType.SelectedValue, "string", false));//1
                ParameterList.Add(GetValueSetParameter(slp_YearMonthS.Text, "string", false));//2
                ParameterList.Add(GetValueSetParameter(slp_YearMonthE.Text, "string", false));//3
                ParameterList.Add(GetValueSetParameter(txt_ProID_S.Text, "string", false));//4
                ParameterList.Add(GetValueSetParameter(txt_ProID_E.Text, "string", false));//5
                ParameterList.Add("");//6
                ParameterList.Add("");//7
                ParameterList.Add(GetValueSetParameter(slp_Store_S.Text, "string", false));//8
                ParameterList.Add(GetValueSetParameter(slp_Store_E.Text, "string", false));//9
                ParameterList.Add("");//10
                ParameterList.Add(GetValueSetParameter(rbl_discStatus.SelectedValue, "int", false));//11
                ParameterList.Add(GetValueSetParameter(TextBoxRowCountLimit.Text, "int", false));//12     
                ParameterList.Add(GetValueSetParameter(rbl_EdType.SelectedValue, "string", false));//13
                ParameterList.Add(GetValueSetParameter(rbl_Checkmonth.SelectedValue, "int", false));//14       
            }

            DataTable dt = new DataTable();

            dt = bco.QueryData(ParameterList);

            #endregion

            if (dt == null || (dt != null && dt.Rows.Count <= 0))
            {
                SetPageDefault();
                GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Save, false, "", btnUpdate, WUI_GMToolbarV.ClickAction.ButtonClick);

                ErrorMsgLabel.Text = "查無資料";
            }
            else
            {
                hid_EdType.Value = rbl_EdType.SelectedValue;
                hid_ProType.Value = rbl_proType.SelectedValue;

                btnUpdate.Visible = true;
                btnCancel.Visible=true;
                btnQuery.Visible = false;

                if (rbl_EdType.SelectedValue == "V")
                {
                    btn_UPDATE_BATCH.Enabled = true;
                    slp_CheckMonth.ReadOnly = false;
                }

                GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Save, true, "", btnUpdate, WUI_GMToolbarV.ClickAction.ButtonClick);

                #region 查詢完控制項重置
                //抓取本頁初次登記的時間
                string SessionIDName = "STM381_GridView1" + PageTimeStamp.Value;

                Session["SessionID"] = SessionIDName;
                Session[SessionIDName] = dt;
                GridView1.DataSource = dt;
                //設定分頁大小
                GridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) < 0) ? 10 : int.Parse(TextBoxPagesize.Text);
                GridView1.PageIndex = 0;
                GridView1.DataBind();
                 #endregion

                Session[SessionIDName + "edType"] = rbl_EdType.SelectedValue;
                Session[SessionIDName + "proType"] = rbl_proType.SelectedValue;

            }
        }
        catch (Exception ex)
        {
            WaringLogProcess(ex.Message);
            this.ErrorMsgLabel.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0];  //直接取第一個
        }
        finally { Finally_Function(); }
    }