IsPostBack问题

时间:2013-12-14 05:57:04

标签: c# sql database sql-update 3-tier

我正在尝试为3层志愿者注册包装会话系统。首先,在页面加载时,我得到了某些打包会话的详细信息:

        if (!IsPostBack)
        {
            string packingID = Request.QueryString["id"];

            packingIndv = packing.getPacking(packingID);
            if (packingIndv == null)
            {
                lbl_msg.Text = "Error in getting packing session details!";
            }
            else
            {
                lbl_ID.Text = packingIndv.packingID;
                lbl_date.Text = packingIndv.date.ToString("dd/M/yyyy", CultureInfo.InvariantCulture); ;
                lbl_location.Text = packingIndv.location;
                lbl_volunteerAvailable.Text = packingIndv.volunteerAvailable.ToString();
                lbl_status.Text = packingIndv.status;
            }
        }

之后,志愿者可以点击加入按钮,程序将执行:

在加入按钮打开后的表示层中单击:

string userLogged = Session["userLogged"].ToString();
        UserBLL user = new UserBLL();
        string userID = user.getUserIDByName(userLogged);

        PackingBLL packing = new PackingBLL();
        string msg = "";
        msg = packing.joinPacking(userID, lbl_ID.Text);
        lbl_msg.Text = msg;

在业务逻辑层:

public string joinPacking(string userID, string packingID)
    {
        string returnMessage = "";

        if(returnMessage.Length == 0)
        {
            Packing packing = new Packing(userID, packingID);
            Boolean success = packing.checkJoinedSession();
            if (success)
            {
                returnMessage += "Same volunteer cannot join same packing session for more than once! <br/>";
            }
            else
            {
                int nofRows = 0;
                nofRows = packing.joinPacking();

                if (nofRows > 0)
                {
                    returnMessage = "Request to volunteer for packing session saved successfully.";
                    int successUpdate = packing.updateRemaining();
                    if (successUpdate > 0)
                    {
                        getPacking(packingID);
                    }
                }
                else
                {
                    returnMessage = "Error! Please try again.";
                }
            }
        }

        return returnMessage;
    }

在数据访问层中:

 public int updateRemaining()
    {
        int result = 0;

        using (var connection = new SqlConnection(FFTHDb.connectionString)) // get your connection string from the other class here
        {
            SqlCommand command = new SqlCommand("UPDATE PackingSession SET volunteerAvailable = volunteerAvailable + 1 WHERE packingID = '" + packingID + "'", connection);
            connection.Open();
            result = command.ExecuteNonQuery();
            connection.Close();
        }
        return result;
    }

对于每位志愿者的每次加入,可用的志愿者将增加一名。我想要做的是从页面加载,我显示打包会话的详细信息。然后当志愿者加入时,志愿者可以直接增加一个。我的所有数据库都运行得很好,它不会在每次成功更新sql语句后自动增加志愿者,因为我必须刷新浏览器才能看到更改。

0 个答案:

没有答案