//明細區更新 protected void btnUpdate_Click(object sender, EventArgs e) { try { #region 檢核欄位 if (SLP_START_RANKQTY.Text == "") { ErrorMsgLabel.Text = "請輸入本數起"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_START_RANKQTY).FindControl("TextBoxCode"); //本數起 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } if (SLP_END_RANKQTY.Text == "") { ErrorMsgLabel.Text = "請輸入本數迄"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_END_RANKQTY).FindControl("TextBoxCode"); //本數迄 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } if (SLP_ADJ_QTY.Text == "") { ErrorMsgLabel.Text = "請輸入加減本數"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_ADJ_QTY).FindControl("TextBoxCode"); //加減本數 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } int test; if (!int.TryParse(SLP_ADJ_QTY.Text, out test)) { ErrorMsgLabel.Text = "請輸入正確加減本數"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_ADJ_QTY).FindControl("TextBoxCode"); //加減本數 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } if (int.Parse(SLP_START_RANKQTY.Text) > int.Parse(SLP_END_RANKQTY.Text)) { ErrorMsgLabel.Text = "本數起不可大於本數迄"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_START_RANKQTY).FindControl("TextBoxCode"); //本數起 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } if (int.Parse(SLP_ADJ_QTY.Text) < int.Parse(SLP_END_RANKQTY.Text) * -1) { ErrorMsgLabel.Text = "本數起不可大於本數迄"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_ADJ_QTY).FindControl("TextBoxCode"); //加減本數 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } string SessionIDName = "ALO123_dt" + PageTimeStamp.Value; DataTable dt = new DataTable(); if ((DataTable)Session[SessionIDName] != null) dt = (DataTable)Session[SessionIDName]; else { dt.Columns.Add("START_RANKQTY"); dt.Columns.Add("END_RANKQTY"); dt.Columns.Add("ADJ_QTY"); dt.Columns.Add("N_STORE_CNT"); dt.Columns.Add("ID"); dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; } foreach (DataRow dr in dt.Rows) { if (!(hidID.Value == int.Parse(dr["START_RANKQTY"].ToString()).ToString() + int.Parse(dr["END_RANKQTY"].ToString()).ToString())) { if (int.Parse(SLP_START_RANKQTY.Text) >= int.Parse(dr["START_RANKQTY"].ToString()) && int.Parse(SLP_START_RANKQTY.Text) <= int.Parse(dr["END_RANKQTY"].ToString())) { ErrorMsgLabel.Text = "本數起迄區間重複"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_START_RANKQTY).FindControl("TextBoxCode"); //加減本數 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } if (int.Parse(SLP_START_RANKQTY.Text) < int.Parse(dr["START_RANKQTY"].ToString()) && (int.Parse(SLP_END_RANKQTY.Text) >= int.Parse(dr["START_RANKQTY"].ToString()))) { ErrorMsgLabel.Text = "本數起迄區間重複"; TextBox tb = (TextBox)((ASP.wui_slp_slp_slpnumber_ascx)SLP_START_RANKQTY).FindControl("TextBoxCode"); //加減本數 ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO123_Focus", "document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();", true); return; } } } #endregion ArrayList ParameterList = new ArrayList();//20091113 ParameterList.Clear(); ParameterList.Add(Request.QueryString["pPG_ID"]); ParameterList.Add(PageTimeStamp.Value + Session["UID"].ToString()); ParameterList.Add(Request.QueryString["pDisNo"]); ParameterList.Add(Request.QueryString["pItem"]); ParameterList.Add(Request.QueryString["pPeriod"]); ParameterList.Add(int.Parse(SLP_START_RANKQTY.Text).ToString()); //本數起 ParameterList.Add(int.Parse(SLP_END_RANKQTY.Text).ToString()); //本數迄 ParameterList.Add(int.Parse(SLP_ADJ_QTY.Text).ToString()); //加減本數 BCO.MaintainDisRecord bco = new BCO.MaintainDisRecord(ConnectionDB); if (hidID.Value == "")//新增 { DataRow dr1 = dt.NewRow(); dr1["START_RANKQTY"] = int.Parse(SLP_START_RANKQTY.Text).ToString(); dr1["END_RANKQTY"] = int.Parse(SLP_END_RANKQTY.Text).ToString(); dr1["ADJ_QTY"] = int.Parse(SLP_ADJ_QTY.Text).ToString(); dr1["N_STORE_CNT"] = bco.QueryRankChangeStoreQty(ParameterList); dr1["ID"] = int.Parse(SLP_START_RANKQTY.Text).ToString() + int.Parse(SLP_END_RANKQTY.Text).ToString(); dt.Rows.Add(dr1); } else//修改 { DataRow dr1 = dt.Rows.Find(hidID.Value); dr1["START_RANKQTY"] = int.Parse(SLP_START_RANKQTY.Text).ToString(); dr1["END_RANKQTY"] = int.Parse(SLP_END_RANKQTY.Text).ToString(); dr1["ADJ_QTY"] = int.Parse(SLP_ADJ_QTY.Text).ToString(); dr1["N_STORE_CNT"] = bco.QueryRankChangeStoreQty(ParameterList); dr1["ID"] = int.Parse(SLP_START_RANKQTY.Text).ToString() + int.Parse(SLP_END_RANKQTY.Text).ToString(); } dt.AcceptChanges(); Session["ALO123_dt" + PageTimeStamp.Value] = dt; GridView2.DataSource = dt; GridView2.DataBind(); panDetail.Visible = true; GridView2.Visible = true; panEdit.Visible = false; btnAdd.Enabled = true; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }