private void btnnatgeo_Click(object sender, EventArgs e)
        {
            Magazines tmp = new Magazines();

            dtmagazines.CurrentCell = dtmagazines.Rows[0].Cells[0];

            if (dtmagazines.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please Select Products !");
            }
            else
            {
                foreach (DataGridViewRow row in dtmagazines.Rows)
                {
                    if (row.Selected == true)
                    {
                        tmp.ProductID = int.Parse(row.Cells[0].Value.ToString());
                        purchase      = new ItemToPurchase(tmp, 1);
                        shopping.AddProductToShoppingCart(purchase);
                    }
                }

                //dtlistshpcrd.DataSource = shopping.PrintShoppingCartProducts();
                lbltutar.Text = shopping.PaymentAmount().ToString() + "TL";
            }
        }
Пример #2
0
        public void RemoveProductToShoppingCart(ItemToPurchase product)
        {
            int miktar = 0;

            conn = GetSqlConnect.getUser();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "Select ProductQuantity From ShoppingCart Where CustomerID=@custom and ProductID=@prod";
            cmd.Connection  = conn.DatabaseConnectionOpen();
            cmd.Parameters.AddWithValue("@custom", m_customerID);
            cmd.Parameters.AddWithValue("@prod", product.Product.ProductID);
            //her @'li parametre farklı olmalı
            using (SqlDataReader read = cmd.ExecuteReader())
            {
                if (read.Read())
                {
                    miktar = int.Parse(read["ProductQuantity"].ToString());
                }
            }
            if (miktar > 1)
            {
                cmd.CommandText = "Update ShoppingCart Set ProductQuantity=@quant Where CustomerID = @custome and ProductID = @product";
                cmd.Parameters.AddWithValue("@product", product.Product.ProductID);
                cmd.Parameters.AddWithValue("@custome", m_customerID);
                cmd.Parameters.AddWithValue("@quant", miktar - product.ProductQuantity);
                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        price = int.Parse(read["Price"].ToString());
                    }
                    _PaymentAmount = _PaymentAmount - price * miktar;
                }
            }
            else
            {
                cmd.CommandText = "Delete From ShoppingCart Where CustomerID = @customer and ProductID = @productid";
                cmd.Parameters.AddWithValue("@productid", product.Product.ProductID);
                cmd.Parameters.AddWithValue("@customer", m_customerID);

                using (SqlDataReader read = cmd.ExecuteReader())
                {
                    if (read.Read())
                    {
                        price = int.Parse(read["Price"].ToString());
                    }
                    _PaymentAmount = _PaymentAmount - price * 1;
                }
            }
            cmd.ExecuteNonQuery();
        }
Пример #3
0
        public void AddProductToShoppingCart(ItemToPurchase product)
        {
            int miktar = 0;

            conn = GetSqlConnect.getUser();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "Select ProductQuantity From ShoppingCart Where CustomerID = @cid and ProductID = @pid";
                cmd.Connection  = conn.DatabaseConnectionOpen();
                cmd.Parameters.AddWithValue("@cid", m_customerID);
                cmd.Parameters.AddWithValue("@pid", product.Product.ProductID);

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        miktar = int.Parse(reader["ProductQuantity"].ToString());
                    }
                }

                if (miktar > 0)
                {
                    cmd.CommandText = "Update ShoppingCart Set ProductQuantity=@quant Where CustomerID = @cuid and ProductID = @puid";
                    cmd.Parameters.AddWithValue("@puid", product.Product.ProductID);
                    cmd.Parameters.AddWithValue("@cuid", m_customerID);
                    cmd.Parameters.AddWithValue("@quant", miktar + product.ProductQuantity);
                }
                else
                {
                    cmd.CommandText = "Insert Into ShoppingCart(CustomerID, ProductID, ProductQuantity) Values (@cuid, @puid, @quantity)";


                    cmd.Parameters.AddWithValue("@cuid", m_customerID);
                    cmd.Parameters.AddWithValue("@puid", product.Product.ProductID);
                    cmd.Parameters.AddWithValue("@quantity", product.ProductQuantity);
                }

                cmd.ExecuteNonQuery();
                ShoppingCartError = true;
            }


            catch (Exception f)
            {
                ShoppingCartError = false;
                UrunDurumu        = f.ToString();
            }
        }
Пример #4
0
        private void button4_Click(object sender, EventArgs e)
        {
            MusicCDs tmp = new MusicCDs();

            if (dtpurchased.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please Select Products !");
            }
            else
            {
                foreach (DataGridViewRow row in dtpurchased.Rows)
                {
                    if (row.Selected == true)
                    {
                        tmp.ProductID = int.Parse(row.Cells[0].Value.ToString());
                        purchase      = new ItemToPurchase(tmp, 1);
                        shopping.RemoveProductToShoppingCart(purchase);
                    }
                }
            }

            dtpurchased.DataSource = shopping.PrintShoppingCartProducts();
            lbltutarpurchase.Text  = shopping.PaymentAmount().ToString() + "TL";
        }