/// <summary> /// 處理查詢資料 /// </summary> /// <returns></returns> public DataTable searchData() { #region 清空靜態變數 Session["STM321_" + PageTimeStamp.Value] = null; #endregion #region 處理查詢 ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(this.SLP_TYPE.Text.Trim(), "string")); ParameterList.Add(GetValueSetParameter(this.STORE_YY.Text.Trim(), "string")); ParameterList.Add(GetValueSetParameter(this.STORE_MM.Text.Trim(), "string")); ParameterList.Add(GetValueSetParameter(TextBoxRowCountLimit.Text, "int")); BCO.MaintainStoreHoliday bco = new MaintainStoreHoliday(ConntionDB); DataTable Dt = bco.QueryByFind(ParameterList, int.Parse(TextBoxRowCountLimit.Text)); #endregion return Dt; }
protected void Btn_Insert_Click(object sender, EventArgs e) { try { if (this.hid_PageStatus.Value == "QUERY" || this.hid_PageStatus.Value == "VIEW" || this.hid_PageStatus.Value == "MODIFY") { int iPageIndex; DataTable Dt = (DataTable)Session["STM321_" + PageTimeStamp.Value]; if (Dt == null || Dt.Rows.Count == 0) { BCO.MaintainStoreHoliday bco = new BCO.MaintainStoreHoliday(ConntionDB); Dt = bco.QuerySchema(); } DataRow dRow = Dt.NewRow(); Dt.Rows.Add(dRow); Session["STM321_" + PageTimeStamp.Value] = Dt; if (Dt.Rows.Count > 0) { double dbTemp = Dt.Rows.Count / gv_Detail.PageSize; iPageIndex = Int32.Parse(Math.Truncate(dbTemp).ToString()); } else { iPageIndex = 0; } this.gv_Detail.PageIndex = iPageIndex; this.setGV((Dt.Rows.Count > gv_Detail.PageSize ? (Dt.Rows.Count - (gv_Detail.PageSize * gv_Detail.PageIndex) - 1) : Dt.Rows.Count - 1), Dt, true); SetGrigViewEditTab(Dt, (Dt.Rows.Count > gv_Detail.PageSize ? (Dt.Rows.Count - (gv_Detail.PageSize * gv_Detail.PageIndex) - 1) : Dt.Rows.Count - 1)); #region 存檔後狀態設定 this.hid_PageStatus.Value = "MODIFY"; this.txt_PageStatus.Text = "MODIFY"; #endregion } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0]; //直接取第一個 } finally { SetPageStatus(); } }
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(); } }
/// <summary> /// 編輯模式設定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gv_Detail_RowUpdating(object sender, GridViewUpdateEventArgs e) { //取消編輯模式→設定GridView的EditIndex = -1 DataTable dt = (DataTable)Session["STM321_" + PageTimeStamp.Value]; if (dt != null && dt.Rows.Count > 0) { string returnValue = ""; int j = e.RowIndex; string ID = ((TextBox)gv_Detail.Rows[j].Cells[0].FindControl("ID")).Text; string STORE_HOLIDAY = ((ASP.wui_slp_slp_slpdate_ascx)gv_Detail.Rows[j].Cells[4].Controls[3]).Text; string STORE_TYPE=((DropDownList)gv_Detail.Rows[j].Cells[1].Controls[1].FindControl("D1")).SelectedValue; string STORE_TYPENAME = ((DropDownList)gv_Detail.Rows[j].Cells[1].Controls[1].FindControl("D1")).SelectedItem.Text; if (STORE_TYPE == "") { this.ShowErrorMessage("請輸入[類別]"); } if (STORE_HOLIDAY == "") { this.ShowErrorMessage("請輸入[日期]"); } ParameterList.Clear(); ParameterList.Add(ID); ParameterList.Add(STORE_TYPE); ParameterList.Add(Convert.ToDateTime(STORE_HOLIDAY)); //檢查是否已存在於資料庫 BCO.MaintainStoreHoliday bco = new MaintainStoreHoliday(ConntionDB); returnValue = bco.QueryExistDB(ParameterList) ? "fail" : "ok"; if (returnValue == "fail") { this.ShowErrorMessage("此筆資料已存在假日設定檔!"); } else if (returnValue == "ok") { foreach (DataRow dr in dt.Rows) { if (ID != dr["ID"].ToString() && STORE_TYPE == dr["STORE_TYPE"].ToString() && Convert.ToDateTime(STORE_HOLIDAY).ToString() == dr["STORE_HOLIDAY"].ToString()) { this.ShowErrorMessage("此筆資料已存在假日設定檔!"); returnValue = "fail"; } } if (returnValue == "ok") { //20101124 僅限用於直接於Gridview新增刪除編輯資料的狀況 //因為dt會保留刪除的資料欄,因此若該資料欄狀態為刪除,應將資料改填入未刪除前的資料的位置 if (dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j].RowState == DataRowState.Deleted) { dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j + 1]["STORE_HOLIDAY"] = STORE_HOLIDAY; dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j + 1]["STORE_YY"] = Convert.ToDateTime(STORE_HOLIDAY).Year.ToString(); dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j + 1]["STORE_MM"] = Convert.ToDateTime(STORE_HOLIDAY).Month.ToString(); dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j + 1]["STORE_TYPE"] = STORE_TYPE; dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j + 1]["STORE_TYPENAME"] = STORE_TYPENAME; } else { dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j]["STORE_HOLIDAY"] = STORE_HOLIDAY; dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j]["STORE_YY"] = Convert.ToDateTime(STORE_HOLIDAY).Year.ToString(); dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j]["STORE_MM"] = Convert.ToDateTime(STORE_HOLIDAY).Month.ToString(); dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j]["STORE_TYPE"] = STORE_TYPE; dt.Rows[gv_Detail.PageIndex * gv_Detail.PageSize + j]["STORE_TYPENAME"] = STORE_TYPENAME; } this.setGV(-1, dt, true); } } } }