· 6 years ago · Jun 12, 2019, 11:54 AM
1/*
2***********IMS CORE*****************
3Order File
41 IDb.cs
52 Database.cs
63 DbTable.cs
7
84 User.cs
95 Staff.cs
106 Customer.cs
11
127 Report.cs
138 InvoiceReport.cs
14
159 Invoice.cs
1610 Sale.cs
1711 Tax.cs
18
1912 InvoiceBuilder.cs
2013 ReportBuilder.cs
2114 OrderBuilder.cs
22
2315 Instance.cs
2416 SaleInstance.cs
2517 AccountingInstance.cs
2618 ReportInstance.cs
2719 LotInstance.cs
2820 GarageInstance.cs
2921 UserInstance.cs
30
3122 IManager.cs
3223 Manager.cs
3324 ManagerFactory.cs
3425 AddonManager.cs
3526 InvoiceManager.cs
3627 BayManager.cs
3728 ReportManager.cs
3829 UserManager.cs
3930 VehicleManager.cs
40
4131 PaymentProcessor.cs
42
4332 IdGenerator.cs
4433 Validate.cs
4534 MsgTable.cs **In the future, add localization**
46*/
47/*
48IMS WINFORM : UI CODE
49Order File
501 Program.cs
512 LoginForm.cs
523 SaleInstanceForm.cs
534 AccountingInstanceForm.cs
545 ReportInstanceForm.cs
556 GarageInstanceForm.cs
567 CreateAddonForm.cs
578 CreateCustomerForm.cs
589 CreateReportForm.cs
5910 CreateVehicleForm.cs
60*/
61
62using System;
63using IMS;
64using System.Collections.Generic;
65using System.Linq;
66using System.Text;
67using System.Threading.Tasks;
68
69namespace IMS
70{
71 /// <summary>
72 /// Interface to access the database.
73 /// </summary>
74 /// <remarks>
75 /// Can allow for different databases to be used with the current
76 /// system without requiring major changes.
77 /// </remarks>
78 public interface IDb
79 {
80 bool Create(DbObject item);
81 DbObject Read(string id);
82 bool Update(DbObject item);
83 bool Delete(string id);
84 List<string> GetIDs { get; }
85 }
86}
87
88using System;
89using System.Collections.Generic;
90using System.Linq;
91using System.Text;
92using System.Threading.Tasks;
93
94namespace IMS
95{
96 /// <summary>
97 /// The object representation of the database which IMS interacts with.
98 /// </summary>
99 /// <remarks>
100 /// Future implementations can include authentication..ect.
101 /// </remarks>
102 public sealed class Database : IDb
103 {
104 private string _name;
105 private List<DbTable> _table;
106 private static Database _instance;
107
108 public static Database Instance
109 {
110 get
111 {
112 if (_instance == null)
113 {
114 throw new Exception("Database not created");
115 }
116 return _instance;
117 }
118 }
119
120 public static void Create(string name)
121 {
122 if (_instance == null)
123 {
124 _instance = new Database(name);
125 }
126 }
127
128 private Database(string name)
129 {
130 _name = name.ToUpper();
131 _table = new List<DbTable>();
132 }
133
134 public List<string> GetIDs
135 {
136 get
137 {
138 List<string> temp = new List<string>();
139 foreach (DbObject itm in _table)
140 {
141 temp.Add(itm.Id);
142 }
143 return temp;
144 }
145 }
146
147 public bool Create(DbObject item)
148 {
149 if (item == null || _table.Contains(item))
150 {
151 throw new ArgumentException("Either the table is null or it already exists within database.");
152 }
153
154 _table.Add(item as DbTable);
155 return true;
156 }
157
158 public bool Delete(string id)
159 {
160 if (id == null) return false;
161 foreach (DbObject itm in _table)
162 {
163 if (itm.Id == id.ToUpper())
164 {
165 _table.Remove(itm as DbTable);
166 return true;
167 }
168 }
169
170 return false;
171 }
172
173 public DbObject Read(string id)
174 {
175 if (id == null) return null;
176 foreach (DbObject item in _table)
177 {
178 if (item.Id == id.ToUpper())
179 {
180 return item;
181 }
182 }
183
184 return null;
185 }
186
187 public bool Update(DbObject item)
188 {
189 if (item == null) return false;
190 int index = _table.IndexOf(Read(item.Id) as DbTable);
191
192 if (!(index == -1))
193 {
194 _table[index] = item as DbTable;
195 return true;
196 }
197
198 return false;
199 }
200 }
201}
202
203using System;
204using IMS;
205using System.Collections.Generic;
206using System.Linq;
207using System.Text;
208using System.Threading.Tasks;
209
210namespace IMS
211{
212 /// <summary>
213 /// An object representation of the database tables stored within
214 /// the database.
215 /// </summary>
216 public class DbTable : DbObject, IDb
217 {
218 private string _name;
219 private List<DbObject> _table;
220
221 public DbTable(string id, string name) : base(id)
222 {
223 _name = name.ToUpper();
224 _table = new List<DbObject>();
225 }
226
227 public List<string> GetIDs
228 {
229 get
230 {
231 List<string> temp = new List<string>();
232 foreach (DbObject itm in _table)
233 {
234 temp.Add(itm.Id);
235 }
236 return temp;
237 }
238 }
239
240 public override string View
241 {
242 get
243 {
244 return _name;
245 }
246 }
247
248 public bool Create(DbObject item)
249 {
250 if (item == null || _table.Contains(item))
251 {
252 return false;
253 }
254
255 foreach (DbObject element in _table)
256 {
257 if (item.Id == element.Id)
258 {
259 return false;
260 }
261 }
262
263 _table.Add(item);
264 return true;
265 }
266
267 public bool Delete(string id)
268 {
269 if (id == null) return false;
270 foreach (DbObject itm in _table)
271 {
272 if (itm.Id == id.ToUpper())
273 {
274 _table.Remove(itm);
275 return true;
276 }
277 }
278
279 return false;
280 }
281
282 public DbObject Read(string id)
283 {
284 if (id == null) return null;
285 foreach (DbObject item in _table)
286 {
287 if (item.Id == id.ToUpper())
288 {
289 return item;
290 }
291 }
292
293 return null;
294 }
295
296 public bool Update(DbObject item)
297 {
298 if (item == null) return false;
299 if (Delete(item.Id))
300 {
301 Create(item);
302 return true;
303 }
304
305 return false;
306
307 }
308 }
309}
310
311using System;
312using System.Collections.Generic;
313using System.Linq;
314using System.Text;
315using System.Threading.Tasks;
316
317namespace IMS.User
318{
319 public abstract class User : DbObject
320 {
321 private string _name;
322
323 public User(string id, string name) : base(id)
324 {
325 _name = name;
326 }
327
328 public string Name
329 {
330 get
331 {
332 return _name;
333 }
334 }
335
336
337 }
338}
339
340using System;
341using System.Collections.Generic;
342using System.Linq;
343using System.Text;
344using System.Threading.Tasks;
345
346namespace IMS
347{
348 public enum JobRole {Sale, Garage, Accounting, Management};
349}
350namespace IMS.User
351{
352 public class Staff : User
353 {
354 private JobRole _role;
355
356 public Staff(string id, string name, JobRole role) : base(id, name)
357 {
358 _role = role;
359 }
360
361 public override string View
362 {
363 get
364 {
365 return "Staff :" + Name + " | Role: " + Role + "\n";
366 }
367 }
368
369 public JobRole Role
370 {
371 get
372 {
373 return _role;
374 }
375 }
376 }
377}
378
379using System;
380using System.Collections.Generic;
381using System.Linq;
382using System.Text;
383using System.Threading.Tasks;
384
385namespace IMS.User
386{
387 public class Customer : User
388 {
389 private string _address;
390 private string _phone;
391
392 public Customer(string id, string name, string address, string phone) : base(id, name)
393 {
394 _address = address;
395 _phone = phone;
396 }
397
398 public override string View
399 {
400 get
401 {
402 return "Customer :" + Name + " | Address: " + Address + " | Phone: " + Phone + "\n";
403 }
404 }
405
406 public string Address
407 {
408 get
409 {
410 return _address;
411 }
412
413 set
414 {
415 _address = value;
416 }
417 }
418
419 public string Phone
420 {
421 get
422 {
423 return _phone;
424 }
425
426 set
427 {
428 _phone = value;
429 }
430 }
431 }
432}
433
434using System;
435using System.Collections.Generic;
436using System.Linq;
437using System.Text;
438using System.Threading.Tasks;
439
440namespace IMS.Report
441{
442 public abstract class Report : DbObject
443 {
444 private string _name;
445 private DateTime _periodStart;
446 private DateTime _periodEnd;
447
448
449 public Report(string id, string name, DateTime periodStart, DateTime periodEnd) : base(id)
450 {
451 _name = name;
452 _periodStart = periodStart;
453 _periodEnd = periodEnd;
454
455 }
456
457 public string Name
458 {
459 get
460 {
461 return _name;
462 }
463 }
464 public string PeriodStart
465 {
466 get
467 {
468 return _periodStart.ToShortDateString();
469 }
470 }
471
472 public string PeriodEnd
473 {
474 get
475 {
476 return _periodEnd.ToShortDateString();
477 }
478 }
479
480
481 public override string View
482 {
483 get
484 {
485 string ss
486 = "Report Title: " + Name + "\n"
487 + "Start Period: " + PeriodStart + "\n"
488 + "End Period: " + PeriodEnd + "\n"
489 + "-----------------------------------------------------\n";
490
491 return ss;
492 }
493 }
494 }
495}
496
497using System;
498using System.Collections.Generic;
499using System.Linq;
500using System.Text;
501using System.Threading.Tasks;
502using IMS.Report;
503
504namespace IMS
505{
506 public enum ReportType { Addon, TradeIn, Sale };
507}
508
509
510namespace IMS.Report
511{
512
513 public class InvoiceReport : Report
514 {
515 private ReportType _reportType;
516 private double _totalSalePrice;
517 private double _amountOfSale;
518
519 public InvoiceReport(string id, string name, ReportType rType, DateTime periodStart, DateTime periodEnd) : base(id, name, periodStart, periodEnd)
520 {
521 _reportType = rType;
522 }
523
524 public ReportType Type
525 {
526 get
527 {
528 return _reportType;
529 }
530 }
531 public double TotalSalePrice { get; set; }
532 public double AverageSalePrice
533 {
534 get
535 {
536 return TotalSalePrice / AmountOfSale;
537 }
538 }
539
540 public int AmountOfSale { get; set; }
541
542 public override string View
543 {
544 get
545 {
546 string reportType = _reportType.ToString();
547 string ss = "**************" + reportType + " Report (Invoice)**************\n"
548 + base.View;
549 ss += reportType + " : " + AmountOfSale + "\n"
550 + "Average " + reportType + " Price: " + AverageSalePrice + "\n"
551 + "Total " + reportType + " Price: " + TotalSalePrice + "\n";
552 return ss;
553 }
554 }
555
556 }
557}
558
559using IMS.User;
560using System;
561using System.Collections.Generic;
562using System.Linq;
563using System.Text;
564using System.Threading.Tasks;
565
566namespace IMS.Invoice
567{
568 public abstract class Invoice : DbObject
569 {
570 private DateTime _date;
571 private Staff _salerep;
572
573
574 public Invoice(string id, Staff saleRep) : base(id)
575 {
576 _date = DateTime.Now;
577 _salerep = saleRep;
578 }
579
580 public DateTime Date
581 {
582 get
583 {
584 return _date;
585 }
586 }
587
588 public override string View
589 {
590 get
591 {
592 return "INVOICE ID: " + Id + "\n" +
593 "INVOICE DATE: " + Date.ToShortDateString() + "\n" +
594 "SALE REP: " + SaleRep.Name + " " + SaleRep.Id + "\n" +
595 "COMPANY : HTV VEHICLE PTD\n" +
596 "COMPANY ADDRESS : 25 Malvin Street, VIC, 3000\n";
597
598 }
599 }
600
601 public Staff SaleRep
602 {
603 get
604 {
605 return _salerep;
606 }
607 }
608
609 public abstract double TotalCost {get;}
610 }
611}
612
613using IMS.User;
614using System;
615using System.Collections.Generic;
616using System.Linq;
617using System.Text;
618using System.Threading.Tasks;
619
620
621namespace IMS.Invoice
622{
623 public class Sale : Invoice
624 {
625 private Vehicle _buyVehicle;
626 private Vehicle _tradeVehicle;
627 private List<Addon> _addon = new List<Addon>();
628
629 public Sale(string id, Staff saleRep, Vehicle buy) : base(id, saleRep)
630 {
631 _buyVehicle = buy;
632 }
633
634 public Sale(string id, Staff saleRep, Vehicle buy, Vehicle trade) : this(id, saleRep, buy)
635 {
636 _tradeVehicle = trade;
637 }
638
639
640 public override string View
641 {
642 get
643 {
644 string s1 = "********SALE INVOICE************\n";
645 s1 += base.View;
646 s1 += "----------------------------------------------------------\n";
647 s1 += "Base Vehicle : " + _buyVehicle.View;
648
649 if (_tradeVehicle != null)
650 {
651 s1 += "TradeIn Vehicle : " + _tradeVehicle.View;
652 }
653
654 s1 += "Addons: \n" + ViewAllAddon;
655
656 s1 += "\nSubTotal: \n"
657 + " Base: " + VehicleCost + "\n"
658 + " Rebate: " + TradeRebateCost + "\n"
659 + " Addon(s): " + AddonCost + "\n";
660 s1 += "Sale Total: " + TotalCost;
661 return s1;
662 }
663 }
664
665
666
667 public bool Add(Addon a)
668 {
669 if (_buyVehicle == null || _addon.Contains(a)) return false;
670 _addon.Add(a);
671 return true;
672 }
673
674 public Vehicle TradeVehicle
675 {
676 get
677 {
678 return _tradeVehicle;
679 }
680 }
681
682 public Vehicle BuyVehicle
683 {
684 get
685 {
686 return _buyVehicle;
687 }
688 }
689
690 public List<Addon> Addon
691 {
692 get
693 {
694 return _addon;
695 }
696 }
697 public override double TotalCost
698 {
699 get
700 {
701 return VehicleCost + TradeRebateCost + AddonCost;
702 }
703 }
704 public double TradeRebateCost
705 {
706 get
707 {
708 if (_tradeVehicle == null)
709 {
710 return 0.00;
711 }
712 return (-(_tradeVehicle.Price * 0.25));
713 }
714 }
715
716 public string ViewAllAddon
717 {
718 get
719 {
720 string s1 = "";
721 foreach (Addon a in Addon)
722 {
723 s1 += a.View;
724 }
725
726 return s1;
727 }
728 }
729
730 public double VehicleCost
731 {
732 get
733 {
734 return _buyVehicle.Price;
735 }
736 }
737
738
739 public double AddonCost
740 {
741 get
742 {
743 double c = 0.0;
744 foreach (Addon a in _addon)
745 {
746 c += a.Price;
747 }
748
749 return c;
750 }
751 }
752
753 }
754}
755
756using IMS.User;
757using System;
758using System.Collections.Generic;
759using System.Linq;
760using System.Text;
761using System.Threading.Tasks;
762
763
764namespace IMS.Invoice
765{
766 public class Tax : Sale
767 {
768 private const double GST = 1.10;
769 private Customer _customer;
770 private string _paymentId;
771
772 public Tax(Sale saleInvoice, Customer customer, string paymentId) : base(saleInvoice.Id,saleInvoice.SaleRep, saleInvoice.BuyVehicle,saleInvoice.TradeVehicle)
773 {
774 _paymentId = paymentId;
775 _customer = customer;
776
777 foreach (Addon a in saleInvoice.Addon)
778 {
779 Add(a);
780 }
781 }
782
783 public override string View
784 {
785 get
786 {
787 string s1 = base.View;
788 s1 += "\n\n********TAX INVOICE************\n";
789 s1 += "CUSTOMER DETAILS: " + Customer.View;
790 s1 += "----------------------------------------------------------\n";
791 s1 += "Payment ID: " + PaymentId + "\n"
792 + "Payment Status: PAID\n";
793 s1 += "----------------------------------------------------------\n";
794 s1 += "\nSubTotal: \n"
795 + " Base (inc GST): " + VehicleCost + "\n"
796 + " Rebate: " + base.TradeRebateCost + "\n"
797 + " Addon(s) (inc GST): " + AddonCost + "\n";
798 s1 += "Tax Total (inc GST): " + TotalCost + "\n";
799 return s1;
800 }
801 }
802
803 public string PaymentId
804 {
805 get
806 {
807 return _paymentId;
808 }
809 }
810
811 public new double VehicleCost
812 {
813 get
814 {
815 return base.VehicleCost * GST;
816 }
817 }
818
819 public new double AddonCost
820 {
821 get
822 {
823 return base.AddonCost * GST;
824 }
825 }
826
827 public Customer Customer
828 {
829 get
830 {
831 return _customer;
832 }
833 }
834
835 public new double TotalCost
836 {
837 get
838 {
839 return base.TotalCost * GST;
840 }
841 }
842 }
843}
844
845using System;
846using System.Collections.Generic;
847using System.Linq;
848using System.Text;
849using System.Threading.Tasks;
850using IMS.User;
851using IMS.Invoice;
852using IMS.Tools;
853
854namespace IMS
855{
856 public enum InvoiceType { Sale, Tax };
857}
858
859namespace IMS.Builder
860{
861 /// <summary>
862 /// Tasked with assembling the either a tax or sale invoice based off
863 /// of the inputted data.
864 /// </summary>
865 public class InvoiceBuilder
866 {
867 private Order _order;
868 private Staff _saleRep;
869 private Customer _customer;
870 private InvoiceType _invoiceType;
871 private string _paymentId;
872 private Sale _saleInvoice;
873
874 public InvoiceBuilder()
875 {
876 _order.addons = new List<Addon>();
877 }
878
879 public string PaymentId
880 {
881 set
882 {
883 if (value != "")
884 {
885 _paymentId = value;
886 }
887 }
888 }
889 public InvoiceType Invoice
890 {
891 set
892 {
893 _invoiceType = value;
894 }
895 }
896 public Staff Staff
897 {
898 set
899 {
900 if (value.Role == JobRole.Sale)
901 {
902 _saleRep = value;
903 }
904 }
905 }
906
907 public Customer Customer
908 {
909 set
910 {
911 _customer = value;
912 }
913 }
914 public Order Order
915 {
916 set
917 {
918 _order = value;
919 }
920 }
921
922 public Sale SaleInvoice
923 {
924 set
925 {
926 _saleInvoice = value;
927 }
928 }
929
930 public Object Prepare()
931 {
932 switch (_invoiceType)
933 {
934 case InvoiceType.Sale:
935 return GenerateSale();
936 case InvoiceType.Tax:
937 return GenerateTax();
938 default:
939 return null;
940 }
941 }
942
943 private Sale GenerateSale()
944 {
945 if (_order.buyVehicle == null || _saleRep == null)
946 {
947 throw new System.ArgumentException("Invalid code path. Need to declare builder parameters!");
948 }
949
950 Sale sInvoice = new Sale(IdGenerator.UniqueId(), _saleRep, _order.buyVehicle, _order.tradeVehicle);
951 foreach (Addon a in _order.addons)
952 {
953 sInvoice.Add(a);
954 }
955
956 return sInvoice;
957 }
958
959 private Tax GenerateTax()
960 {
961 if (_saleInvoice == null || _customer == null || String.IsNullOrEmpty(_paymentId))
962 {
963 throw new System.ArgumentException("Invalid code path. Need to declare builder parameters!");
964 }
965
966 Tax tInvoice = new Tax(_saleInvoice, _customer, _paymentId);
967 return tInvoice;
968 }
969 }
970}
971
972using System;
973using System.Collections.Generic;
974using System.Linq;
975using System.Text;
976using System.Threading.Tasks;
977using IMS.Manager;
978using IMS.Invoice;
979using IMS;
980using IMS.Tools;
981
982namespace IMS.Builder
983{
984 /// <summary>
985 /// Parses the stored invoices to build either an addon, trade-in or sales
986 /// report based off of user inputs.
987 /// </summary>
988 public class ReportBuilder
989 {
990 private string _name;
991 private DateTime _periodStart;
992 private DateTime _periodEnd;
993 private ReportType _reportType;
994
995 private double _totalPrice;
996 private int _amountOfSale;
997
998 Report.InvoiceReport _report;
999 Dictionary<string, IManager> _manager;
1000
1001 public ReportBuilder(Dictionary<string, IManager> manager)
1002 {
1003 _manager = manager;
1004 }
1005
1006 public void Period(string start, string end)
1007 {
1008 try
1009 {
1010 TimeSpan tsStart = new TimeSpan(1, 00, 0);
1011 TimeSpan tsEnd = new TimeSpan(23, 59, 59);
1012
1013 _periodStart = Convert.ToDateTime(start) + tsStart;
1014 _periodEnd = Convert.ToDateTime(end) + tsEnd;
1015 }
1016 catch
1017 {
1018 _periodStart.AddYears(1);
1019 _periodEnd.AddYears(1);
1020 }
1021 }
1022
1023 public string Name
1024 {
1025 set
1026 {
1027 if (ValidateIMS.IsBad(value, @"^[a-zA-Z0-9]+$"))
1028 {
1029 _name = null;
1030 }
1031 _name = value;
1032 }
1033 }
1034 public ReportType Type
1035 {
1036 set
1037 {
1038 _reportType = value;
1039 }
1040 }
1041 public string Prepare()
1042 {
1043 if (_periodStart.Year == 1 || _periodEnd.Year == 1 || String.IsNullOrEmpty(_name))
1044 {
1045 return "Fail.Need to enter correct values for report building.";
1046 }
1047
1048 List<DbObject> lInvoiceList = _manager["Invoice"].RetrieveMany("tax");
1049 _amountOfSale = lInvoiceList.Count();
1050
1051 foreach (Tax tInvoice in lInvoiceList)
1052 {
1053 if (!ValidateIMS.ValidDateRangeCheck(tInvoice, _periodStart, _periodEnd)) continue;
1054 switch (_reportType)
1055 {
1056 case ReportType.Addon:
1057 _totalPrice += tInvoice.AddonCost;
1058 break;
1059 case ReportType.Sale:
1060 _totalPrice += tInvoice.TotalCost;
1061 break;
1062 case ReportType.TradeIn:
1063 _totalPrice += tInvoice.TradeRebateCost;
1064 break;
1065 }
1066
1067 }
1068
1069 _report = new Report.InvoiceReport(IdGenerator.UniqueId(), _name, _reportType, _periodStart, _periodEnd);
1070 _report.TotalSalePrice = _totalPrice;
1071 _report.AmountOfSale = _amountOfSale;
1072 return "Success";
1073
1074 }
1075
1076
1077 public Report.Report Report
1078 {
1079 get
1080 {
1081 return _report;
1082 }
1083 }
1084 }
1085}
1086
1087using System;
1088using System.Collections.Generic;
1089using System.Linq;
1090using System.Text;
1091using System.Threading.Tasks;
1092using IMS.Manager;
1093
1094namespace IMS
1095{
1096 public struct Order
1097 {
1098 public Vehicle buyVehicle;
1099 public List<Addon> addons;
1100 public Vehicle tradeVehicle;
1101 }
1102
1103 public enum VehicleType { Trade, New};
1104}
1105
1106namespace IMS.Builder
1107{
1108 /// <summary>
1109 /// Assembles the vehicle order based off of the inputted data.
1110 /// </summary>
1111 public class OrderBuilder
1112 {
1113 private Order _order;
1114
1115 public OrderBuilder()
1116 {
1117 _order.addons = new List<Addon>();
1118 }
1119
1120 public void Add(Vehicle vehicle, VehicleType vType)
1121 {
1122 switch(vType)
1123 {
1124 case VehicleType.New:
1125 _order.buyVehicle = vehicle;
1126 break;
1127 case VehicleType.Trade:
1128 _order.tradeVehicle = vehicle;
1129 break;
1130 default: throw new ArgumentException("Not valid argument");
1131 }
1132
1133 }
1134
1135 public void SetDiscount(PriceRate discount)
1136 {
1137 if (_order.buyVehicle == null)
1138 {
1139 throw new ArgumentNullException("Can't apply discount to null vehicle");
1140 }
1141 _order.buyVehicle.Price *= ((int)discount * 0.01);
1142 }
1143
1144 public void Add(List<string> addonSelected, List<Addon> availableAddon)
1145 {
1146 _order.addons.Clear();
1147
1148 foreach (string id in addonSelected)
1149 {
1150 foreach (Addon a in availableAddon)
1151 {
1152 if (addonSelected.Contains(a.Id))
1153 {
1154 _order.addons.Add(a);
1155 }
1156 }
1157 }
1158
1159 }
1160
1161 public Order Prepare()
1162 {
1163 if (_order.buyVehicle == null)
1164 {
1165 throw new System.ArgumentException("Invalid code path. Need to declare builder parameters!");
1166 }
1167
1168 return _order;
1169 }
1170
1171 }
1172}
1173
1174using System;
1175using System.Collections.Generic;
1176using System.Linq;
1177using System.Text;
1178using System.Threading.Tasks;
1179using IMS.Manager;
1180
1181namespace IMS.Instance
1182{
1183 /// <summary>
1184 /// Adds the managers (database table operators) needed for reading and writing
1185 /// and doing work on the database data.
1186 /// </summary>
1187 public abstract class Instance
1188 {
1189 protected Dictionary<string, IManager> _manager = new Dictionary<string, IManager>();
1190
1191 /// <summary>
1192 /// Managers used by the Accounting Instance
1193 /// </summary>
1194 public Instance(InvoiceManager im, UserManager um, VehicleManager vm)
1195 {
1196 _manager.Add("Invoice", im);
1197 _manager.Add("User", um);
1198 _manager.Add("Vehicle", vm);
1199 }
1200
1201 /// <summary>
1202 /// Managers used by the Reporting Instance
1203 /// </summary>
1204 public Instance(ReportManager rm, InvoiceManager im)
1205 {
1206 _manager.Add("Report", rm);
1207 _manager.Add("Invoice", im);
1208 }
1209
1210 /// <summary>
1211 /// Managers used by the Garage Instance
1212 /// </summary>
1213 public Instance(VehicleManager vm, AddonManager am, BayManager bm)
1214 {
1215 _manager.Add("Vehicle", vm);
1216 _manager.Add("Addon", am);
1217 _manager.Add("Bay", bm);
1218 }
1219
1220 /// <summary>
1221 /// Managers used by the Sales Instance
1222 /// </summary>
1223 public Instance(VehicleManager vm, AddonManager am, InvoiceManager im, BayManager bm)
1224 {
1225 _manager.Add("Vehicle", vm);
1226 _manager.Add("Addon", am);
1227 _manager.Add("Bay", bm);
1228 _manager.Add("Invoice", im);
1229 }
1230
1231 /// <summary>
1232 /// Managers used by the Lot Instance
1233 /// </summary>
1234 public Instance(VehicleManager vm, BayManager bm)
1235 {
1236 _manager.Add("Vehicle", vm);
1237 _manager.Add("Bay", bm);
1238 }
1239
1240 /// <summary>
1241 /// Managers used by the User Instance
1242 /// </summary>
1243 public Instance(UserManager um)
1244 {
1245 _manager.Add("User", um);
1246 }
1247 }
1248}
1249
1250using System;
1251using System.Collections.Generic;
1252using System.Linq;
1253using System.Text;
1254using System.Threading.Tasks;
1255using IMS.User;
1256using IMS.Builder;
1257using IMS.Invoice;
1258using IMS.Manager;
1259using IMS.Tools;
1260
1261namespace IMS
1262{
1263 public enum PriceRate { Standard = 100, FiveOff = 95, TenOff = 90, FifteenOff = 85, TwentyOff = 80 };
1264}
1265
1266namespace IMS.Instance
1267{
1268 /// <summary>
1269 /// Supports the tasks that the Sale staff are required to handle at HTV,
1270 /// such as adding of trade-in vehicles, selecting of vehicles/addons and
1271 /// price negotiations as well as sales invoice creation.
1272 /// </summary>
1273 public class SaleInstance : Instance
1274 {
1275 private Vehicle _vehicle;
1276 private List<Addon> _compatibleAddons;
1277 private List<string> _selectedAddons;
1278 private Vehicle _tradeIn;
1279 private Staff _saleRep;
1280 private Sale _sInvoice;
1281
1282 public SaleInstance(Staff s, VehicleManager vm, AddonManager am, InvoiceManager im, BayManager bm) : base(vm, am, im, bm)
1283 {
1284 if (s.Role != JobRole.Sale)
1285 {
1286 throw new System.InvalidOperationException("Invalid User! Cannot create sale instance!");
1287 }
1288
1289 _saleRep = s;
1290 _compatibleAddons = new List<Addon>();
1291 _selectedAddons = new List<string>();
1292 }
1293
1294 public string ViewSelectedVehicle
1295 {
1296 get
1297 {
1298 if (_vehicle == null) return "No vehicle selected. No vehicle to view!";
1299 return _vehicle.View;
1300 }
1301 }
1302
1303 public List<Addon> GetSelectedVehicleAvailableAddons
1304 {
1305 get
1306 {
1307 _compatibleAddons.Clear();
1308
1309 List<DbObject> addonList = _manager["Addon"].RetrieveMany(_vehicle.Id);
1310 if (addonList != null)
1311 {
1312 foreach (Addon a in addonList)
1313 {
1314 _compatibleAddons.Add(a);
1315 }
1316 }
1317 return _compatibleAddons;
1318 }
1319 }
1320
1321 public Addon ViewSelectedAddon(string id)
1322 {
1323
1324 foreach (Addon a in _compatibleAddons)
1325 {
1326 if (a.Id != id) continue;
1327 return a;
1328 }
1329
1330 return null;
1331 }
1332
1333 public bool SelectBaseVehicle(string bayId)
1334 {
1335 if (!(_manager["Bay"].Contain(bayId)))
1336 {
1337 return false;
1338 }
1339
1340 Bay bay = _manager["Bay"].Retrieve(bayId) as Bay;
1341 _vehicle = _manager["Vehicle"].Retrieve(bay.Vehicle) as Vehicle;
1342 return true;
1343 }
1344
1345 public void SelectAddon(string addonId)
1346 {
1347 if (!(_selectedAddons.Contains(addonId)))
1348 {
1349 _selectedAddons.Add(addonId);
1350 }
1351 }
1352
1353 public string GetTradeVehicle(Vehicle tradeIn)
1354 {
1355 if (!ValidateIMS.IsValid(tradeIn))
1356 {
1357 return "Fail. Not right format";
1358 }
1359
1360 // Requires an explicit check because the vehicle is not being entered into the database
1361 // at this moment. It will be added once sale has been processed.
1362 if (_manager["Vehicle"].Contain(tradeIn.Id))
1363 {
1364 return "Fail. Already exists within system";
1365 }
1366
1367 _tradeIn = tradeIn;
1368 return "Success.";
1369
1370 }
1371
1372 public string ViewInvoice
1373 {
1374 get
1375 {
1376 return _sInvoice.View;
1377 }
1378 }
1379
1380 public string RemoveInvoice()
1381 {
1382 if (!_manager["Invoice"].Contain(_sInvoice.Id))
1383 {
1384 return "Fail. No invoice";
1385 }
1386
1387 _manager["Invoice"].Delete(_sInvoice.Id);
1388 //_sInvoice = null;
1389
1390 return "Success.";
1391 }
1392
1393 public string CreateSale(PriceRate discount)
1394 {
1395 if (_vehicle == null || _compatibleAddons == null || _selectedAddons == null)
1396 {
1397 return "Missing key sales details";
1398 }
1399
1400 OrderBuilder oBuild = new OrderBuilder();
1401 oBuild.Add(_vehicle, VehicleType.New);
1402 oBuild.Add(_tradeIn, VehicleType.Trade);
1403 oBuild.SetDiscount(discount);
1404 oBuild.Add(_selectedAddons, _compatibleAddons);
1405 Order orders = oBuild.Prepare();
1406
1407 InvoiceBuilder iBuild = new InvoiceBuilder();
1408 iBuild.Staff = _saleRep;
1409 iBuild.Order = orders;
1410 _sInvoice = iBuild.Prepare() as Sale;
1411
1412 return _manager["Invoice"].Add(_sInvoice);
1413 }
1414
1415 }
1416}
1417
1418using IMS.User;
1419using IMS.Manager;
1420using IMS.Invoice;
1421using IMS.Payment;
1422using IMS.Builder;
1423using IMS.Tools;
1424
1425namespace IMS.Instance
1426{
1427 /// <summary>
1428 /// Supports the entering of sales invoices, retrieving/creating of new/existing customers,
1429 /// processing of payment and development of a tax invoice.
1430 /// </summary>
1431 public class AccountingInstance : Instance
1432 {
1433 private Sale _sInvoice;
1434 private Customer _customer;
1435 private Tax _tInvoice;
1436
1437 public AccountingInstance(Staff s, InvoiceManager im, UserManager um, VehicleManager vm) : base (im, um, vm)
1438 {
1439 if (s.Role != JobRole.Accounting)
1440 {
1441 throw new System.InvalidOperationException("Invalid User! Cannot create accounting instance!");
1442 }
1443 }
1444
1445 /// <summary>
1446 /// Get the the users invoice id so that the sales invoice can be retreived.
1447 /// </summary>
1448 public string Invoice(string invoiceId)
1449 {
1450 _sInvoice = _manager["Invoice"].Retrieve(invoiceId) as Sale;
1451
1452 if (_sInvoice == null)
1453 {
1454 return "The sale invoice cannot be found.";
1455 }
1456
1457 return "Success.";
1458 }
1459
1460 public Customer Customer
1461 {
1462 set
1463 {
1464 _customer = value;
1465 }
1466 }
1467
1468 /// <summary>
1469 /// Process the payment and produces a tax invoice
1470 /// </summary>
1471 public string CreatePayment(CreditCard card)
1472 {
1473 if (_customer == null || _sInvoice == null)
1474 {
1475 return "Need to declare payment parameters!";
1476 }
1477
1478 string lResult = "";
1479 PaymentProcessor pProcessor = new PaymentProcessor();
1480 lResult = pProcessor.SetPaymentDetail(card);
1481 if (lResult != "VALID")
1482 {
1483 return "Payment details are not vaild.";
1484 }
1485
1486 string paymentId = pProcessor.Pay(_sInvoice.TotalCost);
1487 if (paymentId == "ERROR")
1488 {
1489 return "An error occoured with the payment system. Unknown!.";
1490 }
1491
1492 InvoiceBuilder iBuild = new InvoiceBuilder();
1493 iBuild.Invoice = InvoiceType.Tax;
1494 iBuild.SaleInvoice = _sInvoice;
1495 iBuild.Customer = _customer;
1496 iBuild.PaymentId = paymentId;
1497 _tInvoice = iBuild.Prepare() as Tax;
1498
1499 UpdateVehicleInventoryState();
1500
1501 string msg = _manager["Invoice"].Update(_tInvoice);
1502
1503 if (msg != "Successfully updated.")
1504 {
1505 return msg;
1506 }
1507 return "Payment Success.";
1508 }
1509
1510 private void UpdateVehicleInventoryState()
1511 {
1512 // Add trade-in vehicle to vehicle list
1513 if (_tInvoice.TradeVehicle != null)
1514 {
1515 _manager["Vehicle"].Add(_tInvoice.TradeVehicle);
1516 }
1517
1518 // Set vehicle as sold
1519 Vehicle baseVehicle = _manager ["Vehicle"].Retrieve(_tInvoice.BuyVehicle.Id) as Vehicle;
1520 baseVehicle.Sold = true;
1521 _manager ["Vehicle"].Update(baseVehicle);
1522 }
1523
1524 public double ViewTotal
1525 {
1526 get
1527 {
1528 return _sInvoice.TotalCost * 1.10;
1529 }
1530 }
1531
1532 public string ViewTax
1533 {
1534 get
1535 {
1536 if (_tInvoice == null)
1537 {
1538 return "Tax Invoice : Not Available.";
1539 }
1540 return _tInvoice.View;
1541 }
1542 }
1543 }
1544}
1545
1546using System;
1547using System.Collections.Generic;
1548using System.Linq;
1549using System.Text;
1550using System.Threading.Tasks;
1551using IMS.User;
1552using IMS.Manager;
1553using IMS.Builder;
1554
1555namespace IMS.Instance
1556{
1557 /// <summary>
1558 /// Supports the managements staff requirments, such as viewing and creating reports.
1559 /// </summary>
1560 public class ReportInstance : Instance
1561 {
1562 public ReportInstance(Staff s, ReportManager rm, InvoiceManager im) : base(rm,im)
1563 {
1564 if (s.Role != JobRole.Management)
1565 {
1566 throw new System.InvalidOperationException("Invalid User! Cannot create report instance!");
1567 }
1568 }
1569
1570 public string CreateReport(string reportName, string periodStart, string periodEnd, ReportType rType)
1571 {
1572 ReportBuilder rBuild = new ReportBuilder(_manager);
1573 rBuild.Name = reportName;
1574 rBuild.Period(periodStart, periodEnd);
1575 rBuild.Type = rType;
1576
1577 string lOutputMsg = rBuild.Prepare();
1578 if (lOutputMsg == "Success")
1579 {
1580 Report.Report lReport = rBuild.Report;
1581 if (lReport != null)
1582 {
1583 lOutputMsg = _manager["Report"].Add(lReport);
1584 }
1585 }
1586 return lOutputMsg;
1587 }
1588
1589 public string ViewSelectedReport(string reportId)
1590 {
1591 Report.Report lSelectedReport = _manager["Report"].Retrieve(reportId) as Report.Report;
1592 if (lSelectedReport == null)
1593 {
1594 return "Please select a report.";
1595 }
1596 return lSelectedReport.View;
1597 }
1598
1599 public List<string> GetReportList
1600 {
1601 get
1602 {
1603 return _manager["Report"].GetIDs;
1604 }
1605 }
1606
1607 }
1608}
1609
1610using System;
1611using System.Collections.Generic;
1612using System.Linq;
1613using System.Text;
1614using System.Threading.Tasks;
1615using IMS.Manager;
1616using IMS;
1617
1618namespace IMS.Instance
1619{
1620 /// <summary>
1621 ///
1622 /// </summary>
1623 public sealed class LotInstance : Instance
1624 {
1625 private static LotInstance _instance;
1626
1627 public static LotInstance Instance
1628 {
1629 get
1630 {
1631 if (_instance == null)
1632 {
1633 throw new Exception("Lot instance not created");
1634 }
1635 return _instance;
1636 }
1637 }
1638
1639 public static void Create(VehicleManager vm, BayManager bm)
1640 {
1641 if (_instance == null)
1642 {
1643 _instance = new LotInstance(vm,bm);
1644 }
1645 }
1646
1647 private LotInstance(VehicleManager vm, BayManager bm) : base(vm,bm)
1648 {
1649
1650 }
1651
1652 /// <summary>
1653 /// Get all the bays of unsold vehicles
1654 /// </summary>
1655 public List<string> BaysWithNonSoldVehicles
1656 {
1657 get
1658 {
1659 List<DbObject> vList = _manager["Vehicle"].RetrieveMany("UnSold");
1660 List<DbObject> bList = _manager["Bay"].RetrieveMany("Occupied");
1661
1662 List<string> nonSoldVehicleBay = new List<string>();
1663 foreach (Bay b in bList)
1664 {
1665 foreach (Vehicle v in vList)
1666 {
1667 if (b.Vehicle == v.Id)
1668 {
1669 nonSoldVehicleBay.Add(b.Id);
1670 }
1671 }
1672 }
1673
1674 return nonSoldVehicleBay;
1675 }
1676 }
1677
1678 /// <summary>
1679 /// Get all the unoccupied bays.
1680 /// </summary>
1681 public List<string> OpenBays
1682 {
1683 get
1684 {
1685 List<DbObject> bList = _manager["Bay"].RetrieveMany("free");
1686 List<string> openBay = new List<string>();
1687 foreach (Bay b in bList)
1688 {
1689 openBay.Add(b.Id);
1690 }
1691
1692 return openBay;
1693 }
1694 }
1695
1696 /// <summary>
1697 /// Get a list of all vehicles that have been sold.
1698 /// </summary>
1699 public List<string> SoldVehicles
1700 {
1701 get
1702 {
1703
1704 List<DbObject> vList = _manager["Vehicle"].RetrieveMany("sold");
1705 List<string> soldVehicle = new List<string>();
1706
1707 foreach (Vehicle v in vList)
1708 {
1709 soldVehicle.Add(v.Id);
1710 }
1711
1712 return soldVehicle;
1713 }
1714 }
1715
1716 /// <summary>
1717 /// Loops through vehicles in inventory and note down vehicles without a bay allocation.
1718 /// </summary>
1719 public List<string> UnallocatedVehicles
1720 {
1721 get
1722 {
1723 List<string> vList = _manager["Vehicle"].GetIDs;
1724 List<DbObject> bList = _manager["Bay"].RetrieveMany("occupied");
1725 List<string> unallocatedVehicle = new List<string>(vList);
1726
1727 foreach (string v in vList)
1728 {
1729 foreach (Bay b in bList)
1730 {
1731 if (v == b.Vehicle)
1732 {
1733 unallocatedVehicle.Remove(v);
1734 }
1735 }
1736 }
1737
1738 return unallocatedVehicle;
1739 }
1740 }
1741 }
1742}
1743
1744using System;
1745using System.Collections.Generic;
1746using System.Linq;
1747using System.Text;
1748using System.Threading.Tasks;
1749using IMS.User;
1750using IMS.Manager;
1751using IMS.Invoice;
1752using IMS.Tools;
1753
1754namespace IMS.Instance
1755{
1756 /// <summary>
1757 /// Supports adding of vehicles \ addons, assigning new vehicles and removing sold vehicles.
1758 /// </summary>
1759 public class GarageInstance : Instance
1760 {
1761 string _vehicleId = "";
1762 string _addonId = "";
1763
1764 public GarageInstance(Staff s, VehicleManager vm, AddonManager am, BayManager bm) : base(vm, am, bm)
1765 {
1766 if (s.Role != JobRole.Garage)
1767 {
1768 throw new System.InvalidOperationException("Invalid User! Cannot create garage instance!");
1769 }
1770 }
1771
1772 /// <summary>
1773 /// View the recently added addon.
1774 /// </summary>
1775 public string ViewAddAddon
1776 {
1777 get
1778 {
1779 Addon a = _manager["Addon"].Retrieve(_addonId) as Addon;
1780 if(a == null) return "No addon to show. No addon has been added yet.";
1781 return a.View;
1782 }
1783 }
1784
1785 /// <summary>
1786 /// View the recently added vehicle.
1787 /// </summary>
1788 public string ViewAddVehicle
1789 {
1790 get
1791 {
1792 Vehicle v = _manager["Vehicle"].Retrieve(_vehicleId) as Vehicle;
1793 if (v == null) return "No vehicle to show. No vehicle has been added yet.";
1794 return v.View;
1795 }
1796 }
1797
1798 /// <summary>
1799 /// Validates and adds the entered vehicle into the vehicle inventory.
1800 /// </summary>
1801 public string Add(Vehicle vehicle)
1802 {
1803 if (!ValidateIMS.IsValid(vehicle))
1804 {
1805 return "Fail. Not right format";
1806 }
1807
1808 if (_manager["Vehicle"].Contain(vehicle.Id))
1809 {
1810 return "Fail. Already exists within system";
1811 }
1812
1813 _vehicleId = vehicle.Id;
1814
1815 return _manager["Vehicle"].Add(vehicle);
1816 }
1817
1818 /// <summary>
1819 /// Validates and adds the entered addon into the addon inventory.
1820 /// </summary>
1821 public string Add(Addon addon)
1822 {
1823 if (!ValidateIMS.IsValid(addon))
1824 {
1825 return "Fail. Not right format";
1826 }
1827
1828 _addonId = addon.Id;
1829
1830 return _manager["Addon"].Add(addon);
1831 }
1832
1833 /// <summary>
1834 /// Adds an ID of the vehicle in the inventory to the given bay.
1835 /// </summary>
1836 public string AssignVehicleToBay(string vehicleId, string bayId)
1837 {
1838 if (!(_manager["Vehicle"].Contain(vehicleId)) || !(_manager["Bay"].Contain(bayId)))
1839 {
1840 return "Fail.One or more of the items does not exist within the system.";
1841 }
1842
1843 Bay selectedBay = _manager["Bay"].Retrieve(bayId) as Bay;
1844 selectedBay.Vehicle = vehicleId;
1845 return _manager["Bay"].Update(selectedBay);
1846 }
1847
1848 /// <summary>
1849 /// Removes an ID of the vehicle in the inventory to the given bay.
1850 /// </summary>
1851 private string RemoveVehicleFromBay(string vehicleId)
1852 {
1853 List<DbObject> bList = _manager["Bay"].RetrieveMany("occupied");
1854 foreach( Bay bay in bList)
1855 {
1856 if(bay.Vehicle == vehicleId)
1857 {
1858 bay.Vehicle = null;
1859 return _manager["Bay"].Update(bay);
1860 }
1861 }
1862
1863 return "Fail.Vehicle not stored in bay.";
1864 }
1865
1866 /// <summary>
1867 /// Removes the vehicle from the inventory as well as calling another method which
1868 /// removes the ID of the vehicle in the given bay.
1869 /// </summary>
1870 public string RemoveVehicle(string vehicleId)
1871 {
1872 if (_manager["Vehicle"].Contain(vehicleId))
1873 {
1874 _manager["Vehicle"].Delete(vehicleId);
1875 return RemoveVehicleFromBay(vehicleId);
1876 }
1877
1878 return "Fail.Vehicle does not exist.";
1879 }
1880
1881 }
1882}
1883
1884using System;
1885using System.Collections.Generic;
1886using System.Linq;
1887using System.Text;
1888using System.Threading.Tasks;
1889using IMS.Manager;
1890using IMS.User;
1891using IMS.Tools;
1892
1893namespace IMS.Instance
1894{
1895 public sealed class UserInstance : Instance
1896 {
1897 private static UserInstance _instance;
1898
1899 public static UserInstance Instance
1900 {
1901 get
1902 {
1903 if (_instance == null)
1904 {
1905 throw new Exception("User Instance not created");
1906 }
1907 return _instance;
1908 }
1909 }
1910
1911 public static void Create(UserManager um)
1912 {
1913 if (_instance == null)
1914 {
1915 _instance = new UserInstance(um);
1916 }
1917 }
1918 private UserInstance(UserManager um) : base(um)
1919 {
1920
1921 }
1922
1923 public User.User LocateUser(Type userType, string userId)
1924 {
1925 User.User _user = _manager["User"].Retrieve(userId) as User.User;
1926
1927 switch (userType.Name)
1928 {
1929 case nameof(Staff):
1930 _user = _user as Staff;
1931 return _user;
1932 case nameof(Customer):
1933 _user = _user as Customer;
1934 return _user;
1935 default:
1936 return null;
1937 }
1938 }
1939
1940 public string CreateUser(User.User user)
1941 {
1942 if (!ValidateIMS.IsValid(user))
1943 {
1944 return "Fail. Not right format";
1945 }
1946
1947 return _manager["User"].Add(user);
1948 }
1949
1950 }
1951}
1952
1953using System;
1954using System.Collections.Generic;
1955using System.Linq;
1956using System.Text;
1957using System.Threading.Tasks;
1958
1959namespace IMS.Manager
1960{
1961 public interface IManager
1962 {
1963 string Add(DbObject item);
1964 List<DbObject> RetrieveMany(string id);
1965 DbObject Retrieve(string id);
1966 string Update(DbObject item);
1967 string Delete(string id);
1968 List<string> GetIDs { get; }
1969 bool Contain(string id);
1970 }
1971}
1972
1973using System;
1974using System.Collections.Generic;
1975using System.Linq;
1976using System.Text;
1977using System.Threading.Tasks;
1978
1979namespace IMS.Manager
1980{
1981 /// <summary>
1982 /// Interacts with the database through the manager and provides a
1983 /// "buffer" between the database implementation and the application.
1984 /// Allows for type specific manipulation and validation of data types
1985 /// Add, delete, remove, update and retreival of database items done via this manager
1986 /// </summary>
1987 public abstract class Manager : IManager
1988 {
1989 protected IDb _db;
1990
1991 public Manager(string table, Database db)
1992 {
1993 _db = db.Read(table) as IDb;
1994 if (_db == null)
1995 {
1996 throw new System.NullReferenceException("The table does not exist. Cannot be null");
1997 }
1998 }
1999
2000 /// <summary>
2001 /// Allows for the type specific validation and adding of sub-types of DbObject
2002 /// </summary>
2003 public abstract string Add(DbObject item);
2004
2005 public string Delete(string id)
2006 {
2007 if (_db.Delete(id))
2008 {
2009 return "Successfully deleted.";
2010 }
2011 else
2012 {
2013 return "No such item found.";
2014 }
2015 }
2016
2017 /// <summary>
2018 /// Retreives all the items stored within the managed table
2019 /// </summary>
2020 public virtual List<DbObject> RetrieveMany(string id)
2021 {
2022 if (id.ToLower() != "all")
2023 {
2024 throw new ArgumentException("Needs to include an 'all' quantifier");
2025 }
2026 List<DbObject> output = new List<DbObject>();
2027 List<string> idList = _db.GetIDs;
2028 foreach (string ids in idList)
2029 {
2030 output.Add(_db.Read(ids));
2031 }
2032 return output;
2033 }
2034
2035 public string Update(DbObject item)
2036 {
2037 if (_db.Update(item))
2038 {
2039 return "Successfully updated.";
2040 }
2041
2042 return "No such item found";
2043 }
2044
2045 /// <summary>
2046 /// Retrieves a single item from the database
2047 /// </summary>
2048 public DbObject Retrieve(string id)
2049 {
2050 return _db.Read(id);
2051 }
2052
2053 /// <summary>
2054 /// Retrieves ID's of all the items within the database table
2055 /// </summary>
2056 public List<string> GetIDs
2057 {
2058 get
2059 {
2060 return _db.GetIDs;
2061 }
2062 }
2063
2064 public bool Contain(string id)
2065 {
2066 return GetIDs.Contains(id);
2067 }
2068
2069 }
2070}
2071
2072using System;
2073using System.Collections.Generic;
2074using System.Linq;
2075using System.Text;
2076using System.Threading.Tasks;
2077
2078namespace IMS.Manager
2079{
2080 public sealed class ManagerFactory
2081 {
2082 public static IManager GetManager(Type manager)
2083 {
2084 IManager instance = null;
2085
2086 switch (manager.Name)
2087 {
2088 case nameof(BayManager):
2089 instance = BayManager.Instance;
2090 break;
2091 case nameof(VehicleManager):
2092 instance = VehicleManager.Instance;
2093 break;
2094 case nameof(InvoiceManager):
2095 instance = InvoiceManager.Instance;
2096 break;
2097 case nameof(AddonManager):
2098 instance = AddonManager.Instance;
2099 break;
2100 case nameof(ReportManager):
2101 instance = ReportManager.Instance;
2102 break;
2103 case nameof(UserManager):
2104 instance = UserManager.Instance;
2105 break;
2106 default: throw new Exception("Manager does not exist or not created");
2107 }
2108
2109 return instance;
2110 }
2111
2112 public static void Create(Type manager, string name,Database db)
2113 {
2114 switch (manager.Name)
2115 {
2116 case nameof(BayManager):
2117 BayManager.Create(name, db);
2118 break;
2119 case nameof(VehicleManager):
2120 VehicleManager.Create(name, db);
2121 break;
2122 case nameof(InvoiceManager):
2123 InvoiceManager.Create(name, db);
2124 break;
2125 case nameof(AddonManager):
2126 AddonManager.Create(name, db);
2127 break;
2128 case nameof(ReportManager):
2129 ReportManager.Create(name, db);
2130 break;
2131 case nameof(UserManager):
2132 UserManager.Create(name, db);
2133 break;
2134 default: throw new Exception("Manager of that type does not exist");
2135 }
2136 }
2137 }
2138}
2139
2140using System;
2141using System.Collections.Generic;
2142using System.Linq;
2143using System.Text;
2144using System.Threading.Tasks;
2145using IMS.Tools;
2146
2147namespace IMS.Manager
2148{
2149 /// <summary>
2150 /// Interacts with the database through the addon manager.
2151 /// Allows accessing of addon specific methods.
2152 /// Add, delete, remove, update and retreival of addons done via this manager.
2153 /// </summary>
2154 public sealed class AddonManager : Manager, IManager
2155 {
2156 private static AddonManager _instance;
2157
2158 public static AddonManager Instance
2159 {
2160 get
2161 {
2162 if (_instance == null)
2163 {
2164 throw new Exception("Addon manager not created");
2165 }
2166 return _instance;
2167 }
2168 }
2169
2170 public static void Create(string atable, Database db)
2171 {
2172 if (_instance == null)
2173 {
2174 _instance = new AddonManager(atable, db);
2175 }
2176 }
2177 private AddonManager(string atable, Database db) : base(atable, db)
2178 {
2179 }
2180
2181 public override string Add(DbObject item)
2182 {
2183 Addon a = item as Addon;
2184
2185 if(a == null)
2186 {
2187 throw new NullReferenceException("Not of type Addon");
2188 }
2189
2190 if (_db.Create(item))
2191 {
2192 return "Successfully added addon";
2193 }
2194
2195 return "Duplication! Addon already exists. ID:" + item.Id;
2196 }
2197
2198 /// <summary>
2199 /// Gets all addons that are compatible with a specified vehicle id.
2200 /// </summary>
2201 public override List<DbObject> RetrieveMany(string id)
2202 {
2203 List<DbObject> output = new List<DbObject>();
2204 List<string> idList = _db.GetIDs;
2205 foreach (string ids in idList)
2206 {
2207 Addon a = _db.Read(ids) as Addon;
2208 if (!(a.IsCompatible(id))) continue;
2209 output.Add(_db.Read(ids));
2210 }
2211 return output;
2212 }
2213 }
2214}
2215
2216using System;
2217using System.Collections.Generic;
2218using System.Linq;
2219using System.Text;
2220using System.Threading.Tasks;
2221using IMS.Invoice;
2222using IMS.User;
2223
2224namespace IMS.Manager
2225{
2226 public sealed class InvoiceManager : Manager, IManager
2227 {
2228 /// <summary>
2229 /// Interacts with the database through the invoice manager
2230 /// Allows accessing of invoice specific methods
2231 /// Add, delete, remove, update and retreival of invoice done via this manager
2232 /// </summary>
2233
2234 private static InvoiceManager _instance;
2235 public static InvoiceManager Instance
2236 {
2237 get
2238 {
2239 if (_instance == null)
2240 {
2241 throw new Exception("Invoice Manager not created");
2242 }
2243 return _instance;
2244 }
2245 }
2246
2247 public static void Create(string itable, Database db)
2248 {
2249 if (_instance == null)
2250 {
2251 _instance = new InvoiceManager(itable, db);
2252 }
2253 }
2254 private InvoiceManager(string itable, Database db) : base(itable, db)
2255 {
2256 }
2257
2258 public override string Add(DbObject item)
2259 {
2260 Invoice.Invoice i = item as Invoice.Invoice;
2261
2262 if (i == null)
2263 {
2264 throw new NullReferenceException("Not of type Invoice");
2265 }
2266
2267 if (_db.Create(item))
2268 {
2269 return "Successfully added invoice.";
2270 }
2271
2272 return "Duplication! Invoice already exists. ID:" + item.Id;
2273 }
2274
2275 public override List<DbObject> RetrieveMany(string id)
2276 {
2277 List<DbObject> lOutput = new List<DbObject>();
2278 List<string> lIdList = _db.GetIDs;
2279 foreach (string ids in lIdList)
2280 {
2281 Invoice.Invoice lInvoice = null;
2282 switch (id.ToLower())
2283 {
2284 case "tax":
2285 lInvoice = _db.Read(ids) as Tax;
2286 break;
2287 case "sale":
2288 lInvoice = _db.Read(ids) as Sale;
2289 break;
2290 case "all":
2291 lInvoice = _db.Read(ids) as Invoice.Invoice;
2292 break;
2293 default:
2294 throw new ArgumentException("Needs to be either tax / sale or all");
2295 }
2296
2297 if (lInvoice != null) lOutput.Add(lInvoice);
2298 }
2299 return lOutput;
2300 }
2301 }
2302}
2303
2304using System;
2305using System.Collections.Generic;
2306using System.Linq;
2307using System.Text;
2308using System.Threading.Tasks;
2309
2310namespace IMS.Manager
2311{
2312 /// <summary>
2313 /// Interacts with the database through the bay manager
2314 /// Add, delete, remove, update and retreival of vehicle bays done via this manager
2315 /// </summary>
2316 public sealed class BayManager : Manager, IManager
2317 {
2318 private static BayManager _instance;
2319
2320 public static BayManager Instance
2321 {
2322 get
2323 {
2324 if (_instance == null)
2325 {
2326 throw new Exception("Bay manager not created");
2327 }
2328 return _instance;
2329 }
2330 }
2331
2332 public static void Create(string btable, Database db)
2333 {
2334 if (_instance == null)
2335 {
2336 _instance = new BayManager(btable, db);
2337 }
2338 }
2339
2340 private BayManager(string btable, Database db) : base(btable, db)
2341 {
2342 }
2343
2344 public override string Add(DbObject item)
2345 {
2346 Bay b = item as Bay;
2347
2348 if (b == null)
2349 {
2350 throw new NullReferenceException("Not of type Bay");
2351 }
2352
2353 if (_db.Create(item))
2354 {
2355 return "Successfully added bay";
2356 }
2357
2358 return "Duplication! Bay already exists. ID:" + item.Id;
2359 }
2360
2361 /// <summary>
2362 /// Reterives bays based on the current occupation status
2363 /// </summary>
2364 public override List<DbObject> RetrieveMany(string id)
2365 {
2366 List<DbObject> output = new List<DbObject>();
2367 List<string> idList = _db.GetIDs;
2368 foreach (string ids in idList)
2369 {
2370 Bay b = _db.Read(ids) as Bay;
2371
2372 switch (id.ToLower())
2373 {
2374 case "occupied":
2375 if (!(b.Available)) output.Add(b);
2376 break;
2377 case "free":
2378 if (b.Available) output.Add(b);
2379 break;
2380 case "all":
2381 output.Add(b);
2382 break;
2383 default:
2384 throw new ArgumentException("Needs to be either occupied / free or all");
2385 }
2386 }
2387
2388 return output;
2389 }
2390 }
2391}
2392
2393using System;
2394using System.Collections.Generic;
2395using System.Linq;
2396using System.Text;
2397using System.Threading.Tasks;
2398using IMS.Report;
2399
2400namespace IMS.Manager
2401{
2402 public sealed class ReportManager : Manager,IManager
2403 {
2404 /// <summary>
2405 /// Interacts with the database through the report manager
2406 /// Allows accessing of report specific methods
2407 /// Add, delete, remove, update and retreival of reports done via this manager
2408 /// </summary>
2409 private static ReportManager _instance;
2410
2411 public static ReportManager Instance
2412 {
2413 get
2414 {
2415 if (_instance == null)
2416 {
2417 throw new Exception("Report Manager not created");
2418 }
2419 return _instance;
2420 }
2421 }
2422
2423 public static void Create(string rtable, Database db)
2424 {
2425 if (_instance == null)
2426 {
2427 _instance = new ReportManager(rtable, db);
2428 }
2429 }
2430
2431 private ReportManager(string rtable, Database db) : base(rtable,db)
2432 {
2433 }
2434
2435 public override string Add(DbObject item)
2436 {
2437 Report.Report r = item as Report.Report;
2438
2439 if (r == null)
2440 {
2441 throw new NullReferenceException("Not of type Report");
2442 }
2443
2444 if (_db.Create(item))
2445 {
2446 return "Successfully added report.";
2447 }
2448
2449 return "Duplication! Report already exists. ID:" + item.Id;
2450 }
2451 }
2452}
2453
2454using System;
2455using System.Collections.Generic;
2456using System.Linq;
2457using System.Text;
2458using System.Threading.Tasks;
2459using IMS.User;
2460
2461namespace IMS.Manager
2462{
2463 public sealed class UserManager : Manager,IManager
2464 {
2465 /// <summary>
2466 /// Interacts with the database through the user manager
2467 /// Allows accessing of user specific methods
2468 /// Add, delete, remove, update and retreival of users done via this manager
2469 /// </summary>
2470 ///
2471 private static UserManager _instance;
2472 public static UserManager Instance
2473 {
2474 get
2475 {
2476 if (_instance == null)
2477 {
2478 throw new Exception("User Manager not created");
2479 }
2480 return _instance;
2481 }
2482 }
2483
2484 public static void Create(string utable, Database db)
2485 {
2486 if (_instance == null)
2487 {
2488 _instance = new UserManager(utable, db);
2489 }
2490 }
2491 private UserManager(string utable, Database db) : base(utable, db)
2492 {
2493 }
2494
2495 public override string Add(DbObject item)
2496 {
2497 User.User u = item as User.User;
2498
2499 if (u == null)
2500 {
2501 throw new NullReferenceException("Not of type User");
2502 }
2503
2504 if (_db.Create(item))
2505 {
2506 return "Successfully added user.";
2507 }
2508
2509 return "Duplication! User already exists. ID:" + item.Id;
2510 }
2511 }
2512}
2513
2514
2515using System;
2516using System.Collections.Generic;
2517using System.Linq;
2518using System.Text;
2519using System.Threading.Tasks;
2520
2521namespace IMS.Manager
2522{
2523 public sealed class VehicleManager : Manager, IManager
2524 {
2525 /// <summary>
2526 /// Interacts with the database through the vehicle manager
2527 /// Allows accessing of vehicle specific methods
2528 /// Add, delete, remove, update and retreival of vehicles done via this manager
2529 /// </summary>
2530 ///
2531 private static VehicleManager _instance;
2532 public static VehicleManager Instance
2533 {
2534 get
2535 {
2536 if (_instance == null)
2537 {
2538 throw new Exception("Vehicle Manager not created");
2539 }
2540 return _instance;
2541 }
2542 }
2543
2544 public static void Create(string vtable, Database db)
2545 {
2546 if (_instance == null)
2547 {
2548 _instance = new VehicleManager(vtable, db);
2549 }
2550 }
2551 private VehicleManager(string vtable, Database db) : base(vtable, db)
2552 {
2553
2554 }
2555
2556 public override string Add(DbObject item)
2557 {
2558 Vehicle v = item as Vehicle;
2559
2560 if (v == null)
2561 {
2562 throw new NullReferenceException("Not of type Vehicle");
2563 }
2564
2565 if (_db.Create(item))
2566 {
2567 return "Successfully added vehicle.";
2568 }
2569
2570 return "Duplication! Vehicle already exists. ID:" + item.Id;
2571 }
2572
2573 public override List<DbObject> RetrieveMany(string id)
2574 {
2575 List<DbObject> output = new List<DbObject>();
2576 List<string> idList = _db.GetIDs;
2577 foreach (string ids in idList)
2578 {
2579 Vehicle v = _db.Read(ids) as Vehicle;
2580
2581 switch (id.ToLower())
2582 {
2583 case "unsold":
2584 if (!(v.Sold)) output.Add(v);
2585 break;
2586 case "sold":
2587 if (v.Sold) output.Add(v);
2588 break;
2589 case "all":
2590 output.Add(v);
2591 break;
2592 default:
2593 throw new ArgumentException("Needs to be either unsold / sold or all");
2594 }
2595 }
2596 return output;
2597 }
2598 }
2599}
2600
2601using System;
2602using System.Collections.Generic;
2603using System.Linq;
2604using System.Text;
2605using System.Threading.Tasks;
2606
2607namespace IMS
2608{
2609 public struct CreditCard
2610 {
2611 public string cardNumber;
2612 public int expirationDate;
2613 public int cardCode;
2614 }
2615
2616}
2617
2618namespace IMS.Payment
2619{
2620 /// <summary>
2621 /// Deals with the processing of payment.
2622 /// Processes payment details and payment process using online vendor.
2623 /// </summary>
2624 public class PaymentProcessor
2625 {
2626 /// <summary>
2627 /// Processes the credit card details with an online vendor
2628 /// Vendor automatically checks whether it is a Visa, Mastercard..ect
2629 /// </summary>
2630 public string SetPaymentDetail(CreditCard c)
2631 {
2632 // Authorise with online retailer
2633 // https://developer.authorize.net/api/reference/index.html
2634 return "VALID";
2635
2636 }
2637
2638 public string Pay(double price)
2639 {
2640 // Pay with online retailer
2641 // https://developer.authorize.net/api/reference/index.html
2642 return "PAYID-1223456-Example";
2643 }
2644 }
2645}
2646
2647using System;
2648using System.Collections.Generic;
2649using System.Linq;
2650using System.Text;
2651using System.Threading.Tasks;
2652
2653namespace IMS.Tools
2654{
2655 /// <summary>
2656 /// Generates a unique id, that consists of numbers and letters
2657 /// just like a google youtube video link.
2658 /// </summary>
2659 public class IdGenerator
2660 {
2661 // https://stackoverflow.com/questions/11313205/generate-a-unique-id
2662 // Author: Ashraf Ali
2663 public static string UniqueId()
2664 {
2665 StringBuilder builder = new StringBuilder();
2666 Enumerable
2667 .Range(65, 26)
2668 .Select(e => ((char)e).ToString())
2669 .Concat(Enumerable.Range(97, 26).Select(e => ((char)e).ToString()))
2670 .Concat(Enumerable.Range(0, 10).Select(e => e.ToString()))
2671 .OrderBy(e => Guid.NewGuid())
2672 .Take(11)
2673 .ToList().ForEach(e => builder.Append(e));
2674 return builder.ToString();
2675 }
2676 }
2677}
2678
2679using System;
2680using System.Collections.Generic;
2681using System.Linq;
2682using System.Text;
2683using System.Threading.Tasks;
2684using IMS.User;
2685using System.Text.RegularExpressions;
2686
2687namespace IMS.Tools
2688{
2689 /// <summary>
2690 /// Provides methods to validate the user inputs
2691 /// </summary>
2692 public class ValidateIMS
2693 {
2694 public static bool IsBad(string t, string regex)
2695 {
2696 return !(Regex.IsMatch(t, regex));
2697 }
2698
2699 public static bool IsValid(DbObject item)
2700 {
2701 if (item == null)
2702 {
2703 return false;
2704 }
2705
2706 switch (item.GetType().Name)
2707 {
2708 case nameof(Vehicle):
2709 return IsVehicleValid(item as Vehicle);
2710 case nameof(Addon):
2711 return IsAddonValid(item as Addon);
2712 case nameof(Customer):
2713 return IsCustomerValid(item as Customer);
2714 default: return false;
2715 }
2716 }
2717
2718 private static bool IsVehicleValid(Vehicle item)
2719 {
2720 if (ValidateIMS.IsBad(item.Id, @"^[a-zA-Z0-9]{1,10}$") || ValidateIMS.IsBad(item.Model, @"^[a-zA-Z0-9-]{1,25}$") || item.Price <= 0.00)
2721 {
2722 return false;
2723 }
2724
2725 return true;
2726 }
2727
2728 private static bool IsAddonValid(Addon item)
2729 {
2730 if (ValidateIMS.IsBad(item.Id, @"^[a-zA-Z0-9]{1,10}$") || ValidateIMS.IsBad(item.Name, @"^[a-zA-Z0-9-]{1,25}$") || item.Price <= 0.00)
2731 {
2732 return false;
2733 }
2734
2735 return true;
2736 }
2737
2738 private static bool IsCustomerValid(Customer item)
2739 {
2740 if (ValidateIMS.IsBad(item.Id, @"^[a-zA-Z0-9]{1,10}$") || ValidateIMS.IsBad(item.Name, @"^[a-zA-Z ]{1,50}$") || ValidateIMS.IsBad(item.Address, @"^[a-zA-Z0-9, ]{1,70}$") || ValidateIMS.IsBad(item.Phone, @"^\d{10}$"))
2741 {
2742 return false;
2743 }
2744
2745 return true;
2746 }
2747
2748 public static bool ValidDateRangeCheck(Invoice.Invoice invoice, DateTime start, DateTime end)
2749 {
2750 int lStart = invoice.Date.CompareTo(start);
2751 int lEnd = invoice.Date.CompareTo(end);
2752
2753 // Less than zero ; earlier date
2754 // Greater than zero; later date
2755 if (lStart >= 0 && lEnd <= 0) return true;
2756 return false;
2757 }
2758 }
2759}
2760
2761
2762using System;
2763using System.Collections.Generic;
2764using System.Linq;
2765using System.Text;
2766using System.Threading.Tasks;
2767
2768namespace IMS
2769{
2770 public enum EnumMsg
2771 {
2772 // Exception message table
2773 MSG_NULL_EXCEPTION_NOT_ADDON = -2000,
2774 MSG_NULL_EXCEPTION_NOT_REPORT = -1999,
2775 MSG_NULL_EXCEPTION_NOT_USER = -1998,
2776 MSG_NULL_EXCEPTION_NOT_VEHICLE = -1997,
2777 MSG_NULL_EXCEPTION_NOT_INVOICE = -1996,
2778 MSG_NULL_EXCEPTION_NOT_BAY = -1995,
2779
2780 // Managers message table
2781 MSG_SUCCESS_ADD_REPORT,
2782 MSG_SUCCESS_ADD_USER,
2783 MSG_SUCCESS_ADD_VEHICLE,
2784 MSG_SUCCESS_ADD_INVOICE,
2785 MSG_SUCCESS_ADD_BAY,
2786 MSG_SUCCESS_ADD_ADDON,
2787 MSG_ERROR_DUPLICATE_REPORT = -1000,
2788 MSG_ERROR_DUPLICATE_USER = -999,
2789 MSG_ERROR_DUPLICATE_VEHICLE = -998,
2790 MSG_ERROR_DUPLICATE_INVOICE = -997,
2791 MSG_ERROR_DUPLICATE_BAY = -996,
2792 MSG_ERROR_DUPLICATE_ADDON = -995,
2793
2794 // Payment Processor message table
2795 MSG_VALID_CARD
2796
2797 // Instances message table
2798
2799
2800 };
2801}
2802
2803namespace IMS.Tools
2804{
2805 /// <summary>
2806 /// Allows for the messages displayed to the user to be collated using a string table
2807 /// ,thus, allowing for localization in the future.
2808 /// </summary>
2809 public class StringTable
2810 {
2811 public static string EnumToString(EnumMsg msg)
2812 {
2813 switch(msg)
2814 {
2815 default: return "Unknown msg.TODO.";
2816 }
2817 }
2818 }
2819}
2820
2821/*START OF UI CODE*/
2822
2823using System;
2824using System.Collections.Generic;
2825using System.Linq;
2826using System.Threading.Tasks;
2827using System.Windows.Forms;
2828using IMS.User;
2829using IMS;
2830using IMS.Manager;
2831using IMS.Report;
2832using IMS.Instance;
2833
2834namespace IMS_GUI
2835{
2836 public class ManagerShared
2837 {
2838 public static BayManager bm = ManagerFactory.GetManager(typeof(BayManager)) as BayManager;
2839 public static VehicleManager vm = ManagerFactory.GetManager(typeof(VehicleManager)) as VehicleManager;
2840 public static AddonManager am = ManagerFactory.GetManager(typeof(AddonManager)) as AddonManager;
2841 public static UserManager um = ManagerFactory.GetManager(typeof(UserManager)) as UserManager;
2842 public static InvoiceManager im = ManagerFactory.GetManager(typeof(InvoiceManager)) as InvoiceManager;
2843 public static ReportManager rm = ManagerFactory.GetManager(typeof(ReportManager)) as ReportManager;
2844 }
2845
2846 public class WinFormShared
2847 {
2848 public static Vehicle vehicle = null;
2849 public static Addon addon = null;
2850 }
2851
2852 static class Program
2853 {
2854 public static Staff staffAccount;
2855
2856 static Database FakeData(int amount)
2857 {
2858 // Database
2859 Database.Create("HTV Database");
2860 Database db = Database.Instance;
2861
2862 // DbTable
2863 DbTable dbTableBay = new DbTable("bay", "Bay Table");
2864 DbTable dbTableVehicle = new DbTable("vehicle", "Vehicle Table");
2865 DbTable dbTableAddon = new DbTable("addon", "Addon Table");
2866 DbTable dbTableUser = new DbTable("user", "User Table");
2867
2868 DbTable dbTableInvoice = new DbTable("invoice", "Invoice Table");
2869 DbTable dbTableReport = new DbTable("report", "Report Table");
2870
2871
2872 // Bays
2873 for (int i = 0; i < amount; i++)
2874 {
2875 Bay x = new Bay("B000" + (i.ToString()));
2876 if (i < amount/2)
2877 {
2878 x.Vehicle = "VIN0000" + (i.ToString());
2879 }
2880
2881 dbTableBay.Create(x);
2882 }
2883
2884 // Vehicle
2885 string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2886 for (int i = 0; i < amount; i++)
2887 {
2888 string model = (chars[new Random().Next(chars.Length)] + chars[new Random().Next(chars.Length)] + chars[new Random().Next(chars.Length)] + chars[new Random().Next(chars.Length)]).ToString();
2889 Vehicle x = new Vehicle("VIN0000" + (i.ToString()), (Brand)new Random().Next(0, 11), model, new DateTime(new Random().Next(1990, 2019), 01, 01), new Random().Next(30000, 150000));
2890 if (i < amount/3)
2891 {
2892 x.Sold = true;
2893 }
2894 dbTableVehicle.Create(x);
2895
2896 }
2897
2898 // Addon
2899 for (int i = 0; i < amount; i++)
2900 {
2901 Addon a = new Addon("A000" + (i.ToString()), "AddonTA10" + (i.ToString()), "Addon is xyz blah", new Random().Next(100, 3500));
2902 a.Compatible = "VIN0000" + (i.ToString());
2903 dbTableAddon.Create(a);
2904
2905 Addon b = new Addon("A100" + (i.ToString()), "AddonTB10" + (i.ToString()), "Addon is xyz blah", new Random().Next(100, 3500));
2906 b.Compatible = "VIN0000" + (i.ToString());
2907 dbTableAddon.Create(b);
2908
2909 Addon c = new Addon("A200" + (i.ToString()), "AddonTC10" + (i.ToString()), "Addon is xyz blah", new Random().Next(100, 3500));
2910 c.Compatible = "VIN0000" + (i.ToString());
2911 dbTableAddon.Create(c);
2912 }
2913
2914 // Users
2915 for (int i = 0; i < amount; i++)
2916 {
2917 string name = (chars[new Random().Next(chars.Length)] + chars[new Random().Next(chars.Length)] + chars[new Random().Next(chars.Length)] + chars[new Random().Next(chars.Length)]).ToString();
2918 Customer c = new Customer("C00" + (i.ToString()), "Customer Name", "25 Makaby Street, VIC, 3752", "0418534687");
2919
2920
2921 dbTableUser.Create(c);
2922 }
2923
2924 Staff s1 = new Staff("S10", "Example Name", JobRole.Sale);
2925 Staff s2 = new Staff("S20", "Example Name", JobRole.Accounting);
2926 Staff s3 = new Staff("S30", "Example Name", JobRole.Management);
2927 Staff s4 = new Staff("S40", "Example Name", JobRole.Garage);
2928
2929 dbTableUser.Create(s1);
2930 dbTableUser.Create(s2);
2931 dbTableUser.Create(s3);
2932 dbTableUser.Create(s4);
2933
2934 IMS.Builder.InvoiceBuilder iBuild = new IMS.Builder.InvoiceBuilder();
2935 Order z;
2936 z.addons = new List<Addon>() { new Addon("A00001", "AddonTA10", "Addon is xyz blah", 5600.00) };
2937 z.buyVehicle = new Vehicle("VIN00001", Brand.Audi, "MN-67", new DateTime(new Random().Next(1990, 2019), 01, 01), new Random().Next(30000, 150000));
2938 z.tradeVehicle = null;
2939 iBuild.Order = z;
2940 iBuild.Staff = new Staff("SR689", "Example Staff", JobRole.Sale);
2941
2942 IMS.Invoice.Sale iSale = iBuild.Prepare() as IMS.Invoice.Sale;
2943
2944 dbTableInvoice.Create(iSale);
2945
2946
2947 InvoiceReport dd = new InvoiceReport("R006","Test Report Name", ReportType.Sale, new DateTime(2019, 01, 01), new DateTime(2019, 04, 01));
2948 dd.AmountOfSale = 60;
2949 dd.TotalSalePrice = 176500.00;
2950
2951 dbTableReport.Create(dd);
2952
2953 db.Create(dbTableBay);
2954 db.Create(dbTableVehicle);
2955 db.Create(dbTableAddon);
2956 db.Create(dbTableUser);
2957 db.Create(dbTableInvoice);
2958 db.Create(dbTableReport);
2959
2960 return db;
2961
2962 }
2963
2964 /// <summary>
2965 /// The main entry point for the application.
2966 /// </summary>
2967 [STAThread]
2968 static void Main()
2969 {
2970 Database db = FakeData(10);
2971
2972 ManagerFactory.Create(typeof(BayManager), "bay", db);
2973 ManagerFactory.Create(typeof(VehicleManager), "vehicle", db);
2974 ManagerFactory.Create(typeof(AddonManager), "addon", db);
2975 ManagerFactory.Create(typeof(UserManager), "user", db);
2976 ManagerFactory.Create(typeof(InvoiceManager), "invoice", db);
2977 ManagerFactory.Create(typeof(ReportManager), "report", db);
2978
2979 LotInstance.Create(VehicleManager.Instance, BayManager.Instance);
2980 UserInstance.Create(UserManager.Instance);
2981
2982 Application.EnableVisualStyles();
2983 Application.SetCompatibleTextRenderingDefault(false);
2984 Application.Run(new LoginForm());
2985 }
2986 }
2987}
2988
2989using System;
2990using System.Collections.Generic;
2991using System.ComponentModel;
2992using System.Data;
2993using System.Drawing;
2994using System.Linq;
2995using System.Text;
2996using System.Threading.Tasks;
2997using System.Windows.Forms;
2998using IMS.User;
2999using IMS;
3000using IMS.Instance;
3001
3002namespace IMS_GUI
3003{
3004 public partial class LoginForm : Form
3005 {
3006 UserInstance uInstance = UserInstance.Instance;
3007 public LoginForm()
3008 {
3009 InitializeComponent();
3010 }
3011
3012 private void btnLogin_Click(object sender, EventArgs e)
3013 {
3014 Program.staffAccount = uInstance.LocateUser(typeof(Staff), txtUsername.Text) as Staff;
3015 if (Program.staffAccount != null)
3016 {
3017 //this.Hide();
3018 switch (Program.staffAccount.Role)
3019 {
3020 case JobRole.Accounting:
3021 AccountingInstanceForm aInstanceForm = new AccountingInstanceForm();
3022 aInstanceForm.ShowDialog();
3023 break;
3024 case JobRole.Sale:
3025 SaleInstanceForm sInstanceForm = new SaleInstanceForm();
3026 sInstanceForm.ShowDialog();
3027 break;
3028 case JobRole.Garage:
3029 GarageInstanceForm gInstanceForm = new GarageInstanceForm();
3030 gInstanceForm.ShowDialog();
3031 break;
3032 case JobRole.Management:
3033 ReportInstanceForm rInstanceForm = new ReportInstanceForm();
3034 rInstanceForm.ShowDialog();
3035 break;
3036 default:
3037 throw new ArgumentException("Unknown user! Unknown instance to create!");
3038 }
3039
3040 }
3041 else
3042 {
3043 MessageBox.Show("The user account does not exist.", "Unknown User", MessageBoxButtons.OK);
3044 }
3045
3046 }
3047 }
3048}
3049
3050using System;
3051using System.Collections.Generic;
3052using System.Windows.Forms;
3053using IMS.Instance;
3054using IMS;
3055using System.Drawing.Printing;
3056using System.Drawing;
3057
3058namespace IMS_GUI
3059{
3060 public partial class SaleInstanceForm : Form
3061 {
3062 SaleInstance sInstance = new SaleInstance(Program.staffAccount, ManagerShared.vm, ManagerShared.am, ManagerShared.im, ManagerShared.bm);
3063 LotInstance lInstance = LotInstance.Instance;
3064
3065 public SaleInstanceForm()
3066 {
3067 InitializeComponent();
3068 }
3069
3070 private void SaleInstance_Load(object sender, EventArgs e)
3071 {
3072 List<string> bList = lInstance.BaysWithNonSoldVehicles;
3073 foreach (string bId in bList)
3074 {
3075 cbBay.Items.Add(bId);
3076 }
3077
3078 cbPriceRate.DataSource = Enum.GetValues(typeof(PriceRate));
3079 }
3080
3081 private void btnVehicleSelect_Click(object sender, EventArgs e)
3082 {
3083 cblAddon.Items.Clear();
3084
3085 //Load vehicle that is in bay
3086 if (sInstance.SelectBaseVehicle(cbBay.SelectedItem as string))
3087 {
3088 tbVehicleDetails.Text = sInstance.ViewSelectedVehicle;
3089 dynamic aList = sInstance.GetSelectedVehicleAvailableAddons;
3090
3091 foreach (Addon a in aList)
3092 {
3093 cblAddon.Items.Add(a.Id);
3094 }
3095 }
3096 else
3097 {
3098 tbVehicleDetails.Text = "No vehicle selected";
3099 }
3100 }
3101
3102 private void btnTradeVehicleAdd_Click(object sender, EventArgs e)
3103 {
3104 CreateVehicleForm sInstanceForm = new CreateVehicleForm();
3105 sInstanceForm.ShowDialog();
3106
3107 string msg = sInstance.GetTradeVehicle(WinFormShared.vehicle);
3108 if (msg == "Success.")
3109 {
3110 tbShowTradeInVehicle.Text = WinFormShared.vehicle.View;
3111 }
3112 else
3113 {
3114 MessageBox.Show(msg, "Add Trade-in Vehicle", MessageBoxButtons.OK);
3115 }
3116 }
3117
3118 private void btnCreateSale_Click(object sender, EventArgs e)
3119 {
3120 sInstance.SelectBaseVehicle(cbBay.SelectedItem as string);
3121 foreach (dynamic addon in cblAddon.CheckedItems)
3122 {
3123 sInstance.SelectAddon(addon as string);
3124 }
3125
3126 string msg = sInstance.CreateSale((PriceRate)cbPriceRate.SelectedItem);
3127 if (msg != "Missing key sales details")
3128 {
3129 tbInvoice.Text = sInstance.ViewInvoice.Replace("\n", "\r\n");
3130 tbcSale.SelectTab(3);
3131 btnCreateSale.Hide();
3132 btnClose.Show();
3133 }
3134 else
3135 {
3136 MessageBox.Show(msg, "Create Sale", MessageBoxButtons.OK);
3137 }
3138 }
3139
3140 private void btnClearTradeInVehicle_Click(object sender, EventArgs e)
3141 {
3142 WinFormShared.vehicle = null;
3143 tbShowTradeInVehicle.Text = "";
3144 }
3145
3146 private void cblAddon_SelectedIndexChanged(object sender, EventArgs e)
3147 {
3148 if (cblAddon.SelectedItem != null)
3149 {
3150 Addon a = sInstance.ViewSelectedAddon(cblAddon.SelectedItem as string);
3151 tbAddonDetail.Text = a.View;
3152 }
3153
3154 }
3155
3156 private void btnClose_Click(object sender, EventArgs e)
3157 {
3158 this.Close();
3159 }
3160
3161 private void btnPrint_Click(object sender, EventArgs e)
3162 {
3163 PrintDocument pd = new PrintDocument();
3164 pd.PrintPage += new PrintPageEventHandler(xDoc);
3165 PrintDialog pdi = new PrintDialog();
3166 pdi.Document = pd;
3167 if (pdi.ShowDialog() == DialogResult.OK)
3168 {
3169 pd.Print();
3170 }
3171 }
3172
3173 private void xDoc(object sender, PrintPageEventArgs e)
3174 {
3175 e.Graphics.DrawString(tbInvoice.Text, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, 20, 20);
3176 }
3177
3178 private void btnDeleteInvoice_Click(object sender, EventArgs e)
3179 {
3180 string msg = sInstance.RemoveInvoice();
3181 if (msg == "Success.")
3182 {
3183 tbInvoice.Clear();
3184 }
3185
3186 MessageBox.Show(msg, "Remove Sale Invoice", MessageBoxButtons.OK);
3187 }
3188 }
3189}
3190
3191using System;
3192using System.Collections.Generic;
3193using System.ComponentModel;
3194using System.Data;
3195using System.Drawing;
3196using System.Linq;
3197using System.Text;
3198using System.Threading.Tasks;
3199using System.Windows.Forms;
3200using IMS;
3201using IMS.Instance;
3202using IMS.User;
3203using System.Drawing.Printing;
3204
3205namespace IMS_GUI
3206{
3207 public partial class AccountingInstanceForm : Form
3208 {
3209 AccountingInstance aInstance = new AccountingInstance(Program.staffAccount, ManagerShared.im, ManagerShared.um, ManagerShared.vm);
3210 UserInstance uInstance = UserInstance.Instance;
3211
3212 public static Customer newCustomer = null;
3213
3214 public AccountingInstanceForm()
3215 {
3216 InitializeComponent();
3217 }
3218
3219 private void btnGetInvoice_Click(object sender, EventArgs e)
3220 {
3221 string msg = aInstance.Invoice(txtInvoiceId.Text);
3222 MessageBox.Show(msg, "Invoice", MessageBoxButtons.OK);
3223 try
3224 {
3225 lblTotalValue.Text = aInstance.ViewTotal.ToString();
3226 }
3227 catch
3228 {
3229 lblTotalValue.Text = "_______";
3230 }
3231 }
3232
3233 private void btnGetExistingCustomer_Click(object sender, EventArgs e)
3234 {
3235 string msg = "Customer does not exist.";
3236 Customer _customer = uInstance.LocateUser(typeof(Customer), txtCustomerExisting.Text) as Customer;
3237
3238 if (_customer != null)
3239 {
3240 msg = "Found user.";
3241 aInstance.Customer = _customer;
3242 }
3243
3244 MessageBox.Show(msg, "Customer", MessageBoxButtons.OK);
3245 }
3246
3247 private void btnPay_Click(object sender, EventArgs e)
3248 {
3249 CreditCard card;
3250 card.cardNumber = txtCardNumber.Text;
3251 card.cardCode = Convert.ToInt32(nudCardCode.Text);
3252 card.expirationDate = Convert.ToInt32(nudCardExpire.Text);
3253
3254 string msg = aInstance.CreatePayment(card);
3255 MessageBox.Show(msg, "Invoice", MessageBoxButtons.OK);
3256
3257 if (msg == "Payment Success.")
3258 {
3259 txtInvoiceView.Text = aInstance.ViewTax.Replace("\n", "\r\n");
3260
3261 tabControl1.SelectTab(1);
3262 //tabControl1.Enabled = false;
3263 btnPay.Hide();
3264 btnGetInvoice.Enabled = false;
3265 btnGetExistingCustomer.Enabled = false;
3266 btnCreateNewCustomer.Enabled = false;
3267 }
3268 }
3269
3270 private void btnClose_Click(object sender, EventArgs e)
3271 {
3272 this.Close();
3273 }
3274
3275 private void btnCreateNewCustomer_Click(object sender, EventArgs e)
3276 {
3277 CreateCustomerForm createCustomerForm = new CreateCustomerForm();
3278 createCustomerForm.ShowDialog();
3279
3280 string msg = uInstance.CreateUser(newCustomer);
3281 MessageBox.Show(msg, "Customer", MessageBoxButtons.OK);
3282 }
3283
3284 private void btnPrint_Click(object sender, EventArgs e)
3285 {
3286 PrintDocument pd = new PrintDocument();
3287 pd.PrintPage += new PrintPageEventHandler(xDoc);
3288 PrintDialog pdi = new PrintDialog();
3289 pdi.Document = pd;
3290 if (pdi.ShowDialog() == DialogResult.OK)
3291 {
3292 pd.Print();
3293 }
3294 }
3295
3296 private void xDoc(object sender, PrintPageEventArgs e)
3297 {
3298 e.Graphics.DrawString(txtInvoiceView.Text, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, 20, 20);
3299 }
3300 }
3301}
3302
3303using System;
3304using System.Collections.Generic;
3305using System.ComponentModel;
3306using System.Data;
3307using System.Drawing;
3308using System.Linq;
3309using System.Text;
3310using System.Threading.Tasks;
3311using System.Windows.Forms;
3312using IMS.Instance;
3313using IMS.Report;
3314using IMS;
3315using System.Drawing.Printing;
3316
3317namespace IMS_GUI
3318{
3319 public partial class ReportInstanceForm : Form
3320 {
3321 ReportInstance rInstance = new ReportInstance(Program.staffAccount, ManagerShared.rm, ManagerShared.im);
3322 public static string txtName = "";
3323 public static string txtStartPeriod = "";
3324 public static string txtEndPeriod = "";
3325 public static string txtReportType = "";
3326
3327 public ReportInstanceForm()
3328 {
3329 InitializeComponent();
3330 }
3331
3332 private void ReportInstanceForm_Load(object sender, EventArgs e)
3333 {
3334 lbReport.Items.Clear();
3335 List<string> lReportList = rInstance.GetReportList;
3336 foreach(string r in lReportList)
3337 {
3338 lbReport.Items.Add(r);
3339 }
3340
3341 }
3342
3343 private void lbReport_SelectedIndexChanged(object sender, EventArgs e)
3344 {
3345 try
3346 {
3347 txtReportView.Text = rInstance.ViewSelectedReport(lbReport.SelectedItem as string).Replace("\n", "\r\n");
3348 }
3349 catch
3350 {
3351 txtReportView.Text = "";
3352 }
3353
3354 }
3355
3356 private void btnClose_Click(object sender, EventArgs e)
3357 {
3358 this.Close();
3359 }
3360
3361 private void btnCreateReport_Click(object sender, EventArgs e)
3362 {
3363 string lMsg = "";
3364 CreateReportForm rForm = new CreateReportForm();
3365 rForm.ShowDialog();
3366
3367 ReportType myStatus;
3368 Enum.TryParse(txtReportType, out myStatus);
3369 lMsg = rInstance.CreateReport(txtName,txtStartPeriod, txtEndPeriod, myStatus);
3370 MessageBox.Show(lMsg, "Create Report", MessageBoxButtons.OK);
3371 ReportInstanceForm_Load(sender, e);
3372 }
3373
3374 private void btnPrint_Click(object sender, EventArgs e)
3375 {
3376 PrintDocument pd = new PrintDocument();
3377 pd.PrintPage += new PrintPageEventHandler(xDoc);
3378 PrintDialog pdi = new PrintDialog();
3379 pdi.Document = pd;
3380 if (pdi.ShowDialog() == DialogResult.OK)
3381 {
3382 pd.Print();
3383 }
3384 }
3385 private void xDoc(object sender, PrintPageEventArgs e)
3386 {
3387 e.Graphics.DrawString(txtReportView.Text, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, 20, 20);
3388 }
3389 }
3390}
3391
3392using System;
3393using System.Collections.Generic;
3394using System.ComponentModel;
3395using System.Data;
3396using System.Drawing;
3397using System.Linq;
3398using System.Text;
3399using System.Threading.Tasks;
3400using System.Windows.Forms;
3401using IMS;
3402using IMS.Instance;
3403
3404namespace IMS_GUI
3405{
3406 public partial class GarageInstanceForm : Form
3407 {
3408 GarageInstance gInstance = new GarageInstance(Program.staffAccount, ManagerShared.vm, ManagerShared.am, ManagerShared.bm);
3409 LotInstance lInstance = LotInstance.Instance;
3410
3411 public GarageInstanceForm()
3412 {
3413 InitializeComponent();
3414 }
3415
3416 private void GarageInstanceForm_Load(object sender, EventArgs e)
3417 {
3418 lbUnassignedVehicle.Items.Clear();
3419 lbSoldVehicleRemove.Items.Clear();
3420 cbOpenBay.Items.Clear();
3421
3422 // Load the unassigned vehicles
3423 List<string> vList = lInstance.UnallocatedVehicles;
3424 foreach (string vId in vList)
3425 {
3426 lbUnassignedVehicle.Items.Add(vId);
3427 }
3428
3429 // Load the sold vehicles
3430 List<string> sList = lInstance.SoldVehicles;
3431 foreach (string sId in sList)
3432 {
3433 lbSoldVehicleRemove.Items.Add(sId);
3434 }
3435
3436 // Load the available bays
3437 List<string> bList = lInstance.OpenBays;
3438 foreach (string bId in bList)
3439 {
3440 cbOpenBay.Items.Add(bId);
3441 }
3442 }
3443
3444 private void btnSoldVehicleRemove_Click(object sender, EventArgs e)
3445 {
3446 string msg = gInstance.RemoveVehicle(lbSoldVehicleRemove.SelectedItem as string);
3447 MessageBox.Show(msg, "Remove Vehicle", MessageBoxButtons.OK);
3448 GarageInstanceForm_Load(sender, e);
3449 }
3450
3451 private void btnAssignVehicleToBay_Click(object sender, EventArgs e)
3452 {
3453 string msg = gInstance.AssignVehicleToBay(lbUnassignedVehicle.SelectedItem as string, cbOpenBay.SelectedItem as string);
3454 MessageBox.Show(msg, "Assign Vehicle", MessageBoxButtons.OK);
3455 GarageInstanceForm_Load(sender, e);
3456 }
3457
3458 private void btnAddVehicle_Click(object sender, EventArgs e)
3459 {
3460 CreateVehicleForm vInstanceForm = new CreateVehicleForm();
3461 vInstanceForm.ShowDialog();
3462 }
3463
3464 private void btnAddAddon_Click(object sender, EventArgs e)
3465 {
3466 CreateAddonForm aInstanceForm = new CreateAddonForm();
3467 aInstanceForm.ShowDialog();
3468 }
3469
3470 private void btnAddConfirm_Click(object sender, EventArgs e)
3471 {
3472 string msg = "Enter in a items details, then click Add.";
3473
3474 if (WinFormShared.addon != null && WinFormShared.vehicle != null)
3475 {
3476 MessageBox.Show("Can only add a single item", "Adding Items", MessageBoxButtons.OK);
3477 }
3478 else
3479 {
3480 if (WinFormShared.addon != null)
3481 {
3482 msg = gInstance.Add(WinFormShared.addon);
3483 tbAddDetail.Text = gInstance.ViewAddAddon;
3484 }
3485 else if(WinFormShared.vehicle != null)
3486 {
3487 msg = gInstance.Add(WinFormShared.vehicle);
3488 tbAddDetail.Text = gInstance.ViewAddVehicle;
3489 }
3490
3491 MessageBox.Show(msg, "Adding Item", MessageBoxButtons.OK);
3492 }
3493 }
3494
3495 private void btnAddClear_Click(object sender, EventArgs e)
3496 {
3497 tbAddDetail.Text = "";
3498 WinFormShared.vehicle = null;
3499 WinFormShared.addon = null;
3500 }
3501
3502 private void btnClose_Click(object sender, EventArgs e)
3503 {
3504 this.Close();
3505 }
3506 }
3507}
3508
3509using System;
3510using System.Collections.Generic;
3511using System.ComponentModel;
3512using System.Data;
3513using System.Drawing;
3514using System.Linq;
3515using System.Text;
3516using System.Threading.Tasks;
3517using System.Windows.Forms;
3518using IMS;
3519
3520namespace IMS_GUI
3521{
3522 public partial class CreateAddonForm : Form
3523 {
3524 public CreateAddonForm()
3525 {
3526 InitializeComponent();
3527 }
3528
3529 private void btnAddAddon_Click(object sender, EventArgs e)
3530 {
3531 WinFormShared.addon = new Addon(txtId.Text, txtName.Text, txtDesc.Text, Convert.ToDouble(nudPrice.Text));
3532 this.Close();
3533 }
3534 }
3535}
3536
3537using System;
3538using System.Collections.Generic;
3539using System.ComponentModel;
3540using System.Data;
3541using System.Drawing;
3542using System.Linq;
3543using System.Text;
3544using System.Threading.Tasks;
3545using System.Windows.Forms;
3546using IMS.User;
3547
3548namespace IMS_GUI
3549{
3550 public partial class CreateCustomerForm : Form
3551 {
3552 public CreateCustomerForm()
3553 {
3554 InitializeComponent();
3555 }
3556
3557 private void btnAddCustomer_Click(object sender, EventArgs e)
3558 {
3559 AccountingInstanceForm.newCustomer = new Customer(txtId.Text, txtName.Text, txtAddress.Text, txtPhone.Text);
3560 this.Hide();
3561 }
3562 }
3563}
3564
3565using System;
3566using System.Collections.Generic;
3567using System.ComponentModel;
3568using System.Data;
3569using System.Drawing;
3570using System.Linq;
3571using System.Text;
3572using System.Threading.Tasks;
3573using System.Windows.Forms;
3574using IMS;
3575
3576namespace IMS_GUI
3577{
3578 public partial class CreateReportForm : Form
3579 {
3580 public CreateReportForm()
3581 {
3582 InitializeComponent();
3583 cbReportType.DataSource = Enum.GetValues(typeof(ReportType));
3584 }
3585
3586 private void btnCreate_Click(object sender, EventArgs e)
3587 {
3588 ReportInstanceForm.txtName = txtName.Text;
3589 ReportInstanceForm.txtStartPeriod = txtPeriodStart.Text;
3590 ReportInstanceForm.txtEndPeriod = txtPeriodEnd.Text;
3591 ReportInstanceForm.txtReportType = cbReportType.SelectedItem.ToString();
3592 this.Close();
3593 }
3594
3595 private void CreateReportForm_Load(object sender, EventArgs e)
3596 {
3597 ReportInstanceForm.txtName = "";
3598 ReportInstanceForm.txtStartPeriod = "";
3599 ReportInstanceForm.txtEndPeriod = "";
3600 ReportInstanceForm.txtReportType = "";
3601 }
3602 }
3603}
3604
3605using System;
3606using System.Collections.Generic;
3607using System.ComponentModel;
3608using System.Data;
3609using System.Drawing;
3610using System.Linq;
3611using System.Text;
3612using System.Threading.Tasks;
3613using System.Windows.Forms;
3614using IMS;
3615using System.Text.RegularExpressions;
3616
3617namespace IMS_GUI
3618{
3619 public partial class CreateVehicleForm : Form
3620 {
3621 public CreateVehicleForm()
3622 {
3623 InitializeComponent();
3624 }
3625
3626 private void CreateVehicleForm_Load(object sender, EventArgs e)
3627 {
3628 cbBrand.DataSource = Enum.GetValues(typeof(Brand));
3629 cbYear.DataSource = Enumerable.Range(1990, DateTime.Now.Year - 1990 + 1).ToList();
3630 }
3631
3632 private void btnAddVehicle_Click(object sender, EventArgs e)
3633 {
3634 WinFormShared.vehicle = new Vehicle(txtId.Text, (Brand)cbBrand.SelectedItem, txtModel.Text, new DateTime(Convert.ToInt32(cbYear.SelectedItem), 01, 01), Convert.ToDouble(nudPrice.Text));
3635 this.Close();
3636 }
3637
3638 private void panel1_Paint(object sender, PaintEventArgs e)
3639 {
3640
3641 }
3642
3643 private void label1_Click(object sender, EventArgs e)
3644 {
3645
3646 }
3647
3648 private void txtId_TextChanged(object sender, EventArgs e)
3649 {
3650
3651 }
3652
3653 private void label3_Click(object sender, EventArgs e)
3654 {
3655
3656 }
3657
3658 private void cbBrand_SelectedIndexChanged(object sender, EventArgs e)
3659 {
3660
3661 }
3662
3663 private void label2_Click(object sender, EventArgs e)
3664 {
3665
3666 }
3667
3668 private void txtModel_TextChanged(object sender, EventArgs e)
3669 {
3670
3671 }
3672
3673 private void label4_Click(object sender, EventArgs e)
3674 {
3675
3676 }
3677
3678 private void cbYear_SelectedIndexChanged(object sender, EventArgs e)
3679 {
3680
3681 }
3682
3683 private void label5_Click(object sender, EventArgs e)
3684 {
3685
3686 }
3687
3688 private void lblSaleInstanceHeading_Click(object sender, EventArgs e)
3689 {
3690
3691 }
3692
3693 private void txtPrice_TextChanged(object sender, EventArgs e)
3694 {
3695
3696 }
3697 }
3698}