Advertisement
canezzy

Untitled

May 29th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.23 KB | None | 0 0
  1. using emlekmu.models;
  2. using emlekmu.models.IO;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using Type = emlekmu.models.Type;
  20. using Color = emlekmu.models.Color;
  21.  
  22. namespace emlekmu
  23. {
  24. /// <summary>
  25. /// Interaction logic for MainContent.xaml
  26. /// </summary>
  27. public partial class MainContent : UserControl
  28. {
  29. #region Event listeners
  30. #endregion
  31. #region Data
  32.  
  33.  
  34.  
  35. protected virtual void OnPropertyChanged(string name)
  36. {
  37. if (PropertyChanged != null)
  38. {
  39. PropertyChanged(this, new PropertyChangedEventArgs(name));
  40. }
  41. }
  42.  
  43. public event PropertyChangedEventHandler PropertyChanged;
  44.  
  45. public ObservableCollection<Type> types;
  46. public ObservableCollection<Type> Types
  47. {
  48. get
  49. {
  50. return types;
  51. }
  52. set
  53. {
  54. if (value != types)
  55. {
  56. types = value;
  57. OnPropertyChanged("Types");
  58. }
  59. }
  60. }
  61.  
  62. ObservableCollection<Monument> monuments;
  63. public ObservableCollection<Monument> Monuments
  64. {
  65. get
  66. {
  67. return monuments;
  68. }
  69. set
  70. {
  71. if (value != monuments)
  72. {
  73. monuments = value;
  74. OnPropertyChanged("Monuments");
  75. }
  76. }
  77. }
  78. ObservableCollection<Monument> searchedMonuments;
  79. public ObservableCollection<Monument> SearchedMonuments
  80. {
  81. get
  82. {
  83. return searchedMonuments;
  84. }
  85. set
  86. {
  87. if (value != searchedMonuments)
  88. {
  89. searchedMonuments = value;
  90. OnPropertyChanged("SearchedMonuments");
  91. }
  92. }
  93. }
  94. ObservableCollection<Monument> filteredMonuments;
  95. public ObservableCollection<Monument> FilteredMonuments
  96. {
  97. get
  98. {
  99. return filteredMonuments;
  100. }
  101. set
  102. {
  103. if (value != filteredMonuments)
  104. {
  105. filteredMonuments = value;
  106. OnPropertyChanged("FilteredMonuments");
  107. }
  108. }
  109. }
  110.  
  111. ObservableCollection<Tag> tags;
  112. public ObservableCollection<Tag> Tags
  113. {
  114. get
  115. {
  116. return tags;
  117. }
  118. set
  119. {
  120. if (value != tags)
  121. {
  122. tags = value;
  123. OnPropertyChanged("Tags");
  124. }
  125. }
  126. }
  127. #endregion
  128.  
  129. #region Search parameters
  130. int id_s;
  131. string name_s;
  132. string typeName_s;
  133. string era_s;
  134. int arch_s;
  135. int unesco_s;
  136. int populated_s;
  137. string touristicStatus_s;
  138. int min_income_s;
  139. int max_income_s;
  140. List<Tag> tags_s;
  141.  
  142.  
  143. int id_f;
  144. string name_f;
  145. string typeName_f;
  146. string era_f;
  147. int arch_f;
  148. int unesco_f;
  149. int populated_f;
  150. string touristicStatus_f;
  151. int min_income_f;
  152. int max_income_f;
  153. List<Tag> tags_f;
  154. #endregion
  155. #region Lists
  156.  
  157. #endregion
  158. #region Monument
  159. public delegate Monument onAddMonument(Monument m);
  160. public delegate Monument onRemoveMonument(int id);
  161. public delegate Monument onEditMonument(Monument m);
  162. public delegate Monument onFindMonument(int id);
  163. public delegate void onFindMonuments(int id, string name, string typeName, string era, int arch, int unesco, int populated, string touristicStatus, int min_income, int max_income, List<Tag> tags);
  164. public delegate void onFilterMonuments(int id, string name, string typeName, string era, int arch, int unesco, int populated, string touristicStatus, int min_income, int max_income, List<Tag> tags);
  165.  
  166.  
  167. public onAddMonument addMonumentCallback { get; set; }
  168. public onRemoveMonument removeMonumentCallback { get; set; }
  169. public onEditMonument editMonumentCallback { get; set; }
  170. public onFindMonument findMonumentCallback { get; set; }
  171. public onFindMonuments findMonumentsCallback { get; set; }
  172. public onFilterMonuments filterMonumentsCallback { get; set; }
  173.  
  174. Monument addMonument(Monument t)
  175. {
  176. this.Monuments.Add(t);
  177. this.findMonuments(
  178. this.id_s,
  179. this.name_s,
  180. this.typeName_s,
  181. this.era_s,
  182. this.arch_s,
  183. this.unesco_s,
  184. this.populated_s,
  185. this.touristicStatus_s,
  186. this.min_income_s,
  187. this.max_income_s,
  188. this.tags_s);
  189. this.filterMonuments(
  190. this.id_f,
  191. this.name_f,
  192. this.typeName_f,
  193. this.era_f,
  194. this.arch_f,
  195. this.unesco_f,
  196. this.populated_f,
  197. this.touristicStatus_f,
  198. this.min_income_f,
  199. this.max_income_f,
  200. this.tags_f);
  201. return t;
  202. }
  203.  
  204. Monument removeMonument(int id)
  205. {
  206. foreach (var m in this.Monuments)
  207. {
  208. if (m.Id == id)
  209. {
  210. this.Monuments.Remove(m);
  211. this.findMonuments(
  212. this.id_s,
  213. this.name_s,
  214. this.typeName_s,
  215. this.era_s,
  216. this.arch_s,
  217. this.unesco_s,
  218. this.populated_s,
  219. this.touristicStatus_s,
  220. this.min_income_s,
  221. this.max_income_s,
  222. this.tags_s);
  223. this.filterMonuments(
  224. this.id_f,
  225. this.name_f,
  226. this.typeName_f,
  227. this.era_f,
  228. this.arch_f,
  229. this.unesco_f,
  230. this.populated_f,
  231. this.touristicStatus_f,
  232. this.min_income_f,
  233. this.max_income_f,
  234. this.tags_f);
  235. return m;
  236. }
  237. }
  238. return null;
  239. }
  240.  
  241. Monument editMonument(Monument t)
  242. {
  243. if (this.Monuments.Remove(t))
  244. {
  245. this.Monuments.Add(t);
  246. this.findMonuments(
  247. this.id_s,
  248. this.name_s,
  249. this.typeName_s,
  250. this.era_s,
  251. this.arch_s,
  252. this.unesco_s,
  253. this.populated_s,
  254. this.touristicStatus_s,
  255. this.min_income_s,
  256. this.max_income_s,
  257. this.tags_s);
  258. this.filterMonuments(
  259. this.id_f,
  260. this.name_f,
  261. this.typeName_f,
  262. this.era_f,
  263. this.arch_f,
  264. this.unesco_f,
  265. this.populated_f,
  266. this.touristicStatus_f,
  267. this.min_income_f,
  268. this.max_income_f,
  269. this.tags_f);
  270. return t;
  271. }
  272. return null;
  273. }
  274.  
  275. Monument findMonument(int id)
  276. {
  277. foreach (var m in this.Monuments)
  278. {
  279. if (m.Id == id)
  280. {
  281. return m;
  282. }
  283. }
  284. return null;
  285. }
  286.  
  287. void findMonuments(
  288. int id,
  289. string name,
  290. string typeName,
  291. string era,
  292. int arch,
  293. int unesco,
  294. int populated,
  295. string touristicStatus,
  296. int min_income,
  297. int max_income,
  298. List<Tag> tags
  299. )
  300. {
  301. this.id_s = id;
  302. this.name_s = name;
  303. this.typeName_s = typeName;
  304. this.era_s = era;
  305. this.arch_s = arch;
  306. this.unesco_s = unesco;
  307. this.populated_s = populated;
  308. this.touristicStatus_s = touristicStatus;
  309. this.min_income_s = min_income;
  310. this.max_income_s = max_income;
  311. this.tags_s = tags;
  312. List<Monument> sMonuments = new List<Monument>(this.Monuments);
  313. foreach (var monument in this.Monuments)
  314. {
  315. if (id != -1)
  316. {
  317. if (monument.Id != id)
  318. {
  319. sMonuments.Remove(monument);
  320. }
  321. }
  322.  
  323. if (name != "")
  324. {
  325. if (!monument.Name.ToLower().Contains(name.ToLower()))
  326. {
  327. sMonuments.Remove(monument);
  328. }
  329. }
  330.  
  331. if (typeName != "")
  332. {
  333. if (!monument.Type.Name.ToString().ToLower().Contains(typeName.ToLower()))
  334. {
  335. sMonuments.Remove(monument);
  336. }
  337. }
  338.  
  339. if (era != "")
  340. {
  341. if (!monument.Era.ToString().ToLower().Contains(era.ToLower()))
  342. {
  343. sMonuments.Remove(monument);
  344. }
  345. }
  346.  
  347. if (arch != -1)
  348. {
  349. bool match = false;
  350. if (arch == 1)
  351. match = true;
  352. if (monument.ArcheologicallyExplored != match)
  353. {
  354. sMonuments.Remove(monument);
  355. }
  356.  
  357. }
  358.  
  359. if (unesco != -1)
  360. {
  361. bool match = false;
  362. if (unesco == 1)
  363. match = true;
  364. if (monument.Unesco != match)
  365. {
  366. sMonuments.Remove(monument);
  367. }
  368. }
  369.  
  370. if (populated != -1)
  371. {
  372. bool match = false;
  373. if (populated == 1)
  374. match = true;
  375. if (monument.PopulatedRegion != match)
  376. {
  377. sMonuments.Remove(monument);
  378. }
  379. }
  380.  
  381. if (touristicStatus != "")
  382. {
  383. if (!monument.TouristicStatus.ToString().ToLower().Contains(touristicStatus.ToLower()))
  384. {
  385. sMonuments.Remove(monument);
  386. }
  387. }
  388.  
  389. if (min_income != -1)
  390. {
  391. if (monument.Income < min_income)
  392. {
  393. sMonuments.Remove(monument);
  394. }
  395. }
  396.  
  397. if (max_income != -1)
  398. {
  399. if (monument.Income > max_income)
  400. {
  401. sMonuments.Remove(monument);
  402. }
  403.  
  404. }
  405.  
  406. if (Tags.Count != 0)
  407. {
  408. bool match = false;
  409. foreach (var t in Tags)
  410. {
  411. if (monument.Tags.IndexOf(t) != -1)
  412. match = true;
  413. }
  414.  
  415. if (!match)
  416. sMonuments.Remove(monument);
  417. }
  418. }
  419.  
  420. this.searchedMonuments = new ObservableCollection<Monument>(sMonuments);
  421. }
  422.  
  423. void filterMonuments(
  424. int id,
  425. string name,
  426. string typeName,
  427. string era,
  428. int arch,
  429. int unesco,
  430. int populated,
  431. string touristicStatus,
  432. int min_income,
  433. int max_income,
  434. List<Tag> tags
  435. )
  436. {
  437. this.id_f = id;
  438. this.name_f = name;
  439. this.typeName_f = typeName;
  440. this.era_f = era;
  441. this.arch_f = arch;
  442. this.unesco_f = unesco;
  443. this.populated_f = populated;
  444. this.touristicStatus_f = touristicStatus;
  445. this.min_income_f = min_income;
  446. this.max_income_f = max_income;
  447. this.tags_f = tags;
  448. List<Monument> fMonuments = new List<Monument>(this.searchedMonuments);
  449. foreach (var monument in this.searchedMonuments)
  450. {
  451. if (id != -1)
  452. {
  453. if (monument.Id != id)
  454. {
  455. fMonuments.Remove(monument);
  456. }
  457. }
  458.  
  459. if (name != "")
  460. {
  461. if (!monument.Name.ToLower().Contains(name.ToLower()))
  462. {
  463. fMonuments.Remove(monument);
  464. }
  465. }
  466.  
  467. if (typeName != "")
  468. {
  469. if (!monument.Type.Name.ToString().ToLower().Contains(typeName.ToLower()))
  470. {
  471. fMonuments.Remove(monument);
  472. }
  473. }
  474.  
  475. if (era != "")
  476. {
  477. if (!monument.Era.ToString().ToLower().Contains(era.ToLower()))
  478. {
  479. fMonuments.Remove(monument);
  480. }
  481. }
  482.  
  483. if (arch != -1)
  484. {
  485. bool match = false;
  486. if (arch == 1)
  487. match = true;
  488. if (monument.ArcheologicallyExplored != match)
  489. {
  490. fMonuments.Remove(monument);
  491. }
  492.  
  493. }
  494.  
  495. if (unesco != -1)
  496. {
  497. bool match = false;
  498. if (unesco == 1)
  499. match = true;
  500. if (monument.Unesco != match)
  501. {
  502. fMonuments.Remove(monument);
  503. }
  504. }
  505.  
  506. if (populated != -1)
  507. {
  508. bool match = false;
  509. if (populated == 1)
  510. match = true;
  511. if (monument.PopulatedRegion != match)
  512. {
  513. fMonuments.Remove(monument);
  514. }
  515. }
  516.  
  517. if (touristicStatus != "")
  518. {
  519. if (!monument.TouristicStatus.ToString().ToLower().Contains(touristicStatus.ToLower()))
  520. {
  521. fMonuments.Remove(monument);
  522. }
  523. }
  524.  
  525. if (min_income != -1)
  526. {
  527. if (monument.Income < min_income)
  528. {
  529. fMonuments.Remove(monument);
  530. }
  531. }
  532.  
  533. if (max_income != -1)
  534. {
  535. if (monument.Income > max_income)
  536. {
  537. fMonuments.Remove(monument);
  538. }
  539.  
  540. }
  541.  
  542. if (Tags.Count != 0)
  543. {
  544. bool match = false;
  545. foreach (var t in Tags)
  546. {
  547. if (monument.Tags.IndexOf(t) != -1)
  548. match = true;
  549. }
  550.  
  551. if (!match)
  552. fMonuments.Remove(monument);
  553. }
  554. }
  555.  
  556. this.searchedMonuments = new ObservableCollection<Monument>(fMonuments);
  557. }
  558.  
  559. #endregion
  560.  
  561. #region Type
  562. public delegate Type onAddType(Type t);
  563. public delegate Type onRemoveType(int id);
  564. public delegate Type onEditType(Type t);
  565. public delegate Type onFindType(int id);
  566.  
  567.  
  568. public onAddType addTypeCallback { get; set; }
  569. public onRemoveType removeTypeCallback { get; set; }
  570. public onEditType editTypeCallback { get; set; }
  571. public onFindType findTypeCallback { get; set; }
  572.  
  573. Type addType(Type t)
  574. {
  575. this.Types.Add(t);
  576. return t;
  577. }
  578.  
  579. Type removeType(int id)
  580. {
  581. foreach (var t in this.Types)
  582. {
  583. if (t.Id == id)
  584. {
  585. this.Types.Remove(t);
  586. return t;
  587. }
  588. }
  589. return null;
  590. }
  591.  
  592. Type editType(Type t)
  593. {
  594. if (this.Types.Remove(t))
  595. {
  596. this.Types.Add(t);
  597. return t;
  598. }
  599. return null;
  600. }
  601.  
  602. Type findType(int id)
  603. {
  604. foreach (var t in this.Types)
  605. {
  606. if (t.Id == id)
  607. return t;
  608. }
  609. return null;
  610. }
  611.  
  612. #endregion
  613.  
  614. #region Tag
  615. public delegate Tag onAddTag(Tag t);
  616. public delegate Tag onRemoveTag(string id);
  617. public delegate Tag onEditTag(Tag t);
  618. public delegate Tag onFindTag(string id);
  619.  
  620.  
  621. public onAddTag addTagCallback { get; set; }
  622. public onRemoveTag removeTagCallback { get; set; }
  623. public onEditTag editTagCallback { get; set; }
  624. public onFindTag findTagCallback { get; set; }
  625.  
  626. Tag addTag(Tag t)
  627. {
  628. this.tags.Add(t);
  629. return t;
  630. }
  631.  
  632. Tag removeTag(string id)
  633. {
  634. foreach (var t in this.tags)
  635. {
  636. if (t.Id == id)
  637. {
  638. this.tags.Remove(t);
  639. return t;
  640. }
  641. }
  642. return null;
  643. }
  644.  
  645. Tag editTag(Tag t)
  646. {
  647. if (this.tags.Remove(t))
  648. {
  649. this.tags.Add(t);
  650. return t;
  651. }
  652. return null;
  653. }
  654.  
  655. Tag findTag(string id)
  656. {
  657. foreach (var t in this.tags)
  658. {
  659. if (t.Id == id)
  660. return t;
  661. }
  662. return null;
  663. }
  664.  
  665.  
  666. #endregion
  667. public MainContent()
  668. {
  669. Tags = new ObservableCollection<Tag>();
  670.  
  671. this.Tags.Add(new Tag("Good", new Color(0, 100, 166), "Very good tag"));
  672. this.Tags.Add(new Tag("GRood", new Color(100, 0, 166), "Very grood tag"));
  673. this.Tags.Add(new Tag("GRooden", new Color(100, 166, 0), "Very grooden tag"));
  674. this.Tags.Add(new Tag("Good", new Color(100, 100, 166), "Even verier good tag"));
  675. this.Tags.Add(new Tag("GRood", new Color(100, 100, 166), "Even verier grood tag"));
  676. this.Tags.Add(new Tag("GRooden", new Color(100, 166, 100), "Even verier grooden tag"));
  677. this.Tags.Add(new Tag("Good", new Color(45, 100, 166), "Even verier beste tag"));
  678. this.Tags.Add(new Tag("GRood", new Color(130, 207, 166), "Even verier bestere tag"));
  679. this.Tags.Add(new Tag("GRooden", new Color(114, 20, 35), "Even verier besterederen tag"));
  680. this.Tags.Add(new Tag("Good", new Color(66, 100, 200), "Even verier more grood beste tag"));
  681. this.Tags.Add(new Tag("GRood", new Color(70, 100, 50), "Even verier more grooder beste tag"));
  682. this.Tags.Add(new Tag("GRooden", new Color(20, 30, 20), "Even verier more grooderen bestere tagEven verier more grooderen bestere tagEven verier more grooderen bestere tagEven verier more grooderen bestere tagEven verier more grooderen bestere tagEven verier more grooderen bestere tag"));
  683. InitializeComponent();
  684.  
  685.  
  686.  
  687. Root.DataContext = this;
  688. // data initialization
  689. DataGraph dataGraph = XmlParser.deserialize();
  690. Types = new ObservableCollection<Type>(dataGraph.types);
  691.  
  692. // Tag callback initialization
  693. this.addTagCallback = new onAddTag(addTag);
  694. this.removeTagCallback = new onRemoveTag(removeTag);
  695. this.editTagCallback = new onEditTag(editTag);
  696. this.findTagCallback = new onFindTag(findTag);
  697.  
  698. // Type callback initialization
  699. this.addTypeCallback = new onAddType(addType);
  700. this.removeTypeCallback = new onRemoveType(removeType);
  701. this.editTypeCallback = new onEditType(editType);
  702. this.findTypeCallback = new onFindType(findType);
  703.  
  704. // Monument callback initialization
  705. this.addMonumentCallback = new onAddMonument(addMonument);
  706. this.removeMonumentCallback = new onRemoveMonument(removeMonument);
  707. this.editMonumentCallback = new onEditMonument(editMonument);
  708. this.findMonumentCallback = new onFindMonument(findMonument);
  709. this.findMonumentsCallback = new onFindMonuments(findMonuments);
  710. this.filterMonumentsCallback = new onFilterMonuments(filterMonuments);
  711. }
  712.  
  713. }
  714. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement