Advertisement
Guest User

Untitled

a guest
Jan 25th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Windows.Markup;
  15. using System.IO;
  16. using System.Windows.Threading;
  17. using Microsoft.VisualBasic;
  18. using System.Xml;
  19. using System.ComponentModel;
  20. using System.Windows.Forms;
  21. using System.Net;
  22. using System.Threading;
  23.  
  24. namespace scoreboardManager
  25. {
  26. /*
  27. reminder for in-app images/videos/content/etc
  28. Logo.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Scoreman Logo.png"));
  29. */
  30. public partial class Startup : Window
  31. {
  32. private string settingsPath = "";
  33. private string teamDatabasePath = "";
  34. private string studioURL = "http://studio.cbtg.us/scoreman/login.php"; //Username: MrTest Pass: Chrisdw1945!
  35. private string userDocumentPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/scoreman/";
  36. private int screenIndex; //which app screen [0 = login] [1 = event id] [2 = pick a sport]
  37. private bool settings;
  38. private bool[] databaseChanges = { true, true, true };
  39. private string currDatabaseVersion; //0.0.0
  40. private int carouselIndex; //[0 = Baseball] [1 = Football] [2 = Soccer]
  41. private bool selectedSport;
  42. Utils utils = new Utils();
  43.  
  44. public Startup()
  45. {
  46. InitializeComponent();//XAML built in initalization
  47. AppInitalize();
  48.  
  49. screenIndex = 0;
  50. UpdateUI(false);
  51.  
  52. carouselIndex = 3;//starting index
  53. SportLeft2.IsEnabled = false;
  54. SportLeft1.IsEnabled = false;
  55. SportCenter.IsEnabled = true;
  56. SportRight1.IsEnabled = false;
  57. SportRight2.IsEnabled = false;
  58. CycleCarosuel(false);
  59. }
  60. private void AppInitalize()
  61. {
  62. //---------------Check connection
  63. if (utils.CheckInternetConnection(studioURL) == false)//change in the future, for offline use
  64. return;
  65. //---------------Check if the directory exists
  66. settingsPath = Directory.Exists(userDocumentPath) ? userDocumentPath + "scoreman.ini" : System.IO.Directory.CreateDirectory(userDocumentPath) + "scoreman.ini";
  67. //---------------Check if the scoreman.ini exists
  68. if (!File.Exists(settingsPath))
  69. {
  70. System.Windows.Forms.MessageBox.Show("Please Select a path containing the Team Database", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  71. using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
  72. {
  73. DialogResult folderBrowserDialogResult = folderBrowserDialog.ShowDialog();
  74.  
  75. if (folderBrowserDialogResult == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(folderBrowserDialog.SelectedPath))
  76. teamDatabasePath = folderBrowserDialog.SelectedPath;
  77. else
  78. System.Windows.Forms.MessageBox.Show("Team Data not found! Must be a root folder containing data and logos, Configure this under the options menu.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  79. }
  80. using (StreamWriter f = File.CreateText(settingsPath))
  81. {
  82. f.WriteLine(settingsPath);//path
  83. f.WriteLine(teamDatabasePath);//team path
  84. f.WriteLine(".");//username
  85. f.WriteLine(".");//password
  86. f.WriteLine("100");//databaseVersion
  87. }
  88. using (StreamWriter w = File.CreateText(teamDatabasePath + "/version.txt"))
  89. w.WriteLine("000");
  90. databaseChanges[0] = false;
  91. databaseChanges[1] = true;
  92. databaseChanges[2] = false;
  93. }
  94. //--------------Read ini file
  95. string[] lines = File.ReadAllLines(settingsPath);// 0 = settingsPath, 1 = teamDatabasePath, 2 = username, 3 = password
  96.  
  97. //if (lines[1] != null)
  98. // System.Windows.MessageBox.Show("Team Data could not be found, please re-assign these paths");
  99. if (lines[1] != ".")
  100. {
  101. DatabasePath.Text = lines[1];
  102. databaseChanges[0] = true;
  103. databaseChanges[1] = false;
  104. databaseChanges[2] = true;
  105. }
  106. else
  107. {
  108. System.Windows.MessageBox.Show("Team Data could not be found, please re-assign these paths", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  109. databaseChanges[0] = false;
  110. databaseChanges[1] = true;
  111. databaseChanges[2] = false;
  112. }
  113.  
  114. try
  115. {
  116. if (lines[2] != "." || lines[3] != ".")
  117. {
  118. Username.Text = lines[2];
  119. Password.Password = lines[3];
  120. }
  121. }
  122. catch
  123. {
  124. Username.Text = "";
  125. Password.Password = "";
  126. }
  127. try { currDatabaseVersion = lines[4]; } catch { currDatabaseVersion = "Unknown"; }
  128. }
  129. private void UpdateTeamDatabase (string path)
  130. {
  131. if(File.Exists(path))
  132. {
  133. string data = File.ReadAllText(path);
  134. if(data.ToString() == currDatabaseVersion)
  135. System.Windows.Forms.MessageBox.Show("Database is already up-to-date", "Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  136. else
  137. {
  138. DialogResult prompt = System.Windows.Forms.MessageBox.Show("Are you sure you want to Update?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  139. if (prompt == System.Windows.Forms.DialogResult.Yes)
  140. {
  141. databaseChanges[2] = false;
  142. }
  143. else
  144. {
  145. databaseChanges[2] = true;
  146. }
  147. }
  148. }
  149. else
  150. {
  151. System.Windows.Forms.MessageBox.Show("Version Identifer not found", "Update", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  152. using (StreamWriter w = File.CreateText(path))
  153. w.WriteLine("000");
  154. }
  155. }
  156. private void ApplyChangesToINI()
  157. {
  158. using (StreamWriter writer = new StreamWriter(File.Open(settingsPath, FileMode.Truncate)))
  159. {
  160. writer.Flush();
  161. writer.WriteLine(settingsPath);
  162. writer.WriteLine(DatabasePath.Text);
  163. if (RememberLogin.IsChecked == true)
  164. {
  165. writer.WriteLine(Username.Text);
  166. writer.WriteLine(Password.Password);
  167. }
  168. writer.Close();
  169. }
  170. }
  171. private void ApplicationLogIn ()
  172. {
  173. if (utils.VerifyAccountOnServer(studioURL, Username.Text, Password.Password))
  174. {
  175. ApplyChangesToINI();
  176. screenIndex = 1;
  177. UpdateUI(false);
  178. }
  179. else
  180. {
  181. screenIndex = 0;
  182. UpdateUI(false);
  183. }
  184. }
  185. private void CycleCarosuel (bool goingRight)
  186. {
  187. System.Windows.Controls.Image[] sportsImages = { SportLeft2_Image, SportLeft1_Image, SportCenter_Image, SportRight1_Image, SportRight2_Image };
  188.  
  189. carouselIndex = goingRight ? carouselIndex += 1 : carouselIndex -= 1;
  190. carouselIndex = (carouselIndex < 0) ? 0 : ((carouselIndex > 7) ? 7 : carouselIndex);
  191.  
  192. if (carouselIndex == 0)
  193. {
  194. sportsImages[0].Source = null;
  195. sportsImages[1].Source = null;
  196. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Baseball-512x512.png"));
  197. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Basketball-512x512.png"));
  198. sportsImages[4].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Football-512x512.png"));
  199. }
  200. else if (carouselIndex == 1)
  201. {
  202. sportsImages[0].Source = null;
  203. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Baseball-512x512.png"));
  204. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Basketball-512x512.png"));
  205. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Football-512x512.png"));
  206. sportsImages[4].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Soccer-512x512.png"));
  207. }
  208. else if (carouselIndex == 2)
  209. {
  210. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Baseball-512x512.png"));
  211. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Basketball-512x512.png"));
  212. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Football-512x512.png"));
  213. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Soccer-512x512.png"));
  214. sportsImages[4].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Softball-512x512.png"));
  215. }
  216. else if (carouselIndex == 3)
  217. {
  218. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Basketball-512x512.png"));
  219. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Football-512x512.png"));
  220. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Soccer-512x512.png"));
  221. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Softball-512x512.png"));
  222. sportsImages[4].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Tennis-512x512.png"));
  223. }
  224. else if (carouselIndex == 4)
  225. {
  226. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Football-512x512.png"));
  227. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Soccer-512x512.png"));
  228. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Softball-512x512.png"));
  229. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Tennis-512x512.png"));
  230. sportsImages[4].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Vollyball-512x512.png"));
  231. }
  232. else if (carouselIndex == 5)
  233. {
  234. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Soccer-512x512.png"));
  235. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Softball-512x512.png"));
  236. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Tennis-512x512.png"));
  237. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Vollyball-512x512.png"));
  238. sportsImages[4].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Wrestling-512x512.png"));
  239. }
  240. else if (carouselIndex == 6)
  241. {
  242. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Softball-512x512.png"));
  243. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Tennis-512x512.png"));
  244. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Vollyball-512x512.png"));
  245. sportsImages[3].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Wrestling-512x512.png"));
  246. sportsImages[4].Source = null;
  247. }
  248. else if (carouselIndex == 7)
  249. {
  250. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Tennis-512x512.png"));
  251. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Vollyball-512x512.png"));
  252. sportsImages[2].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Wrestling-512x512.png"));
  253. sportsImages[3].Source = null;
  254. sportsImages[4].Source = null;
  255. }
  256. else if (carouselIndex == 8)
  257. {
  258. sportsImages[0].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Vollyball-512x512.png"));
  259. sportsImages[1].Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Wrestling-512x512.png"));
  260. sportsImages[2].Source = null;
  261. sportsImages[3].Source = null;
  262. sportsImages[4].Source = null;
  263. }
  264. }
  265. private void UpdateUI (bool atSettingsScreen)
  266. {
  267. if (!atSettingsScreen)
  268. {
  269. if (screenIndex == 0)//login
  270. {
  271. Login_Screen.Visibility = Visibility.Visible;
  272. EventID_Screen.Visibility = Visibility.Hidden;
  273. SportSelection_Screen.Visibility = Visibility.Hidden;
  274. Settings_Screen.Visibility = Visibility.Hidden;
  275.  
  276. FirstCircle.Opacity = 1.0;
  277. MiddleCircle.Opacity = 0.25;
  278. LastCircle.Opacity = 0.25;
  279. }
  280. else if (screenIndex == 1)//event id
  281. {
  282. Login_Screen.Visibility = Visibility.Hidden;
  283. EventID_Screen.Visibility = Visibility.Visible;
  284. SportSelection_Screen.Visibility = Visibility.Hidden;
  285. Settings_Screen.Visibility = Visibility.Hidden;
  286.  
  287. FirstCircle.Opacity = 0.25;
  288. MiddleCircle.Opacity = 1.0;
  289. LastCircle.Opacity = 0.25;
  290. }
  291. else//sport selection
  292. {
  293. Login_Screen.Visibility = Visibility.Hidden;
  294. EventID_Screen.Visibility = Visibility.Hidden;
  295. SportSelection_Screen.Visibility = Visibility.Visible;
  296. Settings_Screen.Visibility = Visibility.Hidden;
  297.  
  298. FirstCircle.Opacity = 0.25;
  299. MiddleCircle.Opacity = 0.25;
  300. LastCircle.Opacity = 1.0;
  301. }
  302. }
  303. else
  304. {
  305. Login_Screen.Visibility = Visibility.Hidden;
  306. EventID_Screen.Visibility = Visibility.Hidden;
  307. SportSelection_Screen.Visibility = Visibility.Hidden;
  308. Settings_Screen.Visibility = Visibility.Visible;
  309.  
  310. FirstCircle.Opacity = 0.25;
  311. MiddleCircle.Opacity = 0.25;
  312. LastCircle.Opacity = 0.25;
  313. }
  314. //------database settings
  315. RemoveDatabase.Opacity = databaseChanges[0] ? 1.0f : 0.25f;
  316. RemoveDatabase.IsEnabled = databaseChanges[0] ? true : false;
  317. DownloadDatabase.Opacity = databaseChanges[1] ? 1.0f : 0.25f;
  318. DownloadDatabase.IsEnabled = databaseChanges[1] ? true : false;
  319. UpdateDatabase.Opacity = databaseChanges[2] ? 1.0f : 0.25f;
  320. UpdateDatabase.IsEnabled = databaseChanges[2] ? true : false;
  321. DatabaseIdentifer.Content = utils.ValidateDatabasePath(teamDatabasePath + "/") ? "Offline Database Linked : Version " + currDatabaseVersion : "Offline Database Not Found : Version " + currDatabaseVersion;
  322. }
  323. //------------LINK OUR FUNCTIONS TO XAML FUNCTIONS--------------
  324. protected override void OnClosing(CancelEventArgs e)
  325. {
  326. utils.CloseWindow(e, true, "", selectedSport);
  327. }
  328. private void Browse_TeamData_Click(object sender, RoutedEventArgs e)
  329. {
  330. FolderBrowserDialog fb1 = new FolderBrowserDialog();
  331. DialogResult r1 = fb1.ShowDialog();
  332.  
  333. if (r1 == System.Windows.Forms.DialogResult.Cancel)
  334. DatabasePath.Text = DatabasePath.Text;
  335. else if (r1 == System.Windows.Forms.DialogResult.OK)
  336. {
  337. if (utils.ValidateDatabasePath(fb1.SelectedPath))
  338. {
  339. DatabasePath.Text = fb1.SelectedPath;
  340. ApplyChangesToINI();
  341. }
  342. else
  343. {
  344. System.Windows.Forms.MessageBox.Show("Database could not be validated! Please check the path for any misspelled or missing folders. Must contain 'data' and 'logos'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  345. }
  346. }
  347. UpdateUI(true);
  348. }
  349. private void EventID_Next(object sender, RoutedEventArgs e)
  350. {
  351. if (EventID.Text == "Event ID")
  352. System.Windows.Forms.MessageBox.Show("Enter an Event ID", "Event ID", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  353. else
  354. {
  355. screenIndex = 2;
  356. UpdateUI(false);
  357. }
  358. }
  359. private void EventID_Offline(object sender, RoutedEventArgs e)
  360. {
  361. screenIndex = 2;
  362. UpdateUI(false);
  363. }
  364. private void RemoveDatabase_Click(object sender, RoutedEventArgs e)
  365. {
  366. DialogResult prompt = System.Windows.Forms.MessageBox.Show("Are you sure you want to remove the Offline Team Database?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  367. if(prompt == System.Windows.Forms.DialogResult.Yes)
  368. {
  369. databaseChanges[0] = false;
  370. databaseChanges[1] = true;
  371. databaseChanges[2] = false;
  372.  
  373. //Directory.Delete(teamDatabasePath, true);
  374. //ApplyChangesToINI();
  375.  
  376. UpdateUI(true);
  377. }
  378. }
  379. private void OnPressEnter(object sender, System.Windows.Input.KeyEventArgs e)
  380. {
  381. if (e.Key == Key.Enter)
  382. {
  383. if (screenIndex == 0)
  384. ApplicationLogIn();
  385. }
  386. }
  387. private void DownloadDatabase_Click(object sender, RoutedEventArgs e)
  388. {
  389. databaseChanges[0] = true;
  390. databaseChanges[1] = false;
  391. databaseChanges[2] = true;
  392. UpdateUI(true);
  393. }
  394. private void UpdateDatabase_Click(object sender, RoutedEventArgs e)
  395. {
  396. UpdateTeamDatabase(teamDatabasePath + "/version.txt");
  397. UpdateUI(true);
  398. }
  399. private void Ellipse_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
  400. {
  401. Ellipse elp = sender as Ellipse;
  402. elp.Fill = new SolidColorBrush(Colors.White);
  403. }
  404. private void Ellipse_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  405. {
  406. Ellipse elp = sender as Ellipse;
  407. elp.Fill = new SolidColorBrush(Colors.Black);
  408. }
  409. private void Button_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
  410. {
  411. System.Windows.Controls.Button b = sender as System.Windows.Controls.Button;
  412. b.Foreground = new SolidColorBrush(Colors.Black);
  413. }
  414. private void Button_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  415. {
  416. System.Windows.Controls.Button b = sender as System.Windows.Controls.Button;
  417. b.Foreground = new SolidColorBrush(Colors.White);
  418. }
  419. private void StartScoring_Click(object sender, RoutedEventArgs e)
  420. {
  421. //if (utils.ValidateDatabasePath(teamDatabasePath))
  422. //{
  423. if (carouselIndex == 0)
  424. {
  425. selectedSport = true;
  426. Baseball b = new Baseball();
  427. b.Show();
  428. Close();
  429. }
  430. else if (carouselIndex == 1)
  431. {
  432. selectedSport = true;
  433. Basketball b = new Basketball();
  434. b.Show();
  435. Close();
  436. }
  437. else if (carouselIndex == 2)
  438. {
  439. selectedSport = true;
  440. Football f = new Football();
  441. f.Show();
  442. Close();
  443. }
  444. else if (carouselIndex == 3)
  445. {
  446. selectedSport = true;
  447. Soccer s = new Soccer();
  448. s.Show();
  449. Close();
  450. }
  451. else if (carouselIndex == 4)
  452. {
  453. selectedSport = true;
  454. Baseball b = new Baseball();
  455. b.Show();
  456. Close();
  457. }
  458. else if (carouselIndex == 5)
  459. {
  460.  
  461. }
  462. else if (carouselIndex == 6)
  463. {
  464.  
  465. }
  466. else if (carouselIndex == 7)
  467. {
  468. selectedSport = true;
  469. Wrestling w = new Wrestling();
  470. w.Show();
  471. Close();
  472. }
  473. //}
  474. //else
  475. //{
  476. //System.Windows.MessageBox.Show("Team Database Path is missing!");
  477. //UpdateUI(true);
  478. // }
  479. }
  480. private void LogOn_Click(object sender, RoutedEventArgs e) { ApplicationLogIn(); }
  481. private void SettingsButt_Click(object sender, RoutedEventArgs e) { settings = !settings; UpdateUI(settings); }
  482. private void MiddleCircle_MouseDown(object sender, MouseButtonEventArgs e) { screenIndex = 1; UpdateUI(false); }
  483. private void FirstCircle_MouseDown(object sender, MouseButtonEventArgs e) { screenIndex = 0; UpdateUI(false); }
  484. private void LastCircle_MouseDown(object sender, MouseButtonEventArgs e) { screenIndex = 2; UpdateUI(false); }
  485. private void ArrowRight_Click(object sender, RoutedEventArgs e) { CycleCarosuel(true); }
  486. private void ArrowLeft_Click(object sender, RoutedEventArgs e) { CycleCarosuel(false); }
  487. }
  488. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement