Пример #1
0
    protected void Btn_Save_Click(object sender, EventArgs e)
    {
        try
        {

            #region 資料儲存

            BCO.MaintainChainGift bco = new BCO.MaintainChainGift(ConnectionDB);

            {
                switch (this.hid_PageStatus.Value)
                {
                    case "INSERT":
                        #region  處理新增作業

                        {
                            DataTable dtExist = new DataTable();
                            dtExist = bco.QueryChainGiftByPK(this.getParameterList());
                            if (dtExist != null && dtExist.Rows.Count > 0)
                            {
                                ErrorMsgLabel.Text = "已有相同的資料存在,請確認";
                                return;
                            }

                            #region 儲存新增資料


                            // 做資料儲存的動作
                            int v_ID = 0;
                            v_ID = bco.CreateMasterAndDetail(this.getParameterList(), (DataTable)Session["MKT153_DTL_" + PageTimeStamp.Value], null);

                            if (v_ID == 0)
                            {
                                throw new Exception("新增0筆資料!");
                            }
                            else
                            {
                                //由新增模式切換至檢視模式
                                this.hid_PageStatus.Value = "VIEW";
                                this.txt_PageStatus.Text = "VIEW";
                                this.hiddenID.Value = v_ID.ToString();
                            }


                            #endregion

                        }

                        #endregion


                        break;
                    case "EDIT":
                        {

                            #region  處理修改作業
                            try
                            {

                                if (this.hid_DetlStatus.Value != "VIEW")
                                {
                                    //ShowErrorMessage("請將編輯的資料列做[更新]或[取消],再按此鈕");
                                    ErrorMsgLabel.Text = "請將編輯的資料列做[更新]或[取消],再按此鈕";
                                    return;
                                }
                                else
                                {
                                    if (1 == 1)//this.checkDetailData())
                                    {
                                        #region 取得更新前舊值


                                        #region 使用XML轉回DataSet

                                        DataSet DsMaster = new DataSet();
                                        System.IO.StringReader srM = new System.IO.StringReader(MasterOLDData.InnerHtml);
                                        DsMaster.ReadXml(srM);
                                        DataTable dtMasterOLD = DsMaster.Tables[0];

                                        DataTable dtDetailOLD = (DataTable)Session["MKT153_OLDDTL_" + PageTimeStamp.Value];

                                        DataTable dtDetailNEW = (DataTable)Session["MKT153_DTL_" + PageTimeStamp.Value];

                                        ArrayList alDeleteDtl = (ArrayList)Session["MKT153_DTLDELETE_" + PageTimeStamp.Value];

                                        #endregion

                                        #endregion


                                        bco.UpdateMasterAndDetail(this.getParameterList(), dtDetailNEW, null, dtMasterOLD, dtDetailOLD, alDeleteDtl);


                                    }

                                }

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

                            #endregion  處理修改作業

                            break;
                        }
                        break;
                }

            #endregion

                #region 存檔後資料重新讀取
                databind_Mst();

                #endregion

                #region 存檔後狀態設定

                this.hid_PageStatus.Value = "VIEW";
                this.txt_PageStatus.Text = "VIEW";

                #endregion

            }

        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.ToString();
        }
        finally
        {
            if (this.ErrorMsgLabel.Text == "")
            {
                SetPageStatus();
                SetDefaultValue();
            }

        }
    }