diff --git a/BE/GuestRequest.cs b/BE/GuestRequest.cs index feecfa7..0be1e36 100644 --- a/BE/GuestRequest.cs +++ b/BE/GuestRequest.cs @@ -13,7 +13,7 @@ public class GuestRequest : requirement requirement requirement = new requirement(); - public int GuestRequestKey { get; private set; } + public int GuestRequestKey { get; set; } public String PrivateName { get; set; } public String FamilyName { get; set; } public String MailAddress { get; set; } @@ -21,23 +21,7 @@ public class GuestRequest : requirement public DateTime RegistrationDate { get; set; } public DateTime EntryDate { get; set; } public DateTime ReleaseDate { get; set; } - /* - public Area Area { get; set; } - public String SubArea { get; set; } - public HostingType HostingType { get; set; } - public int Adults { get; set; } - public int Children { get; set; } - public Requirements Pool { get; set; } - public Requirements Jacuzzi { get; set; } - public Requirements Garden { get; set; } - public Requirements ChildrensAttractions { get; set; } - //******************** - public Requirements SpredBads { get; set; } - public Requirements AirCondsner { get; set; } - public Requirements frisider { get; set; } - public Requirements SingogNaerBy { get; set; } - public Requirements NaerPublicTrensportion { get; set; } - */ + /// /// c-tor /// diff --git a/BE/HostingUnit.cs b/BE/HostingUnit.cs index f3153d5..95cdae2 100644 --- a/BE/HostingUnit.cs +++ b/BE/HostingUnit.cs @@ -12,7 +12,7 @@ namespace BE public class HostingUnit : requirement { requirement requirement = new requirement(); - public int HostingUnitKey { get; private set; } + public int HostingUnitKey { get; set; } public Host Owner { get; set; } public String HostingUnitName { get; set; } diff --git a/BE/Order.cs b/BE/Order.cs index 9ec7705..a862ebc 100644 --- a/BE/Order.cs +++ b/BE/Order.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Serialization; using Utilities; namespace BE @@ -14,8 +15,10 @@ public class Order public int HostingUnitKey { get; set; } public int GuestRequestKey { get; set; } - public DateTime CreateDate { get; set; } + public DateTime OrderDate { get; set; } + + public DateTime CreateDate { get; set; } public OrderStatus Status { get; set; } public override string ToString() diff --git a/BL/IBL.cs b/BL/IBL.cs index 6963983..c6d6f1f 100644 --- a/BL/IBL.cs +++ b/BL/IBL.cs @@ -14,7 +14,7 @@ interface IBL bool IsDateAvailable(DateTime start, DateTime end, int unitKey); void CloseOrder(Order order); void SendMail(Order order); - bool UnitRemove(int unit); + void UnitRemove(int unit); List UintsAvailable(DateTime start, int numOfDays); int NumOfDays(DateTime date); diff --git a/BL/MyBl.cs b/BL/MyBl.cs index ba67b72..c9f0e8f 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -1,646 +1,755 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using BE; -using System.Reflection; - -using DAL; -using System.Net.Mail; -using System.Net; -using System.Windows; - -namespace BL -{ - public class MyBl : IBL - { - DALImp myDAL = new DALImp(); - - #region GuestRequest - - /// - /// Add Guest Request - /// - public bool AddGuestRequest(GuestRequest req) - { - //TODO - //check id and name and move to DAL - myDAL.AddGuestRequestToList(req); - return true; - } - - /// - /// Return Guest Request By any requirment - /// - public IEnumerable GuestRequestBy(Func predicate = null) - { - if (predicate == null) - return myDAL.ReturnGuestRequestList().AsEnumerable(); - return myDAL.ReturnGuestRequestList().Where(predicate); - } - - - /// - /// Number of Guest Request per area - /// - /// Dictionary - 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) } - }; - } - - /// - /// Number of Guest-request per rquirement - /// - /// - /// - 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) } - }; - } - - /// - /// Gruping Order Guest Request By Location - /// - /// - public IEnumerable> GuestRequestOrderBy_Location() - { - IEnumerable> result = - from gr in myDAL.ReturnGuestRequestList() - group gr by gr.Area; - return result; - } - - /// - /// Gruping Order Guest Request By Number Of Vacationers - /// - /// - public IEnumerable> GuestRequest_OrderBy_NumberOfVacationers() - { - IEnumerable> result = - from gr in myDAL.ReturnGuestRequestList() - group gr by (gr.Adults + gr.Children); - return result; - } - - #endregion GuestRequest - - #region Host - - /// - /// Add Host - /// - /// - /// - public bool AddHost(Host host) - { - if (myDAL.returnHostList((x) => (x == host)) != null) - { - myDAL.AddHostToList(host); - return true; - } - else - { - return false; - } - - } - - /// - /// Return host list - /// - /// - public IEnumerable GetHosts() - { - return myDAL.returnHostList(); - } - - /// - /// Return the number Of Hosting Units In Host - /// - /// - /// - public int NumOfHostingUnitsInHost(Host host) - { - int sum = 0; - foreach (var hu in myDAL.ReturnHostingUnitList()) - { - if (hu.Owner.HostKey == host.HostKey) - sum++; - } - return sum; - } - - /// - /// 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; - } - - #endregion Host - - //update - #region HostingUnit - - /// - /// Add Hosting Unit - /// - public void AddHostingUnit(HostingUnit unit) - { - myDAL.AddHostingUnitToList(unit); - } - - /// - /// Check if Unit can be remove - /// - public bool UnitRemove(int unit) - { - int x = 0; - foreach (var item in myDAL.ReturenAllOrders()) - { - if (item.HostingUnitKey == unit) - { - if (item.Status == OrderStatus.UntreatedYet) - { - return false; - } - x = item.HostingUnitKey; - } - } - HostingUnit y = GetHostingUnit(Convert.ToInt32(unit)); - myDAL.DeleteHostingUnit(y); - return true; - } - - /// - /// Return all units available in given date range - /// - public List UintsAvailable(DateTime start, int numOfDays) - { - List listOfUnits = new List(); - - DateTime end = start.AddDays(numOfDays); - var x = myDAL.ReturnHostingUnitList(null); - foreach (var item in x) - { - - if (IsDateAvailable(start, end, item.HostingUnitKey)) - { - listOfUnits.Add(item); - } - - } - - return listOfUnits; - } - - /// - /// 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; - } - - /// - /// Find Hosting Unit by key - /// - /// - /// - public HostingUnit GetHostingUnit(int key) - { - return (myDAL.ReturnHostingUnitList(x => x.HostingUnitKey == key)).First(); - } - - /// - /// Return Husting uinits By any requirment - /// - public IEnumerable HustingUnitsBy(Func predicate = null) - { - return myDAL.ReturnHostingUnitList(predicate); - } - - /// - /// Gruping Order Hosting Unit By Location - /// - /// - public IEnumerable> HostingUnit_OrderBy_Location() - { - IEnumerable> result = - from hu in myDAL.ReturnHostingUnitList() - group hu by hu.Area; - 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) } - }; - } - - #endregion HostingUnit - //new husting unit - #region Order - - /// - /// create a new order - /// - public bool AddOrder(Order neworder) - { - IDAL instance = FactorySingletonDal.Instance; - - //Order order = instance.ReturenAllOrders((x)=> x.OrderKey == neworder.OrderKey).First(); - //if (order.Status == OrderStatus.CloseByClient || order.Status == OrderStatus.CloseByClientTimeOut) - //{ - // return false; - //} - //else - //{ - instance.AddOrderToList(neworder); - //} - return true; - } - - /// - /// Close the order and handle the Implications - /// - public void CloseOrder(Order order) - { - if (order.Status == OrderStatus.CloseByClient) - { - //TODO: - //close status for changes - - HostingUnit hostingUnit = GetHostingUnit(Convert.ToInt32(order.HostingUnitKey)); - GuestRequest guestRequest = GuestRequestBy(x=>x.GuestRequestKey== order.GuestRequestKey).First(); - for (DateTime dateTime = guestRequest.EntryDate; dateTime <= guestRequest.ReleaseDate; dateTime.AddDays(1)) - { - hostingUnit.Diary.Add(dateTime); - } - //TODO add Commision - //To Where?? - - //Change client STATUS - guestRequest.Status = ClientStatus.CloseByApp; - - } - } - - //need to replace the one in idal with this - public void UpdateOrder(Order order) - { - try - { - myDAL.UpdateOrder(order.OrderKey, order.Status); - } - catch (Exception ex) - { - throw new Exception("Can't update order" + ex); - } - } - - /// - /// Get Orders by predicate - /// - /// - /// - public IEnumerable GetOrders(Func predicate = null) - { - if (predicate == null) - return myDAL.ReturenAllOrders().AsEnumerable(); - return myDAL.ReturenAllOrders().Where(predicate); - } - - /// - /// Return number of orders that sent to client - /// - public int OrdersPerClient(GuestRequest req) - { - int counter = 0; - foreach (var item in myDAL.ReturenAllOrders()) - { - if (item.GuestRequestKey == req.GuestRequestKey) - { - if (item.Status == OrderStatus.MailSent) - counter++; - } - } - return counter; - } - - /// - /// Return number of orders that seccessfully close - /// - public int OrdersPerUnit(HostingUnit unit) - { - int counter = 0; - foreach (var item in myDAL.ReturenAllOrders()) - { - if (item.HostingUnitKey == unit.HostingUnitKey) - { - if (item.Status == OrderStatus.CloseByClient) - counter++; - } - } - return counter; - } - - /// - /// Return all Orders that created X dayes before - /// - public List OrdersUntilDate(int days) - { - return myDAL.ReturenAllOrders(x => NumOfDays(x.CreateDate) == days).ToList(); ; - } - - /// - /// Average Orders per client - /// - /// - public double averageOrdersPerClient() - { - double sum = 0; - foreach (var guestRequest in GuestRequestBy()) - { - sum += OrdersPerClient(guestRequest); - } - return sum; - } - - /// - /// Average Orders per hosting unit - /// - /// - public double averageOrdersPerHostingUnit() - { - double sum = 0; - foreach (var hostingUnit in HustingUnitsBy()) - { - sum += OrdersPerUnit(hostingUnit); - } - return sum; - } - - #endregion Order - - #region Date - - /// - /// Is date available - /// - public bool IsDateAvailable(DateTime start, DateTime end, int unitKey) - { - - HostingUnit x = GetHostingUnit(unitKey); - start.AddDays(1); - for (DateTime i = start; i < end; i.AddDays(1)) - { - if(x.Diary.FindIndex((z) => z == i) != -1 ) - { - return false; - } - } - - 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; - } - - #endregion Date - - /// - /// 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; - } - - /// - /// Make key for password - /// - /// - /// - public double KeyForPassword(int password) - { - return Math.Sin(password) * Math.Sqrt(password); - } - - /// - /// Creates Offers by area and available dates - /// - public void CreateOffer(GuestRequest req) - { - List hostingUnits = UintsAvailable(req.EntryDate, NumOfDays(req.EntryDate, req.EntryDate)); - foreach (var item in hostingUnits) - { - Offer y = new Offer(); - - foreach (var guest in GuestRequestBy((x => x.Area == item.Area))) - { - y.GuestKey = guest.GuestRequestKey; - y.UnitKey = item.HostingUnitKey; - } - - if (y != null) - Offer.ListOfOffers.Add(y); - } - - } - - public bool IsAccountCharged(Host host) - { - //HOW TO CHECK IF ACCOUNT CHARGED?? - throw new NotImplementedException(); - } - - /// - /// GetBankInfoFromTheWeb - /// - public void GetBankInfoFromTheWeb() - { - //C:\Users\ipewz\Documents\GitHub\Mini_project_Windows_system - //const string xmlLocalPath = @"atm.xml"; - const string xmlLocalPath = @"C:\Users\ipewz\Documents\GitHub\Mini_project_Windows_system\ATM.xml"; - WebClient wc = new WebClient(); - try - { - string xmlServerPath = - @"http://www.boi.org.il/he/BankingSupervision/BanksAndBranchLocations/Lists/BoiBankBranchesDocs/atm.xml"; - wc.DownloadFile(xmlServerPath, xmlLocalPath); - } - catch (Exception) - { - string xmlServerPath = @"http://www.jct.ac.il/~coshri/atm.xml"; - wc.DownloadFile(xmlServerPath, xmlLocalPath); - } - finally - { - wc.Dispose(); - } - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using BE; +using System.Reflection; + +using DAL; +using System.Net.Mail; +using System.Net; +using System.Windows; +using System.Threading; + +namespace BL +{ + public class MyBl : IBL + { + DalXML myDAL = new DalXML(); + + /// + /// Add Guest Request + /// + public bool AddGuestRequest(GuestRequest req) + { + + if (myDAL.ReturnGuestRequestList((x) => x.GuestRequestKey == req.GuestRequestKey).ToList().Count == 0) + { + myDAL.addGuestRequest(req); + return true; + } + else + { + return false; + } + + } + + /// + /// Add Hosting Unit + /// + public void AddHostingUnit(HostingUnit unit) + { + if (myDAL.ReturnHostingUnitList((x) => x.HostingUnitKey == unit.HostingUnitKey).ToList().Count == 0) + { + myDAL.addHostingUnit(unit); + } + else + { + throw new Exception("This Hosting unit exist already!"); + } + + } + + /// + /// create a new order + /// + public bool AddOrder(Order neworder) + { + + //Order order = instance.ReturenAllOrders((x)=> x.OrderKey == neworder.OrderKey).First(); + //if (order.Status == OrderStatus.CloseByClient || order.Status == OrderStatus.CloseByClientTimeOut) + //{ + // return false; + //} + //else + //{ + myDAL.addOrder(neworder); + //} + return true; + } + + /// + /// Close the order and handle the Implications + /// + public void CloseOrder(Order order) + { + if (order.Status == OrderStatus.CloseByClient) + { + //TODO: + //close status for changes + + HostingUnit x = GetHostingUnit(Convert.ToInt32(order.HostingUnitKey)); + GuestRequest y = GetGusetRequest(Convert.ToInt32(order.GuestRequestKey)); + for (DateTime i = y.EntryDate; i <= y.ReleaseDate; i.AddDays(1)) + { + x.Diary.Add(i); + } + + + //TODO add Commision + //To Where?? + + //Change client STATUS + y.Status = ClientStatus.CloseByApp; + + } + } + + public void RemoveHost(Host host) + { + throw new NotImplementedException(); + } + + /// + /// Is date available + /// + public bool IsDateAvailable(DateTime start, DateTime end, int unitKey) + { + + HostingUnit x = GetHostingUnit(unitKey); + start.AddDays(1); + for (DateTime i = start; i < end; i.AddDays(1)) + { + if (x.Diary.FindIndex((z) => z == i) != -1) + { + return false; + } + } + + return true; + + } + + /// + /// Check if end day later than the start date + /// + public bool IsDateCorrect(DateTime start, DateTime end) + { + return(end > start)? true:false; + } + + public void UpdateHost(Host host) + { + throw new NotImplementedException(); + } + + /// + /// 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 == OrderStatus.MailSent) + // { + // Console.WriteLine( + // $"You order:\n" + + // $"Create Date: {order.CreateDate}\n" + + // $"Order Date: {order.OrderDate}\n" + + // $"Hosting Unit Key: {order.HostingUnitKey}\n" + // ); + // } + //} + + /// + /// Return number of orders that sent to client + /// + public int OrdersPerClient(GuestRequest req) + { + int counter = 0; + foreach (var item in myDAL.ReturenAllOrders()) + { + if (item.GuestRequestKey == req.GuestRequestKey) + { + if (item.Status == OrderStatus.MailSent) + counter++; + } + } + return counter; + } + + /// + /// Return number of orders that seccessfully close + /// + public int OrdersPerUnit(HostingUnit unit) + { + int counter = 0; + foreach (var item in myDAL.ReturenAllOrders()) + { + if (item.HostingUnitKey == unit.HostingUnitKey) + { + if (item.Status == OrderStatus.CloseByClient) + counter++; + } + } + return counter; + } + + /// + /// Check if Unit can be remove + /// + public void UnitRemove(int unitKey) + { + foreach (var item in myDAL.ReturenAllOrders()) + { + if ((item.HostingUnitKey == unitKey) && (item.Status == OrderStatus.UntreatedYet)) + { + throw new Exception("Can't delete this unit, whan some order still open!"); + } + } + HostingUnit hostingUnit = GetHostingUnit(Convert.ToInt32(unitKey)); + try + { + myDAL.DeleteHostingUnit(hostingUnit); + } + catch (Exception ex) + { + throw new Exception("" + ex); + } + } + + /// + /// Update Unit + /// + /// + public void UpdateUnit(HostingUnit hostingUnit) + { + try + { + UnitRemove(hostingUnit.HostingUnitKey); + AddHostingUnit(hostingUnit); + MessageBox.Show($"Hosting unit: {hostingUnit.HostingUnitName} updated Seccessfuly!"); + } + catch (Exception ex) + { + MessageBox.Show($"Error during Update {hostingUnit.HostingUnitName} please try again later! " + ex); + } + } + + + + /// + /// Return all units available in given date range + /// + public List UintsAvailable(DateTime start, int numOfDays) + { + List listOfUnits = new List(); + + DateTime end = start.AddDays(numOfDays); + var x = myDAL.ReturnHostingUnitList(null); + foreach (var item in x) + { + + if (IsDateAvailable(start, end, item.HostingUnitKey)) + { + listOfUnits.Add(item); + } + + } + + return listOfUnits; + } + + /// + /// Add new Host + /// + public bool AddHost(Host host) + { + if (myDAL.returnHostList((x) => x.HostKey == host.HostKey).ToList().Count == 0) + { + myDAL.addHost(host); + return true; + } + else + { + return false; + } + + + + + } + + /// + /// Return Guest Request By any requirment + /// + public IEnumerable GuestRequestBy(Func predicate = null) + { + if (predicate == null) + return myDAL.getAllGuestRequests().AsEnumerable(); + return myDAL.getAllGuestRequests().Where(predicate); + } + + /// + /// Return Husting uinits By any requirment + /// + public IEnumerable HustingUnitsBy(Func predicate = null) + { + return myDAL.ReturnHostingUnitList(predicate); + } + + + /// + /// Creates Offers by area and available dates + /// + public void CreateOffer(GuestRequest req) + { + List hostingUnits = UintsAvailable(req.EntryDate, NumOfDays(req.EntryDate, req.EntryDate)); + foreach (var item in hostingUnits) + { + Offer y = new Offer(); + + foreach (var guest in GuestRequestBy((x => x.Area == item.Area))) + { + y.GuestKey = guest.GuestRequestKey; + y.UnitKey = item.HostingUnitKey; + } + + if (y != null) + Offer.ListOfOffers.Add(y); + } + + } + + /// + /// Return all Orders that created X dayes before + /// + public List OrdersUntilDate(int days) + { + return myDAL.ReturenAllOrders(x => NumOfDays(x.CreateDate) == days).ToList(); ; + } + + #region ///// Helpers ///// + + /// + /// Find Guset Request by ID + /// + /// + /// + GuestRequest GetGusetRequest(int key) + { + return (myDAL.ReturnGuestRequestList(x => x.GuestRequestKey == key)).First(); + } + + /// + /// Find Hosting Unit by key + /// + /// + /// + public HostingUnit GetHostingUnit(int key) + { + return (myDAL.ReturnHostingUnitList(x => x.HostingUnitKey == key)).First(); + } + + #endregion + + #region ///// NOT IMPLAMENTED ///// + + public bool IsAccountCharged(Host host) + { + //HOW TO CHECK IF ACCOUNT CHARGED?? + throw new NotImplementedException(); + } + + #endregion + + #region ///// Gruping ///// + + /// + /// Order Guest Request By Location + /// + /// + public IEnumerable> GuestRequestOrderBy_Location() + { + IEnumerable> result = + from gr in myDAL.ReturnGuestRequestList() + group gr by gr.Area; + return result; + } + + /// + /// Order Guest Request By Number Of Vacationers + /// + /// + public IEnumerable> GuestRequest_OrderBy_NumberOfVacationers() + { + IEnumerable> result = + from gr in myDAL.ReturnGuestRequestList() + group gr by (gr.Adults + gr.Children); + return result; + } + + /// + /// 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; + //} + + /// + /// Order Hosting Unit By Location + /// + /// + public IEnumerable> HostingUnit_OrderBy_Location() + { + IEnumerable> result = + from hu in myDAL.ReturnHostingUnitList() + group hu by hu.Area; + return result; + } + + /// + /// Return the number Of Hosting Units In Host + /// + /// + /// + public int NumOfHostingUnitsInHost(Host host) + { + int sum = 0; + foreach (var hu in myDAL.ReturnHostingUnitList()) + { + if (hu.Owner.HostKey == host.HostKey) + sum++; + } + return sum; + } + + #endregion + + + 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); + } + + /// + /// 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 + { + Thread thread = new Thread(GetBankInfoFromTheWeb); + thread.Start(); + } + 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); + } + + if(NewDay()) + { + try + { + Thread thread = new Thread(RefreshDatabase); + thread.Start(); + } + catch (Exception ex) + { + // throw new Exception("Can't get bank info from the web " + ex); + MessageBox.Show("Fail to refresh the database! \n " + ex); + } + } + + } + + private void RefreshDatabase() { } + private bool NewDay() { return true; } + + /// + /// 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.Credentials = from; + 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); + } + + + + /// + /// GetBankInfoFromTheWeb + /// + public void GetBankInfoFromTheWeb() + { + //C:\Users\ipewz\Documents\GitHub\Mini_project_Windows_system + //const string xmlLocalPath = @"atm.xml"; + const string xmlLocalPath = @"ATM.xml"; + WebClient wc = new WebClient(); + try + { + string xmlServerPath = + @"http://www.boi.org.il/he/BankingSupervision/BanksAndBranchLocations/Lists/BoiBankBranchesDocs/atm.xml"; + wc.DownloadFile(xmlServerPath, xmlLocalPath); + } + catch (Exception) + { + string xmlServerPath = @"http://www.jct.ac.il/~coshri/atm.xml"; + wc.DownloadFile(xmlServerPath, xmlLocalPath); + } + finally + { + wc.Dispose(); + } + + } + + public double averageOrdersPerClient() + { + double sum = 0; + foreach (var guestRequest in GuestRequestBy()) + { + sum += OrdersPerClient(guestRequest); + } + return sum; + } + + } } \ No newline at end of file diff --git a/DAL/BE_Extensions.cs b/DAL/BE_Extensions.cs index cf8c594..28b804e 100644 --- a/DAL/BE_Extensions.cs +++ b/DAL/BE_Extensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,23 +6,160 @@ using BE; using System.Xml.Linq; using System.Reflection; +using System.Xml.Serialization; +using System.IO; namespace DAL { public static class BE_Extensions { - + + #region Clones + /// + /// Clone + /// + /// + /// + public static Order Clone(this Order order) + { + return new Order + { + OrderKey = order.OrderKey, + Status = order.Status, + CreateDate = order.CreateDate, + GuestRequestKey = order.GuestRequestKey, + HostingUnitKey = order.HostingUnitKey, + OrderDate = order.OrderDate + }; + } + /// + /// Clone + /// + /// + /// + public static Host Clone(this Host host) + { + return new Host + { + HostKey = host.HostKey, + PrivateName = host.PrivateName, + FamilyName = host.FamilyName , + PhoneNumber = host.PhoneNumber, + MailAddress = host.MailAddress, + BankAccount = host.BankAccount.Clone(), + CollectionClearance = host.CollectionClearance + }; + } + /// + /// Clone + /// + /// + /// + public static BankAccount Clone(this BankAccount bankAccount) + { + return new BankAccount + { + BankNumber = bankAccount.BankNumber, + BankName = bankAccount.BankName, + BranchNumber = bankAccount.BranchNumber, + BranchAddress = bankAccount.BranchAddress, + BranchCity = bankAccount.BranchCity, + BankAccountNumber = bankAccount.BankAccountNumber + }; + } + + + //To-Do + public static HostingUnit Clone(this HostingUnit hostingUnit) + { + return new HostingUnit + { + //To-Do + }; + } + public static requirement Clone(this requirement requirement) + { + return new requirement + { + //To-Do + }; + } + public static GuestRequest Clone(this GuestRequest guestRequest) + { + return new GuestRequest + { + //To-Do + }; + } + + + + + #endregion Clones + + + public static XElement ToXML(this Order d) + { return new XElement("Order", new XElement("OrderKey", d.OrderKey.ToString()), new XElement("HostingUnitKey", d.HostingUnitKey.ToString()), new XElement("GuestRequestKey", d.GuestRequestKey.ToString()), - new XElement("CreateDate", d.CreateDate.ToString()), - new XElement("OrderDate", d.OrderDate.ToString()), + new XElement("CreateDate", d.CreateDate.ToString("o")), + new XElement("OrderDate", d.OrderDate.ToString("o")), new XElement("Status", d.Status.ToString()) ); } - + + //public static XElement ToXML(this BattlePlayer b) + //{ + // return new XElement("BattlePlayer", + // new XElement("Name", b.Name.ToString()), + // new XElement("Board", + // (from v in b.Board.ToString() + // select v).ToArray(), + // (from v in b.OpponentBoard.ToString() + // select v).ToArray() + // ) + // ); + //} + + public static void SaveToXML(T source, string path) + { + FileStream file = new FileStream(path, FileMode.Create); + XmlSerializer xmlSerializer = new XmlSerializer(source.GetType()); + xmlSerializer.Serialize(file, source); + file.Close(); + } + + public static T LoadFromXML(string path) + { + FileStream file = new FileStream(path, FileMode.Open); + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + T result = (T)xmlSerializer.Deserialize(file); + file.Close(); + return result; + } + + public static string ToXMLstring(this T toSerialize) + { + using (StringWriter textWriter = new StringWriter()) + { + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + xmlSerializer.Serialize(textWriter, toSerialize); + return textWriter.ToString(); + } + } + public static T ToObject(this string toDeserialize) + { + using (StringReader textReader = new StringReader(toDeserialize)) + { + XmlSerializer xmlSerializer = new XmlSerializer(typeof(T)); + return (T)xmlSerializer.Deserialize(textReader); + } + } + + } } \ No newline at end of file diff --git a/DAL/DAL.csproj b/DAL/DAL.csproj index a4a4df1..4fa4a01 100644 --- a/DAL/DAL.csproj +++ b/DAL/DAL.csproj @@ -44,6 +44,8 @@ + + diff --git a/DAL/DalXML.cs b/DAL/DalXML.cs new file mode 100644 index 0000000..a343493 --- /dev/null +++ b/DAL/DalXML.cs @@ -0,0 +1,402 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using BE; +using DataSource; + +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() + { + serialOrder = Int32.Parse(DataSource.DataSourceXML.Orders.Element("lastSerial").Value); + serialGuestRequest = Int32.Parse(DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value); + // TO DO + } + + 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() + { + 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/Dal_XML_imp.cs b/DAL/Dal_XML_imp.cs new file mode 100644 index 0000000..c49cd9c --- /dev/null +++ b/DAL/Dal_XML_imp.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DAL +{ + class Dal_XML_imp + { + + } +} diff --git a/DAL/FactorySingletonDal.cs b/DAL/FactorySingletonDal.cs index 29afb9c..8fd010d 100644 --- a/DAL/FactorySingletonDal.cs +++ b/DAL/FactorySingletonDal.cs @@ -1,4 +1,5 @@ -using System; +using DataSource; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,17 +9,21 @@ namespace DAL { public static class FactorySingletonDal { + private static IDAL instance = null; static FactorySingletonDal() { } public static IDAL Instance { + get { + if (instance == null) { - instance = new DALImp(); + instance = new DalXML(); + } return instance; } diff --git a/DataSource/DataSource.csproj b/DataSource/DataSource.csproj index 49a65d0..240910b 100644 --- a/DataSource/DataSource.csproj +++ b/DataSource/DataSource.csproj @@ -42,6 +42,7 @@ + @@ -50,5 +51,12 @@ BE + + + + + + + \ No newline at end of file diff --git a/DataSource/DataSourceList.cs b/DataSource/DataSourceList.cs index 9841104..364e620 100644 --- a/DataSource/DataSourceList.cs +++ b/DataSource/DataSourceList.cs @@ -4,14 +4,39 @@ using System.Text; using System.Threading.Tasks; using BE; +using System.Xml.Serialization; +using System.IO; namespace DataSource { - public static class DataSourceList + static public class DataSourceList { + + //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 Hosts = new List(); + public static List HostingUnits = new List(); + public static List Orders = new List(); + public static List GuestRequests = new List(); } } diff --git a/DataSource/DataSourceXML.cs b/DataSource/DataSourceXML.cs new file mode 100644 index 0000000..5c88075 --- /dev/null +++ b/DataSource/DataSourceXML.cs @@ -0,0 +1,149 @@ +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; + +namespace DataSource +{ + public static class DataSourceXML + { + //private static string currentDirectory = Directory.GetCurrentDirectory(); + private static string solutionDirectory = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).FullName).FullName).FullName; + + private static string filePath = System.IO.Path.Combine(solutionDirectory, "DataSource", "DataXML"); + + + private static XElement orderRoot = null; + private static XElement guestRequestRoot = null; + private static XElement hostRoot = null; + private static XElement hostingUnitRoot = null; + + + private static string orderPath = Path.Combine(filePath, "OrderXml.xml"); + private static string guestRequestPath = Path.Combine(filePath, "GuestRequestXml.xml"); + private static string hostPath = Path.Combine(filePath, "HostXml.xml"); + private static string hostingUnitPath = Path.Combine(filePath, "HostingUnitXml.xml"); + + + + static DataSourceXML() + { + bool exists = Directory.Exists(filePath); + if (!exists) + { + Directory.CreateDirectory(filePath); + } + + if (!File.Exists(orderPath)) + { + CreateFile("Orders", orderPath); + + } + orderRoot = LoadData(orderPath); + + if (!File.Exists(hostPath)) + { + CreateFile("Hosts", hostPath); + + } + hostRoot = LoadData(hostPath); + + if (!File.Exists(hostingUnitPath)) + { + CreateFile("HostingUnits", hostingUnitPath); + + } + hostingUnitRoot = LoadData(hostingUnitPath); + + + if (!File.Exists(guestRequestPath)) + { + CreateFile("GuestRequests", guestRequestPath); + + } + guestRequestRoot = LoadData(guestRequestPath); + + } + private static void CreateFile(string typename, string path) + { + XElement root = new XElement(typename); + root.Save(path); + } + + public static void SaveOrders() + { + orderRoot.Save(orderPath); + } + + public static void SaveHostingUnits() + { + hostingUnitRoot.Save(hostingUnitPath); + } + + public static void SaveHosts() + { + hostRoot.Save(hostPath); + } + + public static void SaveGuestRequests() + { + guestRequestRoot.Save(guestRequestPath); + } + + public static XElement Orders + { + get + { + orderRoot = LoadData(orderPath); + return orderRoot; + } + } + + public static XElement Hosts + { + get + { + hostRoot = LoadData(hostPath); + return hostRoot; + } + } + + public static XElement HostingUnits + { + get + { + hostingUnitRoot = LoadData(hostingUnitPath); + return hostingUnitRoot; + } + } + + public static XElement GuestRequests + { + get + { + guestRequestRoot = LoadData(guestRequestPath); + return guestRequestRoot; + } + } + + private static XElement LoadData(string path) + { + XElement root; + try + { + root = XElement.Load(path); + } + catch + { + throw new Exception("File upload problem"); + } + return root; + } + + + } +} diff --git a/DataSource/DataXML/GuestRequestXml.xml b/DataSource/DataXML/GuestRequestXml.xml new file mode 100644 index 0000000..d0fec14 --- /dev/null +++ b/DataSource/DataXML/GuestRequestXml.xml @@ -0,0 +1,100 @@ + + + 10000005 + + Jerusalem + old city + Hotel + 2 + 1 + Necessary + NotNecessary + NotNecessary + Necessary + NotNecessary + Necessary + Possible + Necessary + Possible + 10000000 + zareh + parz + penhes@gmail.com + Open + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + + + North + tabrios + Zimmer + 4 + 0 + Necessary + Necessary + Necessary + NotNecessary + Necessary + Necessary + Necessary + Possible + Possible + 10000001 + kalmen + kalmenovitz + kalmenovitz@gmail.com + Open + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + + + Center + tal aviv + RentingRoom + 2 + 2 + NotNecessary + NotNecessary + NotNecessary + Necessary + NotNecessary + Necessary + Necessary + Necessary + Necessary + 10000003 + afreim + cohn + cohn@gmail.com + Open + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + + + Jerusalem + old city + Hotel + 2 + 5 + Possible + Possible + NotNecessary + Necessary + NotNecessary + Necessary + Possible + Necessary + Possible + 10000006 + aser + golomb + golomb@gmail.com + Open + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + + \ No newline at end of file diff --git a/DataSource/DataXML/HostXml.xml b/DataSource/DataXML/HostXml.xml new file mode 100644 index 0000000..e2ce053 --- /dev/null +++ b/DataSource/DataXML/HostXml.xml @@ -0,0 +1,67 @@ + + + + 11111111 + david + cohn + 054-5555555 + sale@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111111 + + + + + 22222222 + moses + levi + 054-6666666 + hotel@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111112 + + + + + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + + + 0 + manster + frankinstin + 666 + hall + 0 + + 852 + + 852 + + + 85 + + + \ No newline at end of file diff --git a/DataSource/DataXML/HostingUnitXml.xml b/DataSource/DataXML/HostingUnitXml.xml new file mode 100644 index 0000000..0acd880 --- /dev/null +++ b/DataSource/DataXML/HostingUnitXml.xml @@ -0,0 +1,367 @@ + + + + North + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000000 + + 11111111 + david + cohn + 054-5555555 + sale@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111111 + + + + hotel clifornia + + + North + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000001 + + 11111111 + david + cohn + 054-5555555 + sale@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111111 + + + + hotel hong-kong + + + North + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000003 + + 11111111 + david + cohn + 054-5555555 + sale@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111111 + + + + hotel paris + + + Center + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000006 + + 22222222 + moses + levi + 054-6666666 + hotel@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111112 + + + + hotel tal-aviv + + + Jerusalem + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000010 + + 22222222 + moses + levi + 054-6666666 + hotel@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111112 + + + + hotel jeruselm + + + North + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000015 + + 22222222 + moses + levi + 054-6666666 + hotel@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111112 + + + + hotel tavriea + + + North + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000021 + + 22222222 + moses + levi + 054-6666666 + hotel@gmai.com + + 123 + poalim + 432 + jefo 121 + jeruselm + 11111112 + + + + hotel hifa + + + North + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000028 + + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + + zimer of the north + + + Jerusalem + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000036 + + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + + zimer of the Jerusalem + + + South + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000045 + + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + + zimer of the South + + + North + vc + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + Possible + Possible + Possible + Necessary + Possible + Necessary + 10000040 + + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + +vvvv + + \ No newline at end of file diff --git a/DataSource/DataXML/OrderXml.xml b/DataSource/DataXML/OrderXml.xml new file mode 100644 index 0000000..9a6920c --- /dev/null +++ b/DataSource/DataXML/OrderXml.xml @@ -0,0 +1,28 @@ + + + 10000009 + + 10000007 + 10000003 + 10000001 + 2020-01-27T20:40:58.9922545+02:00 + 2020-01-27T20:40:58.9922545+02:00 + MailSent + + + 10000008 + 10000003 + 10000001 + 2020-01-27T20:41:17.1073695+02:00 + 2020-01-27T20:41:17.1073695+02:00 + MailSent + + + 10000009 + 10000021 + 10000003 + 2020-01-27T21:34:06.2123047+02:00 + 2020-01-27T21:34:06.2123047+02:00 + MailSent + + \ No newline at end of file diff --git a/DataSource/DataXML1/GuestRequestXml.xml b/DataSource/DataXML1/GuestRequestXml.xml new file mode 100644 index 0000000..7b866a5 --- /dev/null +++ b/DataSource/DataXML1/GuestRequestXml.xml @@ -0,0 +1,42 @@ + + + 1000001 + + 1000000 + ASDA + ASDAS + AS@HH.KK + NotYetApproved + 0001-01-01T00:00:00 + 2020-01-19T11:52:17.9355397+02:00 + 2020-01-21T11:52:17.9355397+02:00 + Jerusalem + ASD + Zimmer + 2 + 3 + Necessary + Necessary + Necessary + Necessary + + + 1000001 + dxs + EFG + GR@GG.GG + NotYetApproved + 0001-01-01T00:00:00 + 2020-01-19T11:53:23.7121693+02:00 + 2020-01-21T11:53:23.7121693+02:00 + Jerusalem + asd + Zimmer + 55 + 54 + Necessary + Necessary + Necessary + Necessary + + \ No newline at end of file diff --git a/DataSource/DataXML1/HostXml.xml b/DataSource/DataXML1/HostXml.xml new file mode 100644 index 0000000..9dfb370 --- /dev/null +++ b/DataSource/DataXML1/HostXml.xml @@ -0,0 +1,30 @@ + + + + 123 + d ca suffit + qwere + 3324 + daas@hhh.jjj + 3123 + Yes + + + 5555 + qwre + adsa + 232 + fdsf + 12321 + Yes + + + 1424 + buffalo + Falery Chisqkar Destin + 052 + aaaa@gmail.com + 15141 + Maybe + + \ No newline at end of file diff --git a/DataSource/DataXML1/HostingUnitXml.xml b/DataSource/DataXML1/HostingUnitXml.xml new file mode 100644 index 0000000..d28178a --- /dev/null +++ b/DataSource/DataXML1/HostingUnitXml.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/DataSource/DataXML1/OrderXml.xml b/DataSource/DataXML1/OrderXml.xml new file mode 100644 index 0000000..00457dc --- /dev/null +++ b/DataSource/DataXML1/OrderXml.xml @@ -0,0 +1,28 @@ + + + 25 + + 23 + 10000010 + 10000025 + 30/12/2019 16:52:25 + 02/01/2020 16:52:25 + NotYetApproved + + + 24 + 12123 + 10000005 + 30/12/2019 16:52:25 + 02/01/2020 16:52:25 + NotYetApproved + + + 25 + 12123 + 10000005 + 30/12/2019 16:52:25 + 02/01/2020 16:52:25 + NotYetApproved + + \ No newline at end of file diff --git a/PL/Program.cs b/PL/Program.cs index 0d6a3c6..6892b34 100644 --- a/PL/Program.cs +++ b/PL/Program.cs @@ -208,10 +208,10 @@ void siteMangerScreen() } - bool deleteHustingUnit() + void deleteHustingUnit() { Console.WriteLine("Enter hosting unit key"); - return newBL.UnitRemove(inputSarielNumber(10000000)); + newBL.UnitRemove(inputSarielNumber(10000000)); } void updateHustingUnit() diff --git a/PL/preCode.cs b/PL/preCode.cs index b0a33da..a9975e4 100644 --- a/PL/preCode.cs +++ b/PL/preCode.cs @@ -5,7 +5,7 @@ namespace PL { - + public class preCode { BL.MyBl mybl = new MyBl(); @@ -209,8 +209,6 @@ public void initialize() mybl.AddGuestRequest(gr); #endregion kalmen_request - - #region afreim_request gr = new GuestRequest(); diff --git a/PLWPF/HostUpdateWindow.xaml b/PLWPF/HostUpdateWindow.xaml new file mode 100644 index 0000000..d9aef88 --- /dev/null +++ b/PLWPF/HostUpdateWindow.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/PLWPF/HostUpdateWindow.xaml.cs b/PLWPF/HostUpdateWindow.xaml.cs new file mode 100644 index 0000000..557046d --- /dev/null +++ b/PLWPF/HostUpdateWindow.xaml.cs @@ -0,0 +1,30 @@ +using BE; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace PLWPF +{ + /// + /// Interaction logic for HostUpdateWindow.xaml + /// + public partial class HostUpdateWindow : Window + { + public HostUpdateWindow(Host host) + { + InitializeComponent(); + UpdateHostFrame.Content = new HostUserControl(host,false); + DeleteHostFrame.Content = new HostUserControl(host,true); + } + } +} diff --git a/PLWPF/HostUserControl.xaml b/PLWPF/HostUserControl.xaml new file mode 100644 index 0000000..de55241 --- /dev/null +++ b/PLWPF/HostUserControl.xaml @@ -0,0 +1,57 @@ + + + +