Exemple #1
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();
        }
Exemple #2
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();
            }
        }
Exemple #3
0
        public DataTable PrintShoppingCartProducts()
        {
            DataTable dt = new DataTable();

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

            cmd.CommandText = "Select ShoppingCart.ProductID AS ÜrünID, Products.Name AS ÜrünAdı, ShoppingCart.ProductQuantity AS ÜrünMiktarı, Products.Price AS ÜrünFiyatı,Products.Type From ShoppingCart Inner Join Products On ShoppingCart.ProductID = Products.ProductID Where ShoppingCart.CustomerID = @cid";
            cmd.Connection  = conn.DatabaseConnectionOpen();

            cmd.Parameters.AddWithValue("@cid", m_customerID);

            using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
            {
                adapter.Fill(dt);
            }


            return(dt);
        }
Exemple #4
0
        private void btnsign_Click(object sender, EventArgs e)
        {
            GetSqlConnect user = GetSqlConnect.getUser();

            if (txtUserName.Text == "" || txtUserPassword.Text == "")
            {
                MessageBox.Show("Please Fill in the Fields!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (user.Login(txtUserName.Text, txtUserPassword.Text) == true)
                {
                    MessageBox.Show("Access Succeed!");
                    this.Hide();
                    FormUser2 form = new FormUser2();
                    form.ShowDialog();
                }
                else
                {
                    MessageBox.Show("User Not Found !", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }