-1

私の ASP.NET プロジェクトでは、クエリ文字列を使用して新しい配列項目を追加します。配列アイテムが追加されると、クライアントがブラウザをリロードします。同じアイテムをもう一度追加します。リロードのタイミングごとに発生します。

しかし、私はこれを望んでいません。このブラウザのリロードを停止するか、同じ配列アイテムを停止することは可能ですか?

私のURLは -

51402/ItemGrid.aspx?id=3035

次に、id=3035アイテムが配列に追加されました。

ページ読み込みイベントのマイ コード

string query ="";
            int array_no;
            if (Convert.ToUInt32(GlobalClass.GlobalarrayNo.ToString()) == 0)
            {
                array_no = 0;
                Array.Clear(roomno, 0, roomno.Length);
            }
            else
            {
                array_no = Convert.ToInt32(GlobalClass.GlobalarrayNo.ToString());
            }
            id = Convert.ToInt32(Request.QueryString["id"]);
            if (!Page.IsPostBack)
            {               
                // ******* Happy Status ************

                decimal happyfromtime = 0;
                string happyper="";             
                string happytotime = "";
                query = "SELECT Parameters_Parameter3,Parameters_Parameter2,Parameters_Parameter1,Parameters_Parameter4 FROM MCS_Parameters WHERE Parameters_TYPE ='HAPHOU'";
                MySqlConnection connection = new MySqlConnection(GlobalClass.GlobalConnString.ToString());
                MySqlCommand command = new MySqlCommand(query, connection);
                connection.Open();
                MySqlDataReader Reader = command.ExecuteReader();
                while (Reader.Read())
                {
                    happyfromtime= Convert.ToDecimal(Reader[0].ToString());
                    happyper=Reader[1].ToString();
                    happystatus= Convert.ToInt32(Reader[2].ToString());
                    happytotime = Reader[3].ToString();
                }
                connection.Close();

                string t = GlobalClass.GlobalserverTime.ToString();
                t= t.Substring(0,5);
                t = t.Replace(":",".");

                //ALLTRIM(CurCate.Fb_Item_Creation_HappyhoursStatus)='Yes'
                if ((Convert.ToDecimal(t) > Convert.ToDecimal(happyfromtime)) && (Convert.ToDecimal(t) < Convert.ToDecimal(happytotime)) && (happystatus == 1))                
                {
                    tHappy_Status = 1;
                }

                if (GlobalClass.GlobalservedAt == "RST")
                {
                    query = "select a.Fb_Item_Creation_ItemDescription, a.Fb_Item_Creation_RestaurantPrice, a.Fb_Item_Creation_ItemCode, a.Fb_Item_Creation_TaxStatus, "
                            + "a.Fb_Item_Creation_VatPercentage, a.Fb_Item_Creation_ServicechargeStatus, a.Fb_Item_Creation_SurchargeStatus, a.Fb_Item_Creation_DiscountStatus,"
                            + "a.FB_Item_ID, b.Fb_Category_Stock, b.Fb_Category_Name,a.Fb_Item_Creation_ModifierStatus,a.Fb_Item_Creation_HappyhoursStatus from fb_item_creation a, fb_category b "
                            + "where a.FB_Item_ID = '" + id + "' and a.Fb_Item_Creation_DeleteStatus=0 and "
                            + "a.Fb_Item_Creation_OutletId='" + GlobalClass.GlobaloutletId + "' "
                            + "and a.Fb_Item_Creation_ItemGroupId='" + GlobalClass.GlobalitemGroupId + "' and b.Fb_Category_DeleteStatus=0 and "
                            + "b.Fb_Category_Id = a.Fb_Item_Creation_ItemCategoryId";
                }
                else if (GlobalClass.GlobalservedAt == "BAR")
                {
                    query = "select a.Fb_Item_Creation_ItemDescription, a.Fb_Item_Creation_BarPrice, a.Fb_Item_Creation_ItemCode, a.Fb_Item_Creation_TaxStatus, "
                            + "a.Fb_Item_Creation_VatPercentage, a.Fb_Item_Creation_ServicechargeStatus, a.Fb_Item_Creation_SurchargeStatus, a.Fb_Item_Creation_DiscountStatus,"
                            + "a.FB_Item_ID, b.Fb_Category_Stock, b.Fb_Category_Name,a.Fb_Item_Creation_ModifierStatus,a.Fb_Item_Creation_HappyhoursStatus,a.Fb_Item_Creation_HappyhoursStatus from fb_item_creation a, fb_category b "
                            + "where a.FB_Item_ID = '" + id + "' and a.Fb_Item_Creation_DeleteStatus=0 and "
                            + "a.Fb_Item_Creation_OutletId='" + GlobalClass.GlobaloutletId + "' "
                            + "and a.Fb_Item_Creation_ItemGroupId='" + GlobalClass.GlobalitemGroupId + "' and b.Fb_Category_DeleteStatus=0 and "
                            + "b.Fb_Category_Id = a.Fb_Item_Creation_ItemCategoryId";
                }
                else
                {
                    query = "select a.Fb_Item_Creation_ItemDescription, a.Fb_Item_Creation_RoomPrice, a.Fb_Item_Creation_ItemCode, a.Fb_Item_Creation_TaxStatus, "
                            + "a.Fb_Item_Creation_VatPercentage, a.Fb_Item_Creation_ServicechargeStatus, a.Fb_Item_Creation_SurchargeStatus, a.Fb_Item_Creation_DiscountStatus,"
                            + "a.FB_Item_ID, b.Fb_Category_Stock, b.Fb_Category_Name,a.Fb_Item_Creation_ModifierStatus from fb_item_creation a, fb_category b "
                            + "where a.FB_Item_ID = '" + id + "' and a.Fb_Item_Creation_DeleteStatus=0 and "
                            + "a.Fb_Item_Creation_OutletId='" + GlobalClass.GlobaloutletId + "' "
                            + "and a.Fb_Item_Creation_ItemGroupId='" + GlobalClass.GlobalitemGroupId + "' and b.Fb_Category_DeleteStatus=0 and "
                            + "b.Fb_Category_Id = a.Fb_Item_Creation_ItemCategoryId";
                }
                connection = new MySqlConnection(GlobalClass.GlobalConnString.ToString());

                command = new MySqlCommand(query, connection);
                connection.Open();
                Reader = command.ExecuteReader();
                while (Reader.Read())
                {
                    roomno[array_no, 0] = Reader[0].ToString(); // Fb_Item_Creation_ItemDescription
                    if (GlobalClass.GlobalopenCode == "OPEN")
                    {

                        roomno[array_no, 0] = GlobalClass.GlobalopenDes.ToString(); // Fb_Item_Creation_ItemDescription
                        roomno[array_no, 1] = GlobalClass.GlobalopenRate.ToString(); // Fb_Item_Creation_RoomPrice
                        roomno[array_no, 2] = GlobalClass.GlobalopenQty.ToString();                // Qty
                        roomno[array_no, 3] = Reader[2].ToString(); // Fb_Item_Creation_ItemCode
                        roomno[array_no, 4] = Reader[3].ToString(); // Fb_Item_Creation_TaxStatus
                        roomno[array_no, 5] = Reader[4].ToString(); // Fb_Item_Creation_VatPercentage
                        roomno[array_no, 6] = Reader[5].ToString(); // Fb_Item_Creation_ServicechargeStatus
                        roomno[array_no, 7] = Reader[6].ToString(); // Fb_Item_Creation_SurchargeStatus
                        roomno[array_no, 8] = Reader[7].ToString(); // Fb_Item_Creation_DiscountStatus
                        roomno[array_no, 9] = Reader[8].ToString(); // FB_Item_ID
                        roomno[array_no, 10] = Reader[9].ToString(); // Fb_Category_Stock
                        roomno[array_no, 11] = Reader[10].ToString(); // Fb_Category_Name
                        roomno[array_no, 12] = Reader[1].ToString();  // Total = rate * qty
                        roomno[array_no, 13] = Reader[11].ToString(); //Fb_Item_Creation_ModifierStatus
                        roomno[array_no, 14] = ""; //Fb_Kot_Item_TouchLine
                        roomno[array_no, 15] = ""; // UserModifier
                        roomno[array_no, 16] = Reader[12].ToString(); // HappyHours


                        array_no++;
                        GlobalClass.GlobalarrayNo = array_no;
                    }
                    else if (roomno[array_no, 0] == "OPEN")
                    {
                        Response.Redirect("OpenItem.aspx" + "?id=" + id);
                    }
                    else
                    {
                        roomno[array_no, 1] = Reader[1].ToString(); // Fb_Item_Creation_RoomPrice
                        roomno[array_no, 2] = "1";                  // Qty
                        roomno[array_no, 3] = Reader[2].ToString(); // Fb_Item_Creation_ItemCode
                        roomno[array_no, 4] = Reader[3].ToString(); // Fb_Item_Creation_TaxStatus
                        roomno[array_no, 5] = Reader[4].ToString(); // Fb_Item_Creation_VatPercentage
                        roomno[array_no, 6] = Reader[5].ToString(); // Fb_Item_Creation_ServicechargeStatus
                        roomno[array_no, 7] = Reader[6].ToString(); // Fb_Item_Creation_SurchargeStatus
                        roomno[array_no, 8] = Reader[7].ToString(); // Fb_Item_Creation_DiscountStatus
                        roomno[array_no, 9] = Reader[8].ToString(); // FB_Item_ID
                        roomno[array_no, 10] = Reader[9].ToString(); // Fb_Category_Stock
                        roomno[array_no, 11] = Reader[10].ToString(); // Fb_Category_Name
                        roomno[array_no, 12] = Reader[1].ToString();  // Total = rate * qty
                        roomno[array_no, 13] = Reader[11].ToString(); //Fb_Item_Creation_ModifierStatus
                        roomno[array_no, 14] = ""; //Fb_Kot_Item_TouchLine
                        roomno[array_no, 15] = ""; // UserModifier                        
                        roomno[array_no, 16] = Reader[12].ToString(); // HappyHours

                        if ((tHappy_Status == 1) && (roomno[array_no, 16].ToString()=="Yes"))
                        {
                            roomno[array_no, 8] = "Yes";
                        }

                        array_no++;
                        GlobalClass.GlobalarrayNo = array_no;

                        //var nameValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
                        //nameValues.Set("sortBy", "4");
                        //string url = Request.Url.AbsolutePath;
                        //string updatedQueryString = "?" + nameValues.ToString();
                        //Response.Redirect(url + updatedQueryString);
                    }
                }
                connection.Close();

                ViewState["btn"] = "1";
                ViewState["tot"] = "0";
                ViewState["happystatus"] = happystatus;
                btn_click = Convert.ToInt32(ViewState["btn"].ToString());
                int len = array_no;
                while (len > 8)
                {
                    len = len - 8;
                    tot++;
                }

                if (len != 0) tot++;
                ViewState["tot"] = tot;
                fun();
                //CreatingTmpModdbf1();

                // Modifier Text
                int seq = Convert.ToInt32(Request.QueryString["seq"]);
                string text = Request.QueryString["text"];
                if (text != null)
                {
                    roomno[seq - 1, 15] = text;
                }
            }

!postback は、私の問題を回避するのに役立ちません。

static class GlobalClass
    {
        private static string myConnString1 = "";
        private static int userId = 0;
        private static string userName = "";
        private static int outletId = 0;
        private static int itemGroupId = 0;
        private static DateTime serverDate;
        private static string serverTime = "";
        private static string tableName = "";
        private static string serverdAt = "";
        private static int arrayNo = 0;
        private static int waiterId = 0;
        private static int covers = 0;
        private static string kotno = "";


        public static string GlobalConnString
        {
            get { return myConnString1; }
            set { myConnString1 = value; }                     
        }

        public static int GlobaluserId
        {
            get { return userId;}
            set { userId = value; }
        }

        public static string GlobaluserName
        {
            get { return userName; }
            set { userName = value; }
        }

        public static int GlobaloutletId
        {
            get { return outletId; }
            set { outletId = value; }
        }

        public static DateTime GlobalserverDate
        {
            get { return serverDate; }
            set { serverDate = value; }
        }

        public static string GlobalserverTime
        {
            get { return serverTime; }
            set { serverTime = value; }
        }

        public static string GlobaltableName
        {
            get { return tableName; }
            set { tableName = value; }
        }

        public static int GlobalitemGroupId
        {
            get { return itemGroupId; }
            set { itemGroupId = value; }
        }

        public static string GlobalservedAt
        {
            get { return serverdAt; }
            set { serverdAt = value; }
        }

        public static int GlobalarrayNo
        {
            get { return arrayNo; }
            set { arrayNo = value; }
        }

        public static int GlobalwaiterId
        {
            get { return waiterId; }
            set { waiterId = value; }
        }

        public static int Globalcovers
        {
            get { return covers; }
            set { covers = value; }
        }

        public static string GlobalkotNo
        {
            get { return kotno ; }
            set { kotno = value; }
        }

        public static string staffId = "";
        public static string staffCategoryId = "";

        public static string GlobalstaffId
        {
            get { return staffId; }
            set { staffId = value; }
        }

        public static string GlobalstaffCategoryId
        {
            get { return staffCategoryId; }
            set { staffCategoryId = value; }
        }

        public static string openCode = "";
        public static string openDes = "";

        public static string GlobalopenCode
        {
            get { return openCode; }
            set { openCode = value; }
        }

        public static string GlobalopenDes
        {
            get { return openDes; }
            set { openDes = value; }
        }

        public static string openQty = "";
        public static string openRate = "";

        public static string GlobalopenQty
        {
            get { return openQty; }
            set { openQty = value; }
        }

        public static string GlobalopenRate
        {
            get { return openRate; }
            set { openRate = value; }
        }
    } 
4

3 に答える 3

0

アイテムを追加した後、別のページにリダイレクトできます。たとえば、51402/ItemGrid.aspx

また、get request を使用してデータを保存/編集/削除することはお勧めできません。投稿を使用することをお勧めします。

于 2012-08-21T05:36:57.620 に答える
0

Page_Load 内の配列に項目を追加する場合は、項目を追加するコードを次のようにラップすることができます。

If Not Page.IsPostBack Then
    //Your array item adding code here
End If

これにより、ユーザーがページを更新した場合にアイテムが再度追加されるのを防ぐことができます。ただし、ティムに反響し、間違っていると仮定した場合は、コードを投稿する必要があると言いたいです。

于 2012-08-21T05:37:20.600 に答える
0

I assume that your array is static/shared. Static variables are shared across the whole app domain and all threads. Hence every user uses the same variable.

Don't use static variables therefor, instead of persisting the array you should use the querystring again.

If this was a wrong assumption you should show us your code

于 2012-08-21T05:30:37.590 に答える