コード例 #1
0
        /// <summary>
        /// Method called when listview's item's button clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lvProducts_OnItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (user.UserId != 0)
            {
                ListViewDataItem dataItem = (ListViewDataItem)e.Item;

                //lvProducts = (ListView)Cache["lvProducts"];
                int ProductId =
                    int.Parse(lvProducts.DataKeys[dataItem.DisplayIndex].Value.ToString());

                if (String.Equals(e.CommandName, "DeleteProduct"))
                {
                    adpProduct.UpdateProductType("Deleted", ProductId);
                }
                else if (String.Equals(e.CommandName, "UpdateProduct"))
                {
                    //Response.Redirect("~/Default.aspx");
                    Response.Redirect("~/Product.aspx?ProductId=" + ProductId);
                }
                BindData();
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }
コード例 #2
0
ファイル: Default.aspx.cs プロジェクト: pasamirb/FinalProject
        /// <summary> Method to for OnClick of ListView Items. </summary>
        /// <returns>void.</returns>
        protected void lvProducts_OnItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (user.UserId != 0)
            {
                if (String.Equals(e.CommandName, "Enquiry"))
                {
                    // Verify that the employee ID is not already in the list. If not, add the
                    // employee to the list.
                    /// <summary> Store the ListViewDataItem. </summary>
                    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

                    /// <summary> Store the Product ID. </summary>
                    //tblProductDetails[dataItem.DataItemIndex];
                    int ProductId =
                        int.Parse(lvProducts.DataKeys[dataItem.DisplayIndex].Value.ToString());
                    /// <summary> Store the Product User ID. </summary>
                    int ProductUserId = int.Parse(e.CommandArgument.ToString());
                    tblMessageProductUser = adpMessageProductUser.GetMessages(ProductUserId, ProductId);
                    if (tblMessageProductUser.Count > 0)
                    {
                        Response.Redirect("~/Messages.aspx");
                    }
                    else
                    {
                        adpMessage.Insert("Hey, I am interesterd in this product. Is it still available?", user.UserId, ProductUserId, ProductId);
                    }
                    //System.Diagnostics.Debug.WriteLine("Parameter" + param);
                }
                else if (String.Equals(e.CommandName, "Buy"))
                {
                    /// <summary> Store the ListViewDataItem. </summary>
                    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

                    //tblProductDetails[dataItem.DataItemIndex];
                    /// <summary> Store the Product ID. </summary>
                    int ProductId =
                        int.Parse(lvProducts.DataKeys[dataItem.DisplayIndex].Value.ToString());
                    /// <summary> Store the Product User ID. </summary>
                    int ProductUserId = int.Parse(e.CommandArgument.ToString());

                    /// <summary> Store the ROW object. </summary>
                    FinalProjectDataset.ProductDetailRow row = tblProductDetails[dataItem.DisplayIndex];
                    if (string.Equals(row.ProductType, "Available"))
                    {
                        adpUserProduct.Insert(user.UserId, ProductId, 1);
                        if (adpUserProduct.GetTotalQtyByProduct(ProductId) == row.ProductQty)
                        {
                            //row.ProductType = "Sold";
                            adpProduct.UpdateProductType("Sold", row.ProductId);
                            tblProductDetails[dataItem.DisplayIndex].ProductType = "Sold";
                            //Response.Redirect("");
                        }
                    }
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }