-1

在我的 ASP.NET 项目中,我在查询字符串的帮助下添加了一个新的数组项。添加数组项后,我的客户端会重新加载浏览器。所以同一个项目再添加一次。它发生在每个重新加载时间。

但我不想要这个。是否有可能停止此浏览器重新加载或停止相同的数组项?

我的网址是 -

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

我假设您的数组是静态/共享的。静态变量在整个应用程序域和所有线程中共享。因此,每个用户都使用相同的变量。

不要为此使用静态变量,而不是持久化数组,您应该再次使用查询字符串。

如果这是一个错误的假设,您应该向我们展示您的代码

于 2012-08-21T05:30:37.590 回答
0

添加项目后,您可以重定向到另一个页面。例如 51402/ItemGrid.aspx

同样使用 get 请求来保存/编辑/删除数据也不是好主意,最好使用 post。

于 2012-08-21T05:36:57.620 回答
0

如果要将项目添加到 Page_Load 内的数组中,您可能需要将添加项目的代码包装在以下内容中:

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

如果用户刷新页面,这将防止再次添加项目。不过,我想回应 Tim 并说如果我假设不正确,您应该发布您的代码。

于 2012-08-21T05:37:20.600 回答