Example #1
0
    // Save 事件
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        gv_Detail_CacheUpdate();

        DataTable NewDetail = null;

        string strCheckMsg = string.Empty;

        ErrorMsgLabel.Text = "";

        try
        {
            BCO.VAM15_BCO bco = new BCO.VAM15_BCO(ConntionDB);

            if (this.SLP_PROMOTE.Text.Trim() == "")
            {
                ErrorMsgLabel.Text = "檔期編號必填!!";
                return;
            }

            if (CheckExist_PROMOTE(this.SLP_PROMOTE.Text.Trim()) == false)
            {
                ErrorMsgLabel.Text = "此檔期編號不存在!!";
                return;
            }

            if (ViewState["Mode"].ToString() == "INSERT")
            {

                ParameterList.Clear();
                ParameterList.Add(SLP_PROMOTE.Text.Trim());

                DataTable dtCheck = bco.QueryDetail(ParameterList);

                if (dtCheck.Rows.Count > 0)
                {
                    ErrorMsgLabel.Text = "此檔期編號已有設定資料存在!!";
                    return;
                }

            }
            //1.同一個檔期,廠商,稅別 只允許一筆
            //2.如果廠商未輸入要提示哪一行
            //3.無明細不允許儲存

            int iSaveRows = 0;//預計儲存的筆數

            for (int i = 0; i < gv_Detail.Rows.Count; i++)
            {
                string strVendor = ((SLP_VendorBase)gv_Detail.Rows[i].FindControl("SLP_Vendor")).Text.Trim();
                string strTAXTYPE = ((ASP.sys_slp_slp_enumbase_ascx)gv_Detail.Rows[i].FindControl("SLP_TAXTYPE")).Text.Trim();
                string strSUM_AMT = ((TextBox)gv_Detail.Rows[i].FindControl("txtSUM_AMT")).Text.Trim();
                if ((strVendor == "") && (strSUM_AMT != "0"))
                {
                    strCheckMsg += "第 " + (i + 1) + " 列 資料輸入不完整<br />";
                }
                else if (strVendor != "")
                {
                    if (CheckExist_Vendor(strVendor) == false)
                    {
                        strCheckMsg += "第 " + (i + 1) + " 列 廠商編號不存在<br />";
                    }
                    else
                    {
                        iSaveRows++;
                        for (int j = 0; j < gv_Detail.Rows.Count; j++)
                        {
                            if (i != j)
                            {
                                if ((strVendor == ((SLP_VendorBase)gv_Detail.Rows[j].FindControl("SLP_Vendor")).Text.Trim()) &&
                                    (strTAXTYPE == ((ASP.sys_slp_slp_enumbase_ascx)gv_Detail.Rows[j].FindControl("SLP_TAXTYPE")).Text.Trim()))
                                {
                                    strCheckMsg += "第 " + (i + 1) + " 列 與第 " + (j + 1) + " 列 為相同的廠商和稅別資料 <br />";
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (strCheckMsg != "")
            {
                ErrorMsgLabel.Text = strCheckMsg;
                return;
            }
            if (iSaveRows == 0)
            {
                ErrorMsgLabel.Text = "明細資料未設定!!";
                return;
            }

            ParameterList.Clear();
            ParameterList.Add(SLP_PROMOTE.Text.Trim());
            ParameterList.Add(Session["UID"].ToString());
            ParameterList.Add(SLP_UPDATEUSER.Text.Trim());
            ParameterList.Add(txtUPDATEDATE.Text.Trim());

            bco.SaveData((DataTable)Session["VAM15_DTL_" + PageTimeStamp.Value], ParameterList);

            Response.Redirect("VAM152.aspx?PROMOTE_ID=" + this.SLP_PROMOTE.Text.Trim() + "&SSID=" + ViewState["SSID"].ToString() + "&mode=VIEW&Code=VAM15");

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