Пример #1
0
    //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)((ASP.wui_slp_slp_slpnumber_ascx)GridView2.Rows[i].FindControl("txtDIS_QTY")).FindControl("TextBoxCode");
        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)
                {
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO122_Alert", "alert('配本數量必須大於0');", true);
                    ErrorMsgLabel.Text = "配本數量必須大於0";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO122_Alert", "window.setTimeout(function set_focus(){document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();}, 800);", true);
                    return;
                }
                string SessionIDName = "ALO122_dt5" + PageTimeStamp.Value;
                DataTable dt = (DataTable)Session[SessionIDName];
                dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
                try
                {
                    DataRow Dr = dt.Rows.Find(((Label)GridView2.Rows[i].FindControl("lblID")).Text);
                    DateTime DT = DateTime.Now; //異動時間
                    ArrayList ParameterList = new ArrayList();//20091113

                    ParameterList.Clear();
                    ParameterList.Add(PageTimeStamp.Value + Session["UID"].ToString());
                    ParameterList.Add(((Label)GridView2.Rows[i].FindControl("lblID")).Text); //ID
                    ParameterList.Add(tb.Text); //配本數量
                    ParameterList.Add(Session["UID"].ToString()); //登入者
                    ParameterList.Add(DT);
                    BCO.MaintainDisRecord bco = new BCO.MaintainDisRecord(ConnectionDB);
                    bco.UpdateStoreDisQtyFor122(ParameterList, null);
                    //調整後路線合計數量
                    txtN_DIS_TOT_OQTY.Text = Convert.ToString(int.Parse(txtN_DIS_TOT_OQTY.Text) + (int.Parse(tb.Text) - int.Parse(lb.Text)));
                    txtDIS_STO_CQTY.Text = txtN_DIS_TOT_OQTY.Text;//調整後通路合計數量 = 調整後路線合計數量
                    //差異量
                    txtDiff.Text = Convert.ToString(int.Parse(txtN_DIS_TOT_OQTY.Text) - int.Parse(txtN_DIS_TOT_QTY.Text));
                    btnDis_Update.Enabled = true;//只要按下「更新」鈕,就把「配量更新」鈕打開
                    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();
                    UpdatePanel1.Update();
                    UpdatePanel3.Update();
                }
                catch (Exception ex) { this.ErrorMsgLabel.Text = ex.Message; dt.RejectChanges(); }
            }
            else
            {
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO122_Alert", "alert('請輸入數字');", true);
                ErrorMsgLabel.Text = "請輸入正整數";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO122_Alert", "window.setTimeout(function set_focus(){document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();}, 800);", true);
                return;
            }
        }
        else
        {
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO122_Alert", "alert('配本數量必須大於0');", true);
            ErrorMsgLabel.Text = "配本數量不可小於0";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ALO122_Alert", "window.setTimeout(function set_focus(){document.all['" + tb.ClientID + "'].focus(); document.all['" + tb.ClientID + "'].select();}, 800);", true);
            return;
        }
    }