示例#1
0
    // 存檔
    protected void btnSave_Click(object sender, EventArgs e)
    {
        panAdd.Visible = false;
        Btn_InsertItem.Enabled = true;
        GridView1.AllowSorting = true; //解除新增狀態時禁止排序
        switch (this.hid_PageStatus.Text)
        {
            case "EDIT":
            case "LOAD":
            case "ADD_DETAIL":
                try
                {
                    if (GridView1.Rows.Count <= 0)
                    {
                        ErrorMsgLabel.Text = "請輸入資料";
                        return;
                    }
                    else
                    {
                        DateTime dNow = DateTime.Now;
                        PURModel.MaintainPurchaseDeliveryGoods BCO = new PURModel.MaintainPurchaseDeliveryGoods(ConnectionDB);
                        DataTable dt = getDetailData();
                        if (dt != null)
                            if (this.checkDetailData(dt))   //判斷Grid資料是否有重覆
                            {
                                try
                                {
                                    UnLockControlChk();//取消對ControlChk的鎖定編輯
                                    ViewState["ControlChk"] = null;
                                }
                                catch (Exception Ex)
                                {
                                    DataTable ddt = getControlChk();
                                    if (ddt.Rows.Count > 0)
                                    {
                                        if (Ex.Message.IndexOf("刪除資料失敗") > 0)
                                        {
                                            ErrorMsgLabel.Text = "資料已被" + ddt.Rows[0]["UPDATEUID"].ToString() + "鎖定,請按「取消」後重新操作";
                                            return;
                                        }
                                    }
                                    else
                                        if (Ex.Message.IndexOf("刪除資料失敗") > 0)
                                        {
                                            ErrorMsgLabel.Text = "資料已被他人異動過,請按「取消」後重新操作";
                                            return;
                                        }
                                }
                                #region 取得更新前舊值,使用XML轉回DataSet

                                DataTable dtDetailOLD = new DataTable();

                                //進入畫面直接新增明細時,並不會有舊資料
                                if (hid_PageStatus.Text != "ADD_DETAIL")
                                {
                                    DataSet DsDetail = new DataSet();
                                    System.IO.StringReader srD = new System.IO.StringReader(DetailOLDData.InnerHtml);
                                    DsDetail.ReadXml(srD);
                                    dtDetailOLD = DsDetail.Tables[0];

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

                                #endregion

                                GetData(); //先惕除刪除勾選的資料
                                dt = getDetailData(); //再抓一次(惕除刪除勾選的資料)
                                BCO.UpdateMaster(this.getMasterParameterList(), dt, null, dtDetailOLD, this.getPickData(), dNow);

                                btnDelItem.Visible = false;
                                //btnImportOnDate.Visible = true;
                                //進入畫面直接新增明細後,將資料放到XML
                                if (hid_PageStatus.Text == "ADD_DETAIL")
                                {
                                    dt.TableName = "Table";
                                    DataSet Ds = new DataSet();

                                    foreach (DataRow dr in dt.Rows)
                                    {
                                        if (dr["UPDATEUID"] == System.DBNull.Value)
                                        {
                                            dr["UPDATEUID"] = Session["UID"].ToString();
                                            dr["UPDATEDATE"] = dNow;
                                        }
                                    }
                                    try
                                    {
                                        Ds.Tables.Add(dt);
                                    }
                                    catch (Exception ex)
                                    {
                                        Ds = dt.DataSet;
                                    }
                                    DetailOLDData.InnerHtml = Ds.GetXml();
                                }
                            }
                            else
                                return;

                        ViewState["Insert"] = "0"; //解除新增狀態
                        ViewState["ChkAll"] = "0"; //解除刪除全選狀態

                        //進入畫面直接新增明細儲存後,不要重新查詢
                        if (hid_PageStatus.Text != "ADD_DETAIL" && hid_AddDetail.Value != "ADD_DETAIL")
                            databind();
                        else
                        {
                            GridView1.DataSource = dt;
                            GridView1.DataBind();
                            SetPageStatus();
                        }

                        //由檢視模式切換至編輯模式
                        this.hid_PageStatus.Text = "VIEW";

                        //改成檢視模式
                        btnPrint.Visible = false;
                        btnEdit.Visible = true;
                        btnCancel.Visible = true;
                        btnSave.Visible = false;
                        Btn_InsertItem.Enabled = false;
                        if (GridView1.Rows.Count > 0)
                        {
                            for (int i = 0; i < GridView1.Rows.Count; i++)
                            {
                                if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
                                {
                                    ((PIC.VDS2G.WebUI.SLP.MKT_SLP_GiftItem)GridView1.Rows[i].FindControl("VIRTUAL_CODE")).ReadOnly = true;
                                    ((PIC.VDS2G.WebUI.SLP.SLP_ItemPeriod)GridView1.Rows[i].FindControl("PERIOD")).ReadOnly = true;
                                    ((RadioButton)GridView1.Rows[i].FindControl("rdoPICK_SELECT1")).Enabled = false;
                                    ((RadioButton)GridView1.Rows[i].FindControl("rdoPICK_SELECT2")).Enabled = false;
                                    ((CheckBox)GridView1.Rows[i].FindControl("chkGV_Del")).Enabled = false;
                                    ((Button)GridView1.Rows[i].FindControl("btn_GV_Set")).Enabled = true;
                                    ((Button)GridView1.Rows[i].FindControl("btn_GV_Find")).Enabled = true;
                                }
                                ((CheckBox)GridView1.HeaderRow.FindControl("chkAll")).Enabled = false;
                            }
                            btnPrint.Visible = true;

                            string outPick = "", outRestrain = "";
                            getGridPickCnt(out outPick, out outRestrain);
                            LabelQueryRecordCount.Text = "品項數:理貨品:" + outPick + " 筆 管制品:" + outRestrain + " 筆&nbsp;&nbsp;&nbsp;&nbsp;";
                        }
                        Session["PageStatus" + PageTimeStamp.Value] = hid_PageStatus.Text;

                        //檢視模式(隱藏查詢鈕,顯示取消鈕)
                        this.txtPLAN_ACCEPT_DATE.ReadOnly = true;
                        this.txtPICK_BATCH.ReadOnly = true;
                        this.txtPICK_BATCH.CssClass = "readtxtbox";
                        if (hid_PageStatus.Text == "EDIT")
                            this.Btn_InsertItem.Enabled = false;
                        this.chkPICK_SELECT_1.Enabled = false;
                        this.chkPICK_SELECT_2.Enabled = false;
                        btnLoad.Visible = false;
                        ButtonQuery.Visible = false;
                        btnCancel.Visible = true;
                        UpdatePanel1.Update();
                        btnImportOnDate.Enabled = false;

                        GMToolbar1.GMToolbarStatus = WUI_GMToolbarV.GMToolbarStatusEnum.Other;
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Find, true, "PUR041.aspx?Code=PUR04", null, WUI_GMToolbarV.ClickAction.LinkURL);
                       // GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.FindExport, true, "", this.btnEdit, WUI_GMToolbarV.ClickAction.ButtonClick);
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.New, false, string.Empty, this.btnEdit, WUI_GMToolbarV.ClickAction.ButtonClick);
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Save, false, string.Empty, this.btnSave, WUI_GMToolbarV.ClickAction.ButtonClick);
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Edit, true, string.Empty, this.btnEdit, WUI_GMToolbarV.ClickAction.ButtonClick);
                        GMToolbar1.ButtonEnableControl(WUI_GMToolbarV.ButtonType.Delete, false, string.Empty, this.btnEdit, WUI_GMToolbarV.ClickAction.ButtonClick);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.IndexOf("資料已被他人異動") > 0)
                        ErrorMsgLabel.Text = "資料已被他人異動,請重新查詢";
                    else
                        ErrorMsgLabel.Text = ex.Message;
                }
                SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value);
                DataTable Dt = (DataTable)Session[SessionIDName];
                if (Dt.Rows.Count == 0) btnCancel_Click(null, null);
                break;
            default:
                break;
        }
    }