/// <summary> /// 儲存鈕 /// </summary> protected void btnSave_Click(object sender, EventArgs e) { string SessionIDName = "CGD281_" + PageTimeStamp.Value; DataTable Dt = null; DataTable DT_Add = null; DataTable DT_Mod = null; DataTable DT_Del = null; if (Session[SessionIDName] != null) { Dt = (DataTable)Session[SessionIDName]; DT_Add = Dt.GetChanges(DataRowState.Added); DT_Mod = Dt.GetChanges(DataRowState.Modified); DT_Del = Dt.GetChanges(DataRowState.Deleted); } else { ErrorMsgLabel.Text = "目前無資料異動"; return; } if (DT_Add == null && DT_Mod == null && DT_Del == null) { ErrorMsgLabel.Text = "目前無資料異動"; return; } CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); CGDModel.MaintainPickWorkstation BCO = new CGDModel.MaintainPickWorkstation(ConntionDB); try { //刪除---------------------------------------------------------------------------------------------------------- if (DT_Del != null) { foreach (DataRow dRow in DT_Del.Rows) { ParameterList.Clear(); ParameterList.Add(dRow["DPS_CODE", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["STATION_NO", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original])); string MSG = BCO.DeletePick_Workstation(ParameterList, DBT); if ( MSG == "NODATA" ) { throw new Exception("DB_NODATA"); } } } //新增---------------------------------------------------------------------------------------------------------- if (DT_Add != null) { foreach (DataRow dRow in DT_Add.Rows) { ParameterList.Clear(); ParameterList.Add(dRow["CREATEUID"]); ParameterList.Add(dRow["UPDATEUID"]); ParameterList.Add(dRow["STATUS"]); ParameterList.Add(dRow["ENABLE"]); ParameterList.Add(dRow["DPS_CODE"]); ParameterList.Add(dRow["STATION_NO"]); ParameterList.Add(dRow["USE_LOCATE_CNT"]); ParameterList.Add(dRow["LIMIT_LOCATE_CNT"]); ParameterList.Add(dRow["INTERFLOW_LOCATE"]); ParameterList.Add(dRow["SHELF"]); BCO.CreatePick_Workstation(ParameterList, DBT); } } //修改---------------------------------------------------------------------------------------------------------- if (DT_Mod != null) { foreach (DataRow dRow in DT_Mod.Rows) { string v_DPS_CODE = hidlbl_DPS_CODE.Text.Trim(); string v_STATION_NO = dRow["STATION_NO", DataRowVersion.Original].ToString(); DateTime v_UPDATEDATE = Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original]); ParameterList.Clear(); ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["DPS_CODE", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["STATION_NO", DataRowVersion.Current].ToString()); ParameterList.Add(Convert.ToInt32(dRow["USE_LOCATE_CNT", DataRowVersion.Current].ToString())); ParameterList.Add(Convert.ToInt32(dRow["LIMIT_LOCATE_CNT", DataRowVersion.Current].ToString())); ParameterList.Add(dRow["INTERFLOW_LOCATE", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["SHELF", DataRowVersion.Current].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["CREATEDATE", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["CREATEUID", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["STATUS", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["ENABLE", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["DPS_CODE", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["STATION_NO", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToInt32(dRow["USE_LOCATE_CNT", DataRowVersion.Original].ToString())); ParameterList.Add(Convert.ToInt32(dRow["LIMIT_LOCATE_CNT", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["INTERFLOW_LOCATE", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["SHELF", DataRowVersion.Original].ToString()); string MSG = BCO.UpdatePick_Workstation(ParameterList, DBT); if (MSG == "NODATA") { throw new Exception("DB_NODATA"); } } } DBT.Commit();//交易成功 btnQuery_Click(null, null); ErrorMsgLabel.Text = "儲存完畢"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 儲存完畢 ');", true); } catch (Exception ex) { DBT.Rollback();//交易失敗 if (ex.Message.IndexOf("違反必須為唯一的限制條件") > 0) { ErrorMsgLabel.Text = "新增之站所已重複"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 新增之站所已重複 ');", true); return; } if (ex.Message.IndexOf("NODATA") > 0) { ErrorMsgLabel.Text = "原資料已異動過,請重新查詢資料後再作處理"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 原資料已異動過,請重新查詢資料後再作處理 ');", true); return; } ErrorMsgLabel.Text = ex.Message; } txtSTATION_NO.Text = ""; txtUSE_LOCATE_CNT.Text = ""; txtLIMIT_LOCATE_CNT.Text = ""; chkINTERFLOW_LOCATE.Checked = false; chkSHELF.Checked = false; Panel1.Visible = false; }
/// <summary> /// databind 繫結查詢資料到GridView1 /// </summary> private void databind() { //抓取本頁初次登記的時間 string SessionIDName = "CGD281_" + PageTimeStamp.Value; CGDModel.MaintainPickWorkstation BCO = new CGDModel.MaintainPickWorkstation(ConntionDB); DataTable Dt; if (Session[SessionIDName] != null) { Dt = (DataTable)Session[SessionIDName]; } else { ParameterList.Clear(); ParameterList.Add(this.ddlDPS_CODE.Text.Trim()); Dt = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.Custom, ParameterList); } if (Dt.Rows.Count == 0) { if (Mode != "ADD") ErrorMsgLabel.Text = "查無資料"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 查無資料 ');", true); } Session[SessionIDName] = Dt; DataView DV1 = Dt.DefaultView; DV1.RowFilter = "rownum <= " + Convert.ToString(Convert.ToInt32(TextBoxRowCountLimit.Text.Trim()) - 1); GridView1.DataSource = DV1; GridView1.Visible = true; //設定分頁大小 GridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) < 0) ? 10 : int.Parse(TextBoxPagesize.Text); GridView1.PageIndex = 0; GridView1.DataBind(); }
/// <summary> /// 插入鈕 /// </summary> protected void btnInsert_Click(object sender, EventArgs e) { #region 檢查輸入值 if (txtSTATION_NO.Text.Trim() == "") { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert('[站別]不得為空白');", true); return; } if (txtUSE_LOCATE_CNT.Text.Trim() == "") { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert('[實體儲區數]不得為空白');", true); return; } if (txtLIMIT_LOCATE_CNT.Text.Trim() == "") { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert('[上限儲區數]不得為空白');", true); return; } #endregion string SessionIDName = "CGD281_" + PageTimeStamp.Value; DataTable Dt = null; try { if (Session[SessionIDName] != null) { Dt = (DataTable)Session[SessionIDName]; } else { CGDModel.MaintainPickWorkstation BCO = new CGDModel.MaintainPickWorkstation(ConntionDB); ParameterList.Clear(); Dt = BCO.QuerySwitch(CGDModel.MaintainPickWorkstation.QueryType.Empty, ParameterList); } if (Mode == "EDIT") { for (int i = 0; i <= Dt.Rows.Count - 1; i++) { if (Dt.Rows[i].RowState != DataRowState.Deleted) { if (Dt.Rows[i]["STATION_NO"].ToString() == txtSTATION_NO.Text) { Dt.Rows[i]["UPDATEDATE"] = DateTime.Now; Dt.Rows[i]["UPDATEUID"] = Session["UID"].ToString(); Dt.Rows[i]["DPS_CODE"] = hidlbl_DPS_CODE.Text; Dt.Rows[i]["STATION_NO"] = txtSTATION_NO.Text; Dt.Rows[i]["USE_LOCATE_CNT"] = txtUSE_LOCATE_CNT.Text; Dt.Rows[i]["LIMIT_LOCATE_CNT"] = txtLIMIT_LOCATE_CNT.Text; Dt.Rows[i]["INTERFLOW_LOCATE"] = (chkINTERFLOW_LOCATE.Checked) ? "Y" : "N"; Dt.Rows[i]["SHELF"] = (chkSHELF.Checked) ? "Y" : "N"; } } } } else if (Mode == "ADD") { //檢查是否有重複站所 string repeat = ""; for (int i = 0; i <= Dt.Rows.Count - 1; i++) { if (Dt.Rows[i].RowState != DataRowState.Deleted) { if (Dt.Rows[i]["STATION_NO"].ToString() == txtSTATION_NO.Text) { repeat = "Yes"; ErrorMsgLabel.Text = "新增之站所已重複"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 新增之站所已重複 ');", true); return; } } } //開始插入 tempID = 0; tempRownum = 0; DataView tempDT = new DataView(); tempDT.Table = Dt.Copy(); tempDT.Sort = "ID ASC"; if (Dt.Rows.Count != 0) { tempID = Convert.ToInt32(tempDT[tempDT.Count - 1]["ID"].ToString()); } tempDT.Sort = "rownum ASC"; if (Dt.Rows.Count != 0) { tempRownum = Convert.ToInt32(tempDT[tempDT.Count - 1]["rownum"].ToString()); } DataRow dRow = Dt.NewRow(); //ID和PID暫自訂, 真正寫入CO時會重取 int v_ID = tempID + 1; int v_PID = tempID + 1; int v_ROWNUM = tempRownum + 1; dRow["ID"] = v_ID; dRow["CODE"] = v_PID; dRow["rownum"] = v_ROWNUM; dRow["CREATEDATE"] = DateTime.Now; dRow["UPDATEDATE"] = DateTime.Now; dRow["CREATEUID"] = Session["UID"].ToString(); dRow["UPDATEUID"] = Session["UID"].ToString(); dRow["STATUS"] = "1"; dRow["ENABLE"] = "1"; if (hidlbl_DPS_CODE.Text != "") { dRow["DPS_CODE"] = hidlbl_DPS_CODE.Text; } else { dRow["DPS_CODE"] = ddlDPS_CODE.SelectedItem.Text; } dRow["STATION_NO"] = txtSTATION_NO.Text; dRow["USE_LOCATE_CNT"] = txtUSE_LOCATE_CNT.Text; dRow["LIMIT_LOCATE_CNT"] = txtLIMIT_LOCATE_CNT.Text; dRow["INTERFLOW_LOCATE"] = (chkINTERFLOW_LOCATE.Checked) ? "Y" : "N"; dRow["SHELF"] = (chkSHELF.Checked) ? "Y" : "N"; Dt.Rows.Add(dRow); } txtSTATION_NO.Text = ""; txtUSE_LOCATE_CNT.Text = ""; txtLIMIT_LOCATE_CNT.Text = ""; chkINTERFLOW_LOCATE.Checked = false; chkSHELF.Checked = false; Panel1.Visible = false; Session[SessionIDName] = Dt; DataView DV1 = Dt.DefaultView; DV1.RowFilter = "rownum <= " + Convert.ToString(Convert.ToInt32(TextBoxRowCountLimit.Text.Trim()) - 1); GridView1.DataSource = DV1; GridView1.Visible = true; //設定分頁大小 GridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) < 0) ? 10 : int.Parse(TextBoxPagesize.Text); GridView1.DataBind(); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } finally { } }