Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (UserLogin.getSession().Equals(""))
     {
         Response.Redirect("UserLogin.aspx");
     }
     else
     {
         try
         {
             errorMsg.Visible = false;
             SqlCommand     cmd     = new SqlCommand("select * from Product where email='" + UserLogin.getSession() + "'", con);
             SqlDataAdapter adpData = new SqlDataAdapter(cmd);
             DataTable      dt      = new DataTable();
             adpData.Fill(dt);
             DataList2.DataSource = dt;
             DataList2.DataBind();
             con.Close();
         }
         catch (Exception)
         {
             ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('No data found regards given image id..');", true);
         }
     }
 }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (txtPrice.Text.Equals("") || txtQuantity.Text.Equals("") || startDate.Text.Equals("") || endDate.Text.Equals("") || imgFile.Equals(""))
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please fill all the fields.');", true);
            }
            else
            {
                string path = Path.GetFileName(imgFile.PostedFile.FileName);
                imgFile.SaveAs(@"C:\Users\user\source\repos\Sales_pk\Sales_pk\User_Interface_Layer\Product_Images\" + path);
                int quan  = Convert.ToInt32(txtQuantity.Text);
                int pric  = Convert.ToInt32(txtPrice.Text);
                var strt  = Convert.ToDateTime(startDate.Text);
                var end   = Convert.ToDateTime(endDate.Text);
                var today = DateTime.Now;
                if ((quan > 0) && (pric > 0) && (strt >= today) && (end > today) && (end > strt))
                {
                    Product product = new Product();
                    using (Entities db = new Entities())
                    {
                        var  loggedin = UserLogin.getSession();
                        User user     = db.Users.Where(x => x.email == loggedin).FirstOrDefault();

                        var imagPath = "Product_Images/" + path;
                        var pic      = db.Products.Where(x => x.img == imagPath).Any();
                        if (pic == false)
                        {
                            product.email      = user.email;
                            product.size       = sizeDdl.SelectedItem.Text;
                            product.price      = pric;
                            product.quantity   = quan;
                            product.start_date = strt;
                            product.end_date   = end;
                            product.img        = "Product_Images/" + path;
                            product.gender     = genderDdl.SelectedItem.Text;
                            product.location   = user.location;
                            product.city       = user.city;
                            product.brand      = user.brand;

                            db.Products.Add(product);
                            db.SaveChanges();

                            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Data Successfully added.');", true);
                            txtPrice.Text    = "";
                            txtQuantity.Text = "";
                            startDate.Text   = "";
                            endDate.Text     = "";
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('This image already uploaded. Please rename or or make sure about it.');", true);
                        }
                    }
                }
                else
                {
                    if (quan > 0)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Quantity.');", true);
                    }
                    if ((pric > 0))
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Price.');", true);
                    }
                    if (strt >= today)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid Start. Must after or today');", true);
                    }
                    if (end >= today)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid end. Must after today or start date');", true);
                    }
                }
            }
        }