Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["myRecent"] == null)
            {
                myRecent            = new RecentData();
                Session["myRecent"] = myRecent;
            }
            myRecent = (RecentData)Session["myRecent"];

            if (myRecent.Items.Count == 0)
            {
                recent.Style.Add("display", "none");
            }
            else
            {
                imageListView.DataSource = myRecent.Items;
                imageListView.DataBind();
            }
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null)
            {
                Response.Redirect("Gallery.aspx");
            }
            else
            {
                if (Session["myCart"] == null)
                {
                    myCart            = new CartData();
                    Session["myCart"] = myCart;
                }
                myCart = (CartData)Session["myCart"];

                if (Session["myRecent"] == null)
                {
                    myRecent            = new RecentData();
                    Session["myRecent"] = myRecent;
                }
                myRecent = (RecentData)Session["myRecent"];

                int    imageID = Convert.ToInt32(Request.QueryString["id"].ToString());
                string sql     = "SELECT imageID, imageName, imageDesc, imageType, imagePrice, imageDateUploaded, imageLocation, "
                                 + "concat(artistFName, ' ', artistLName) as artistName FROM Image, Artist WHERE Image.imageID = @imageID AND Artist.artistID = Image.artistID";

                using (SqlConnection con = new SqlConnection(Helper.sqlCon))
                {
                    con.Open();

                    SqlCommand   cmd = new SqlCommand(sql, con);
                    SqlParameter m   = new SqlParameter("@imageID", imageID);
                    cmd.Parameters.Add(m);

                    SqlDataReader dr = cmd.ExecuteReader();

                    int cartQty = 0;
                    for (int i = 0; i < myCart.Items.Count; i++)
                    {
                        if (imageID == myCart.Items[i].imageID)
                        {
                            cartQty = myCart.Items[i].qty;
                        }
                    }

                    RangeValidatorQty.MaximumValue = (CheckStock(imageID, Helper.sqlCon) - cartQty).ToString();

                    if (RangeValidatorQty.MaximumValue == "0")
                    {
                        txtQty.Text     = "0";
                        btnCart.Enabled = false;
                    }

                    try
                    {
                        while (dr.Read())
                        {
                            lblID.Text     = dr.GetInt32(0).ToString();
                            lblName.Text   = dr.GetString(1);
                            lblDesc.Text   = dr.GetString(2);
                            lblType.Text   = dr.GetString(3);
                            lblPrice.Text  = "RM" + dr.GetSqlMoney(4).ToString();
                            lblDate.Text   = dr.GetDateTime(5).ToShortDateString();
                            img.Src        = "/Images/" + dr.GetString(6) + "?" + DateTime.Now.Ticks.ToString();
                            lblArtist.Text = dr.GetString(7);
                        }
                    }
                    catch (Exception ex) { }
                    finally
                    {
                        con.Close();
                        dr.Close();
                    }
                }

                DataTable dt = new DataTable();
                using (SqlConnection con = new SqlConnection(Helper.sqlCon))
                {
                    con.Open();
                    SqlCommand   cmd = new SqlCommand(sql, con);
                    SqlParameter m   = new SqlParameter("@imageID", imageID);

                    cmd.Parameters.Add(m);
                    dt.Load(cmd.ExecuteReader());
                    con.Close();
                }

                DataRow row = dt.Rows[0];

                myRecent.Insert(new RecentItem(imageID, row["imageName"].ToString(), row["imageLocation"].ToString(), Double.Parse(row["imagePrice"].ToString())));
            }
        }