Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace IDS_GUI
- {
- /// <summary>
- /// Interaction logic for Rent_and_Return.xaml
- /// </summary>
- public partial class Rent_and_Return : Window
- {
- string txtbxSubmittedValue = "";
- SqlConnection connection = new SqlConnection("Data Source=10.204.2.49,1433; Network Library=DBMSSOCN; Initial Catalog=IDS_Prod; User ID=idsuser; Password=p@ssword3");
- public Rent_and_Return()
- {
- InitializeComponent();
- hideControls();
- RRpageLbl.Visibility = Visibility.Visible;
- rrBorder.Visibility = Visibility.Visible;
- RRpageLbl.Content = "Please Choose an Option Below:";
- }
- private void hideControls()
- {
- rAndrBorder.Visibility = Visibility.Hidden;
- fnameTxtBx2.Visibility = Visibility.Hidden;
- lnameTxtBx2.Visibility = Visibility.Hidden;
- phoneTxtBx2.Visibility = Visibility.Hidden;
- ageTxtBx2.Visibility = Visibility.Hidden;
- idTxtBx2.Visibility = Visibility.Hidden;
- rentBtn.Visibility = Visibility.Hidden;
- addToRent.Visibility = Visibility.Hidden;
- customerExistsLbl.Visibility = Visibility.Hidden;
- custExistYesRB.Visibility = Visibility.Hidden;
- custExistNoRB.Visibility = Visibility.Hidden;
- videoNameTxtBx.Visibility = Visibility.Hidden;
- videoIdTxtBx.Visibility = Visibility.Hidden;
- rentalDaysTxtBx.Visibility = Visibility.Hidden;
- videoInfoLbl.Visibility = Visibility.Hidden;
- vidTxtBx.Visibility = Visibility.Hidden;
- returnlistView.Visibility = Visibility.Hidden;
- rentlistView.Visibility = Visibility.Hidden;
- returnBtn.Visibility = Visibility.Hidden;
- existingCustomerlistView.Visibility = Visibility.Hidden;
- search.Visibility = Visibility.Hidden;
- createUser.Visibility = Visibility.Hidden;
- rentalCost.Visibility = Visibility.Hidden;
- removeRent.Visibility = Visibility.Hidden;
- returnRemove.Visibility = Visibility.Hidden;
- customerIDTxtBx.Visibility = Visibility.Hidden;
- }
- private void rentRB_Checked(object sender, RoutedEventArgs e)
- {
- RRpageLbl.Content = "Rent a Video";
- //Unhides all controls for renting a video
- rAndrBorder.Visibility = Visibility.Visible;
- fnameTxtBx2.Visibility = Visibility.Hidden;
- lnameTxtBx2.Visibility = Visibility.Hidden;
- phoneTxtBx2.Visibility = Visibility.Hidden;
- ageTxtBx2.Visibility = Visibility.Hidden;
- idTxtBx2.Visibility = Visibility.Hidden;
- rentBtn.Visibility = Visibility.Visible;
- addToRent.Visibility = Visibility.Visible;
- customerExistsLbl.Visibility = Visibility.Visible;
- custExistYesRB.Visibility = Visibility.Visible;
- custExistNoRB.Visibility = Visibility.Visible;
- videoNameTxtBx.Visibility = Visibility.Visible;
- videoIdTxtBx.Visibility = Visibility.Visible;
- rentalDaysTxtBx.Visibility = Visibility.Visible;
- videoInfoLbl.Visibility = Visibility.Visible;
- rentlistView.Visibility = Visibility.Visible;
- rAndrBorder.Visibility = Visibility.Visible;
- vidTxtBx.Visibility = Visibility.Hidden;
- returnlistView.Visibility = Visibility.Hidden;
- returnBtn.Visibility = Visibility.Hidden;
- existingCustomerlistView.Visibility = Visibility.Hidden;
- search.Visibility = Visibility.Hidden;
- rentalCost.Visibility = Visibility.Visible;
- removeRent.Visibility = Visibility.Visible;
- returnRemove.Visibility = Visibility.Hidden;
- customerIDTxtBx.Visibility = Visibility.Hidden;
- // addReturn.Visibility = Visibility.Hidden;
- // customerIDTxtBx.Visibility = Visibility.Hidden;
- }
- private void returnRB_Checked(object sender, RoutedEventArgs e)
- {
- RRpageLbl.Content = "Return a Video";
- //Hides controls from renting a video
- rAndrBorder.Visibility = Visibility.Hidden;
- fnameTxtBx2.Visibility = Visibility.Hidden;
- lnameTxtBx2.Visibility = Visibility.Hidden;
- phoneTxtBx2.Visibility = Visibility.Hidden;
- ageTxtBx2.Visibility = Visibility.Hidden;
- idTxtBx2.Visibility = Visibility.Hidden;
- rentBtn.Visibility = Visibility.Hidden;
- addToRent.Visibility = Visibility.Hidden;
- customerExistsLbl.Visibility = Visibility.Hidden;
- custExistYesRB.Visibility = Visibility.Hidden;
- custExistNoRB.Visibility = Visibility.Hidden;
- videoNameTxtBx.Visibility = Visibility.Hidden;
- videoIdTxtBx.Visibility = Visibility.Hidden;
- rentalDaysTxtBx.Visibility = Visibility.Hidden;
- videoInfoLbl.Visibility = Visibility.Hidden;
- rentlistView.Visibility = Visibility.Hidden;
- customerIDTxtBx.Visibility = Visibility.Hidden;
- rAndrBorder.Visibility = Visibility.Visible;
- vidTxtBx.Visibility = Visibility.Visible;
- returnlistView.Visibility = Visibility.Visible;
- returnBtn.Visibility = Visibility.Visible;
- existingCustomerlistView.Visibility = Visibility.Hidden;
- search.Visibility = Visibility.Hidden;
- rentalCost.Visibility = Visibility.Hidden;
- createUser.Visibility = Visibility.Hidden;
- removeRent.Visibility = Visibility.Hidden;
- returnRemove.Visibility = Visibility.Visible;
- //addReturn.Visibility = Visibility.Visible;
- }
- private void custExistYesRB_Checked(object sender, RoutedEventArgs e)
- {
- fnameTxtBx2.Visibility = Visibility.Hidden;
- lnameTxtBx2.Visibility = Visibility.Hidden;
- phoneTxtBx2.Visibility = Visibility.Hidden;
- idTxtBx2.Visibility = Visibility.Hidden;
- ageTxtBx2.Visibility = Visibility.Hidden;
- createUser.Visibility = Visibility.Hidden;
- customerIDTxtBx.Visibility = Visibility.Visible;
- existingCustomerlistView.Visibility = Visibility.Visible;
- search.Visibility = Visibility.Visible;
- removeRent.Visibility = Visibility.Visible;
- }
- private void custExistNoRB_Checked(object sender, RoutedEventArgs e)
- {
- fnameTxtBx2.Visibility = Visibility.Hidden;
- lnameTxtBx2.Visibility = Visibility.Hidden;
- phoneTxtBx2.Visibility = Visibility.Hidden;
- idTxtBx2.Visibility = Visibility.Hidden;
- ageTxtBx2.Visibility = Visibility.Hidden;
- createUser.Visibility = Visibility.Visible;
- customerIDTxtBx.Visibility = Visibility.Hidden;
- existingCustomerlistView.Visibility = Visibility.Hidden;
- search.Visibility = Visibility.Hidden;
- removeRent.Visibility = Visibility.Hidden;
- customerIDTxtBx.Visibility = Visibility.Hidden;
- }
- private void button_Click(object sender, RoutedEventArgs e)
- {
- Dashboard goHome = new Dashboard();
- goHome.Show();
- this.Close();
- }
- private void addToRentBtn_Click(object sender, RoutedEventArgs e)
- {
- String videoID = videoIdTxtBx.Text;
- // int rentCost = 3; may not need this
- int b;
- bool isBValid = int.TryParse(rentalDaysTxtBx.Text, out b);
- bool validID = true;
- if ((bool)rentRB.IsChecked) //&& (videoIdTxtBx.Text.Any(char.IsLetter) || videoIdTxtBx.Text.Length != 10))
- {
- // if (videoIdTxtBx.Text.Any(char.IsLetter))
- // {
- //MessageBox.Show("Please Enter a Movie ID");
- SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.tblInventory WHERE Quantity=@Quantity AND InvID = @InvID", connection);
- connection.Open();
- SqlDataReader dbRdr = null;
- cmd.Parameters.AddWithValue("@Quantity", 0);
- cmd.Parameters.AddWithValue("@InvID", videoID);
- dbRdr = cmd.ExecuteReader();
- while (dbRdr.Read())
- {
- validID = false;
- }
- connection.Close();
- // }
- if ((bool)!custExistNoRB.IsChecked && (bool)!custExistYesRB.IsChecked)
- {
- MessageBox.Show("Please Enter the Customer Information");
- return;
- }
- if (videoIdTxtBx.Text.Any(char.IsLetter) || (videoIdTxtBx.Text.Length < 10 || videoIdTxtBx.Text.Length > 10))
- {
- MessageBox.Show("Please Enter A Valid Video ID (10 Digits)");
- videoIdTxtBx.Text = "Video ID";
- return;
- }
- if (rentalDaysTxtBx.Text.Any(char.IsLetter))
- {
- MessageBox.Show("Please Enter A Number for Rental Days");
- rentalDaysTxtBx.Text = "Rental Days";
- return;
- }
- if (rentalCost.Text.Any(char.IsLetter))
- {
- MessageBox.Show("Please Enter A Number for Rental Cost");
- rentalCost.Text = "Rental Cost";
- return;
- }
- if (Convert.ToInt32(this.rentalDaysTxtBx.Text) > 7)
- {
- MessageBox.Show("Please Enter A Day Less Than 7");
- rentalDaysTxtBx.Text = "Rental Days";
- return;
- }
- if (videoNameTxtBx.Text != "Video Name" && validID == true)
- {
- // var row = new { VideoName = videoNameTxtBx.Text, RentalCost = (rentCost * b) };
- var row = new { VideoName = videoNameTxtBx.Text, RentalCost = Convert.ToInt32(this.rentalCost.Text) * b, MovieID = videoIdTxtBx.Text , RentDays=rentalDaysTxtBx.Text };
- rentlistView.Items.Add(row);
- }
- if (validID == false)
- {
- MessageBox.Show("This Has Already Been Rented");
- }
- }
- videoNameTxtBx.Text = "Video Name";
- videoIdTxtBx.Text = "Video ID";
- rentalDaysTxtBx.Text = "Rental Days";
- rentalCost.Text = "Rental Cost";
- }
- private void rentBtn_Click(object sender, RoutedEventArgs e) //change this method to send to database
- {
- int b;
- bool isBValid = int.TryParse(rentalDaysTxtBx.Text, out b);
- if ((bool)!custExistYesRB.IsChecked && (bool)!custExistNoRB.IsChecked)
- {
- MessageBox.Show("Please Enter the Required Information");
- return;
- }
- if ((bool)custExistNoRB.IsChecked)
- {
- if (ageTxtBx2.Text.Any(char.IsLetter) && ageTxtBx2.Text.Length <= 3)
- {
- MessageBox.Show("Please Enter A Valid Age");
- ageTxtBx2.Text = "Age";
- return;
- }
- if (fnameTxtBx2.Text.Any(char.IsPunctuation) || fnameTxtBx2.Text.Any(char.IsDigit))
- {
- MessageBox.Show("Please Use A Valid First Name");
- fnameTxtBx2.Text = "First Name";
- return;
- }
- if (lnameTxtBx2.Text.Any(char.IsPunctuation) || lnameTxtBx2.Text.Any(char.IsDigit))
- {
- MessageBox.Show("Please Use A Valid Last Name");
- lnameTxtBx2.Text = "Last Name";
- return;
- }
- if ((phoneTxtBx2.Text.Length < 10 || phoneTxtBx2.Text.Length > 10) || !phoneTxtBx2.Text.All(char.IsDigit))
- {
- MessageBox.Show("Please Enter A 10 Digit Phone Number");
- phoneTxtBx2.Text = "Phone Number";
- return;
- }
- }
- if ((bool)custExistYesRB.IsChecked)
- {
- if (customerIDTxtBx.Text.Any(char.IsPunctuation)) //|| customerIDTxtBx.Text.Any(char.IsDigit))
- {
- MessageBox.Show("Please Enter A Valid Customer ID");
- customerIDTxtBx.Text = "Customer ID";
- return;
- }
- if (videoIdTxtBx.Text.All(char.IsDigit) && videoIdTxtBx.Text.Length == 10)
- {
- MessageBox.Show("Please Enter A Valid Movie ID");
- videoIdTxtBx.Text = "Movie ID";
- }
- // string userName = UserName.GetValue<string>("userName");
- while (rentlistView.Items.Count > 0)
- {
- String query = "INSERT INTO dbo.rental (invID, employeeID, custID, expected_return_date, cost) Values(@InvID,@employeeID,@custID, @expected_return_date, @cost)";
- SqlCommand command = new SqlCommand(query, connection);
- char[] delimeterChars = { '=', ',', '}' };
- string[] split = rentlistView.Items[0].ToString().Split(delimeterChars);
- string[] splat = existingCustomerlistView.SelectedItem.ToString().Split(delimeterChars);
- DateTime date = DateTime.Now;
- Int32 addedDays = (Convert.ToInt32(split[7].Trim()));
- date = date.AddDays(addedDays);
- DateTime end = date;
- command.Parameters.AddWithValue("@InvID", split[5].Trim());
- command.Parameters.AddWithValue("@employeeID", "Jsmith6");
- command.Parameters.AddWithValue("@custID", splat[5].Trim());
- command.Parameters.AddWithValue("@expected_return_date", date);
- command.Parameters.AddWithValue("@cost", split[3].Trim());
- connection.Open();
- command.ExecuteNonQuery();
- connection.Close();
- returnlistView.Items.Remove(returnlistView.Items[0]);
- }
- videoNameTxtBx.Text = "Video Name";
- videoIdTxtBx.Text = "Video ID";
- rentalDaysTxtBx.Text = "Rental Days";
- rentalCost.Text = "Rental Cost";
- }
- SqlCommand get_history = new SqlCommand("SELECT * FROM dbo.get_history(@customer)", connection);
- connection.Open();
- SqlDataReader dbRdr = null;
- get_history.Parameters.AddWithValue("@customer", customerIDTxtBx.Text);
- dbRdr = get_history.ExecuteReader();
- if (dbRdr.Read())
- {
- // get_history.Parameters.AddWithValue("@customer", customerIDTxtBx.Text);
- String x = dbRdr[0].ToString();
- MessageBox.Show(x);
- }
- connection.Close();
- decimal price = 0;
- int count = 0;
- while (rentlistView.Items.Count > count)
- {
- char[] delimeterChars = { '=', ',', '}' };
- string[] split = rentlistView.Items[count].ToString().Split(delimeterChars);
- //price = Convert.ToInt32(split[3].Trim());
- price = price + Convert.ToDecimal(split[3].Trim());
- count++;
- }
- MessageBox.Show("Total Cost is " + price);
- int parsedValue;
- rentlistView.Items.Clear();
- if (!int.TryParse(ageTxtBx2.Text, out parsedValue))
- {
- }
- if (int.TryParse(fnameTxtBx2.Text, out parsedValue))
- {
- }
- if (int.TryParse(lnameTxtBx2.Text, out parsedValue))
- {
- }
- fnameTxtBx2.Text = "First Name";
- lnameTxtBx2.Text = "Last Name";
- phoneTxtBx2.Text = "Phone Number";
- ageTxtBx2.Text = "Age";
- // customerIDTxtBx.Text = "Customer Name";
- }
- private void vidTxtBx_TextChanged(object sender, TextChangedEventArgs e)
- {
- if ((bool)returnRB.IsChecked)
- {
- string movieId = vidTxtBx.Text;
- bool movieInDb = false;
- if (movieId.Length == 10 && movieId.All(char.IsDigit))
- {
- var row = new
- {
- VideoName = String.Empty,
- MovieID = String.Empty
- };
- SqlCommand cmd1 = new SqlCommand("SELECT * FROM dbo.tblInventory WHERE InvID=@InvID AND Quantity=@Quantity", connection);
- connection.Open();
- cmd1.Parameters.AddWithValue("@InvID", movieId);
- cmd1.Parameters.AddWithValue("@Quantity", 0);
- SqlDataReader dbRdr = null;
- dbRdr = cmd1.ExecuteReader();
- while (dbRdr.Read())
- {
- row = new
- {
- VideoName = (dbRdr["Title"].ToString()),
- MovieID = (dbRdr["InvID"].ToString())
- };
- movieInDb = true;
- }
- if (movieInDb == true)
- {
- returnlistView.Items.Add(row);
- }
- vidTxtBx.Text = String.Empty;
- }
- if (movieId.Length == 10 && movieInDb == false)
- {
- MessageBox.Show("Movie ID \"" + movieId + "\" not rented out", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- connection.Close();
- }
- }
- private void returnlistView_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- }
- private void fnameTxtBx2_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(fnameTxtBx2.Text) || fnameTxtBx2.Text.Equals("First Name"))
- {
- fnameTxtBx2.Text = "";
- }
- }
- private void fnameTxtBx2_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(fnameTxtBx2.Text))
- {
- fnameTxtBx2.Text = "First Name";
- }
- }
- private void fnameTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (fnameTxtBx2.Text != "First Name")
- {
- if (fnameTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void lnameTxtBx2_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(lnameTxtBx2.Text) || lnameTxtBx2.Text.Equals("Last Name"))
- {
- lnameTxtBx2.Text = "";
- }
- }
- private void lnameTxtBx2_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(lnameTxtBx2.Text))
- {
- lnameTxtBx2.Text = "Last Name";
- }
- }
- private void lnameTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (lnameTxtBx2.Text != "Last Name")
- {
- if (lnameTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void phoneTxtBx2_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(phoneTxtBx2.Text) || phoneTxtBx2.Text.Equals("Phone Number"))
- {
- phoneTxtBx2.Text = "";
- }
- }
- private void phoneTxtBx2_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(phoneTxtBx2.Text))
- {
- phoneTxtBx2.Text = "Phone Number";
- }
- }
- private void phoneTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (phoneTxtBx2.Text != "Phone Number")
- {
- if (phoneTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void ageTxtBx2_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(ageTxtBx2.Text) || ageTxtBx2.Text.Equals("Age"))
- {
- ageTxtBx2.Text = "";
- }
- }
- private void ageTxtBx2_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(ageTxtBx2.Text))
- {
- ageTxtBx2.Text = "Age";
- }
- }
- private void ageTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (ageTxtBx2.Text != "Age")
- {
- if (ageTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void videoNameTxtBx_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(videoNameTxtBx.Text) || videoNameTxtBx.Text.Equals("Video Name"))
- {
- videoNameTxtBx.Text = "";
- }
- }
- private void videoNameTxtBx_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(videoNameTxtBx.Text))
- {
- videoNameTxtBx.Text = "Video Name";
- }
- }
- private void videoNameTxtBx_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (videoNameTxtBx.Text != "Video Name")
- {
- if (videoNameTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void videoIdTxtBx_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(videoIdTxtBx.Text) || videoIdTxtBx.Text.Equals("Video ID"))
- {
- videoIdTxtBx.Text = "";
- }
- }
- private void videoIdTxtBx_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(videoIdTxtBx.Text))
- {
- videoIdTxtBx.Text = "Video ID";
- }
- }
- private void videoIdTxtBx_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (videoIdTxtBx.Text != "Video ID")
- {
- if (videoIdTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void vidTxtBx_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(vidTxtBx.Text) || vidTxtBx.Text.Equals("Video ID"))
- {
- vidTxtBx.Text = "";
- }
- }
- private void vidTxtBx_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(vidTxtBx.Text))
- {
- vidTxtBx.Text = "Video ID";
- }
- }
- private void rentalDaysTxtBx_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(rentalDaysTxtBx.Text) || rentalDaysTxtBx.Text.Equals("Rental Days"))
- {
- rentalDaysTxtBx.Text = "";
- }
- }
- private void rentalDaysTxtBx_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(rentalDaysTxtBx.Text))
- {
- rentalDaysTxtBx.Text = "Rental Days";
- }
- }
- private void rentalDaysTxtBx_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (rentalDaysTxtBx.Text != "Rental Days")
- {
- if (rentalDaysTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void customerIDTxtBx_GotFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(customerIDTxtBx.Text) || customerIDTxtBx.Text.Equals("Customer ID"))
- {
- customerIDTxtBx.Text = "";
- }
- }
- private void customerIDTxtBx_LostFocus(object sender, EventArgs e)
- {
- if (String.IsNullOrWhiteSpace(customerIDTxtBx.Text))
- {
- customerIDTxtBx.Text = "Customer ID";
- }
- }
- private void customerIDTxtBx_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (customerIDTxtBx.Text != "Customer ID")
- {
- if (customerIDTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void addReturn_Click(object sender, EventArgs e) //return stuff
- {
- if ((bool)returnRB.IsChecked)
- {
- while (returnlistView.Items.Count > 0)
- {
- char[] delimeterChars = { '=', ',', '}' };
- string[] split = returnlistView.Items[0].ToString().Split(delimeterChars);
- DateTime today = DateTime.Now;
- SqlCommand sqlCmd = new SqlCommand("UPDATE dbo.rental SET date_returned=@date_returned WHERE InvID=@InvID", connection);
- sqlCmd.Parameters.AddWithValue("@date_returned", today);
- sqlCmd.Parameters.AddWithValue("@InvID", split[3].Trim());
- connection.Open();
- sqlCmd.ExecuteNonQuery();
- connection.Close();
- SqlCommand command = new SqlCommand("UPDATE dbo.tblInventory SET Quantity = @Quantity WHERE InvID = @InvID", connection);
- command.Parameters.AddWithValue("@Quantity", 1);
- command.Parameters.AddWithValue("@InvID", split[3].Trim());
- connection.Open();
- command.ExecuteNonQuery();
- connection.Close();
- returnlistView.Items.Remove(returnlistView.Items[0]);
- }
- MessageBox.Show("Return Was Successful");
- returnlistView.Items.Clear();
- }
- }
- private void search_Click(object sender, RoutedEventArgs e) //completely works! rent stuff
- {
- if (customerIDTxtBx.Text == "Customer ID")
- {
- SqlCommand then = new SqlCommand("SELECT FirstName, Phone_num, custID FROM dbo.tblCustomers", connection);
- SqlDataReader other = null;
- connection.Open();
- other = then.ExecuteReader();
- while (other.Read())
- {
- var row = new
- {
- CustomerName = (other["FirstName"].ToString()),
- PhoneNumber = (other["Phone_num"].ToString()),
- CustomerID = (other["custID"].ToString())
- };
- existingCustomerlistView.Items.Add(row);
- existingCustomerlistView.IsEnabled = true;
- }
- connection.Close();
- }
- else
- {
- SqlCommand search = new SqlCommand("SELECT FirstName, Phone_num, custID FROM dbo.tblCustomers WHERE custID = @custID", connection);
- existingCustomerlistView.Items.Clear();
- search.Parameters.AddWithValue("@custID", customerIDTxtBx.Text);
- SqlDataReader dbRdr = null;
- connection.Open();
- dbRdr = search.ExecuteReader();
- while (dbRdr.Read())
- {
- var row = new
- {
- CustomerName = (dbRdr["FirstName"].ToString()),
- PhoneNumber = (dbRdr["Phone_num"].ToString()),
- CustomerID = (dbRdr["custID"].ToString())
- };
- existingCustomerlistView.Items.Add(row);
- existingCustomerlistView.IsEnabled = true;
- }
- connection.Close();
- }
- }
- private void rentlistView_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- }
- private void textBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- }
- private void createUser_Click(object sender, RoutedEventArgs e)
- {
- Profile win3 = new Profile();
- win3.Show();
- this.Close();
- }
- private void rentalCost_GotFocus(object sender, RoutedEventArgs e)
- {
- if (String.IsNullOrWhiteSpace(rentalCost.Text) || rentalCost.Text.Equals("Rental Cost"))
- {
- rentalCost.Text = "";
- }
- }
- private void rentalCost_LostFocus(object sender, RoutedEventArgs e)
- {
- if (String.IsNullOrWhiteSpace(rentalCost.Text))
- {
- rentalCost.Text = "Rental Cost";
- }
- }
- private void rentalCost_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (rentalCost.Text != "Rental Cost")
- {
- if (rentalCost.Text != txtbxSubmittedValue) //use this for the rent button
- {
- }
- }
- }
- private void removeRent_Click(object sender, RoutedEventArgs e)
- {
- if (rentlistView.SelectedItem != null)
- {
- while (rentlistView.SelectedItems.Count > 0)
- {
- rentlistView.Items.Remove(rentlistView.SelectedItems[0]);
- }
- }
- }
- private void returnRemove_Click(object sender, RoutedEventArgs e)
- {
- if (returnlistView.SelectedItem != null)
- {
- while (returnlistView.SelectedItems.Count > 0)
- {
- returnlistView.Items.Remove(returnlistView.SelectedItems[0]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement