protected void btnUpdate_Click(object sender, EventArgs e)
        {
            u.Email = tbEmail.Text;

            Membership.UpdateUser(u);
            Int32    day   = Int32.Parse(ddlDay.SelectedValue);
            Int32    month = Int32.Parse(ddlMonth.SelectedValue);
            Int32    year  = Int32.Parse(ddlYear.SelectedValue);
            Int32    Age   = DateTime.Now.Year - year;
            DateTime DOB   = new DateTime(year, month, day);

            if (artist != null)
            {
                artist.ContactNo   = tbContact.Text;
                artist.Name        = tbName.Text;
                artist.Address     = tbAddress.Text;
                artist.Age         = Age;
                artist.DateOfBirth = DOB;
                _db.ARTISTs.Attach(artist);
                _db.Entry(artist).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
            }
            else
            {
                customer.ContactNo   = tbContact.Text;
                customer.Name        = tbName.Text;
                customer.Address     = tbAddress.Text;
                customer.Age         = Age;
                customer.DateOfBirth = DOB;
                _db.CUSTOMERs.Attach(customer);
                _db.Entry(customer).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
            }
            Response.Redirect("~/UpdateProfile.aspx");
        }
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            //Get the reference of the clicked button.
            Button button = (sender as Button);

            //Get the command argument
            string[] commandArgument = button.CommandArgument.ToString().Split(';');

            int wishlistId = Convert.ToInt32(commandArgument[0]);
            int productId  = Convert.ToInt32(commandArgument[1]);

            //System.Diagnostics.Debug.WriteLine(wishlistId + "," + productId);
            ShoppingCart sc = new ShoppingCart();

            sc.AddToCart(productId);

            GalleryEntities1 db = new GalleryEntities1();
            var item            = new WISHLIST {
                WishlistId = wishlistId
            };

            db.Entry(item).State = EntityState.Deleted;
            try
            {
                db.SaveChanges();
                Response.Redirect("~/Wishlistaspx.aspx");
            }
            catch (DbUpdateConcurrencyException)
            {
                ModelState.AddModelError("",
                                         String.Format("Item with id {0} no longer exists in the database.", wishlistId));
            }
        }
        protected void DeleteButton_Click(object sender, ImageClickEventArgs e)
        {
            //Get the reference of the clicked button.
            ImageButton button = (sender as ImageButton);

            //Get the command argument
            string commandArgument = button.CommandArgument;

            int wishlistid = int.Parse(commandArgument);

            GalleryEntities1 db = new GalleryEntities1();
            var item            = new WISHLIST {
                WishlistId = wishlistid
            };

            db.Entry(item).State = EntityState.Deleted;
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                ModelState.AddModelError("",
                                         String.Format("Item with id {0} no longer exists in the database.", wishlistid));
            }
        }
Beispiel #4
0
        protected void CreateUserWizard1_CreatedUser(Object sender, EventArgs e)
        {
            MembershipUser newUser    = Membership.GetUser(CreateUserWizard1.UserName);
            Guid           newUserId  = (Guid)newUser.ProviderUserKey;
            string         Name       = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Name")).Text;
            string         Address    = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Address")).Text;
            string         Contact    = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Contact")).Text;
            DropDownList   ddlYear    = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Year");
            DropDownList   ddlMonth   = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Month");
            DropDownList   ddlDay     = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Day");
            Int32          day        = Int32.Parse(ddlDay.SelectedValue);
            Int32          month      = Int32.Parse(ddlMonth.SelectedValue);
            Int32          year       = Int32.Parse(ddlYear.SelectedValue);
            Int32          Age        = DateTime.Now.Year - year;
            DateTime       DOB        = new DateTime(year, month, day);
            DropDownList   registerAs = (DropDownList)(CreateUserWizardStep1.ContentTemplateContainer.FindControl("registerAs"));
            String         value      = registerAs.SelectedValue;


            using (SqlConnection myConnection = new SqlConnection(connectionString))
            {
                SqlCommand mycommand = null;
                if (value.Equals("Members"))
                {
                    mycommand = new SqlCommand("new_user", myConnection);
                }
                else
                {
                    mycommand = new SqlCommand("new_artist", myConnection);
                }
                mycommand.CommandType = System.Data.CommandType.StoredProcedure;
                mycommand.Parameters.Add("Name", SqlDbType.VarChar).Value            = Name;
                mycommand.Parameters.Add("Address", SqlDbType.VarChar).Value         = Address;
                mycommand.Parameters.Add("DateOfBirth", SqlDbType.Date).Value        = DOB.Date;
                mycommand.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value = newUserId;
                mycommand.Parameters.Add("Age", SqlDbType.Int).Value         = Age;
                mycommand.Parameters.Add("Contact", SqlDbType.VarChar).Value = Contact;
                myConnection.Open();
                mycommand.ExecuteNonQuery();


                myConnection.Close();
                Roles.AddUserToRole(CreateUserWizard1.UserName, value);
            }

            GalleryEntities1 _db  = new GalleryEntities1();
            CART             cart = new Models.CART();

            cart.UserId   = newUserId;
            cart.Date     = DateTime.Now;
            cart.Discount = 0;

            _db.CARTs.Add(cart);
            _db.SaveChanges();
            HttpContext.Current.Session["CartId"] = cart.CartId;
        }
Beispiel #5
0
        protected void btnPayment_Click(object sender, EventArgs e)
        {
            GalleryEntities1 _db       = new GalleryEntities1();
            ShoppingCart     cs        = new ShoppingCart();
            List <CARTITEM>  orderItem = cs.GetCartItems();

            ORDER order = new ORDER
            {
                date     = DateTime.Now,
                discount = 0,
                UserId   = (Guid)u.ProviderUserKey,
                //PaymentId = null,
                status = "pending"
            };

            _db.ORDERs.Add(order);
            _db.SaveChanges();


            for (int i = 0; i < orderItem.Count(); i++)
            {
                ORDERDETAIL orderDetail = new ORDERDETAIL();


                orderDetail.ProductId  = orderItem[i].ProductId;
                orderDetail.OrderId    = order.OrderId;
                orderDetail.Quantity   = orderItem[i].Quantity;
                orderDetail.TotalPrice = (orderItem[i].Quantity * _db.PRODUCTs.Find(orderItem[i].ProductId).Price);

                _db.ORDERDETAILs.Add(orderDetail);
                _db.SaveChanges();
            }
            Session["total"]   = cs.GetTotal().ToString();
            Session["orderid"] = order.OrderId.ToString();



            Response.Redirect("~/Payment.aspx");
        }
        protected void btnWishlist_Click(object sender, EventArgs e)
        {
            bool loginStatus = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            if (loginStatus)
            {
                GalleryEntities1 _db = new GalleryEntities1();
                int  productID       = Convert.ToInt32(Request.QueryString["ProductID"]);
                Guid userId          = (Guid)Membership.GetUser().ProviderUserKey;

                var existingItem = from w in _db.WISHLISTs
                                   where w.ProductId == productID && w.UserId == userId
                                   select w;

                if (existingItem.Any())
                {
                    successAdd.Style["display"] = "none";
                    failedAdd.Style["display"]  = "block";
                    System.Diagnostics.Debug.WriteLine("exist");
                }
                else
                {
                    WISHLIST item = new WISHLIST();
                    item.ProductId = productID;
                    item.UserId    = userId;

                    if (ModelState.IsValid)
                    {
                        // Save changes here

                        _db.WISHLISTs.Add(item);
                        _db.SaveChanges();

                        successAdd.Style["display"] = "block";
                        failedAdd.Style["display"]  = "none";
                    }
                    System.Diagnostics.Debug.WriteLine("not exist");
                }
            }
            else
            {
                MasterPage         masterPage          = this.Master as MasterPage;
                ModalPopupExtender ModalPopupExtender1 = (ModalPopupExtender)masterPage.FindControl("ModalPopupExtender1");
                ModalPopupExtender1.Show();
            }
        }
Beispiel #7
0
 //Update the item in the database
 public void UpdateItem(int updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new GalleryEntities1())
     {
         try
         {
             var myItem = (from c in _db.CARTITEMs where c.CartId == updateCartID && c.PRODUCT.ProductId == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Beispiel #8
0
        public void FormViewPayment_InsertItem()
        {
            String  orderid    = (String)Session["orderid"];
            int     orderidInt = Convert.ToInt32(Session["orderid"]);
            TextBox address    = (TextBox)FormViewPayment.FindControl("txtboxAddress");

            Session["address"] = address.Text;



            using (var _db1 = new GalleryEntities1())
            {
                try
                {
                    var myItem = (from c in _db1.ORDERs where c.OrderId == orderidInt select c).FirstOrDefault();
                    if (myItem != null)
                    {
                        myItem.status = "Paid";
                        _db1.SaveChanges();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Update Order Status - " + exp.Message.ToString(), exp);
                }


                PAYMENT payment = new PAYMENT();
                TryUpdateModel(payment);
                payment.Date    = DateTime.Now;
                payment.OrderId = orderid;
                // Guid userId = (Guid)Membership.GetUser().ProviderUserKey;
                if (ModelState.IsValid)
                {
                    GalleryEntities1 _db = new GalleryEntities1();
                    _db.PAYMENTs.Add(payment);
                    _db.SaveChanges();
                }

                Response.Redirect("~/PaymentSucess.aspx");
            }
        }
Beispiel #9
0
 //Remove the item from the database
 public void RemoveItem(int removeCartID, int removeProductID)
 {
     using (var _db = new GalleryEntities1())
     {
         try
         {
             var myItem = (from c in _db.CARTITEMs where c.CartId == removeCartID && c.PRODUCT.ProductId == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 _db.CARTITEMs.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Beispiel #10
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void fvAddItem_UpdateItem([QueryString] int ProductId)
        {
            Testing.Models.PRODUCT item = null;

            GalleryEntities1 _db = new GalleryEntities1();

            item = _db.PRODUCTs.Find(ProductId);
            // Load the item here, e.g. item = MyDataLayer.Find(id);
            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", ProductId));
                return;
            }

            TryUpdateModel(item);


            //To convert the image to binary
            FileUpload     imageUpload   = (FileUpload)fvAddItem.FindControl("imageUpload");
            HttpPostedFile postedFile    = imageUpload.PostedFile;
            string         fileName      = Path.GetFileName(postedFile.FileName);
            string         fileExtension = Path.GetExtension(fileName);
            int            fileSize      = postedFile.ContentLength;

            if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" ||
                fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png")
            {
                Stream       stream       = postedFile.InputStream;
                BinaryReader binaryReader = new BinaryReader(stream);
                byte[]       bytes        = binaryReader.ReadBytes((int)stream.Length);
                item.Image = bytes;
            }

            if (ModelState.IsValid)
            {
                // Save changes here, e.g. MyDataLayer.SaveChanges();
                _db.SaveChanges();
                Response.Redirect("~/UpdateGallery.aspx");
            }
        }
Beispiel #11
0
        public void fvAddItem_InsertItem()
        {
            var item = new PRODUCT();

            TryUpdateModel(item);

            //Get the username for the currently logged in user
            Guid userId = (Guid)Membership.GetUser().ProviderUserKey;

            item.ArtistId = userId;

            //To convert the image to binary
            FileUpload     imageUpload   = (FileUpload)fvAddItem.FindControl("imageUpload");
            HttpPostedFile postedFile    = imageUpload.PostedFile;
            string         fileName      = Path.GetFileName(postedFile.FileName);
            string         fileExtension = Path.GetExtension(fileName);
            int            fileSize      = postedFile.ContentLength;

            if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" ||
                fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png")
            {
                Stream stream = postedFile.InputStream;
                byte[] bytes  = ResizeUploadedImage(stream);
                item.Image = bytes;
            }

            item.Description = item.Description.Replace(Environment.NewLine, "<br />");

            if (ModelState.IsValid)
            {
                // Save changes here
                GalleryEntities1 _db = new GalleryEntities1();
                _db.PRODUCTs.Add(item);
                _db.SaveChanges();
                Response.Redirect("~/ViewGallery.aspx");
            }
        }
Beispiel #12
0
        public void fvAddProduct_InsertItem()
        {
            PRODUCT item = new PRODUCT();

            TryUpdateModel(item);

            //Get the username for the currently logged in user
            MembershipUser membershipUser = Membership.GetUser("Username");
            Guid           userId         = (Guid)membershipUser.ProviderUserKey;

            item.ArtistId = userId;
            Image productImage = (Image)fvAddProduct.FindControl("productImage");

            byte[] imgData = System.IO.File.ReadAllBytes(Server.MapPath(productImage.ImageUrl));
            item.Image = imgData;
            if (ModelState.IsValid)
            {
                // Save changes here
                GalleryEntities1 _db = new GalleryEntities1();
                _db.PRODUCTs.Add(item);
                _db.SaveChanges();
                Response.Redirect("~/ViewGallery.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (ShoppingCart shoppingCart = new ShoppingCart())
            {
                shoppingCart.EmptyCart();
            }

            int       orderid = Convert.ToInt32(Session["orderid"]);
            DataTable dt      = new DataTable();

            dt.Columns.AddRange(new DataColumn[4] {
                new DataColumn("ProductId", typeof(int)),
                new DataColumn("Name", typeof(string)),
                new DataColumn("Quantity", typeof(int)),
                new DataColumn("TotalPrice", typeof(Double))
            });

            GalleryEntities1   _db          = new GalleryEntities1();
            List <ORDERDETAIL> orderdetails = _db.ORDERDETAILs.Where(
                c => c.OrderId == orderid).ToList();

            for (int i = 0; i < orderdetails.Count; i++)
            {
                PRODUCT product         = _db.PRODUCTs.Find(orderdetails[i].ProductId);
                String  stockCount      = product.Stock;
                int     stockCountValue = Convert.ToInt32(stockCount);
                stockCountValue--;
                stockCount    = stockCountValue.ToString();
                product.Stock = stockCount;
                _db.SaveChanges();
                dt.Rows.Add(orderdetails[i].ProductId, product.Name, orderdetails[i].Quantity, orderdetails[i].TotalPrice);
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            double total1 = Convert.ToDouble(Session["total"]);

            // Label lblTotal = (Label)GridView1.FindControl("lblTotal");
            lblTotal.Text = String.Format("{0:0.00}", total1);


            //for receipt email
            string    companyName = "Gallery Website";
            string    address     = Convert.ToString(Session["address"]);
            int       orderid1    = Convert.ToInt32(Session["orderid"]);
            int       orderNo     = orderid1;
            DataTable dt1         = new DataTable();

            dt1.Columns.AddRange(new DataColumn[4] {
                new DataColumn("ProductId", typeof(int)),
                new DataColumn("Name", typeof(string)),
                new DataColumn("Quantity", typeof(int)),
                new DataColumn("Total Price", typeof(Double))
            });

            GalleryEntities1   _db1          = new GalleryEntities1();
            List <ORDERDETAIL> orderdetails1 = _db1.ORDERDETAILs.Where(
                c => c.OrderId == orderid1).ToList();

            for (int i = 0; i < orderdetails1.Count; i++)
            {
                PRODUCT product = _db1.PRODUCTs.Find(orderdetails1[i].ProductId);

                dt1.Rows.Add(orderdetails1[i].ProductId, product.Name, orderdetails1[i].Quantity, orderdetails1[i].TotalPrice);
            }

            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    StringBuilder sb = new StringBuilder();

                    //Generate Invoice/Receipt Header.
                    sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>");
                    sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>Receipt</b></td></tr>");
                    sb.Append("<tr><td colspan = '2'></td></tr>");
                    sb.Append("<tr><td><b>Order No: </b>");
                    sb.Append(orderNo);
                    sb.Append("</td><td align = 'right'><b>Date: </b>");
                    sb.Append(DateTime.Now);
                    sb.Append(" </td></tr>");
                    sb.Append("<tr><td><b>Company Name: </b>");
                    sb.Append(companyName);
                    sb.Append("</td><td align = 'right'><b>Address: </b>");
                    sb.Append(address);
                    sb.Append("</td></tr>");
                    sb.Append("</table>");
                    sb.Append("<br />");

                    //Generate Invoice (Bill) Items Grid.
                    sb.Append("<table border = '1'>");
                    sb.Append("<tr>");
                    foreach (DataColumn column in dt1.Columns)
                    {
                        sb.Append("<th>");
                        sb.Append(column.ColumnName);
                        sb.Append("</th>");
                    }
                    sb.Append("</tr>");
                    foreach (DataRow row in dt1.Rows)
                    {
                        sb.Append("<tr>");
                        foreach (DataColumn column in dt1.Columns)
                        {
                            sb.Append("<td>");
                            sb.Append(row[column]);
                            sb.Append("</td>");
                        }
                        sb.Append("</tr>");
                    }
                    sb.Append("<tr><td align = 'right' colspan = '");
                    sb.Append(dt1.Columns.Count - 1);
                    sb.Append("'>Total</td>");
                    sb.Append("<td>");
                    double total2 = Convert.ToDouble(Session["total"]);
                    sb.Append(String.Format("{0:0.00}", total2));
                    sb.Append("</td>");
                    sb.Append("</tr></table>");

                    //Export HTML String as PDF.
                    StringReader sr         = new StringReader(sb.ToString());
                    Document     pdfDoc1    = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                    HTMLWorker   htmlparser = new HTMLWorker(pdfDoc1);
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        PdfWriter writer = PdfWriter.GetInstance(pdfDoc1, memoryStream);
                        pdfDoc1.Open();
                        htmlparser.Parse(sr);
                        pdfDoc1.Close();
                        byte[] bytes = memoryStream.ToArray();
                        memoryStream.Close();

                        MembershipUser u = Membership.GetUser(User.Identity.Name);
                        _db = new Models.GalleryEntities1();

                        MailMessage mm = new MailMessage("*****@*****.**", u.Email);
                        mm.Subject = "Receipt PDF";
                        mm.Body    = "Receipt PDF Attachment";
                        mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "ReceiptPDF.pdf"));
                        mm.IsBodyHtml = true;
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host      = "smtp.gmail.com";
                        smtp.EnableSsl = true;
                        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                        NetworkCred.UserName       = "******";
                        NetworkCred.Password       = "******";
                        smtp.UseDefaultCredentials = true;
                        smtp.Credentials           = NetworkCred;
                        smtp.Port = 587;
                        try {
                            smtp.Send(mm);
                        }catch (Exception ex)
                        {
                            Console.Write(ex.StackTrace);
                        }
                    }
                }
            }
        }