Advertisement
Guest User

Untitled

a guest
May 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16.  
  17.  
  18.  
  19. namespace IDS_GUI
  20. {
  21.  
  22. /// <summary>
  23. /// Interaction logic for Rent_and_Return.xaml
  24. /// </summary>
  25. public partial class Rent_and_Return : Window
  26. {
  27. string txtbxSubmittedValue = "";
  28. SqlConnection connection = new SqlConnection("Data Source=10.204.2.49,1433; Network Library=DBMSSOCN; Initial Catalog=IDS_Prod; User ID=idsuser; Password=p@ssword3");
  29.  
  30. public Rent_and_Return()
  31. {
  32. InitializeComponent();
  33. hideControls();
  34. RRpageLbl.Visibility = Visibility.Visible;
  35. rrBorder.Visibility = Visibility.Visible;
  36. RRpageLbl.Content = "Please Choose an Option Below:";
  37.  
  38.  
  39. }
  40.  
  41. private void hideControls()
  42. {
  43. rAndrBorder.Visibility = Visibility.Hidden;
  44. fnameTxtBx2.Visibility = Visibility.Hidden;
  45. lnameTxtBx2.Visibility = Visibility.Hidden;
  46. phoneTxtBx2.Visibility = Visibility.Hidden;
  47. ageTxtBx2.Visibility = Visibility.Hidden;
  48. idTxtBx2.Visibility = Visibility.Hidden;
  49. rentBtn.Visibility = Visibility.Hidden;
  50. addToRent.Visibility = Visibility.Hidden;
  51.  
  52. customerExistsLbl.Visibility = Visibility.Hidden;
  53. custExistYesRB.Visibility = Visibility.Hidden;
  54. custExistNoRB.Visibility = Visibility.Hidden;
  55. videoNameTxtBx.Visibility = Visibility.Hidden;
  56. videoIdTxtBx.Visibility = Visibility.Hidden;
  57. rentalDaysTxtBx.Visibility = Visibility.Hidden;
  58. videoInfoLbl.Visibility = Visibility.Hidden;
  59.  
  60. vidTxtBx.Visibility = Visibility.Hidden;
  61.  
  62. returnlistView.Visibility = Visibility.Hidden;
  63. rentlistView.Visibility = Visibility.Hidden;
  64. returnBtn.Visibility = Visibility.Hidden;
  65. existingCustomerlistView.Visibility = Visibility.Hidden;
  66. search.Visibility = Visibility.Hidden;
  67. createUser.Visibility = Visibility.Hidden;
  68. rentalCost.Visibility = Visibility.Hidden;
  69. removeRent.Visibility = Visibility.Hidden;
  70. returnRemove.Visibility = Visibility.Hidden;
  71. customerIDTxtBx.Visibility = Visibility.Hidden;
  72.  
  73.  
  74. }
  75.  
  76. private void rentRB_Checked(object sender, RoutedEventArgs e)
  77. {
  78. RRpageLbl.Content = "Rent a Video";
  79.  
  80. //Unhides all controls for renting a video
  81. rAndrBorder.Visibility = Visibility.Visible;
  82. fnameTxtBx2.Visibility = Visibility.Hidden;
  83. lnameTxtBx2.Visibility = Visibility.Hidden;
  84. phoneTxtBx2.Visibility = Visibility.Hidden;
  85. ageTxtBx2.Visibility = Visibility.Hidden;
  86. idTxtBx2.Visibility = Visibility.Hidden;
  87. rentBtn.Visibility = Visibility.Visible;
  88. addToRent.Visibility = Visibility.Visible;
  89.  
  90. customerExistsLbl.Visibility = Visibility.Visible;
  91. custExistYesRB.Visibility = Visibility.Visible;
  92. custExistNoRB.Visibility = Visibility.Visible;
  93. videoNameTxtBx.Visibility = Visibility.Visible;
  94. videoIdTxtBx.Visibility = Visibility.Visible;
  95. rentalDaysTxtBx.Visibility = Visibility.Visible;
  96. videoInfoLbl.Visibility = Visibility.Visible;
  97. rentlistView.Visibility = Visibility.Visible;
  98.  
  99. rAndrBorder.Visibility = Visibility.Visible;
  100. vidTxtBx.Visibility = Visibility.Hidden;
  101.  
  102. returnlistView.Visibility = Visibility.Hidden;
  103. returnBtn.Visibility = Visibility.Hidden;
  104. existingCustomerlistView.Visibility = Visibility.Hidden;
  105. search.Visibility = Visibility.Hidden;
  106. rentalCost.Visibility = Visibility.Visible;
  107.  
  108. removeRent.Visibility = Visibility.Visible;
  109. returnRemove.Visibility = Visibility.Hidden;
  110. customerIDTxtBx.Visibility = Visibility.Hidden;
  111.  
  112. // addReturn.Visibility = Visibility.Hidden;
  113.  
  114. // customerIDTxtBx.Visibility = Visibility.Hidden;
  115.  
  116. }
  117.  
  118. private void returnRB_Checked(object sender, RoutedEventArgs e)
  119. {
  120. RRpageLbl.Content = "Return a Video";
  121.  
  122. //Hides controls from renting a video
  123. rAndrBorder.Visibility = Visibility.Hidden;
  124. fnameTxtBx2.Visibility = Visibility.Hidden;
  125. lnameTxtBx2.Visibility = Visibility.Hidden;
  126. phoneTxtBx2.Visibility = Visibility.Hidden;
  127. ageTxtBx2.Visibility = Visibility.Hidden;
  128. idTxtBx2.Visibility = Visibility.Hidden;
  129. rentBtn.Visibility = Visibility.Hidden;
  130. addToRent.Visibility = Visibility.Hidden;
  131.  
  132. customerExistsLbl.Visibility = Visibility.Hidden;
  133. custExistYesRB.Visibility = Visibility.Hidden;
  134. custExistNoRB.Visibility = Visibility.Hidden;
  135. videoNameTxtBx.Visibility = Visibility.Hidden;
  136. videoIdTxtBx.Visibility = Visibility.Hidden;
  137. rentalDaysTxtBx.Visibility = Visibility.Hidden;
  138. videoInfoLbl.Visibility = Visibility.Hidden;
  139. rentlistView.Visibility = Visibility.Hidden;
  140. customerIDTxtBx.Visibility = Visibility.Hidden;
  141.  
  142. rAndrBorder.Visibility = Visibility.Visible;
  143. vidTxtBx.Visibility = Visibility.Visible;
  144.  
  145. returnlistView.Visibility = Visibility.Visible;
  146.  
  147. returnBtn.Visibility = Visibility.Visible;
  148. existingCustomerlistView.Visibility = Visibility.Hidden;
  149. search.Visibility = Visibility.Hidden;
  150. rentalCost.Visibility = Visibility.Hidden;
  151.  
  152. createUser.Visibility = Visibility.Hidden;
  153.  
  154. removeRent.Visibility = Visibility.Hidden;
  155. returnRemove.Visibility = Visibility.Visible;
  156. //addReturn.Visibility = Visibility.Visible;
  157. }
  158.  
  159. private void custExistYesRB_Checked(object sender, RoutedEventArgs e)
  160. {
  161.  
  162. fnameTxtBx2.Visibility = Visibility.Hidden;
  163. lnameTxtBx2.Visibility = Visibility.Hidden;
  164. phoneTxtBx2.Visibility = Visibility.Hidden;
  165. idTxtBx2.Visibility = Visibility.Hidden;
  166. ageTxtBx2.Visibility = Visibility.Hidden;
  167.  
  168. createUser.Visibility = Visibility.Hidden;
  169.  
  170. customerIDTxtBx.Visibility = Visibility.Visible;
  171. existingCustomerlistView.Visibility = Visibility.Visible;
  172. search.Visibility = Visibility.Visible;
  173. removeRent.Visibility = Visibility.Visible;
  174.  
  175. }
  176.  
  177. private void custExistNoRB_Checked(object sender, RoutedEventArgs e)
  178. {
  179. fnameTxtBx2.Visibility = Visibility.Hidden;
  180. lnameTxtBx2.Visibility = Visibility.Hidden;
  181. phoneTxtBx2.Visibility = Visibility.Hidden;
  182. idTxtBx2.Visibility = Visibility.Hidden;
  183. ageTxtBx2.Visibility = Visibility.Hidden;
  184.  
  185. createUser.Visibility = Visibility.Visible;
  186.  
  187. customerIDTxtBx.Visibility = Visibility.Hidden;
  188. existingCustomerlistView.Visibility = Visibility.Hidden;
  189. search.Visibility = Visibility.Hidden;
  190. removeRent.Visibility = Visibility.Hidden;
  191. customerIDTxtBx.Visibility = Visibility.Hidden;
  192. }
  193. private void button_Click(object sender, RoutedEventArgs e)
  194. {
  195. Dashboard goHome = new Dashboard();
  196. goHome.Show();
  197. this.Close();
  198. }
  199.  
  200. private void addToRentBtn_Click(object sender, RoutedEventArgs e)
  201. {
  202. String videoID = videoIdTxtBx.Text;
  203. // int rentCost = 3; may not need this
  204. int b;
  205. bool isBValid = int.TryParse(rentalDaysTxtBx.Text, out b);
  206.  
  207. bool validID = true;
  208. if ((bool)rentRB.IsChecked) //&& (videoIdTxtBx.Text.Any(char.IsLetter) || videoIdTxtBx.Text.Length != 10))
  209. {
  210.  
  211. // if (videoIdTxtBx.Text.Any(char.IsLetter))
  212. // {
  213. //MessageBox.Show("Please Enter a Movie ID");
  214.  
  215.  
  216.  
  217. SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.tblInventory WHERE Quantity=@Quantity AND InvID = @InvID", connection);
  218. connection.Open();
  219.  
  220. SqlDataReader dbRdr = null;
  221. cmd.Parameters.AddWithValue("@Quantity", 0);
  222.  
  223. cmd.Parameters.AddWithValue("@InvID", videoID);
  224. dbRdr = cmd.ExecuteReader();
  225. while (dbRdr.Read())
  226. {
  227. validID = false;
  228.  
  229. }
  230. connection.Close();
  231.  
  232.  
  233. // }
  234. if ((bool)!custExistNoRB.IsChecked && (bool)!custExistYesRB.IsChecked)
  235. {
  236. MessageBox.Show("Please Enter the Customer Information");
  237. return;
  238. }
  239.  
  240. if (videoIdTxtBx.Text.Any(char.IsLetter) || (videoIdTxtBx.Text.Length < 10 || videoIdTxtBx.Text.Length > 10))
  241. {
  242. MessageBox.Show("Please Enter A Valid Video ID (10 Digits)");
  243. videoIdTxtBx.Text = "Video ID";
  244. return;
  245. }
  246.  
  247. if (rentalDaysTxtBx.Text.Any(char.IsLetter))
  248. {
  249. MessageBox.Show("Please Enter A Number for Rental Days");
  250. rentalDaysTxtBx.Text = "Rental Days";
  251. return;
  252. }
  253.  
  254. if (rentalCost.Text.Any(char.IsLetter))
  255. {
  256. MessageBox.Show("Please Enter A Number for Rental Cost");
  257. rentalCost.Text = "Rental Cost";
  258. return;
  259. }
  260.  
  261. if (Convert.ToInt32(this.rentalDaysTxtBx.Text) > 7)
  262. {
  263. MessageBox.Show("Please Enter A Day Less Than 7");
  264. rentalDaysTxtBx.Text = "Rental Days";
  265. return;
  266. }
  267.  
  268. if (videoNameTxtBx.Text != "Video Name" && validID == true)
  269. {
  270.  
  271. // var row = new { VideoName = videoNameTxtBx.Text, RentalCost = (rentCost * b) };
  272. var row = new { VideoName = videoNameTxtBx.Text, RentalCost = Convert.ToInt32(this.rentalCost.Text) * b, MovieID = videoIdTxtBx.Text , RentDays=rentalDaysTxtBx.Text };
  273. rentlistView.Items.Add(row);
  274. }
  275. if (validID == false)
  276. {
  277. MessageBox.Show("This Has Already Been Rented");
  278. }
  279. }
  280.  
  281.  
  282.  
  283. videoNameTxtBx.Text = "Video Name";
  284. videoIdTxtBx.Text = "Video ID";
  285. rentalDaysTxtBx.Text = "Rental Days";
  286. rentalCost.Text = "Rental Cost";
  287.  
  288.  
  289.  
  290. }
  291.  
  292. private void rentBtn_Click(object sender, RoutedEventArgs e) //change this method to send to database
  293. {
  294. int b;
  295. bool isBValid = int.TryParse(rentalDaysTxtBx.Text, out b);
  296. if ((bool)!custExistYesRB.IsChecked && (bool)!custExistNoRB.IsChecked)
  297. {
  298. MessageBox.Show("Please Enter the Required Information");
  299. return;
  300. }
  301.  
  302. if ((bool)custExistNoRB.IsChecked)
  303. {
  304. if (ageTxtBx2.Text.Any(char.IsLetter) && ageTxtBx2.Text.Length <= 3)
  305. {
  306. MessageBox.Show("Please Enter A Valid Age");
  307. ageTxtBx2.Text = "Age";
  308. return;
  309. }
  310.  
  311. if (fnameTxtBx2.Text.Any(char.IsPunctuation) || fnameTxtBx2.Text.Any(char.IsDigit))
  312. {
  313. MessageBox.Show("Please Use A Valid First Name");
  314. fnameTxtBx2.Text = "First Name";
  315. return;
  316. }
  317.  
  318. if (lnameTxtBx2.Text.Any(char.IsPunctuation) || lnameTxtBx2.Text.Any(char.IsDigit))
  319. {
  320. MessageBox.Show("Please Use A Valid Last Name");
  321. lnameTxtBx2.Text = "Last Name";
  322. return;
  323. }
  324.  
  325.  
  326. if ((phoneTxtBx2.Text.Length < 10 || phoneTxtBx2.Text.Length > 10) || !phoneTxtBx2.Text.All(char.IsDigit))
  327. {
  328. MessageBox.Show("Please Enter A 10 Digit Phone Number");
  329. phoneTxtBx2.Text = "Phone Number";
  330. return;
  331. }
  332. }
  333.  
  334. if ((bool)custExistYesRB.IsChecked)
  335. {
  336. if (customerIDTxtBx.Text.Any(char.IsPunctuation)) //|| customerIDTxtBx.Text.Any(char.IsDigit))
  337. {
  338. MessageBox.Show("Please Enter A Valid Customer ID");
  339. customerIDTxtBx.Text = "Customer ID";
  340. return;
  341.  
  342.  
  343. }
  344.  
  345. if (videoIdTxtBx.Text.All(char.IsDigit) && videoIdTxtBx.Text.Length == 10)
  346. {
  347. MessageBox.Show("Please Enter A Valid Movie ID");
  348. videoIdTxtBx.Text = "Movie ID";
  349. }
  350.  
  351. // string userName = UserName.GetValue<string>("userName");​
  352. while (rentlistView.Items.Count > 0)
  353. {
  354. String query = "INSERT INTO dbo.rental (invID, employeeID, custID, expected_return_date, cost) Values(@InvID,@employeeID,@custID, @expected_return_date, @cost)";
  355. SqlCommand command = new SqlCommand(query, connection);
  356.  
  357.  
  358. char[] delimeterChars = { '=', ',', '}' };
  359. string[] split = rentlistView.Items[0].ToString().Split(delimeterChars);
  360. string[] splat = existingCustomerlistView.SelectedItem.ToString().Split(delimeterChars);
  361.  
  362. DateTime date = DateTime.Now;
  363. Int32 addedDays = (Convert.ToInt32(split[7].Trim()));
  364. date = date.AddDays(addedDays);
  365. DateTime end = date;
  366.  
  367.  
  368.  
  369. command.Parameters.AddWithValue("@InvID", split[5].Trim());
  370. command.Parameters.AddWithValue("@employeeID", "Jsmith6");
  371. command.Parameters.AddWithValue("@custID", splat[5].Trim());
  372. command.Parameters.AddWithValue("@expected_return_date", date);
  373. command.Parameters.AddWithValue("@cost", split[3].Trim());
  374.  
  375.  
  376.  
  377.  
  378. connection.Open();
  379. command.ExecuteNonQuery();
  380.  
  381. connection.Close();
  382.  
  383. returnlistView.Items.Remove(returnlistView.Items[0]);
  384.  
  385. }
  386. videoNameTxtBx.Text = "Video Name";
  387. videoIdTxtBx.Text = "Video ID";
  388. rentalDaysTxtBx.Text = "Rental Days";
  389. rentalCost.Text = "Rental Cost";
  390. }
  391.  
  392. SqlCommand get_history = new SqlCommand("SELECT * FROM dbo.get_history(@customer)", connection);
  393. connection.Open();
  394. SqlDataReader dbRdr = null;
  395. get_history.Parameters.AddWithValue("@customer", customerIDTxtBx.Text);
  396.  
  397. dbRdr = get_history.ExecuteReader();
  398.  
  399. if (dbRdr.Read())
  400. {
  401. // get_history.Parameters.AddWithValue("@customer", customerIDTxtBx.Text);
  402.  
  403. String x = dbRdr[0].ToString();
  404.  
  405. MessageBox.Show(x);
  406.  
  407.  
  408. }
  409. connection.Close();
  410.  
  411. decimal price = 0;
  412. int count = 0;
  413. while (rentlistView.Items.Count > count)
  414. {
  415.  
  416. char[] delimeterChars = { '=', ',', '}' };
  417. string[] split = rentlistView.Items[count].ToString().Split(delimeterChars);
  418.  
  419.  
  420.  
  421. //price = Convert.ToInt32(split[3].Trim());
  422. price = price + Convert.ToDecimal(split[3].Trim());
  423.  
  424.  
  425.  
  426.  
  427. count++;
  428. }
  429.  
  430. MessageBox.Show("Total Cost is " + price);
  431.  
  432. int parsedValue;
  433. rentlistView.Items.Clear();
  434.  
  435.  
  436. if (!int.TryParse(ageTxtBx2.Text, out parsedValue))
  437. {
  438.  
  439. }
  440.  
  441. if (int.TryParse(fnameTxtBx2.Text, out parsedValue))
  442. {
  443.  
  444. }
  445. if (int.TryParse(lnameTxtBx2.Text, out parsedValue))
  446. {
  447.  
  448. }
  449.  
  450.  
  451. fnameTxtBx2.Text = "First Name";
  452. lnameTxtBx2.Text = "Last Name";
  453. phoneTxtBx2.Text = "Phone Number";
  454. ageTxtBx2.Text = "Age";
  455. // customerIDTxtBx.Text = "Customer Name";
  456.  
  457.  
  458. }
  459.  
  460. private void vidTxtBx_TextChanged(object sender, TextChangedEventArgs e)
  461. {
  462.  
  463. if ((bool)returnRB.IsChecked)
  464. {
  465. string movieId = vidTxtBx.Text;
  466.  
  467. bool movieInDb = false;
  468.  
  469. if (movieId.Length == 10 && movieId.All(char.IsDigit))
  470. {
  471.  
  472.  
  473. var row = new
  474. {
  475. VideoName = String.Empty,
  476. MovieID = String.Empty
  477.  
  478. };
  479.  
  480. SqlCommand cmd1 = new SqlCommand("SELECT * FROM dbo.tblInventory WHERE InvID=@InvID AND Quantity=@Quantity", connection);
  481. connection.Open();
  482. cmd1.Parameters.AddWithValue("@InvID", movieId);
  483. cmd1.Parameters.AddWithValue("@Quantity", 0);
  484. SqlDataReader dbRdr = null;
  485. dbRdr = cmd1.ExecuteReader();
  486. while (dbRdr.Read())
  487. {
  488.  
  489.  
  490. row = new
  491. {
  492. VideoName = (dbRdr["Title"].ToString()),
  493. MovieID = (dbRdr["InvID"].ToString())
  494.  
  495. };
  496.  
  497. movieInDb = true;
  498. }
  499. if (movieInDb == true)
  500. {
  501. returnlistView.Items.Add(row);
  502.  
  503. }
  504. vidTxtBx.Text = String.Empty;
  505.  
  506. }
  507.  
  508. if (movieId.Length == 10 && movieInDb == false)
  509. {
  510. MessageBox.Show("Movie ID \"" + movieId + "\" not rented out", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  511. }
  512.  
  513. connection.Close();
  514. }
  515. }
  516.  
  517.  
  518. private void returnlistView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  519. {
  520.  
  521. }
  522.  
  523. private void fnameTxtBx2_GotFocus(object sender, EventArgs e)
  524. {
  525. if (String.IsNullOrWhiteSpace(fnameTxtBx2.Text) || fnameTxtBx2.Text.Equals("First Name"))
  526. {
  527. fnameTxtBx2.Text = "";
  528. }
  529. }
  530.  
  531. private void fnameTxtBx2_LostFocus(object sender, EventArgs e)
  532. {
  533. if (String.IsNullOrWhiteSpace(fnameTxtBx2.Text))
  534. {
  535. fnameTxtBx2.Text = "First Name";
  536. }
  537.  
  538. }
  539.  
  540. private void fnameTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
  541. {
  542. if (fnameTxtBx2.Text != "First Name")
  543. {
  544. if (fnameTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
  545. {
  546. }
  547. }
  548. }
  549. private void lnameTxtBx2_GotFocus(object sender, EventArgs e)
  550. {
  551. if (String.IsNullOrWhiteSpace(lnameTxtBx2.Text) || lnameTxtBx2.Text.Equals("Last Name"))
  552. {
  553. lnameTxtBx2.Text = "";
  554. }
  555. }
  556.  
  557. private void lnameTxtBx2_LostFocus(object sender, EventArgs e)
  558. {
  559. if (String.IsNullOrWhiteSpace(lnameTxtBx2.Text))
  560. {
  561. lnameTxtBx2.Text = "Last Name";
  562. }
  563.  
  564. }
  565.  
  566. private void lnameTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
  567. {
  568. if (lnameTxtBx2.Text != "Last Name")
  569. {
  570. if (lnameTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
  571. {
  572. }
  573. }
  574. }
  575.  
  576. private void phoneTxtBx2_GotFocus(object sender, EventArgs e)
  577. {
  578. if (String.IsNullOrWhiteSpace(phoneTxtBx2.Text) || phoneTxtBx2.Text.Equals("Phone Number"))
  579. {
  580. phoneTxtBx2.Text = "";
  581. }
  582. }
  583.  
  584. private void phoneTxtBx2_LostFocus(object sender, EventArgs e)
  585. {
  586. if (String.IsNullOrWhiteSpace(phoneTxtBx2.Text))
  587. {
  588. phoneTxtBx2.Text = "Phone Number";
  589. }
  590.  
  591. }
  592.  
  593. private void phoneTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
  594. {
  595. if (phoneTxtBx2.Text != "Phone Number")
  596. {
  597. if (phoneTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
  598. {
  599. }
  600. }
  601. }
  602.  
  603. private void ageTxtBx2_GotFocus(object sender, EventArgs e)
  604. {
  605. if (String.IsNullOrWhiteSpace(ageTxtBx2.Text) || ageTxtBx2.Text.Equals("Age"))
  606. {
  607. ageTxtBx2.Text = "";
  608. }
  609. }
  610.  
  611. private void ageTxtBx2_LostFocus(object sender, EventArgs e)
  612. {
  613. if (String.IsNullOrWhiteSpace(ageTxtBx2.Text))
  614. {
  615. ageTxtBx2.Text = "Age";
  616. }
  617.  
  618. }
  619.  
  620. private void ageTxtBx2_TextChanged(object sender, TextChangedEventArgs e)
  621. {
  622. if (ageTxtBx2.Text != "Age")
  623. {
  624. if (ageTxtBx2.Text != txtbxSubmittedValue) //use this for the rent button
  625. {
  626. }
  627. }
  628. }
  629.  
  630. private void videoNameTxtBx_GotFocus(object sender, EventArgs e)
  631. {
  632. if (String.IsNullOrWhiteSpace(videoNameTxtBx.Text) || videoNameTxtBx.Text.Equals("Video Name"))
  633. {
  634. videoNameTxtBx.Text = "";
  635. }
  636. }
  637.  
  638. private void videoNameTxtBx_LostFocus(object sender, EventArgs e)
  639. {
  640. if (String.IsNullOrWhiteSpace(videoNameTxtBx.Text))
  641. {
  642. videoNameTxtBx.Text = "Video Name";
  643. }
  644.  
  645. }
  646.  
  647. private void videoNameTxtBx_TextChanged(object sender, TextChangedEventArgs e)
  648. {
  649. if (videoNameTxtBx.Text != "Video Name")
  650. {
  651. if (videoNameTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
  652. {
  653.  
  654. }
  655. }
  656. }
  657.  
  658. private void videoIdTxtBx_GotFocus(object sender, EventArgs e)
  659. {
  660. if (String.IsNullOrWhiteSpace(videoIdTxtBx.Text) || videoIdTxtBx.Text.Equals("Video ID"))
  661. {
  662. videoIdTxtBx.Text = "";
  663. }
  664. }
  665.  
  666. private void videoIdTxtBx_LostFocus(object sender, EventArgs e)
  667. {
  668. if (String.IsNullOrWhiteSpace(videoIdTxtBx.Text))
  669. {
  670. videoIdTxtBx.Text = "Video ID";
  671. }
  672.  
  673. }
  674.  
  675. private void videoIdTxtBx_TextChanged(object sender, TextChangedEventArgs e)
  676. {
  677. if (videoIdTxtBx.Text != "Video ID")
  678. {
  679. if (videoIdTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
  680. {
  681. }
  682. }
  683. }
  684.  
  685. private void vidTxtBx_GotFocus(object sender, EventArgs e)
  686. {
  687. if (String.IsNullOrWhiteSpace(vidTxtBx.Text) || vidTxtBx.Text.Equals("Video ID"))
  688. {
  689. vidTxtBx.Text = "";
  690. }
  691. }
  692.  
  693. private void vidTxtBx_LostFocus(object sender, EventArgs e)
  694. {
  695. if (String.IsNullOrWhiteSpace(vidTxtBx.Text))
  696. {
  697. vidTxtBx.Text = "Video ID";
  698. }
  699.  
  700. }
  701.  
  702.  
  703.  
  704. private void rentalDaysTxtBx_GotFocus(object sender, EventArgs e)
  705. {
  706. if (String.IsNullOrWhiteSpace(rentalDaysTxtBx.Text) || rentalDaysTxtBx.Text.Equals("Rental Days"))
  707. {
  708. rentalDaysTxtBx.Text = "";
  709. }
  710. }
  711.  
  712. private void rentalDaysTxtBx_LostFocus(object sender, EventArgs e)
  713. {
  714. if (String.IsNullOrWhiteSpace(rentalDaysTxtBx.Text))
  715. {
  716. rentalDaysTxtBx.Text = "Rental Days";
  717. }
  718.  
  719. }
  720.  
  721. private void rentalDaysTxtBx_TextChanged(object sender, TextChangedEventArgs e)
  722. {
  723. if (rentalDaysTxtBx.Text != "Rental Days")
  724. {
  725. if (rentalDaysTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
  726. {
  727. }
  728. }
  729. }
  730.  
  731. private void customerIDTxtBx_GotFocus(object sender, EventArgs e)
  732. {
  733. if (String.IsNullOrWhiteSpace(customerIDTxtBx.Text) || customerIDTxtBx.Text.Equals("Customer ID"))
  734. {
  735. customerIDTxtBx.Text = "";
  736. }
  737. }
  738.  
  739. private void customerIDTxtBx_LostFocus(object sender, EventArgs e)
  740. {
  741. if (String.IsNullOrWhiteSpace(customerIDTxtBx.Text))
  742. {
  743. customerIDTxtBx.Text = "Customer ID";
  744. }
  745.  
  746. }
  747.  
  748. private void customerIDTxtBx_TextChanged(object sender, TextChangedEventArgs e)
  749. {
  750. if (customerIDTxtBx.Text != "Customer ID")
  751. {
  752. if (customerIDTxtBx.Text != txtbxSubmittedValue) //use this for the rent button
  753. {
  754. }
  755. }
  756. }
  757.  
  758.  
  759. private void addReturn_Click(object sender, EventArgs e) //return stuff
  760. {
  761.  
  762.  
  763. if ((bool)returnRB.IsChecked)
  764. {
  765.  
  766. while (returnlistView.Items.Count > 0)
  767. {
  768. char[] delimeterChars = { '=', ',', '}' };
  769. string[] split = returnlistView.Items[0].ToString().Split(delimeterChars);
  770.  
  771. DateTime today = DateTime.Now;
  772. SqlCommand sqlCmd = new SqlCommand("UPDATE dbo.rental SET date_returned=@date_returned WHERE InvID=@InvID", connection);
  773. sqlCmd.Parameters.AddWithValue("@date_returned", today);
  774. sqlCmd.Parameters.AddWithValue("@InvID", split[3].Trim());
  775. connection.Open();
  776. sqlCmd.ExecuteNonQuery();
  777. connection.Close();
  778.  
  779. SqlCommand command = new SqlCommand("UPDATE dbo.tblInventory SET Quantity = @Quantity WHERE InvID = @InvID", connection);
  780. command.Parameters.AddWithValue("@Quantity", 1);
  781. command.Parameters.AddWithValue("@InvID", split[3].Trim());
  782. connection.Open();
  783. command.ExecuteNonQuery();
  784. connection.Close();
  785.  
  786. returnlistView.Items.Remove(returnlistView.Items[0]);
  787. }
  788. MessageBox.Show("Return Was Successful");
  789. returnlistView.Items.Clear();
  790.  
  791. }
  792.  
  793. }
  794.  
  795.  
  796. private void search_Click(object sender, RoutedEventArgs e) //completely works! rent stuff
  797. {
  798.  
  799.  
  800.  
  801. if (customerIDTxtBx.Text == "Customer ID")
  802. {
  803. SqlCommand then = new SqlCommand("SELECT FirstName, Phone_num, custID FROM dbo.tblCustomers", connection);
  804. SqlDataReader other = null;
  805. connection.Open();
  806. other = then.ExecuteReader();
  807. while (other.Read())
  808. {
  809. var row = new
  810. {
  811. CustomerName = (other["FirstName"].ToString()),
  812. PhoneNumber = (other["Phone_num"].ToString()),
  813. CustomerID = (other["custID"].ToString())
  814. };
  815. existingCustomerlistView.Items.Add(row);
  816. existingCustomerlistView.IsEnabled = true;
  817. }
  818. connection.Close();
  819. }
  820.  
  821.  
  822.  
  823. else
  824. {
  825. SqlCommand search = new SqlCommand("SELECT FirstName, Phone_num, custID FROM dbo.tblCustomers WHERE custID = @custID", connection);
  826.  
  827. existingCustomerlistView.Items.Clear();
  828. search.Parameters.AddWithValue("@custID", customerIDTxtBx.Text);
  829.  
  830. SqlDataReader dbRdr = null;
  831. connection.Open();
  832. dbRdr = search.ExecuteReader();
  833. while (dbRdr.Read())
  834. {
  835.  
  836. var row = new
  837. {
  838. CustomerName = (dbRdr["FirstName"].ToString()),
  839. PhoneNumber = (dbRdr["Phone_num"].ToString()),
  840. CustomerID = (dbRdr["custID"].ToString())
  841. };
  842.  
  843. existingCustomerlistView.Items.Add(row);
  844. existingCustomerlistView.IsEnabled = true;
  845. }
  846. connection.Close();
  847. }
  848.  
  849. }
  850.  
  851.  
  852.  
  853. private void rentlistView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  854. {
  855.  
  856. }
  857.  
  858. private void textBox_TextChanged(object sender, TextChangedEventArgs e)
  859. {
  860.  
  861. }
  862.  
  863. private void createUser_Click(object sender, RoutedEventArgs e)
  864. {
  865. Profile win3 = new Profile();
  866. win3.Show();
  867. this.Close();
  868. }
  869.  
  870. private void rentalCost_GotFocus(object sender, RoutedEventArgs e)
  871. {
  872. if (String.IsNullOrWhiteSpace(rentalCost.Text) || rentalCost.Text.Equals("Rental Cost"))
  873. {
  874. rentalCost.Text = "";
  875. }
  876. }
  877.  
  878. private void rentalCost_LostFocus(object sender, RoutedEventArgs e)
  879. {
  880. if (String.IsNullOrWhiteSpace(rentalCost.Text))
  881. {
  882. rentalCost.Text = "Rental Cost";
  883. }
  884. }
  885.  
  886. private void rentalCost_TextChanged(object sender, TextChangedEventArgs e)
  887. {
  888. if (rentalCost.Text != "Rental Cost")
  889. {
  890. if (rentalCost.Text != txtbxSubmittedValue) //use this for the rent button
  891. {
  892. }
  893. }
  894. }
  895.  
  896. private void removeRent_Click(object sender, RoutedEventArgs e)
  897. {
  898. if (rentlistView.SelectedItem != null)
  899. {
  900. while (rentlistView.SelectedItems.Count > 0)
  901. {
  902. rentlistView.Items.Remove(rentlistView.SelectedItems[0]);
  903. }
  904. }
  905. }
  906.  
  907. private void returnRemove_Click(object sender, RoutedEventArgs e)
  908. {
  909. if (returnlistView.SelectedItem != null)
  910. {
  911. while (returnlistView.SelectedItems.Count > 0)
  912. {
  913. returnlistView.Items.Remove(returnlistView.SelectedItems[0]);
  914. }
  915. }
  916. }
  917. }
  918. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement