// 新增明細事件 protected void btnAddDetail_Click(object sender, EventArgs e) { ErrorMsgLabel.Text = ""; int iStartID = 0; string strSessionName = "PUR02_DTL_" + PageTimeStamp.Value; if (this.hid_PageStatus.Value == "INSERT" || this.hid_PageStatus.Value == "EDIT") { gv_Detail_CacheUpdate(); gv_Gift_CacheUpdate(); DataTable DetailDt = (DataTable)Session[strSessionName]; if (DetailDt == null || DetailDt.Rows.Count <= 0) { MaintainPurchaseOrder bco = new MaintainPurchaseOrder(ConntionDB); DetailDt = bco.QueryItemSchema(); iStartID = 1; } else { iStartID = int.Parse(DetailDt.Rows[DetailDt.Rows.Count - 1]["ID"].ToString()) + 1; } addRow(ref DetailDt, iStartID); Session[strSessionName] = DetailDt; gv_Detail.DataSource = DetailDt; gv_Detail.PageIndex = 0; gv_Detail.DataBind(); //SetClinetFocus(((TextBox)gv_Detail.Rows[gv_Detail.Rows.Count - 1].Cells[1].Controls[1].FindControl("TextBoxCode")).ClientID); } }
/// <summary> /// Page_Load事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { ErrorMsgLabel.Text = ""; ResultMsgLabel.Text = ""; AuthorityControls(this); if (!IsPostBack) { //寫入首次載入Page TimeStamp PageTimeStamp.Value = string.Format("{0}{1}{2}{3}{4}{5}", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0'), DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0'), DateTime.Now.Second.ToString().PadLeft(2, '0') ); //設定GridView預設的狀態 Initialization_Component(); ViewState["PageIndex_Detail"] = 0; ViewState["PageIndex_Gift"] = 0; #region 設定 Page_Status 狀態 //該頁面共有3種狀態 //檢視 VIEW //編輯 EDIT //新增 INSERT //模式指定 string mode = "VIEW"; if (!string.IsNullOrEmpty(Request.QueryString["mode"])) { mode = Request.QueryString["mode"].ToString().ToUpper(); } ViewState["SSID"] = ""; if (Session[Request.QueryString["SSID"]] != null) { ViewState["SSID"] = Request.QueryString["SSID"]; IDCollection = (StringCollection)Session[ViewState["SSID"].ToString()]; } this.hid_PageStatus.Value = mode; this.txt_PageStatus.Text = mode; if ((mode == "VIEW") || (mode == "EDIT")) { string strPURCHASE_NO = string.Empty; if (!string.IsNullOrEmpty(Request.QueryString["PURCHASE_NO"])) { strPURCHASE_NO = Request.QueryString["PURCHASE_NO"].ToString(); ViewState["PURCHASE_NO"] = strPURCHASE_NO; } DataTable dtMain = Get_MainData(strPURCHASE_NO); if (dtMain.Rows.Count > 0) { this.hiddenPurchaseNo.Value = strPURCHASE_NO; this.hiddenIsClose.Value = dtMain.Rows[0]["IS_CLOSE"].ToString(); this.hiddenIsAccept.Value = dtMain.Rows[0]["IS_AP"].ToString(); } else { this.hiddenPurchaseNo.Value = ""; this.hiddenIsClose.Value = ""; this.hiddenIsAccept.Value = ""; } Session["PUR02_DTL_" + PageTimeStamp.Value] = null; if (mode == "VIEW") { lblStar1.Visible = false; lblStar2.Visible = false; lblStar3.Visible = false; } if (mode == "EDIT") { lblStar1.Visible = true; lblStar2.Visible = true; lblStar3.Visible = true; } } else if (mode == "INSERT") { PUR_PurUser.Text = Session["UID"].ToString(); MaintainPurchaseOrder bco = new MaintainPurchaseOrder(ConntionDB); for (int i = 0; i < 5; i++) { DataTable DetailDt = (DataTable)Session["PUR02_DTL_" + PageTimeStamp.Value]; if (DetailDt == null) DetailDt = bco.QueryItemSchema(); DataTable dtTmp = new DataTable(); dtTmp = bco.QueryItemSchema(); addRow(ref dtTmp, i + 1); DetailDt.Merge(dtTmp); Session["PUR02_DTL_" + PageTimeStamp.Value] = DetailDt; gv_Detail.DataSource = DetailDt; gv_Detail.PageIndex = 0; } gv_Detail.DataBind(); lblStar1.Visible = true; lblStar2.Visible = true; lblStar3.Visible = true; } #endregion SetPageStatus();//設定各種模式預設值 } else { ViewState["NoRefreshItem"] = "0"; //UnSetClinetFocus(); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } finally { ToolBarInit(); this.panel_sku_parent.Attributes.Add("style", "display:none"); } }