コード例 #1
0
ファイル: PUR022.aspx.cs プロジェクト: ChiangHanLung/PIC_VDS
    // Save 事件
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        gv_Detail_CacheUpdate();
        gv_Gift_CacheUpdate();

        DataTable NewDetail = null;
        DataTable NewGift = null;
        string strCheckMsg = string.Empty;
        ErrorMsgLabel.Text = "";
        try
        {
            if (!Page.IsValid)
                return;

            if (this.PUR_PURDate.Text.Trim() == "")
            {
                ErrorMsgLabel.Text = "請必須選取採購日期!!";  //ShowErrorMessage("請必須選取採購日期!!");
                return;
            }
            else
            {
                //DateTime dtChkDate = DateTime.ParseExact(DateTime.Parse(this.PUR_PURDate.Text.Trim()).ToString("yyyy/MM/dd"), "yyyy/MM/dd", null);
                //if (dtChkDate < DateTime.Today)
                //{
                //    ErrorMsgLabel.Text = "採購日期必須大於等於系統日!!";  //ShowErrorMessage("採購日期必須大於等於系統日!!");
                //    return;
                //}

                //判斷採購單的採購日是否己日結
                //VGIModel.CheckVendorAccountClose dbo = new PIC.VDS2G.LGT.VGI.CheckVendorAccountClose(ConntionDB);
                //string IsClosed = dbo.CheckVendorCloseStaus(DateTime.Parse(this.PUR_PURDate.Text).ToString("yyyyMMdd"));
                //if (IsClosed == "1")
                //{
                //    ErrorMsgLabel.Text = "該採購單日已日結,不可進行新增!!";
                //    return;
                //}
            }

            if (this.PUR_PurUser.Text.Trim() == "")
            {
                ErrorMsgLabel.Text = "請必須選取採購人員!!";  //ShowErrorMessage("請必須選取採購人員!!");
                return;
            }

            switch (this.hid_PageStatus.Value)
            {
                case "INSERT":

                    if (this.PUR_VendorCode.Text.Trim() == "")
                    {
                        ErrorMsgLabel.Text = "請必須選取供應商!!";  //ShowErrorMessage("請必須選取供應商!!");
                        break;
                    }

                    if (gv_Detail.Rows.Count <= 0)
                    {
                        ErrorMsgLabel.Text = "請必須輸入明細資料!!";  //ShowErrorMessage("請必須輸入明細資料!!");
                    }
                    else
                    {
                        NewDetail = this.getDetailData();
                        if (NewDetail == null)
                            break;

                        NewGift = this.getGiftData();
                        if (NewGift == null && gv_Gift.Rows.Count > 0)
                            break;

                        strCheckMsg = CheckSaveData();
                        if (strCheckMsg != "")
                        {
                            ErrorMsgLabel.Text = strCheckMsg;
                        }
                        else
                        {
                            MaintainPurchaseOrder bco = new MaintainPurchaseOrder(ConntionDB);
                            string v_PurchaseNo = "";
                            v_PurchaseNo = bco.CreateMasterAndDetail_Gift(this.getMasterParameterList(), DT_DelEmptyRow(NewDetail), NewGift, null);
                            if (v_PurchaseNo == "")
                            {
                                ErrorMsgLabel.Text = "新增 0 筆資料!";
                            }
                            else
                            {
                                Response.Redirect("PUR022.aspx?PURCHASE_NO=" + v_PurchaseNo + "&SSID=&mode=VIEW&Code=PUR02");
                            }
                        }
                    }

                    break;
                case "EDIT":


                    #region 取得更新前舊值

                    DataTable dtMasterOLD = (DataTable)ViewState["MasterOLDData"];

                    DataTable dtDetailOLD = (DataTable)ViewState["DetailOLDData"];

                    DataTable dtGiftOLD = (DataTable)ViewState["GiftOLDData"];
                    #endregion

                    if (dtMasterOLD.Rows.Count == 0)
                    {
                        ErrorMsgLabel.Text = "抓取不到Master舊值,更新失敗!";
                    }
                    if (dtDetailOLD.Rows.Count == 0)
                    {
                        ErrorMsgLabel.Text = "抓取不到Detail舊值,更新失敗!";
                    }

                    NewDetail = this.getDetailData();
                    if (NewDetail == null)
                        break;

                    NewGift = this.getGiftData();
                    if (NewGift == null)
                        break;

                    strCheckMsg = CheckSaveData();
                    if (strCheckMsg != "")
                    {
                        ErrorMsgLabel.Text = strCheckMsg;
                    }
                    else
                    {
                        MaintainPurchaseOrder bco = new MaintainPurchaseOrder(ConntionDB);
                        bco.UpdatePurMasterAndDetail_Gift(this.getMasterParameterList(), DT_DelEmptyRow(NewDetail), NewGift, null, dtMasterOLD, dtDetailOLD, dtGiftOLD);

                        Response.Redirect("PUR022.aspx?PURCHASE_NO=" + ViewState["PURCHASE_NO"].ToString() + "&SSID=" + ViewState["SSID"].ToString() + "&mode=VIEW&Code=PUR02");
                    }
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
    }