Пример #1
0
 public void UpdateTotalPrice()
 {
     TotalPrice         = CheckOutApp.CalculateTotalPrice();
     lblPriceTotal.Text = CheckOutApp.CalculateTotalPrice().ToString();
     //MessageBox.Show(CheckOutApp.CalculateTotalPrice().ToString());
     this.Refresh();
 }
Пример #2
0
        public static void InserOrdersDb(User user)
        {
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("Insert into orderTable values ( @userID, @bill, @status, @address, @mobile);", con);

                cmd.CommandType = CommandType.Text;

                cmd.Parameters.AddWithValue("@userID", user.UserName);
                cmd.Parameters.AddWithValue("@bill", (float)CheckOutApp.CalculateTotalPrice());
                cmd.Parameters.AddWithValue("@status", 0);
                cmd.Parameters.AddWithValue("@address", user.Address);
                cmd.Parameters.AddWithValue("@mobile", user.Mobile);



                cmd.ExecuteNonQuery();

                SqlCommand cmd2 = new SqlCommand("SELECT IDENT_CURRENT('orderTable')", con);
                int        id   = Convert.ToInt32(cmd2.ExecuteScalar());


                cmd2             = new SqlCommand("Insert into notification values (@userID, @message, @notified);", con);
                cmd2.CommandType = CommandType.Text;

                cmd2.Parameters.AddWithValue("@userID", user.UserName);
                cmd2.Parameters.AddWithValue("@message", user.UserName + " has placed an order [" + id + "]");
                cmd2.Parameters.AddWithValue("@notified", 0);

                cmd2.ExecuteNonQuery();



                foreach (CartItemApp cartItemApp in CheckOutApp.itemApps)
                {
                    SqlCommand cmd3 = new SqlCommand("Insert into orderExtension values ( @orderID, @itemCode, @quantity);", con);

                    cmd3.CommandType = CommandType.Text;

                    cmd3.Parameters.AddWithValue("@orderID", id);
                    cmd3.Parameters.AddWithValue("@itemCode", Convert.ToInt32(cartItemApp.ItemCode));
                    cmd3.Parameters.AddWithValue("@quantity", cartItemApp.Quantity);



                    cmd3.ExecuteNonQuery();
                }
                con.Close();


                Console.WriteLine("inserted orders");
            }
        }