Exemple #1
0
    protected void Btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.hid_PageStatus.Value == "MODIFY")
            {
                if (this.gv_Detail.EditIndex != -1)
                {
                    ShowErrorMessage("請將編輯的資料列做更新,再按[儲存]");
                }
                else
                {

                    DataTable Dt = (DataTable)Session["STM321_" + PageTimeStamp.Value];

                    if (Dt == null)
                    {
                        ShowErrorMessage("無異動資料");
                        return;
                    }
                    else
                    {
                        bool bResult = false;

                        BCO.MaintainStoreHoliday bco = new BCO.MaintainStoreHoliday(ConntionDB);

                        if (this.hid_PageStatus.Value == "MODIFY")
                        {
                            
                            #region 重新檢查新增的資料列中,是否有欄位空白的,如果有則刪除不處理
                            DataRow[] drNULL = (DataRow[])Dt.Select("STORE_HOLIDAY is null OR STORE_TYPE is null");

                            foreach (DataRow dr in drNULL)
                            {
                                dr.Delete();
                            }

                            #endregion

                            if (Dt.Rows.Count > 0)
                            {

                                #region 使用XML轉回DataSet
                                DataTable oldDt = null;
                                
                                if (Store_Holiday_Data.InnerHtml != "" && Store_Holiday_Data.InnerHtml != "<NewDataSet />")
                                {
                                    DataSet Ds = new DataSet();
                                    System.IO.StringReader sr = new System.IO.StringReader(Store_Holiday_Data.InnerHtml);
                                    Ds.ReadXml(sr);
                                    oldDt = Ds.Tables[0];
                                }
                                #endregion

                                // 做資料儲存的動作
                                bResult = bco.doSave(Dt, oldDt, null);

                                
                            }

                            Dt = this.searchData();


                            Session["STM321_" + PageTimeStamp.Value] = Dt;


                            #region 將最新的資料,使用XML放置到前端資料
                            
                            Store_Holiday_Data.InnerHtml = Dt.DataSet.GetXml();
                            #endregion


                            #region 存檔後狀態設定

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

                            this.setGV(0, Dt, false);

                            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "ClientScript", "alert('儲存成功');", true);

                            #endregion
                        }

                    }
                }

            }


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

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

    }