protected void addToCartButton_Click(object sender, EventArgs e)
        {
            List <CartObject> newCartObj = new List <CartObject>();

            //Hashtable selectedItemsHashtable = new Hashtable();

            //string file = "C:\\Users\\Kiran\\Desktop\\userCred.xml";
            //Hashtable selectedItemsHashtable = new Hashtable();


            // Loop through each item.
            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected)
                {
                    // If the item is selected, add the value to the list.
                    CartObject tempCartObject = new CartObject();
                    tempCartObject.itemName  = item.Value.ToString();
                    tempCartObject.itemPrice = Convert.ToDouble(allItemsHashtable[tempCartObject.itemName]);
                    //selectedItemsHashtable.Add(tempCartObject.itemName, tempCartObject.itemPrice);
                    newCartObj.Add(tempCartObject);
                }
            }
            int size = newCartObj.Count;

            size         += Convert.ToUInt16(Session["cartCount"].ToString());
            cartLink.Text = "Cart ( " + size + " )";
            updateCartFile(newCartObj);
        }
        protected void OkButton_Click(object sender, EventArgs e)
        {
            string file = "C:\\Users\\Kiran\\Desktop\\Inventory.xml";
            if ((IdTextBox.Text == null) || (NameTextBox.Text == null) || (PriceTextBox.Text == null) || (QauntityTextBox.Text == null))
            {

                ErrorLabel.Visible = true;
            }
            else {
                CartObject item = new CartObject();
                item.itemId = IdTextBox.Text;
                item.itemName = NameTextBox.Text;
                item.itemPrice = Convert.ToDouble(PriceTextBox.Text);
                item.itemQuantity = Convert.ToUInt16(QauntityTextBox.Text);

                if (!File.Exists(file))
                {
                    XmlTextWriter xWriter = new XmlTextWriter(file, Encoding.UTF8);
                    xWriter.Formatting = Formatting.Indented;
                    xWriter.WriteStartElement("items");
                    xWriter.WriteStartElement("item");
                    xWriter.WriteStartElement("itemId");
                    xWriter.WriteString(item.itemId);
                    xWriter.WriteEndElement();
                    xWriter.WriteStartElement("itemName");
                    xWriter.WriteString(item.itemName);
                    xWriter.WriteEndElement();
                    xWriter.WriteStartElement("itemPrice");
                    xWriter.WriteString(Convert.ToString(item.itemPrice));
                    xWriter.WriteEndElement();
                    xWriter.WriteStartElement("itemQuantity");
                    xWriter.WriteString(Convert.ToString(item.itemQuantity));
                    xWriter.WriteEndElement();
                    xWriter.Close();
                }
                else
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(file);
                    XmlNode itemNode = doc.CreateElement("item");
                    XmlNode itemIdNode = doc.CreateElement("itemId");
                    itemIdNode.InnerText = item.itemId;
                    XmlNode itemNameNode = doc.CreateElement("itemName");
                    itemNameNode.InnerText = item.itemName;
                    XmlNode itemPriceNode = doc.CreateElement("itemPrice");
                    itemPriceNode.InnerText = Convert.ToString(item.itemPrice);
                    XmlNode itemQuantityNode = doc.CreateElement("itemQuantity");
                    itemQuantityNode.InnerText = Convert.ToString(item.itemQuantity);
                    itemNode.AppendChild(itemIdNode);
                    itemNode.AppendChild(itemNameNode);
                    itemNode.AppendChild(itemPriceNode);
                    itemNode.AppendChild(itemQuantityNode);
                    doc.DocumentElement.AppendChild(itemNode);
                    doc.Save(file);

                }

            }
        }
        protected void OkButton_Click(object sender, EventArgs e)
        {
            string file = "C:\\Users\\Kiran\\Desktop\\Inventory.xml";

            if ((IdTextBox.Text == null) || (NameTextBox.Text == null) || (PriceTextBox.Text == null) || (QauntityTextBox.Text == null))
            {
                ErrorLabel.Visible = true;
            }
            else
            {
                CartObject item = new CartObject();
                item.itemId       = IdTextBox.Text;
                item.itemName     = NameTextBox.Text;
                item.itemPrice    = Convert.ToDouble(PriceTextBox.Text);
                item.itemQuantity = Convert.ToUInt16(QauntityTextBox.Text);

                if (!File.Exists(file))
                {
                    XmlTextWriter xWriter = new XmlTextWriter(file, Encoding.UTF8);
                    xWriter.Formatting = Formatting.Indented;
                    xWriter.WriteStartElement("items");
                    xWriter.WriteStartElement("item");
                    xWriter.WriteStartElement("itemId");
                    xWriter.WriteString(item.itemId);
                    xWriter.WriteEndElement();
                    xWriter.WriteStartElement("itemName");
                    xWriter.WriteString(item.itemName);
                    xWriter.WriteEndElement();
                    xWriter.WriteStartElement("itemPrice");
                    xWriter.WriteString(Convert.ToString(item.itemPrice));
                    xWriter.WriteEndElement();
                    xWriter.WriteStartElement("itemQuantity");
                    xWriter.WriteString(Convert.ToString(item.itemQuantity));
                    xWriter.WriteEndElement();
                    xWriter.Close();
                }
                else
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(file);
                    XmlNode itemNode   = doc.CreateElement("item");
                    XmlNode itemIdNode = doc.CreateElement("itemId");
                    itemIdNode.InnerText = item.itemId;
                    XmlNode itemNameNode = doc.CreateElement("itemName");
                    itemNameNode.InnerText = item.itemName;
                    XmlNode itemPriceNode = doc.CreateElement("itemPrice");
                    itemPriceNode.InnerText = Convert.ToString(item.itemPrice);
                    XmlNode itemQuantityNode = doc.CreateElement("itemQuantity");
                    itemQuantityNode.InnerText = Convert.ToString(item.itemQuantity);
                    itemNode.AppendChild(itemIdNode);
                    itemNode.AppendChild(itemNameNode);
                    itemNode.AppendChild(itemPriceNode);
                    itemNode.AppendChild(itemQuantityNode);
                    doc.DocumentElement.AppendChild(itemNode);
                    doc.Save(file);
                }
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<CartObject> cartItems = new List<CartObject>();
                string emailId = "*****@*****.**";
                string cartFile = "C:\\Users\\Kiran\\Desktop\\cart.xml";
                XmlDocument doc = new XmlDocument();
                doc.Load(cartFile);

                foreach (XmlNode xNode in doc.SelectNodes("carts/cart"))
                {
                    //TextBox1.Text += "Entered for each loop<br/>";
                    //XmlNode cartNode = xNode.SelectSingleNode("cart");
                    if (xNode.Attributes != null)
                    {
                        //TextBox1.Text += "Found attributes<br/>";
                        if (xNode.Attributes["emailId"].Value == emailId)
                        {
                            //TextBox1.Text += "Found email ID<br/>";
                            XmlNodeList booksNodeList = xNode.ChildNodes;

                            foreach (XmlNode xBookNode in booksNodeList)
                            {

                                //TextBox1.Text += "Printing books<br/>";
                                //added to the list to use later which may come handy while searching
                                CartObject tempCartObject = new CartObject();

                                tempCartObject.itemName = xBookNode.SelectSingleNode("name").InnerText;
                                tempCartObject.itemPrice = Convert.ToDouble(xBookNode.SelectSingleNode("price").InnerText);
                                tempCartObject.itemQuantity = Convert.ToUInt16(xBookNode.SelectSingleNode("quantity").InnerText);
                                cartItems.Add(tempCartObject);

                                //adding to the checkbox list to display on page
                                ListItem item = new ListItem();
                                item.Text = tempCartObject.itemName + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemPrice + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemQuantity;
                                item.Value = tempCartObject.itemName;
                                CheckBoxList1.Items.Add(item);

                            }

                        }
                    }

                }

            }
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List <CartObject> cartItems = new List <CartObject>();
                string            emailId   = "*****@*****.**";
                string            cartFile  = "C:\\Users\\Kiran\\Desktop\\cart.xml";
                XmlDocument       doc       = new XmlDocument();
                doc.Load(cartFile);


                foreach (XmlNode xNode in doc.SelectNodes("carts/cart"))
                {
                    //TextBox1.Text += "Entered for each loop<br/>";
                    //XmlNode cartNode = xNode.SelectSingleNode("cart");
                    if (xNode.Attributes != null)
                    {
                        //TextBox1.Text += "Found attributes<br/>";
                        if (xNode.Attributes["emailId"].Value == emailId)
                        {
                            //TextBox1.Text += "Found email ID<br/>";
                            XmlNodeList booksNodeList = xNode.ChildNodes;

                            foreach (XmlNode xBookNode in booksNodeList)
                            {
                                //TextBox1.Text += "Printing books<br/>";
                                //added to the list to use later which may come handy while searching
                                CartObject tempCartObject = new CartObject();

                                tempCartObject.itemName     = xBookNode.SelectSingleNode("name").InnerText;
                                tempCartObject.itemPrice    = Convert.ToDouble(xBookNode.SelectSingleNode("price").InnerText);
                                tempCartObject.itemQuantity = Convert.ToUInt16(xBookNode.SelectSingleNode("quantity").InnerText);
                                cartItems.Add(tempCartObject);

                                //adding to the checkbox list to display on page
                                ListItem item = new ListItem();
                                item.Text  = tempCartObject.itemName + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemPrice + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemQuantity;
                                item.Value = tempCartObject.itemName;
                                CheckBoxList1.Items.Add(item);
                            }
                        }
                    }
                }
            }
        }
        protected void addToCartButton_Click(object sender, EventArgs e)
        {
            List<CartObject> newCartObj = new List<CartObject>();
            //Hashtable selectedItemsHashtable = new Hashtable();

            //string file = "C:\\Users\\Kiran\\Desktop\\userCred.xml";
            //Hashtable selectedItemsHashtable = new Hashtable();

            // Loop through each item.
            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected)
                {
                    // If the item is selected, add the value to the list.
                    CartObject tempCartObject = new CartObject();
                    tempCartObject.itemName = item.Value.ToString();
                    tempCartObject.itemPrice = Convert.ToDouble(allItemsHashtable[tempCartObject.itemName]);
                    //selectedItemsHashtable.Add(tempCartObject.itemName, tempCartObject.itemPrice);
                    newCartObj.Add(tempCartObject);

                }

            }
            int size = newCartObj.Count;
            size += Convert.ToUInt16(Session["cartCount"].ToString());
            cartLink.Text = "Cart ( " + size + " )";
            updateCartFile(newCartObj);
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Double finalAmount = 0.0;

            if (!IsPostBack)
            {
                List <CartObject> cartItems = new List <CartObject>();
                string            emailId   = "*****@*****.**";
                string            cartFile  = "C:\\Users\\Kiran\\Desktop\\cart.xml";
                XmlDocument       doc       = new XmlDocument();
                doc.Load(cartFile);


                foreach (XmlNode xNode in doc.SelectNodes("carts/cart"))
                {
                    //XmlNode cartNode = xNode.SelectSingleNode("cart");
                    if (xNode.Attributes != null)
                    {
                        if (xNode.Attributes["emailId"].Value == emailId)
                        {
                            XmlNodeList booksNodeList = xNode.ChildNodes;

                            foreach (XmlNode xBookNode in booksNodeList)
                            {
                                //added to the list to use later which may come handy while searching
                                CartObject tempCartObject = new CartObject();

                                tempCartObject.itemName  = xBookNode.SelectSingleNode("name").InnerText;
                                tempCartObject.itemPrice = Convert.ToDouble(xBookNode.SelectSingleNode("price").InnerText);
                                finalAmount += tempCartObject.itemPrice;
                                tempCartObject.itemQuantity = Convert.ToUInt16(xBookNode.SelectSingleNode("quantity").InnerText);
                                cartItems.Add(tempCartObject);

                                //adding to the checkbox list to display on page
                                ListItem item = new ListItem();
                                item.Text  = tempCartObject.itemName + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemPrice + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemQuantity;
                                item.Value = tempCartObject.itemName;
                                ListBox1.Items.Add(item);
                                //CheckBoxList1.Items.Add(item);
                            }
                        }
                    }
                }



                if (!Page.IsPostBack)
                {
                    DataTable dtItems = new DataTable();
                    dtItems.Columns.Add("itemCount");
                    dtItems.Columns.Add("itemValue");
                    dtItems.Columns.Add("quantityValue");
                    dtItems.Columns.Add("amountValue");
                    dtItems.Rows.Add("1", "Cellphone", "10", "200.00");
                    dtItems.Rows.Add("2", "Bag", "2", "250.00");
                    dtItems.Rows.Add("3", "Mouse", "10", "3500.00");
                    dtItems.Rows.Add("4", "Keyboard", "5", "200.00");

                    rptItems.DataSource = dtItems;
                    rptItems.DataBind();
                }
                //FinalAmountLabel.Text = finalAmount.ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Double finalAmount = 0.0;
            if (!IsPostBack)
            {
                List<CartObject> cartItems = new List<CartObject>();
                string emailId = "*****@*****.**";
                string cartFile = "C:\\Users\\Kiran\\Desktop\\cart.xml";
                XmlDocument doc = new XmlDocument();
                doc.Load(cartFile);

                foreach (XmlNode xNode in doc.SelectNodes("carts/cart"))
                {

                    //XmlNode cartNode = xNode.SelectSingleNode("cart");
                    if (xNode.Attributes != null)
                    {

                        if (xNode.Attributes["emailId"].Value == emailId)
                        {

                            XmlNodeList booksNodeList = xNode.ChildNodes;

                            foreach (XmlNode xBookNode in booksNodeList)
                            {
                                //added to the list to use later which may come handy while searching
                                CartObject tempCartObject = new CartObject();

                                tempCartObject.itemName = xBookNode.SelectSingleNode("name").InnerText;
                                tempCartObject.itemPrice = Convert.ToDouble(xBookNode.SelectSingleNode("price").InnerText);
                                finalAmount += tempCartObject.itemPrice;
                                tempCartObject.itemQuantity = Convert.ToUInt16(xBookNode.SelectSingleNode("quantity").InnerText);
                                cartItems.Add(tempCartObject);

                                //adding to the checkbox list to display on page
                                ListItem item = new ListItem();
                                item.Text = tempCartObject.itemName + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemPrice + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + tempCartObject.itemQuantity;
                                item.Value = tempCartObject.itemName;
                                ListBox1.Items.Add(item);
                                //CheckBoxList1.Items.Add(item);

                            }

                        }
                    }

                }

                if (!Page.IsPostBack)
                {
                    DataTable dtItems = new DataTable();
                    dtItems.Columns.Add("itemCount");
                    dtItems.Columns.Add("itemValue");
                    dtItems.Columns.Add("quantityValue");
                    dtItems.Columns.Add("amountValue");
                    dtItems.Rows.Add("1", "Cellphone", "10", "200.00");
                    dtItems.Rows.Add("2", "Bag", "2", "250.00");
                    dtItems.Rows.Add("3", "Mouse", "10", "3500.00");
                    dtItems.Rows.Add("4", "Keyboard", "5", "200.00");

                    rptItems.DataSource = dtItems;
                    rptItems.DataBind();
                }
                //FinalAmountLabel.Text = finalAmount.ToString();
            }
        }