//GridView2的更新鈕 protected void btnUpdate_Click(object sender, EventArgs e) { Button btn = sender as Button; GridViewRow gr = (btn.BindingContainer as GridViewRow); int i = gr.RowIndex; TextBox tb = (TextBox)GridView2.Rows[i].FindControl("txtDIS_QTY"); Label lb = (Label)GridView2.Rows[i].FindControl("lblDIS_QTY"); if (tb.Text.Trim().Length > 0) { uint idx; bool isNum = uint.TryParse(tb.Text, out idx); if (isNum) { if (idx < 0) { ErrorMsgLabel.Text = "配本數量必須大於0"; ErrorMsgLabel.Visible = true; return; } string SessionIDName = "ALO121_dt5" + PageTimeStamp.Value; DataTable dt = (DataTable)Session[SessionIDName]; dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; ArrayList ParameterList = new ArrayList();//20091113 try { DataRow Dr = dt.Rows.Find(((Label)GridView2.Rows[i].FindControl("lblID")).Text); DateTime DT = DateTime.Now; //異動時間 ParameterList.Clear(); ParameterList.Add(((Label)GridView2.Rows[i].FindControl("lblID")).Text); //ID ParameterList.Add(txtDIS_NO.Text); //配本序號 ParameterList.Add(Dr["ITEM"].ToString()); //配本商品品號 ParameterList.Add(Dr["PERIOD"].ToString()); //配本商品期別 ParameterList.Add(Dr["CHAN_NO"].ToString()); //配本通路 ParameterList.Add(Dr["STORE"].ToString()); //配本門市 ParameterList.Add(tb.Text); //配本數量 ParameterList.Add(Session["UID"].ToString()); //登入者 ParameterList.Add(Dr["UPDATEUID"].ToString()); ParameterList.Add(Dr["UPDATEDATE"].ToString()); ParameterList.Add(DT); BCO.MaintainDisRecord bco = new BCO.MaintainDisRecord(ConnectionDB); bco.UpdateStoreDisQtyFor121(ParameterList, null); //更新通路合計配量及路線合計配量 txtDIS_TOT_OQTY.Text = Convert.ToString(int.Parse(txtDIS_TOT_OQTY.Text) + (int.Parse(tb.Text) - int.Parse(lb.Text))); txtN_DIS_TOT_QTY.Text = txtDIS_TOT_OQTY.Text; Dr["DIS_QTY"] = tb.Text; Dr["UPDATEUID"] = Session["UID"].ToString(); Dr["UPDATEDATE"] = DT; //修改DataTable的異動時間,以與DB同步 dt.AcceptChanges(); Session[SessionIDName] = dt; GridView2.DataSource = CopyTable(dt); GridView2.DataBind(); btnConfirm1.Enabled = true; ViewState["hidGridView_PG_ID"] = "GridView2";//用以判斷是否門市清單已修改 UpdatePanel1.Update(); btnPrev2.Enabled = true; btnNext2.Enabled = true; btnQuery2.Enabled = true; btnQuery4.Enabled = true; } catch (Exception ex) { this.ErrorMsgLabel.Text = ex.Message; ErrorMsgLabel.Visible = true; dt.RejectChanges(); } } else { //ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO121_Alert", "alert('請輸入數字');", true); ErrorMsgLabel.Text = "請輸入數字"; ErrorMsgLabel.Visible = true; return; } } else { //ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO121_Alert", "alert('配本數量必須大於0');", true); ErrorMsgLabel.Text = "配本數量必須大於0"; ErrorMsgLabel.Visible = true; return; } }