private void cart_MouseDown(object sender, MouseButtonEventArgs e) { user_cart w = new user_cart(); w.Show(); if (creatingForm != null) { creatingForm.Close(); } this.Close(); }
private void cart_btn_Click(object sender, RoutedEventArgs e) { user_cart w = new user_cart(); w.Show(); if (creatingForm != null) { creatingForm.Close(); } this.Close(); }
public static void lable_plus_click(object sender, RoutedEventArgs e) { string connection_string = " Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = \"C:\\Users\\emad&javad\\Desktop\\visual studio\\Final_Project\\Final_Project\\database.mdf\"; Integrated Security = True; Connect Timeout = 30"; Label lb = e.Source as Label; StackPanel st = lb.Parent as StackPanel; StackPanel st1 = st.Parent as StackPanel; StackPanel st2 = st1.Parent as StackPanel; StackPanel st3 = st2.Parent as StackPanel; Border br = st3.Parent as Border; ScrollViewer sc = br.Parent as ScrollViewer; Grid grid = sc.Parent as Grid; Window window = grid.Parent as Window; SqlConnection sqlConnection = new SqlConnection(connection_string); sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand("select Number_Food from Food_Menu where Name_Food=@Name_Food", sqlConnection); sqlCommand.Parameters.AddWithValue("@Name_Food", ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[0]).Content.ToString().Substring(7)); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); sqlDataReader.Read(); double current_Food_number = double.Parse(sqlDataReader.GetValue(0).ToString()); sqlDataReader.Close(); sqlCommand.Dispose(); if (current_Food_number >= 1) { sqlCommand = new SqlCommand("update Users set Cart +=@Cart where FullName=@FullName", sqlConnection); sqlCommand.Parameters.AddWithValue("@Cart", "," + ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[0]).Content.ToString().Substring(7)); sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName); sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); double number = double.Parse(((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[3]).Content.ToString().Substring(9)); number++; ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[3]).Content = "Number : " + number.ToString(); sqlCommand = new SqlCommand("update Food_Menu set Number_Food =@Number_Food where Name_Food=@Name_Food", sqlConnection); sqlCommand.Parameters.AddWithValue("@Number_Food", current_Food_number - 1); sqlCommand.Parameters.AddWithValue("@Name_Food", ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[0]).Content.ToString().Substring(7)); sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); sqlConnection.Close(); } else { MessageBox.Show("You Can't Order More Than Amount of Food in Menu"); } user_cart w = new user_cart(); w.Show(); window.Close(); }
public static void lable_minus_click(object sender, RoutedEventArgs e) { string connection_string = " Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = \"C:\\Users\\emad&javad\\Desktop\\visual studio\\Final_Project\\Final_Project\\database.mdf\"; Integrated Security = True; Connect Timeout = 30"; Label lb = e.Source as Label; StackPanel st = lb.Parent as StackPanel; StackPanel st1 = st.Parent as StackPanel; StackPanel st2 = st1.Parent as StackPanel; StackPanel st3 = st2.Parent as StackPanel; Border br = st3.Parent as Border; ScrollViewer sc = br.Parent as ScrollViewer; Grid grid = sc.Parent as Grid; Window window = grid.Parent as Window; SqlConnection sqlConnection = new SqlConnection(connection_string); sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand("select Cart from Users where FullName=@FullName", sqlConnection); sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); sqlDataReader.Read(); string cart = sqlDataReader.GetValue(0).ToString(); string Food_name = ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[0]).Content.ToString().Substring(7); int food_index = cart.IndexOf(Food_name); sqlDataReader.Close(); sqlCommand.Dispose(); sqlCommand = new SqlCommand("update Users set Cart=@Cart where FullName=@FullName", sqlConnection); int endIndex = cart.Length - Food_name.Length != food_index ? Food_name.Length + 1 : Food_name.Length; sqlCommand.Parameters.AddWithValue("@Cart", cart.Remove(food_index, endIndex)); sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName); sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); double number = double.Parse(((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[3]).Content.ToString().Substring(9)); number--; ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[3]).Content = "Number : " + number.ToString(); sqlCommand = new SqlCommand("select Number_Food from Food_Menu where Name_Food=@Name_Food", sqlConnection); sqlCommand.Parameters.AddWithValue("@Name_Food", ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[0]).Content.ToString().Substring(7)); sqlDataReader = sqlCommand.ExecuteReader(); sqlDataReader.Read(); double current_Food_number = double.Parse(sqlDataReader.GetValue(0).ToString()); sqlDataReader.Close(); sqlCommand.Dispose(); sqlCommand = new SqlCommand("update Food_Menu set Number_Food =@Number_Food where Name_Food=@Name_Food", sqlConnection); sqlCommand.Parameters.AddWithValue("@Number_Food", current_Food_number + 1); sqlCommand.Parameters.AddWithValue("@Name_Food", ((Label)((StackPanel)((Border)st2.Children[1]).Child).Children[0]).Content.ToString().Substring(7)); sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); sqlConnection.Close(); if (number == 0) { st2.Children.Clear(); st2.Height = 0; } user_cart w = new user_cart(); w.Show(); window.Close(); }