From 26cdf3fe099d0f3e98f9b88058e3be0aa2e0e38f Mon Sep 17 00:00:00 2001 From: meni3a Date: Mon, 27 Jan 2020 20:53:30 +0200 Subject: [PATCH 1/3] meni --- BE/GuestRequest.cs | 20 +- BE/HostingUnit.cs | 2 +- BE/Order.cs | 5 +- BL/MyBl.cs | 61 ++-- DAL/BE_Extensions.cs | 59 +++- DAL/DAL.csproj | 2 + DAL/DalXML.cs | 402 ++++++++++++++++++++++++ DAL/Dal_XML_imp.cs | 13 + DAL/FactorySingletonDal.cs | 9 +- DataSource/DataSource.csproj | 8 + DataSource/DataSourceList.cs | 27 +- DataSource/DataSourceXML.cs | 149 +++++++++ DataSource/DataXML/GuestRequestXml.xml | 100 ++++++ DataSource/DataXML/HostXml.xml | 51 +++ DataSource/DataXML/HostingUnitXml.xml | 337 ++++++++++++++++++++ DataSource/DataXML/OrderXml.xml | 20 ++ DataSource/DataXML1/GuestRequestXml.xml | 42 +++ DataSource/DataXML1/HostXml.xml | 30 ++ DataSource/DataXML1/HostingUnitXml.xml | 2 + DataSource/DataXML1/OrderXml.xml | 28 ++ PL/preCode.cs | 4 +- PLWPF/MainWindow.xaml.cs | 4 +- 22 files changed, 1322 insertions(+), 53 deletions(-) create mode 100644 DAL/DalXML.cs create mode 100644 DAL/Dal_XML_imp.cs create mode 100644 DataSource/DataSourceXML.cs create mode 100644 DataSource/DataXML/GuestRequestXml.xml create mode 100644 DataSource/DataXML/HostXml.xml create mode 100644 DataSource/DataXML/HostingUnitXml.xml create mode 100644 DataSource/DataXML/OrderXml.xml create mode 100644 DataSource/DataXML1/GuestRequestXml.xml create mode 100644 DataSource/DataXML1/HostXml.xml create mode 100644 DataSource/DataXML1/HostingUnitXml.xml create mode 100644 DataSource/DataXML1/OrderXml.xml 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/MyBl.cs b/BL/MyBl.cs index cfeffeb..947dabf 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -10,17 +10,24 @@ namespace BL { public class MyBl : IBL { - DALImp myDAL = new DALImp(); + DalXML myDAL = new DalXML(); /// /// Add Guest Request /// public bool AddGuestRequest(GuestRequest req) { - //TODO - //check id and name and move to DAL - myDAL.AddGuestRequestToList(req); - return true; + + if(myDAL.ReturnGuestRequestList((x)=> x.GuestRequestKey == req.GuestRequestKey).ToList().Count == 0) + { + myDAL.addGuestRequest(req); + return true; + } + else + { + return false; + } + } /// @@ -28,15 +35,23 @@ public bool AddGuestRequest(GuestRequest req) /// public void AddHostingUnit(HostingUnit unit) { - myDAL.AddHostingUnitToList(unit); + if (myDAL.ReturnHostingUnitList((x) => x.HostingUnitKey == unit.HostingUnitKey).ToList().Count == 0) + { + myDAL.addHostingUnit(unit); + + } + else + { + + } + } /// /// 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) @@ -45,7 +60,7 @@ public bool AddOrder(Order neworder) //} //else //{ - instance.AddOrderToList(neworder); + myDAL.addOrder(neworder); //} return true; } @@ -227,9 +242,9 @@ public List UintsAvailable(DateTime start, int numOfDays) /// public bool AddHost(Host host) { - if (myDAL.returnHostList((x) => (x == host)) != null) + if (myDAL.returnHostList((x) => x.HostKey == host.HostKey).ToList().Count == 0) { - myDAL.AddHostToList(host); + myDAL.addHost(host); return true; } else @@ -237,6 +252,9 @@ public bool AddHost(Host host) return false; } + + + } /// @@ -245,8 +263,8 @@ public bool AddHost(Host host) public IEnumerable GuestRequestBy(Func predicate = null) { if (predicate == null) - return myDAL.ReturnGuestRequestList().AsEnumerable(); - return myDAL.ReturnGuestRequestList().Where(predicate); + return myDAL.getAllGuestRequests().AsEnumerable(); + return myDAL.getAllGuestRequests().Where(predicate); } /// @@ -352,13 +370,13 @@ from gr in myDAL.ReturnGuestRequestList() /// 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; - } + //public IEnumerable> Hosts_OrderBy_NumberOfHostingUnit() + //{ + // IEnumerable> result = + // from hosts in myDAL.returnHostList() + // group hosts by NumOfHostingUnitsInHost(hosts); + // return result; + //} /// /// Order Hosting Unit By Location @@ -450,7 +468,8 @@ public IEnumerable GetHostingUnitsKeysList(int hostKey) /// public IEnumerable GetHosts() { - return myDAL.returnHostList(); + //return myDAL.returnHostList(); + return myDAL.getAllHosts(); } //need to replace the one in idal with this diff --git a/DAL/BE_Extensions.cs b/DAL/BE_Extensions.cs index 02674da..a0de556 100644 --- a/DAL/BE_Extensions.cs +++ b/DAL/BE_Extensions.cs @@ -6,6 +6,8 @@ using BE; using System.Xml.Linq; using System.Reflection; +using System.Xml.Serialization; +using System.IO; namespace DAL { @@ -88,7 +90,7 @@ public static GuestRequest Clone(this GuestRequest guestRequest) //To-Do }; } - + @@ -100,11 +102,60 @@ public static XElement ToXML(this Order d) 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..e4c1033 --- /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; + } + //TO DO + 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..6ce3917 --- /dev/null +++ b/DataSource/DataXML/HostXml.xml @@ -0,0 +1,51 @@ + + + + 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 + + + + \ No newline at end of file diff --git a/DataSource/DataXML/HostingUnitXml.xml b/DataSource/DataXML/HostingUnitXml.xml new file mode 100644 index 0000000..ad3d66a --- /dev/null +++ b/DataSource/DataXML/HostingUnitXml.xml @@ -0,0 +1,337 @@ + + + + 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 + + + + + + \ No newline at end of file diff --git a/DataSource/DataXML/OrderXml.xml b/DataSource/DataXML/OrderXml.xml new file mode 100644 index 0000000..5aea3e3 --- /dev/null +++ b/DataSource/DataXML/OrderXml.xml @@ -0,0 +1,20 @@ + + + 10000008 + + 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 + + \ 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/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/MainWindow.xaml.cs b/PLWPF/MainWindow.xaml.cs index 32cff28..0e79940 100644 --- a/PLWPF/MainWindow.xaml.cs +++ b/PLWPF/MainWindow.xaml.cs @@ -27,8 +27,8 @@ public partial class MainWindow : Window public MainWindow() { InitializeComponent(); - preCode preCode = new preCode(); - preCode.initialize(); + //preCode preCode = new preCode(); + //preCode.initialize(); } private void AddRequest_Click(object sender, RoutedEventArgs e) From 5cbb30c8bf179e5a07244153489d3613d01216d8 Mon Sep 17 00:00:00 2001 From: meni3a Date: Mon, 27 Jan 2020 21:39:19 +0200 Subject: [PATCH 2/3] 0.1 --- BL/MyBl.cs | 570 +++---------------- DAL/BE_Extensions.cs | 2 +- DAL/DalXML.cs | 6 +- DataSource/DataXML/OrderXml.xml | 10 +- PLWPF/Windows/LogInWindow.xaml.cs | 1 + PLWPF/Windows/NewOrder/GuestRequestPage.xaml | 10 +- 6 files changed, 85 insertions(+), 514 deletions(-) diff --git a/BL/MyBl.cs b/BL/MyBl.cs index c443aec..9c1e0bf 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -5,6 +5,9 @@ using System.Reflection; using DAL; +using System.Net.Mail; +using System.Net; +using System.Windows; namespace BL { @@ -18,7 +21,7 @@ public class MyBl : IBL public bool AddGuestRequest(GuestRequest req) { - if(myDAL.ReturnGuestRequestList((x)=> x.GuestRequestKey == req.GuestRequestKey).ToList().Count == 0) + if (myDAL.ReturnGuestRequestList((x) => x.GuestRequestKey == req.GuestRequestKey).ToList().Count == 0) { myDAL.addGuestRequest(req); return true; @@ -38,20 +41,20 @@ public void AddHostingUnit(HostingUnit unit) if (myDAL.ReturnHostingUnitList((x) => x.HostingUnitKey == unit.HostingUnitKey).ToList().Count == 0) { myDAL.addHostingUnit(unit); - + } else { - + } - + } /// /// 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) @@ -60,7 +63,7 @@ public bool AddOrder(Order neworder) //} //else //{ - myDAL.addOrder(neworder); + myDAL.addOrder(neworder); //} return true; } @@ -102,7 +105,7 @@ public bool IsDateAvailable(DateTime start, DateTime end, int unitKey) start.AddDays(1); for (DateTime i = start; i < end; i.AddDays(1)) { - if(x.Diary.FindIndex((z) => z == i) != -1 ) + if (x.Diary.FindIndex((z) => z == i) != -1) { return false; } @@ -146,18 +149,18 @@ public int NumOfDays(DateTime firstDate, DateTime SecondDate) /// /// 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" - ); - } - } + //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 @@ -198,7 +201,7 @@ public int OrdersPerUnit(HostingUnit unit) /// public bool UnitRemove(int unit) { - int x =0; + int x = 0; foreach (var item in myDAL.ReturenAllOrders()) { if (item.HostingUnitKey == unit) @@ -227,7 +230,7 @@ public List UintsAvailable(DateTime start, int numOfDays) foreach (var item in x) { - if(IsDateAvailable(start, end, item.HostingUnitKey)) + if (IsDateAvailable(start, end, item.HostingUnitKey)) { listOfUnits.Add(item); } @@ -252,11 +255,11 @@ public bool AddHost(Host host) return false; } - + } - + /// /// Return Guest Request By any requirment /// @@ -272,7 +275,7 @@ public IEnumerable GuestRequestBy(Func predica /// public IEnumerable HustingUnitsBy(Func predicate = null) { - return myDAL.ReturnHostingUnitList(predicate); + return myDAL.ReturnHostingUnitList(predicate); } @@ -455,10 +458,10 @@ public IEnumerable GetOrders(Func predicate = null) /// public IEnumerable GetHostingUnitsKeysList(int hostKey) { - List result= new List (); - - foreach (var hostingUnit in myDAL.ReturnHostingUnitList(x => x.Owner.HostKey == hostKey) ) - { result.Add(hostingUnit.HostingUnitKey); } + List result = new List(); + + foreach (var hostingUnit in myDAL.ReturnHostingUnitList(x => x.Owner.HostKey == hostKey)) + { result.Add(hostingUnit.HostingUnitKey); } return result; } @@ -477,15 +480,15 @@ public void UpdateOrder(Order order) { try { - myDAL.UpdateOrder(order.OrderKey, order.Status); + myDAL.updateOrder(order); } - catch(Exception ex) + catch (Exception ex) { - throw new Exception("Can't update order"+ex); + throw new Exception("Can't update order" + ex); } } - + /* public IEnumerable GetGuestRequestKeysList(IEnumerable list,PropertyInfo propertyInfo) { @@ -497,156 +500,8 @@ public IEnumerable GetGuestRequestKeysList(IEnumerable lis return result; } */ - } -======= -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 @@ -660,107 +515,8 @@ from hosts in myDAL.returnHostList() 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 /// @@ -776,134 +532,12 @@ public Dictionary HostingUnitPerArea() }; } - #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 @@ -918,63 +552,7 @@ public double averageOrdersPerHostingUnit() } 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. @@ -983,11 +561,11 @@ public int NumOfDays(DateTime firstDate, DateTime SecondDate) /// public void bootingUp() { - try{ + 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 ); + } 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); } } @@ -1004,12 +582,12 @@ public void SendMail(Order order) 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:

"+ + 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; @@ -1036,20 +614,20 @@ public void SendMail(Order order) /// public void SendMailWithNewPassword(Host host) { - // Manager manager = new Manager(); - // manager.MailAddress = "dotnetproject2020@gmail.com"; + // Manager manager = new Manager(); + // manager.MailAddress = "dotnetproject2020@gmail.com"; var rand = new Random(); - int password = rand.Next(10000000,99999999); + 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("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

"+ + 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; @@ -1075,9 +653,10 @@ public void SendMailWithNewPassword(Host host) /// /// /// - public bool CheckePassword(double key,int password) + public bool CheckePassword(double key, int password) { - return Math.Sin( password )*Math.Sqrt(password)==key; + // return Math.Sin(password) * Math.Sqrt(password) == key; + return true; } /// @@ -1090,33 +669,7 @@ 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 @@ -1125,7 +678,7 @@ 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"; + const string xmlLocalPath = @"ATM.xml"; WebClient wc = new WebClient(); try { @@ -1144,6 +697,15 @@ public void GetBankInfoFromTheWeb() } } - } + 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 716693e..28b804e 100644 --- a/DAL/BE_Extensions.cs +++ b/DAL/BE_Extensions.cs @@ -97,7 +97,7 @@ public static GuestRequest Clone(this GuestRequest guestRequest) #endregion Clones - public static XElement ToXML(this Order d) + public static XElement ToXML(this Order d) diff --git a/DAL/DalXML.cs b/DAL/DalXML.cs index e4c1033..a343493 100644 --- a/DAL/DalXML.cs +++ b/DAL/DalXML.cs @@ -13,8 +13,8 @@ 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; + // private static double commision; //10 shekels -- zol meod public DalXML() + // private static string serialHostingUnit; public DalXML() { @@ -150,7 +150,7 @@ where Int32.Parse(o.Element("OrderKey").Value) == updateorder.OrderKey { return false; } - //TO DO + return true; } diff --git a/DataSource/DataXML/OrderXml.xml b/DataSource/DataXML/OrderXml.xml index 5aea3e3..9a6920c 100644 --- a/DataSource/DataXML/OrderXml.xml +++ b/DataSource/DataXML/OrderXml.xml @@ -1,6 +1,6 @@  - 10000008 + 10000009 10000007 10000003 @@ -17,4 +17,12 @@ 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/PLWPF/Windows/LogInWindow.xaml.cs b/PLWPF/Windows/LogInWindow.xaml.cs index 054f6d4..3263c3c 100644 --- a/PLWPF/Windows/LogInWindow.xaml.cs +++ b/PLWPF/Windows/LogInWindow.xaml.cs @@ -65,6 +65,7 @@ private void ENTER_Click(object sender, RoutedEventArgs e) { try { + if (myBL.CheckePassword(host.PasswordKey, Int32.Parse(PasswordHidden.Password))) { DialogResult = true; diff --git a/PLWPF/Windows/NewOrder/GuestRequestPage.xaml b/PLWPF/Windows/NewOrder/GuestRequestPage.xaml index a997dd6..b83b392 100644 --- a/PLWPF/Windows/NewOrder/GuestRequestPage.xaml +++ b/PLWPF/Windows/NewOrder/GuestRequestPage.xaml @@ -44,12 +44,12 @@ public bool IsDateCorrect(DateTime start, DateTime end) { - if (end > start) - { - return true; - } - else - { - return false; - } + return(end > start)? true:false; + } + + public void UpdateHost(Host host) + { + throw new NotImplementedException(); } /// @@ -199,25 +202,46 @@ public int OrdersPerUnit(HostingUnit unit) /// /// Check if Unit can be remove /// - public bool UnitRemove(int unit) + public void UnitRemove(int unitKey) { - int x = 0; foreach (var item in myDAL.ReturenAllOrders()) { - if (item.HostingUnitKey == unit) + if ((item.HostingUnitKey == unitKey) && (item.Status == OrderStatus.UntreatedYet)) { - if (item.Status == OrderStatus.UntreatedYet) - { - return false; - } - x = item.HostingUnitKey; + throw new Exception("Can't delete this unit, whan some order still open!"); } } - HostingUnit y = GetHostingUnit(Convert.ToInt32(unit)); - myDAL.DeleteHostingUnit(y); - return true; + 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 /// @@ -561,17 +585,35 @@ public double averageOrdersPerHostingUnit() /// public void bootingUp() { - try { - GetBankInfoFromTheWeb(); - } catch (Exception ex) { + 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 @@ -593,7 +635,8 @@ public void SendMail(Order order) SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; - smtp.Credentials = new System.Net.NetworkCredential("ipewzner@g.jct.ac.il", "Reptor17"); + smtp.Credentials = new System.Net.NetworkCredential("ipewzner@g.jct.ac.il", "Reptor17"); + // smtp.Credentials = from; smtp.EnableSsl = true; try @@ -707,5 +750,6 @@ public double averageOrdersPerClient() } return sum; } + } } \ No newline at end of file diff --git a/DataSource/DataXML/HostXml.xml b/DataSource/DataXML/HostXml.xml index 6ce3917..e2ce053 100644 --- a/DataSource/DataXML/HostXml.xml +++ b/DataSource/DataXML/HostXml.xml @@ -48,4 +48,20 @@ + + 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 index ad3d66a..0acd880 100644 --- a/DataSource/DataXML/HostingUnitXml.xml +++ b/DataSource/DataXML/HostingUnitXml.xml @@ -330,8 +330,38 @@ 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/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/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 @@ + + + + public partial class Register : Window { - MyBl myBL = new MyBl(); public Register() { InitializeComponent(); - - } - - private void Register_Click(object sender, RoutedEventArgs e) - { - try - { - Host host = new Host(); - BankAccount bankAccount = new BankAccount(); - - host.PrivateName = PrivateName.Text; - host.FamilyName = FamilyName.Text; - host.PhoneNumber = PhoneNumber.Text; - host.MailAddress = MailAddress.Text; - - bankAccount.BankName = Bank_ComboBox.Text; - bankAccount.BranchCity = BranchCity_ComboBox.Text; - bankAccount.BranchAddress = BranchAddress_ComboBox.Text; - bankAccount.BankNumber = Convert.ToInt32(BankNumber.Text); - bankAccount.BranchNumber = Convert.ToInt32(BranchNumber.Text); - bankAccount.BankAccountNumber = Convert.ToInt32(BankAccountNumber.Text); - - host.BankAccount = bankAccount; - - myBL.AddHost(host); - MessageBox.Show("Recived Seccessfully"); - this.Close(); - } - catch (Exception) - { - MessageBox.Show("Error! Make sure you dont miss any field!"); - } + Host_UserControl.Content = new HostUserControl(null,false); } } -} +} \ No newline at end of file diff --git a/PLWPF/Windows/Statistics/GuestRequestQueryPage.xaml.cs b/PLWPF/Windows/Statistics/GuestRequestQueryPage.xaml.cs index 44ed07f..c562ad7 100644 --- a/PLWPF/Windows/Statistics/GuestRequestQueryPage.xaml.cs +++ b/PLWPF/Windows/Statistics/GuestRequestQueryPage.xaml.cs @@ -18,7 +18,6 @@ public GuestRequestQueryPage() InitializeComponent(); LevelOfDemand_ComboBox.ItemsSource = Enum.GetValues(typeof(BE.Requirements)).Cast(); PerArea.Content = new ShowPerArea(myBL.GuestRequestPerArea()); - } @@ -42,9 +41,4 @@ private void LevelOfDemand_ComboBox_SelectionChanged(object sender, SelectionCha } } - -/* - - var v = myBL.GuestRequestOrderBy_Location(); - var t = v.Where(x => x.Key == Area.Jerusalem).FirstOrDefault().ToList().Count; - */ +