From 280abd5ac0172a988ac06672b3607b940fd132c3 Mon Sep 17 00:00:00 2001 From: meni3a Date: Thu, 26 Dec 2019 13:06:20 +0200 Subject: [PATCH 01/35] Meni commit --- BL/BL.csproj | 1 + BL/IBL.cs | 28 ++++++++++ BL/MyBl.cs | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 BL/IBL.cs diff --git a/BL/BL.csproj b/BL/BL.csproj index 4600d4a..056bf5c 100644 --- a/BL/BL.csproj +++ b/BL/BL.csproj @@ -41,6 +41,7 @@ + diff --git a/BL/IBL.cs b/BL/IBL.cs new file mode 100644 index 0000000..3388aa0 --- /dev/null +++ b/BL/IBL.cs @@ -0,0 +1,28 @@ +using BE; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BL +{ + interface IBL + { + bool IsDateCorrect(DateTime start, DateTime end); + bool IsAccountCharged(Host host); + bool IsDateAvailable(DateTime start, DateTime end); + void CloseOrder(Order order); + void SendMail(Order order); + + List UintsAvailable(DateTime start, int numOfDays); + int NumOfDays(DateTime date); + int NumOfDays(DateTime firstDate, DateTime SecondDate); + List OrdersUntilDate(int days); + int OrdersPerClient(GuestRequest req); + int OrdersPerUnit(HostingUnit unit); + + + + } +} diff --git a/BL/MyBl.cs b/BL/MyBl.cs index b9a8bfb..0b54cce 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -7,8 +7,11 @@ using DAL; namespace BL { - public class MyBl + public class MyBl : IBL { + /// + /// create a new order + /// public bool AddOrder(Order neworder) { IDal instance = FactorySingletonDal.Instance; @@ -24,5 +27,147 @@ public bool AddOrder(Order neworder) } return true; } + + /// + /// Close the order and handle the Implications + /// + public void CloseOrder(Order order) + { + if (order.Status == Status.CloseByClient) + { + //TODO: + //close status for changes + + //TODO bring the orginals and remove x and y + HostingUnit x = new HostingUnit(); + GuestRequest y = new GuestRequest(); + int month = y.EntryDate.Month; + for (int day = y.EntryDate.Day; day < y.ReleaseDate.Day||y.ReleaseDate.Month!=month; day++) + { + x.Diary[y.EntryDate.Month, day] = true; + + if (day == 31) + { + day = 0; + month++; + } + + } + + //TODO add Commision + //To Where?? + + //Change client STATUS + //duffrante between close by app to close by client?? + y.Status = Status.CloseByApp; + + + } + } + + /// + /// Is date available + /// + public bool IsDateAvailable(DateTime start, DateTime end) + { + HostingUnit x = new HostingUnit(); + GuestRequest y = new GuestRequest(); + int month = y.EntryDate.Month; + for (int day = y.EntryDate.Day; day < y.ReleaseDate.Day || y.ReleaseDate.Month != month; day++) + { + if(x.Diary[y.EntryDate.Month, day] = true) + { + return false; + } + + if (day == 31) + { + day = 0; + month++; + } + + } + + return true; + + } + + /// + /// Check if end day later than the start date + /// + public bool IsDateCorrect(DateTime start, DateTime end) + { + if (end > start) + { + return true; + } + else + { + return false; + } + } + + /// + /// Return number of days from date until now + /// + public int NumOfDays(DateTime date) + { + return (int)(DateTime.Now - date).TotalDays; + } + + /// + /// Return number of days between 2 Date Times OBJ + /// + public int NumOfDays(DateTime firstDate, DateTime SecondDate) + { + return (int)(SecondDate - firstDate).TotalDays; + } + + /// + /// Sending Email to client + /// + public void SendMail(Order order) + { + if (order.Status == Status.MailSent) + { + Console.WriteLine( + $"You order:\n" + + $"Create Date: {order.CreateDate}\n" + + $"Order Date: {order.OrderDate}\n" + + $"Hosting Unit Key: {order.HostingUnitKey}\n" + ); + } + } + + + #region ///// NOT IMPLAMENT ///// + public bool IsAccountCharged(Host host) + { + //HOW TO CHECK IF ACCOUNT CHARGED?? + throw new NotImplementedException(); + } + + public int OrdersPerClient(GuestRequest req) + { + //COLACTION?? + throw new NotImplementedException(); + } + + public int OrdersPerUnit(HostingUnit unit) + { + //COLACTION?? + throw new NotImplementedException(); + } + + public List OrdersUntilDate(int days) + { + throw new NotImplementedException(); + } + + public List UintsAvailable(DateTime start, int numOfDays) + { + throw new NotImplementedException(); + } + #endregion } } From a1a867d388e70c9d8912747104bb8e24fb242c71 Mon Sep 17 00:00:00 2001 From: meni3a Date: Mon, 30 Dec 2019 22:45:36 +0200 Subject: [PATCH 02/35] commit 2 --- BE/Enum.cs | 10 ++++++++-- BE/GuestRequest.cs | 2 +- BE/Order.cs | 2 +- BL/MyBl.cs | 10 +++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/BE/Enum.cs b/BE/Enum.cs index b2a61ab..dc0a976 100644 --- a/BE/Enum.cs +++ b/BE/Enum.cs @@ -6,11 +6,17 @@ namespace BE { - public enum Status + public enum ClientStatus { - NotYetApproved, MailSent, CloseByClient, CloseByApp + Open, CloseByApp, CloseByTimeOut } + public enum OrderStatus + { + UntreatedYet, MailSent, CloseByClientTimeOut, CloseByClient + } + + public enum Area { Jerusalem, North, South, Center diff --git a/BE/GuestRequest.cs b/BE/GuestRequest.cs index c57ce1e..bc19dca 100644 --- a/BE/GuestRequest.cs +++ b/BE/GuestRequest.cs @@ -13,7 +13,7 @@ public class GuestRequest public String PrivateName { get; set; } public String FamilyName { get; set; } public String MailAddress { get; set; } - public Status Status { get; set; } + public ClientStatus Status { get; set; } public DateTime RegistrationDate { get; set; } public DateTime EntryDate { get; set; } public DateTime ReleaseDate { get; set; } diff --git a/BE/Order.cs b/BE/Order.cs index 496b16e..920642b 100644 --- a/BE/Order.cs +++ b/BE/Order.cs @@ -15,7 +15,7 @@ public class Order public String GuestRequestKey { get; set; } public DateTime CreateDate { get; set; } public DateTime OrderDate { get; set; } - public Status Status { get; set; } + public OrderStatus Status { get; set; } public override string ToString() { diff --git a/BL/MyBl.cs b/BL/MyBl.cs index 0b54cce..5c6b52a 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -17,7 +17,7 @@ public bool AddOrder(Order neworder) IDal instance = FactorySingletonDal.Instance; Order order = instance.getOrder(neworder.OrderKey); - if (order.Status == Status.CloseByApp || order.Status == Status.CloseByClient) + if (order.Status == OrderStatus.CloseByClient || order.Status == OrderStatus.CloseByClientTimeOut) { return false; } @@ -33,7 +33,7 @@ public bool AddOrder(Order neworder) /// public void CloseOrder(Order order) { - if (order.Status == Status.CloseByClient) + if (order.Status == OrderStatus.CloseByClient) { //TODO: //close status for changes @@ -59,7 +59,7 @@ public void CloseOrder(Order order) //Change client STATUS //duffrante between close by app to close by client?? - y.Status = Status.CloseByApp; + y.Status = ClientStatus.CloseByApp; } @@ -128,7 +128,7 @@ public int NumOfDays(DateTime firstDate, DateTime SecondDate) /// public void SendMail(Order order) { - if (order.Status == Status.MailSent) + if (order.Status == OrderStatus.MailSent) { Console.WriteLine( $"You order:\n" + @@ -141,7 +141,7 @@ public void SendMail(Order order) #region ///// NOT IMPLAMENT ///// - public bool IsAccountCharged(Host host) + public bool IsAccountCharged(Host host)j { //HOW TO CHECK IF ACCOUNT CHARGED?? throw new NotImplementedException(); From 591da8516f38ad03e320d98db53745dcd2abb3bc Mon Sep 17 00:00:00 2001 From: meni3a Date: Sun, 2 Feb 2020 17:01:08 +0200 Subject: [PATCH 03/35] 2.2 meni --- BE/ATM.cs | 190 +++++++++++++ BE/BE.csproj | 2 + BE/BankDetails.cs | 21 ++ BL/MyBl.cs | 293 +++++++++++++++++++ DAL/DALImp.cs | 281 +++++++++++++++++++ DAL/DalXML.cs | 498 +++++++++++++++++++++++++++++++++ DAL/IDAL.cs | 7 + DataSource/DataSourceList.cs | 24 ++ PLWPF/MainWindow.xaml.cs | 81 ++++++ PLWPF/Windows/Register.xaml | 52 ++++ PLWPF/Windows/Register.xaml.cs | 105 +++++++ 11 files changed, 1554 insertions(+) create mode 100644 BE/ATM.cs create mode 100644 BE/BankDetails.cs create mode 100644 DAL/DALImp.cs create mode 100644 DAL/DalXML.cs create mode 100644 PLWPF/MainWindow.xaml.cs create mode 100644 PLWPF/Windows/Register.xaml create mode 100644 PLWPF/Windows/Register.xaml.cs diff --git a/BE/ATM.cs b/BE/ATM.cs new file mode 100644 index 0000000..59a98fb --- /dev/null +++ b/BE/ATM.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BE +{ + + // NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0. + /// + [System.SerializableAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] + [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] + public partial class ATM + { + + private string קוד_בנקField; + + private string שם_בנקField; + + private string קוד_סניףField; + + private string כתובת_הATMField; + + private string ישובField; + + private string עמלהField; + + private string סוג_ATMField; + + private string מיקום_הATM_ביחס_לסניףField; + + private string גישה_לנכיםField; + + private string קואורדינטת_XField; + + private string קואורדינטת_YField; + + /// + public string קוד_בנק + { + get + { + return this.קוד_בנקField; + } + set + { + this.קוד_בנקField = value; + } + } + + /// + public string שם_בנק + { + get + { + return this.שם_בנקField; + } + set + { + this.שם_בנקField = value; + } + } + + /// + public string קוד_סניף + { + get + { + return this.קוד_סניףField; + } + set + { + this.קוד_סניףField = value; + } + } + + /// + [System.Xml.Serialization.XmlElementAttribute("כתובת_ה-ATM")] + public string כתובת_הATM + { + get + { + return this.כתובת_הATMField; + } + set + { + this.כתובת_הATMField = value; + } + } + + /// + public string ישוב + { + get + { + return this.ישובField; + } + set + { + this.ישובField = value; + } + } + + /// + public string עמלה + { + get + { + return this.עמלהField; + } + set + { + this.עמלהField = value; + } + } + + /// + public string סוג_ATM + { + get + { + return this.סוג_ATMField; + } + set + { + this.סוג_ATMField = value; + } + } + + /// + [System.Xml.Serialization.XmlElementAttribute("מיקום_ה-ATM_ביחס_לסניף")] + public string מיקום_הATM_ביחס_לסניף + { + get + { + return this.מיקום_הATM_ביחס_לסניףField; + } + set + { + this.מיקום_הATM_ביחס_לסניףField = value; + } + } + + /// + public string גישה_לנכים + { + get + { + return this.גישה_לנכיםField; + } + set + { + this.גישה_לנכיםField = value; + } + } + + /// + public string קואורדינטת_X + { + get + { + return this.קואורדינטת_XField; + } + set + { + this.קואורדינטת_XField = value; + } + } + + /// + public string קואורדינטת_Y + { + get + { + return this.קואורדינטת_YField; + } + set + { + this.קואורדינטת_YField = value; + } + } + } + + +} + + diff --git a/BE/BE.csproj b/BE/BE.csproj index 60a1331..298b1b8 100644 --- a/BE/BE.csproj +++ b/BE/BE.csproj @@ -41,7 +41,9 @@ + + diff --git a/BE/BankDetails.cs b/BE/BankDetails.cs new file mode 100644 index 0000000..387eaba --- /dev/null +++ b/BE/BankDetails.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BE +{ + public class BankDetails + { + public int BankNumber { get; set; } + public String BankName { get; set; } + public List Branches; + } + + public class BankBranch + { + public int BranchNumber { get; set; } + public String BranchCity { get; set; } + } +} diff --git a/BL/MyBl.cs b/BL/MyBl.cs index 5c6b52a..fbc08d5 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -4,7 +4,17 @@ using System.Text; using System.Threading.Tasks; using BE; +<<<<<<< Updated upstream using DAL; +======= +using System.Reflection; +using DAL; +using System.Net.Mail; +using System.Net; +using System.Windows; +using System.Threading.Tasks; + +>>>>>>> Stashed changes namespace BL { public class MyBl : IBL @@ -169,5 +179,288 @@ public List UintsAvailable(DateTime start, int numOfDays) throw new NotImplementedException(); } #endregion +<<<<<<< Updated upstream } } +======= + + + public Dictionary GuestRequestPerArea() + { + return new Dictionary + { + { Area.Center , GuestRequestBy().Count(p => p.Area == Area.Center) }, + { Area.Jerusalem , GuestRequestBy().Count(p => p.Area == Area.Jerusalem) }, + { Area.North , GuestRequestBy().Count(p => p.Area == Area.North) } , + { Area.South , GuestRequestBy().Count(p => p.Area == Area.South) } + }; + } + public Dictionary GuestRequestPerRquirement(Requirements requirements) + { + return new Dictionary + { + { "Pool" , GuestRequestBy().Count(p => p.Pool == requirements) }, + { "Jacuzzi" , GuestRequestBy().Count(p => p.Jacuzzi == requirements) }, + { "Garden" , GuestRequestBy().Count(p => p.Garden == requirements) }, + { "ChildrensAttractions" , GuestRequestBy().Count(p => p.ChildrensAttractions == requirements) }, + { "SpredBads" , GuestRequestBy().Count(p => p.SpredBads == requirements) }, + { "AirCondsner" , GuestRequestBy().Count(p => p.AirCondsner == requirements) }, + { "frisider" , GuestRequestBy().Count(p => p.frisider == requirements) }, + { "SingogNaerBy" , GuestRequestBy().Count(p => p.SingogNaerBy == requirements) }, + { "NaerPublicTrensportion" , GuestRequestBy().Count(p => p.NaerPublicTrensportion==requirements) } + }; + } + + + /// + /// Get Orders by predicate + /// + /// + /// + public IEnumerable GetOrders(Func predicate = null) + { + if (predicate == null) + return myDAL.ReturenAllOrders().AsEnumerable(); + return myDAL.ReturenAllOrders().Where(predicate); + } + + /// + /// Get Banks by predicate + /// + /// + /// + public IEnumerable GetBanks(Func predicate = null) + { + if (predicate == null) + return myDAL.ReturnAllLocelBank().AsEnumerable(); + return myDAL.ReturnAllLocelBank().Where(predicate); + } + + + /// + /// return list of all the husting uint key for spasific host + /// + /// + /// + public IEnumerable GetHostingUnitsKeysList(int hostKey) + { + List result = new List(); + + foreach (var hostingUnit in myDAL.ReturnHostingUnitList(x => x.Owner.HostKey == hostKey)) + { result.Add(hostingUnit.HostingUnitKey); } + return result; + } + + /// + /// Return host list + /// + /// + public IEnumerable GetHosts() + { + //return myDAL.returnHostList(); + return myDAL.getAllHosts(); + } + + //need to replace the one in idal with this + public void UpdateOrder(Order order) + { + try + { + myDAL.updateOrder(order); + } + catch (Exception ex) + { + throw new Exception("Can't update order" + ex); + } + } + + + /* + public IEnumerable GetGuestRequestKeysList(IEnumerable list,PropertyInfo propertyInfo) + { + List result = new List(); + + foreach (var i in list) + { result.Add(i.GuestRequestKey); } + { result.Add(i.g; } + return result; + } + */ + + + + /// + /// Gruping Order Hosts By Number Of Hosting Unit + /// + /// + public IEnumerable> Hosts_OrderBy_NumberOfHostingUnit() + { + IEnumerable> result = + from hosts in myDAL.returnHostList() + group hosts by NumOfHostingUnitsInHost(hosts); + return result; + } + + + + /// + /// Number of Hosting Unit per area + /// + /// Dictionary + public Dictionary HostingUnitPerArea() + { + return new Dictionary + { + { Area.Center , HustingUnitsBy().Count(p => p.Area == Area.Center) }, + { Area.Jerusalem , HustingUnitsBy().Count(p => p.Area == Area.Jerusalem) }, + { Area.North , HustingUnitsBy().Count(p => p.Area == Area.North) } , + { Area.South , HustingUnitsBy().Count(p => p.Area == Area.South) } + }; + } + + + /// + /// Average Orders per hosting unit + /// + /// + public double averageOrdersPerHostingUnit() + { + double sum = 0; + foreach (var hostingUnit in HustingUnitsBy()) + { + sum += OrdersPerUnit(hostingUnit); + } + return sum; + } + + + ///// + ///// BootingUp the progrem. + ///// 1) Receive bank data from the web + ///// 2) + ///// + //public void bootingUp() + //{ + // try { + // GetBankInfoFromTheWeb(); + // } catch (Exception ex) { + // // throw new Exception("Can't get bank info from the web " + ex); + // MessageBox.Show("Can't get bank info from the web\n " + ex); + // } + + //} + + + + + /// + /// Sending Email to client + /// + public void SendMail(Order order) + { + MailMessage mail = new MailMessage(); + mail.To.Add(GuestRequestBy(x => x.GuestRequestKey == order.GuestRequestKey).First().MailAddress); + mail.From = new MailAddress(GetHostingUnit(order.HostingUnitKey).Owner.MailAddress); + mail.Subject = "Resort offeras as you request"; + mail.Body = "

You'r request:

" + + GuestRequestBy(x => x.GuestRequestKey == order.GuestRequestKey).First().ToString() + + "

------------------

" + + "

Our offer is:

" + + GetHostingUnit(order.HostingUnitKey).ToString() + + "

Please notify us with return mail to this address:

" + + GetHostingUnit(order.HostingUnitKey).Owner.MailAddress; + mail.IsBodyHtml = true; + + SmtpClient smtp = new SmtpClient(); + smtp.Host = "smtp.gmail.com"; + smtp.Credentials = new System.Net.NetworkCredential("ipewzner@g.jct.ac.il", "Reptor17"); + smtp.EnableSsl = true; + + try + { + smtp.Send(mail); + } + catch (Exception ex) + { + throw new Exception("Email error " + ex); + } + + + } + + /// + /// Send email with new password + /// + /// + public void SendMailWithNewPassword(Host host) + { + // Manager manager = new Manager(); + // manager.MailAddress = "dotnetproject2020@gmail.com"; + var rand = new Random(); + int password = rand.Next(10000000, 99999999); + host.PasswordKey = KeyForPassword(password); + + MailMessage mail = new MailMessage(); + mail.To.Add(host.MailAddress); + // mail.From = new MailAddress("ipewzner@g.jct.ac.il"); + mail.From = new MailAddress(" dotnetproject2020 @gmail.com"); + + mail.Subject = "New password - do not replay!"; + mail.Body = "You'r new password is: " + password + + "

Please change your password after the next login

" + + "

You can change your password in the Host updata section

"; + mail.IsBodyHtml = true; + + SmtpClient smtp = new SmtpClient(); + smtp.Host = "smtp.gmail.com"; + smtp.Credentials = new System.Net.NetworkCredential("dotnetproject2020@gmail.com", "kuku4ever"); + smtp.EnableSsl = true; + + try + { + smtp.Send(mail); + } + catch (Exception ex) + { + throw new Exception("Email error " + ex); + } + + } + + /// + /// Checke if password is curect + /// + /// + /// + /// + public bool CheckePassword(double key, int password) + { + // return Math.Sin(password) * Math.Sqrt(password) == key; + return true; + } + + /// + /// Make key for password + /// + /// + /// + public double KeyForPassword(int password) + { + return Math.Sin(password) * Math.Sqrt(password); + } + + + + public double averageOrdersPerClient() + { + double sum = 0; + foreach (var guestRequest in GuestRequestBy()) + { + sum += OrdersPerClient(guestRequest); + } + return sum; + } + } +} + +>>>>>>> Stashed changes diff --git a/DAL/DALImp.cs b/DAL/DALImp.cs new file mode 100644 index 0000000..4a63085 --- /dev/null +++ b/DAL/DALImp.cs @@ -0,0 +1,281 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using BE; +using DataSource; + + +namespace DAL +{ + public class DALImp + { + + #region ///// Order ///// + + /// + /// Add Order To List + /// + /// + /// + public bool AddOrderToList(Order order) + { + try + { + DataSourceList.Orders.Add(Cloning.Copy(order)); + return true; + } + catch (Exception ex) + { + throw new Exception("Fail to add Order to the list " + ex); + } + } + + /// + /// Update Order + /// + /// + /// + public void UpdateOrder(int OrderKey, OrderStatus status) + { + try + { + //var temp = from order in DataSourceList.Orders + // where order.OrderKey == OrderKey + // select order.Status = status; + + int index = DataSourceList.Orders.FindIndex(x => x.OrderKey == OrderKey); + if (index != -1) + { + DataSourceList.Orders[index].Status = status; + } + } + catch (Exception ex) + { + throw new KeyNotFoundException("OrderKey not feund" + ex); + } + } + + /// + /// Returen Orders from list using predicate for filtering + /// + /// + /// + public IEnumerable ReturenAllOrders(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(DataSourceList.Orders.AsEnumerable()); + return Cloning.Clone(DataSourceList.Orders.Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Orders from the list " + ex); + } + } + + #endregion + + #region ///// HosingUnit ///// + + /// + /// Add Hosting Unit To List + /// + /// + /// + public bool AddHostingUnitToList(HostingUnit hostingUnit) + { + try + { + foreach (var currentHostingUnit in DataSourceList.HostingUnits) + { + if (currentHostingUnit.Equals(hostingUnit)) return false; + } + DataSourceList.HostingUnits.Add(Cloning.Copy(hostingUnit)); + return true; + } + catch (Exception ex) + { + throw new Exception("Fail to add the Hosting-Unit to the list " + ex); + } + } + + /// + /// Delete Hosting Unit from list + /// + /// + /// + public bool DeleteHostingUnit(HostingUnit hu) + { + try + { + return DataSourceList.HostingUnits.Remove(hu); + } + catch (Exception ex) + { + throw new Exception("Fail to delete the Hosting-Unit " + ex); + } + } + + /// + /// Update Hosting Unit + /// + /// + /// + public bool UpdateHostingUnit(HostingUnit hostingUnit) + { + //Remove old + try + { + try + { + DataSourceList.HostingUnits.Remove(DataSourceList.HostingUnits.Find(x => x.HostingUnitKey == hostingUnit.HostingUnitKey)); + } + catch (Exception ex) + { + throw new Exception("can't remove the old Hosting-Unit " + ex); + } + + //insert new + try + { + DataSourceList.HostingUnits.Add(Cloning.Copy(hostingUnit)); + return true; + } + catch (Exception ex) + { + throw new Exception("can't add the new Hosting-Unit " + ex); + } + } + catch (Exception ex) + { + throw new Exception("Fail to update Hosting-Unit becuse it " + ex); + } + } + + /// + /// Returen Hosting Unit from list using predicate for filtering + /// + /// + /// + public IEnumerable ReturnHostingUnitList(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(DataSourceList.HostingUnits.AsEnumerable()); + return Cloning.Clone(DataSourceList.HostingUnits.Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Hosting-Units from the list " + ex); + } + } + + #endregion + + #region ///// Host ///// + + /// + /// Add Host To List + /// + /// + public void AddHostToList(Host host) + { + try + { + DataSourceList.Hosts.Add(Cloning.Copy(host)); + } + catch (Exception ex) + { + throw new Exception("Fail to add the Host to the list " + ex); + } + } + + /// + /// Returen Hosts from list using predicate for filtering + /// + /// + /// + public IEnumerable returnHostList(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(DataSourceList.Hosts.AsEnumerable()); + return Cloning.Clone(DataSourceList.Hosts.Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Hosts from the list " + ex); + } + } + #endregion Host + + #region ///// GuestRequest ///// + + /// + /// Returen Guest Request from list using predicate for filtering + /// + /// + /// + public IEnumerable ReturnGuestRequestList(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(DataSourceList.GuestRequests.AsEnumerable()); + return Cloning.Clone(DataSourceList.GuestRequests.Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Guest-Request from the list " + ex); + } + } + + /// + ///Add Guest Request To List + /// + /// + public void AddGuestRequestToList(GuestRequest gr) + { + try + { + DataSourceList.GuestRequests.Add(Cloning.Copy(gr)); + } + catch (Exception ex) + { + throw new Exception("Fail to add the Guest Request to the list " + ex); + } + } + #endregion GuestRequest + + #region ///// Bank ///// + + /// + /// Return All Locel Bank + /// + /// + public IEnumerable ReturnAllLocelBank() + { + try + { + return new List { "poelim", "marcntil", "laomi", "disceunt", "pagi" }; + } + catch (Exception ex) + { + throw new Exception("Fail to return the Locel-Bank list " + ex); + } + } + + #endregion + + + + + + } +} + + diff --git a/DAL/DalXML.cs b/DAL/DalXML.cs new file mode 100644 index 0000000..1cbd464 --- /dev/null +++ b/DAL/DalXML.cs @@ -0,0 +1,498 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using System.Xml.Serialization; +using BE; +using DataSource; +using System.Net; + +namespace DAL +{ + public class DalXML : IDAL + { + private static int serialGuestRequest; + private static int serialOrder; + // private static double commision; //10 shekels -- zol meod public DalXML() + // private static string serialHostingUnit; + + public DalXML() + { + GetAndStoreBankInfo(); + + serialOrder = Int32.Parse(DataSource.DataSourceXML.Orders.Element("lastSerial").Value); + serialGuestRequest = Int32.Parse(DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value); + + + } + + public bool addGuestRequest(GuestRequest gr) + { + XElement guestRequestElement = XElement.Parse(gr.ToXMLstring()); + DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value = guestRequestElement.Element("GuestRequestKey").Value; + DataSource.DataSourceXML.SaveGuestRequests(); + DataSource.DataSourceXML.GuestRequests.Add(guestRequestElement); + DataSource.DataSourceXML.SaveGuestRequests(); + return true; + } + + public bool addHost(Host host) + { + DataSource.DataSourceXML.Hosts.Add(XElement.Parse(host.ToXMLstring())); + DataSource.DataSourceXML.SaveHosts(); + //DataSource.DataSourceXML.Hosts.Element("lastSerial").Value = host.HostKey.ToXMLstring(); + DataSource.DataSourceXML.SaveHosts(); + return true; + } + + public bool addHostingUnit(HostingUnit HostingUnit) + { + DataSource.DataSourceXML.HostingUnits.Add(XElement.Parse(HostingUnit.ToXMLstring())); + DataSource.DataSourceXML.SaveHosts(); + //DataSource.DataSourceXML.HostingUnits.Element("lastSerial").Value = HostingUnit.HostingUnitKey.ToXMLstring(); + DataSource.DataSourceXML.SaveHostingUnits(); + return true; + } + + public bool addOrder(Order neworder) + { + // XElement findOrder = (from o in DataSource.DataSourceXML.Orders.Elements("Order") + // where Int32.Parse(o.Element("OrderKey").Value) == neworder.OrderKey + // select o).FirstOrDefault(); + //if(findOrder!=null) + //{ + // //throw new Exception("order alraedy exist"); + // return false; + //} + serialOrder = Int32.Parse(DataSource.DataSourceXML.Orders.Element("lastSerial").Value); + neworder.OrderKey = ++serialOrder; + DataSource.DataSourceXML.Orders.Add(neworder.ToXML()); + DataSource.DataSourceXML.SaveOrders(); + DataSource.DataSourceXML.Orders.Element("lastSerial").Value = neworder.OrderKey.ToString(); + DataSource.DataSourceXML.SaveOrders(); + return true; + } + + public List getAllGuestRequests() + { + return (from o in DataSource.DataSourceXML.GuestRequests.Elements("GuestRequest") + select o.ToString().ToObject()).ToList(); + } + + public List getAllHostingUnits() + { + return (from o in DataSource.DataSourceXML.HostingUnits.Elements("HostingUnit") + select o.ToString().ToObject()).ToList(); + } + + public List getAllHosts() + { + return (from o in DataSource.DataSourceXML.Hosts.Elements("Host") + select o.ToString().ToObject()).ToList(); + } + + public List getAllorders() + { + return (from o in DataSource.DataSourceXML.Orders.Elements("Order") + select o.ToString().ToObject()).ToList(); + } + + public GuestRequest getGuestRequest(int id) + { + throw new NotImplementedException(); + } + + public Host getHost(int id) + { + throw new NotImplementedException(); + } + + public HostingUnit getHostingUnit(int id) + { + throw new NotImplementedException(); + } + + public Order getOrder(int id) + { + Order result = null; + XElement findOrder = (from o in DataSource.DataSourceXML.Orders.Elements("Order") + where Int32.Parse(o.Element("OrderKey").Value) == id + select o).FirstOrDefault(); + if (findOrder != null) + { + result = findOrder.ToString().ToObject(); + } + + return result; + + } + + public string getserialGuestRequest() + { + String result = DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value; + return result; + } + + public bool updateGuestRequest(GuestRequest guestRequest) + { + throw new NotImplementedException(); + } + + public bool updateHost(Host host) + { + throw new NotImplementedException(); + } + + public bool updateOrder(Order updateorder) + { + XElement findOrder = (from o in DataSource.DataSourceXML.Orders.Elements("Order") + where Int32.Parse(o.Element("OrderKey").Value) == updateorder.OrderKey + select o).FirstOrDefault(); + + if (findOrder == null) + { + return false; + } + + return true; + } + + public void UpdateOrder(int OrderKey, OrderStatus status) + { + throw new NotImplementedException(); + } + + + #region ///// Order ///// + + /// + /// Add Order To List + /// + /// + /// + public bool AddOrderToList(Order order) + { + try + { + DataSourceList.Orders.Add(Cloning.Copy(order)); + return true; + } + catch (Exception ex) + { + throw new Exception("Fail to add Order to the list " + ex); + } + } + + + /// + /// Returen Orders from list using predicate for filtering + /// + /// + /// + public IEnumerable ReturenAllOrders(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(getAllorders().AsEnumerable()); + return Cloning.Clone(getAllorders().Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Orders from the list " + ex); + } + } + + #endregion + + #region ///// HosingUnit ///// + + /// + /// Add Hosting Unit To List + /// + /// + /// + public bool AddHostingUnitToList(HostingUnit hostingUnit) + { + try + { + foreach (var currentHostingUnit in DataSourceList.HostingUnits) + { + if (currentHostingUnit.Equals(hostingUnit)) return false; + } + DataSourceList.HostingUnits.Add(Cloning.Copy(hostingUnit)); + return true; + } + catch (Exception ex) + { + throw new Exception("Fail to add the Hosting-Unit to the list " + ex); + } + } + + /// + /// Delete Hosting Unit from list + /// + /// + /// + public bool DeleteHostingUnit(HostingUnit hu) + { + try + { + return DataSourceList.HostingUnits.Remove(hu); + } + catch (Exception ex) + { + throw new Exception("Fail to delete the Hosting-Unit " + ex); + } + } + + /// + /// Update Hosting Unit + /// + /// + /// + public bool UpdateHostingUnit(HostingUnit hostingUnit) + { + //Remove old + try + { + try + { + DataSourceList.HostingUnits.Remove(DataSourceList.HostingUnits.Find(x => x.HostingUnitKey == hostingUnit.HostingUnitKey)); + } + catch (Exception ex) + { + throw new Exception("can't remove the old Hosting-Unit " + ex); + } + + //insert new + try + { + DataSourceList.HostingUnits.Add(Cloning.Copy(hostingUnit)); + return true; + } + catch (Exception ex) + { + throw new Exception("can't add the new Hosting-Unit " + ex); + } + } + catch (Exception ex) + { + throw new Exception("Fail to update Hosting-Unit becuse it " + ex); + } + } + + /// + /// Returen Hosting Unit from list using predicate for filtering + /// + /// + /// + public IEnumerable ReturnHostingUnitList(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(getAllHostingUnits().AsEnumerable()); + return Cloning.Clone(getAllHostingUnits().Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Hosting-Units from the list " + ex); + } + } + + #endregion + + #region ///// Host ///// + + /// + /// Add Host To List + /// + /// + public void AddHostToList(Host host) + { + try + { + DataSourceList.Hosts.Add(Cloning.Copy(host)); + } + catch (Exception ex) + { + throw new Exception("Fail to add the Host to the list " + ex); + } + } + + /// + /// Returen Hosts from list using predicate for filtering + /// + /// + /// + public IEnumerable returnHostList(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(getAllHosts().AsEnumerable()); + return Cloning.Clone(getAllHosts().Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Hosts from the list " + ex); + } + } + #endregion Host + + #region ///// GuestRequest ///// + + /// + /// Returen Guest Request from list using predicate for filtering + /// + /// + /// + public IEnumerable ReturnGuestRequestList(Func predicate = null) + { + try + { + if (predicate == null) + return Cloning.Clone(getAllGuestRequests().AsEnumerable()); + return Cloning.Clone(getAllGuestRequests().Where(predicate)); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Guest-Request from the list " + ex); + } + } + + /// + ///Add Guest Request To List + /// + /// + public void AddGuestRequestToList(GuestRequest gr) + { + try + { + DataSourceList.GuestRequests.Add(Cloning.Copy(gr)); + } + catch (Exception ex) + { + throw new Exception("Fail to add the Guest Request to the list " + ex); + } + } + #endregion GuestRequest + + #region ///// Bank ///// + + /// + /// Return All Locel Bank + /// + /// + public IEnumerable ReturnAllLocelBank(Func predicate = null) + { + try + { + if (predicate == null) + return DataSourceList.banks.AsEnumerable(); + return DataSourceList.banks.Where(predicate); + } + catch (Exception ex) + { + throw new Exception("Fail to retrieve the Guest-Request from the list " + ex); + } + } + + #endregion + + + /// + /// GetBankInfoFromTheWeb + /// + public void GetAndStoreBankInfo() + { + //C:\Users\ipewz\Documents\GitHub\Mini_project_Windows_system + //const string xmlLocalPath = @"atm.xml"; + const string xmlLocalPath = @"ATM.xml"; + WebClient wc = new WebClient(); + Task.Run(() => + { + try + { + string xmlServerPath = @"http://www.jct.ac.il/~coshri/atm.xml"; + wc.DownloadFile(xmlServerPath, xmlLocalPath); + } + catch (Exception) + { + string xmlServerPath = + @"http://www.boi.org.il/he/BankingSupervision/BanksAndBranchLocations/Lists/BoiBankBranchesDocs/atm.xml"; + wc.DownloadFile(xmlServerPath, xmlLocalPath); + } + finally + { + wc.Dispose(); + } + + try + { + + XmlRootAttribute xRoot = new XmlRootAttribute(); + xRoot.ElementName = "ATMs"; + xRoot.IsNullable = true; + + XmlSerializer serializer = new XmlSerializer(typeof(List), xRoot); + + using (FileStream stream = File.OpenRead("ATM.xml")) + { + List dezerializedList = (List)serializer.Deserialize(stream); + + foreach (var item in dezerializedList) + { + int findBank = DataSourceList.banks.FindIndex((x) => x.BankNumber == Convert.ToInt32(item.קוד_בנק)); + if (findBank == -1) + { + DataSourceList.banks.Add(new BankDetails { + BankName = item.שם_בנק, + BankNumber = Convert.ToInt32(item.קוד_בנק), + Branches = new List() + { + new BankBranch + { + BranchCity = item.ישוב, + BranchNumber = Convert.ToInt32(item.קוד_סניף) + + } + } + + }); + } + else + { + int findBranch = DataSourceList.banks[findBank].Branches.FindIndex((x) => x.BranchNumber == Convert.ToInt32(item.קוד_סניף)); + if (findBranch == -1) + { + DataSourceList.banks[findBank].Branches.Add(new BankBranch + { + BranchNumber = Convert.ToInt32( item.קוד_סניף), + BranchCity = item.ישוב + }); + } + } + } + } + } + catch (Exception ex) + { + throw new Exception("Fail to return the Locel-Bank list " + ex); + } + }); + + + } + + + + } +} + + + diff --git a/DAL/IDAL.cs b/DAL/IDAL.cs index eca67ea..edd6441 100644 --- a/DAL/IDAL.cs +++ b/DAL/IDAL.cs @@ -27,6 +27,13 @@ public interface IDal IEnumerable returnAllLocelBank(); // קבלת רשימת כל סניפי הבנק הקיימים בארץ +<<<<<<< Updated upstream +======= + IEnumerable ReturnHostingUnitList(Func predicate = null); + IEnumerable ReturnGuestRequestList(Func predicate = null); + IEnumerable ReturenAllOrders(Func predicate = null); + IEnumerable ReturnAllLocelBank(Func predicate = null); +>>>>>>> Stashed changes } } \ No newline at end of file diff --git a/DataSource/DataSourceList.cs b/DataSource/DataSourceList.cs index 9841104..2810b0b 100644 --- a/DataSource/DataSourceList.cs +++ b/DataSource/DataSourceList.cs @@ -9,6 +9,30 @@ namespace DataSource { public static class DataSourceList { +<<<<<<< Updated upstream +======= + + //static void con() + //{ + // Stream stream = File.OpenRead(Environment.CurrentDirectory + "\\hosts.xml"); + // XmlSerializer xmlser = new XmlSerializer(typeof(List)); + // var x = xmlser.Deserialize(stream); + // Console.WriteLine(x); + + //} + + //static void des() + //{ + // Stream stream = File.OpenWrite(Environment.CurrentDirectory + "\\hosts.xml"); + // XmlSerializer xmlser = new XmlSerializer(typeof(List)); + // xmlser.Serialize(stream, Hosts); + // stream.Close(); + //} + + + public static List banks = new List(); + +>>>>>>> Stashed changes public static List Hosts = new List(); public static List HostingUnits = new List(); public static List Orders = new List(); diff --git a/PLWPF/MainWindow.xaml.cs b/PLWPF/MainWindow.xaml.cs new file mode 100644 index 0000000..5adbdfd --- /dev/null +++ b/PLWPF/MainWindow.xaml.cs @@ -0,0 +1,81 @@ +using System; +using System.Windows; +using BE; +using BL; +using PLWPF.Windows; + +namespace PLWPF +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + Host host = null; + MyBl myBL = new MyBl(); + + public MainWindow() + { + + InitializeComponent(); + //preCode preCode = new preCode(); + //preCode.initialize(); + } + + private void AddRequest_Click(object sender, RoutedEventArgs e) + { + //Task t = new Task(() => { }); + Window win = new AddRequestWindow(); + win.Show(); + + } + + private void HostingUnit_Click(object sender, RoutedEventArgs e) + { + if (host != null) + { + Window win = new HostingUnitWindow(host); + win.Show(); + } + else MessageBox.Show("Select User Or Sign Up"); + } + + private void Orders_Click(object sender, RoutedEventArgs e) + { + if (host != null) + { + Window win = new OrdersWindow(host); + win.Show(); + } + else MessageBox.Show("Select User Or Sign Up"); + } + + private void Stat_Click(object sender, RoutedEventArgs e) + { + Window win = new StatisticsWindow(); + win.Show(); + } + + + private void Button_Click(object sender, RoutedEventArgs e) + { + try + { + LogInWindow win = new LogInWindow(); + win.ShowDialog(); + if (win.DialogResult == true) + { + host = win.HostfromLogin; + user.Content = host.PrivateName + " " + host.FamilyName; + } + } + catch (Exception) + { + + MessageBox.Show("Select User Or Sign Up"); + + } + + } + } +} diff --git a/PLWPF/Windows/Register.xaml b/PLWPF/Windows/Register.xaml new file mode 100644 index 0000000..01ad633 --- /dev/null +++ b/PLWPF/Windows/Register.xaml @@ -0,0 +1,52 @@ + + +