diff --git a/BE/ATM.cs b/BE/ATM.cs new file mode 100644 index 0000000..59a98fb --- /dev/null +++ b/BE/ATM.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BE +{ + + // NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0. + /// + [System.SerializableAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] + [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] + public partial class ATM + { + + private string קוד_בנקField; + + private string שם_בנקField; + + private string קוד_סניףField; + + private string כתובת_הATMField; + + private string ישובField; + + private string עמלהField; + + private string סוג_ATMField; + + private string מיקום_הATM_ביחס_לסניףField; + + private string גישה_לנכיםField; + + private string קואורדינטת_XField; + + private string קואורדינטת_YField; + + /// + public string קוד_בנק + { + get + { + return this.קוד_בנקField; + } + set + { + this.קוד_בנקField = value; + } + } + + /// + public string שם_בנק + { + get + { + return this.שם_בנקField; + } + set + { + this.שם_בנקField = value; + } + } + + /// + public string קוד_סניף + { + get + { + return this.קוד_סניףField; + } + set + { + this.קוד_סניףField = value; + } + } + + /// + [System.Xml.Serialization.XmlElementAttribute("כתובת_ה-ATM")] + public string כתובת_הATM + { + get + { + return this.כתובת_הATMField; + } + set + { + this.כתובת_הATMField = value; + } + } + + /// + public string ישוב + { + get + { + return this.ישובField; + } + set + { + this.ישובField = value; + } + } + + /// + public string עמלה + { + get + { + return this.עמלהField; + } + set + { + this.עמלהField = value; + } + } + + /// + public string סוג_ATM + { + get + { + return this.סוג_ATMField; + } + set + { + this.סוג_ATMField = value; + } + } + + /// + [System.Xml.Serialization.XmlElementAttribute("מיקום_ה-ATM_ביחס_לסניף")] + public string מיקום_הATM_ביחס_לסניף + { + get + { + return this.מיקום_הATM_ביחס_לסניףField; + } + set + { + this.מיקום_הATM_ביחס_לסניףField = value; + } + } + + /// + public string גישה_לנכים + { + get + { + return this.גישה_לנכיםField; + } + set + { + this.גישה_לנכיםField = value; + } + } + + /// + public string קואורדינטת_X + { + get + { + return this.קואורדינטת_XField; + } + set + { + this.קואורדינטת_XField = value; + } + } + + /// + public string קואורדינטת_Y + { + get + { + return this.קואורדינטת_YField; + } + set + { + this.קואורדינטת_YField = value; + } + } + } + + +} + + diff --git a/BE/BE.csproj b/BE/BE.csproj index 83a736a..1ebe528 100644 --- a/BE/BE.csproj +++ b/BE/BE.csproj @@ -41,7 +41,9 @@ + + diff --git a/BE/BankDetails.cs b/BE/BankDetails.cs new file mode 100644 index 0000000..387eaba --- /dev/null +++ b/BE/BankDetails.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BE +{ + public class BankDetails + { + public int BankNumber { get; set; } + public String BankName { get; set; } + public List Branches; + } + + public class BankBranch + { + public int BranchNumber { get; set; } + public String BranchCity { get; set; } + } +} diff --git a/BE/Enum.cs b/BE/Enum.cs index 177db34..ce7d756 100644 --- a/BE/Enum.cs +++ b/BE/Enum.cs @@ -27,10 +27,13 @@ public enum HostingType Zimmer, Hotel, Camping, RentingRoom } - public enum Requirements + public enum GestRequirements { Necessary, Possible, NotNecessary } - + public enum UnitRequirements + { + Available, NotAvailable + } } \ No newline at end of file diff --git a/BE/HostingUnit.cs b/BE/HostingUnit.cs index 95cdae2..b0611d8 100644 --- a/BE/HostingUnit.cs +++ b/BE/HostingUnit.cs @@ -15,20 +15,8 @@ public class HostingUnit : requirement public int HostingUnitKey { get; set; } public Host Owner { get; set; } public String HostingUnitName { get; set; } - - - [XmlIgnore] - //public bool[,] Diary { get; private set; } public List Diary { get; set; } - - //[XmlArray("Diary")] - //public bool[] DiaryDto - //{ - // get { return Diary.Flatten(); } - // set { Diary = value.Expand(12); } - //} - - + public HostingUnit() { Diary = new List(); diff --git a/BE/Order.cs b/BE/Order.cs index a862ebc..1a62505 100644 --- a/BE/Order.cs +++ b/BE/Order.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -19,6 +19,7 @@ public class Order public DateTime OrderDate { get; set; } public DateTime CreateDate { get; set; } + public OrderStatus Status { get; set; } public override string ToString() diff --git a/BE/requirement.cs b/BE/requirement.cs index 0d29c33..3ae55d0 100644 --- a/BE/requirement.cs +++ b/BE/requirement.cs @@ -10,22 +10,20 @@ namespace BE [Serializable] public class requirement { - public Area Area { get; set; } public String SubArea { get; set; } public HostingType HostingType { get; set; } - public int Adults { 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; } + public GestRequirements Pool { get; set; } + public GestRequirements Jacuzzi { get; set; } + public GestRequirements Garden { get; set; } + public GestRequirements ChildrensAttractions { get; set; } + public GestRequirements SpredBads { get; set; } + public GestRequirements AirCondsner { get; set; } + public GestRequirements frisider { get; set; } + public GestRequirements SingogNaerBy { get; set; } + public GestRequirements NaerPublicTrensportion { get; set; } /// /// to-string diff --git a/BL/FactorySingletonBL.cs b/BL/FactorySingletonBL.cs index 6cafef1..43a7d71 100644 --- a/BL/FactorySingletonBL.cs +++ b/BL/FactorySingletonBL.cs @@ -6,7 +6,7 @@ namespace BL { - public class FactorySingletonBL + public static class FactorySingletonBL { private static MyBl instance = null; diff --git a/BL/IBL.cs b/BL/IBL.cs index c6d6f1f..4710612 100644 --- a/BL/IBL.cs +++ b/BL/IBL.cs @@ -1,4 +1,4 @@ -using BE; +using BE; using System; using System.Collections.Generic; using System.Linq; @@ -11,6 +11,7 @@ interface IBL { bool IsDateCorrect(DateTime start, DateTime end); bool IsAccountCharged(Host host); + bool IsDateAvailable(DateTime start, DateTime end, int unitKey); void CloseOrder(Order order); void SendMail(Order order); @@ -22,6 +23,7 @@ interface IBL List OrdersUntilDate(int days); int OrdersPerClient(GuestRequest req); int OrdersPerUnit(HostingUnit unit); + bool AddGuestRequest(GuestRequest req); void AddHostingUnit(HostingUnit unit); IEnumerable GuestRequestBy(Func predicate = null); @@ -29,4 +31,5 @@ interface IBL double averageOrdersPerHostingUnit(); } -} \ No newline at end of file +} + diff --git a/BL/MyBl.cs b/BL/MyBl.cs index c9f0e8f..781a52b 100644 --- a/BL/MyBl.cs +++ b/BL/MyBl.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using BE; -using System.Reflection; - using DAL; using System.Net.Mail; using System.Net; @@ -14,24 +12,34 @@ namespace BL { public class MyBl : IBL { - DalXML myDAL = new DalXML(); - + + DalXML myDAL = FactorySingletonDal.Instance; + MailMessage mail; /// /// Add Guest Request /// public bool AddGuestRequest(GuestRequest req) { - - if (myDAL.ReturnGuestRequestList((x) => x.GuestRequestKey == req.GuestRequestKey).ToList().Count == 0) + if (IsDateCorrect(req.EntryDate, req.ReleaseDate)) { - myDAL.addGuestRequest(req); - return true; + + try + { + myDAL.addGuestRequest(req); + return true; + } + catch (Exception ex) + { + //throw new Exception("Fail to add this Guest Request! " + ex); + return false; + } } else { + //throw new Exception("can't add this request, Release Date before Entry Date!"); return false; } - + } /// @@ -39,14 +47,9 @@ public bool AddGuestRequest(GuestRequest req) /// 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!"); - } + } @@ -55,17 +58,38 @@ public void AddHostingUnit(HostingUnit unit) /// public bool AddOrder(Order neworder) { + try + { + var req = GetGusetRequest(neworder.GuestRequestKey); + var unit = GetHostingUnit(neworder.HostingUnitKey); - //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; + if (IsDateAvailable(req.EntryDate, req.ReleaseDate, neworder.HostingUnitKey)) + { + myDAL.addOrder(neworder); + for (var i = req.EntryDate; i <= req.ReleaseDate; i = i.AddDays(1)) + { + unit.Diary.Add(i); + + } + UpdateUnit(unit); + + return true; + } + else + { + return false; + } + + + } + catch (Exception) + { + + return false; + } + + + } /// @@ -95,9 +119,79 @@ public void CloseOrder(Order order) } } + + /// + /// Add new Host + /// + public bool AddHost(Host host) + { + + try + { + myDAL.addHost(host); + return true; + } + catch(Exception ex) + { + throw new Exception("Fail to add the host! "+ex); + } + + } + + /// + /// Update Host + /// + /// + public void UpdateHost(Host host) + { + try + { + myDAL.UpdateHost(host); + MessageBox.Show($"Host: {host.FamilyName} updated Seccessfuly!"); + } + catch (Exception ex) + { + MessageBox.Show($"Error during Update {host.FamilyName} please try again later! " + ex); + } + } + + /// + /// Remove Host and all is units + /// + /// public void RemoveHost(Host host) { - throw new NotImplementedException(); + //check if all the unit that blonge to this host can be deleted + foreach (var unit in myDAL.ReturnHostingUnitList(x => x.Owner.HostKey == host.HostKey)) + { + if (!CanUnitBeDeleted(unit.HostingUnitKey)) + { + throw new Exception("Can't delete the Host, whan some order still open in some of the units!"); + } + } + + //delete all the unit that blonge to this host + foreach (var unit in myDAL.ReturnHostingUnitList(x => x.Owner.HostKey == host.HostKey)) + { + try + { + UnitRemove(unit.HostingUnitKey); + } + catch (Exception ex) + { + throw new Exception("Fail to delete the Host " + ex); + } + } + + //delete the host + try + { + myDAL.DeleteHost(host); + } + catch (Exception ex) + { + throw new Exception("Fail to delete the Host, but delete all is HostingUnit " + ex); + } } /// @@ -108,7 +202,7 @@ 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)) + for (DateTime i = start; i < end; i = i.AddDays(1)) { if (x.Diary.FindIndex((z) => z == i) != -1) { @@ -125,12 +219,7 @@ public bool IsDateAvailable(DateTime start, DateTime end, int unitKey) /// public bool IsDateCorrect(DateTime start, DateTime end) { - return(end > start)? true:false; - } - - public void UpdateHost(Host host) - { - throw new NotImplementedException(); + return (end > start) ? true : false; } /// @@ -147,23 +236,7 @@ public int NumOfDays(DateTime date) 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 @@ -204,13 +277,9 @@ public int OrdersPerUnit(HostingUnit unit) /// 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!"); - } - } + if(!CanUnitBeDeleted(unitKey)) + throw new Exception("Can't delete this unit, whan some order still open!"); + HostingUnit hostingUnit = GetHostingUnit(Convert.ToInt32(unitKey)); try { @@ -218,8 +287,25 @@ public void UnitRemove(int unitKey) } catch (Exception ex) { - throw new Exception("" + ex); + throw new Exception("Fail to delete the unit! " + ex); + } + } + + /// + /// Can Unit Be Deleted? jest if no order that conected to this unit, have Status Untreated Yet! + /// + /// + /// + private bool CanUnitBeDeleted(int unitKey) + { + foreach (var order in myDAL.ReturenAllOrders()) + { + if ((order.HostingUnitKey == unitKey) && (order.Status == OrderStatus.MailSent)) + { + return false; + } } + return true; } /// @@ -230,8 +316,8 @@ public void UpdateUnit(HostingUnit hostingUnit) { try { - UnitRemove(hostingUnit.HostingUnitKey); - AddHostingUnit(hostingUnit); + + myDAL.UpdateHostingUnit(hostingUnit); MessageBox.Show($"Hosting unit: {hostingUnit.HostingUnitName} updated Seccessfuly!"); } catch (Exception ex) @@ -240,8 +326,6 @@ public void UpdateUnit(HostingUnit hostingUnit) } } - - /// /// Return all units available in given date range /// @@ -264,26 +348,7 @@ public List UintsAvailable(DateTime start, int numOfDays) 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 /// @@ -342,7 +407,7 @@ public List OrdersUntilDate(int days) /// GuestRequest GetGusetRequest(int key) { - return (myDAL.ReturnGuestRequestList(x => x.GuestRequestKey == key)).First(); + return (myDAL.ReturnGuestRequestList(x => x.GuestRequestKey == key)).FirstOrDefault(); } /// @@ -352,7 +417,18 @@ GuestRequest GetGusetRequest(int key) /// public HostingUnit GetHostingUnit(int key) { - return (myDAL.ReturnHostingUnitList(x => x.HostingUnitKey == key)).First(); + try + { + var unit = (myDAL.ReturnHostingUnitList(x => x.HostingUnitKey == key)).FirstOrDefault(); + return unit; + } + catch (Exception) + { + + MessageBox.Show("No Hosting Unit No Show"); + return new HostingUnit(); + } + } #endregion @@ -446,7 +522,7 @@ public Dictionary GuestRequestPerArea() { Area.South , GuestRequestBy().Count(p => p.Area == Area.South) } }; } - public Dictionary GuestRequestPerRquirement(Requirements requirements) + public Dictionary GuestRequestPerRquirement(GestRequirements requirements) { return new Dictionary { @@ -524,7 +600,7 @@ public IEnumerable GetGuestRequestKeysList(IEnumerable lis return result; } */ - + /// @@ -580,48 +656,38 @@ public double averageOrdersPerHostingUnit() /// /// BootingUp the progrem. - /// 1) Receive bank data from the web - /// 2) + /// 1)Refresh Database /// - public void bootingUp() + + + /// + /// run on Order database and if Month pass for Order and the status is mail-send it change to CloseByClientTimeOut + /// + public void RefreshDatabase() { + try { - Thread thread = new Thread(GetBankInfoFromTheWeb); - thread.Start(); + TimeSpan timeSpan = new TimeSpan(30, 0, 0, 0, 0); + var t = from order in GetOrders(x => (DateTime.Now - x.OrderDate) > timeSpan) + where order.Status == OrderStatus.MailSent + select order.Status = OrderStatus.CloseByClientTimeOut; } 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); - } + MessageBox.Show("Fail to refresh the database! \n " + ex.Message); } - + } - 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.To.Add(GuestRequestBy(x => x.GuestRequestKey == order.GuestRequestKey).First().MailAddress); + mail.To.Add((GetGusetRequest(order.GuestRequestKey).MailAddress).ToString()); mail.From = new MailAddress(GetHostingUnit(order.HostingUnitKey).Owner.MailAddress); mail.Subject = "Resort offeras as you request"; mail.Body = "

You'r request:

" + @@ -635,8 +701,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 = from; + smtp.Credentials = new System.Net.NetworkCredential("ipewzner@g.jct.ac.il", "Reptor17"); + // smtp.Credentials = from; smtp.EnableSsl = true; try @@ -657,16 +723,13 @@ public void SendMail(Order order) /// 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 = new MailMessage(); mail.To.Add(host.MailAddress); - // mail.From = new MailAddress("ipewzner@g.jct.ac.il"); - mail.From = new MailAddress(" dotnetproject2020 @gmail.com"); + mail.From = new MailAddress("dotnetproject2020@gmail.com"); mail.Subject = "New password - do not replay!"; mail.Body = "You'r new password is: " + password + @@ -678,16 +741,51 @@ public void SendMailWithNewPassword(Host host) smtp.Host = "smtp.gmail.com"; smtp.Credentials = new System.Net.NetworkCredential("dotnetproject2020@gmail.com", "kuku4ever"); smtp.EnableSsl = true; - try { - smtp.Send(mail); + // smtp.Send(mail); + string userState = "test message1"; + smtp.SendCompleted += Smtp_SendCompleted; + smtp.SendAsync(mail, userState); } - catch (Exception ex) + catch (SmtpFailedRecipientsException ex) { - throw new Exception("Email error " + ex); + MessageBox.Show(ex.Message+ " Can't send the message for one or more of the recipients"); } + catch (SmtpException ex) + { + MessageBox.Show(ex.Message + " Server conction error"); + } + catch (ArgumentNullException ex) + { + MessageBox.Show(ex.Message + " Message is empty"); + } + catch (InvalidOperationException ex) + { + MessageBox.Show(ex.Message + "Some info is missing or incorrect"); + } + + } + + private void Smtp_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) + { + String token = (string)e.UserState; + if (e.Cancelled) + { + MessageBox.Show(" Send canceled."+ token); + } + if (e.Error != null) + { + MessageBox.Show(""+ token+ e.Error.ToString()); + } + else + { + MessageBox.Show("Message sent."); + } + mail.Dispose(); + + //mailSent = true; } /// @@ -750,6 +848,17 @@ public double averageOrdersPerClient() } return sum; } - + + /// + /// Get Banks by predicate + /// + /// + /// + public IEnumerable GetBanks(Func predicate = null) + { + if (predicate == null) + return myDAL.ReturnAllLocelBank().AsEnumerable(); + return myDAL.ReturnAllLocelBank().Where(predicate); + } } } \ No newline at end of file diff --git a/DAL/DAL.csproj b/DAL/DAL.csproj index 4fa4a01..dc2a2a1 100644 --- a/DAL/DAL.csproj +++ b/DAL/DAL.csproj @@ -33,6 +33,7 @@ + diff --git a/DAL/DALImp.cs b/DAL/DALImp.cs index 6142aeb..5edb43e 100644 --- a/DAL/DALImp.cs +++ b/DAL/DALImp.cs @@ -8,7 +8,9 @@ namespace DAL { - public class DALImp : IDAL + + public class DALImp + { #region ///// Order ///// diff --git a/DAL/DalXML.cs b/DAL/DalXML.cs index a343493..8f9ffb4 100644 --- a/DAL/DalXML.cs +++ b/DAL/DalXML.cs @@ -1,32 +1,41 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; -using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Xml.Serialization; using BE; using DataSource; +using System.Net; +using System.Globalization; namespace DAL { - public class DalXML : IDAL + public class DalXML { - private static int serialGuestRequest; - private static int serialOrder; + private static Int64 serialGuestRequest; + private static Int64 serialOrder; + private static Int64 serialHost; // 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 + + GetAndStoreBankInfo(); + + serialOrder = Convert.ToInt64(DataSource.DataSourceXML.Orders.Element("lastSerial").Value); + serialGuestRequest = Convert.ToInt64(DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value); + serialHost = Convert.ToInt64(DataSource.DataSourceXML.Hosts.Element("lastSerial").Value); + } public bool addGuestRequest(GuestRequest gr) { XElement guestRequestElement = XElement.Parse(gr.ToXMLstring()); - DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value = guestRequestElement.Element("GuestRequestKey").Value; + guestRequestElement.Element("GuestRequestKey").Value = (++serialGuestRequest).ToString(); + DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value = serialGuestRequest.ToString(); DataSource.DataSourceXML.SaveGuestRequests(); DataSource.DataSourceXML.GuestRequests.Add(guestRequestElement); DataSource.DataSourceXML.SaveGuestRequests(); @@ -35,10 +44,14 @@ public bool addGuestRequest(GuestRequest gr) 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(); + + XElement hostElement = XElement.Parse(host.ToXMLstring()); + hostElement.Element("HostKey").Value = (++serialHost).ToString(); + DataSource.DataSourceXML.Hosts.Element("lastSerial").Value = serialHost.ToString(); DataSource.DataSourceXML.SaveHosts(); + DataSource.DataSourceXML.Hosts.Add(hostElement); + DataSource.DataSourceXML.SaveHosts(); + return true; } @@ -61,12 +74,13 @@ public bool addOrder(Order neworder) // //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()); + XElement OrderElement = XElement.Parse(neworder.ToXMLstring()); + OrderElement.Element("OrderKey").Value = (++serialOrder).ToString(); + DataSource.DataSourceXML.Orders.Element("lastSerial").Value = serialOrder.ToString(); DataSource.DataSourceXML.SaveOrders(); - DataSource.DataSourceXML.Orders.Element("lastSerial").Value = neworder.OrderKey.ToString(); + DataSource.DataSourceXML.Orders.Add(OrderElement); DataSource.DataSourceXML.SaveOrders(); + return true; } @@ -78,8 +92,28 @@ public List getAllGuestRequests() public List getAllHostingUnits() { - return (from o in DataSource.DataSourceXML.HostingUnits.Elements("HostingUnit") + var x = (from o in DataSource.DataSourceXML.HostingUnits.Elements("HostingUnit") select o.ToString().ToObject()).ToList(); + + var list = DataSourceXML.HostingUnits.Elements("HostingUnit").ToList(); + foreach (var item in x) + { + foreach (var k in list) + { + if (k.Element("HostingUnitKey").Value == item.HostingUnitKey.ToString()) + { + var dates = k.Element("Diary").Elements("DateTime").ToList(); + foreach (var v in dates) + { + DateTime date = DateTime.ParseExact(v.Value, "dd/MM/yyyy HH:mm:ss", CultureInfo.CurrentCulture); + item.Diary.Add(date); + } + + } + } + } + return x; + } public List getAllHosts() @@ -124,20 +158,68 @@ where Int32.Parse(o.Element("OrderKey").Value) == id } - public string getserialGuestRequest() + public bool DeleteHost(Host host) { - String result = DataSource.DataSourceXML.GuestRequests.Element("lastSerial").Value; - return result; - } + try + { + XElement hostElement = (from o in DataSourceXML.Hosts.Elements("Host") + where Int32.Parse(o.Element("HostKey").Value) == host.HostKey + select o).FirstOrDefault(); + if (hostElement != null) + { - public bool updateGuestRequest(GuestRequest guestRequest) - { - throw new NotImplementedException(); + hostElement.Remove(); + DataSourceXML.SaveHosts(); + + + } + return true; + + } + catch (Exception ex) + { + + throw new Exception("Fail to delete the Hosting-Unit " + ex); + } } - public bool updateHost(Host host) + public bool UpdateHost(Host host) { - throw new NotImplementedException(); + try + { + XElement hostElement = (from o in DataSourceXML.Hosts.Elements("Host") + where Int32.Parse(o.Element("HostKey").Value) == host.HostKey + select o).FirstOrDefault(); + if (hostElement != null) + { + hostElement.Element("PrivateName").Value = host.PrivateName.ToString(); + hostElement.Element("FamilyName").Value = host.FamilyName; + hostElement.Element("PhoneNumber").Value = host.PhoneNumber.ToString(); + hostElement.Element("MailAddress").Value = host.MailAddress.ToString(); + hostElement.Element("BankAccount").Element("BankNumber").Value = host.BankAccount.BankNumber.ToString(); + hostElement.Element("BankAccount").Element("BankName").Value = host.BankAccount.BankName.ToString(); + hostElement.Element("BankAccount").Element("BranchNumber").Value = host.BankAccount.BranchNumber.ToString(); + hostElement.Element("BankAccount").Element("BranchCity").Value = host.BankAccount.BranchCity.ToString(); + hostElement.Element("BankAccount").Element("BankAccountNumber").Value = host.BankAccount.BankAccountNumber.ToString(); + + + DataSourceXML.SaveHosts(); + + return true; + } + else + { + return false; + } + } + catch (Exception ex) + { + + Console.WriteLine(ex.Message); + return false; + } + + } public bool updateOrder(Order updateorder) @@ -150,15 +232,22 @@ where Int32.Parse(o.Element("OrderKey").Value) == updateorder.OrderKey { return false; } + else + { + + findOrder.Element("OrderKey").Value = updateorder.OrderKey.ToString(); + findOrder.Element("HostingUnitKey").Value = updateorder.HostingUnitKey.ToString(); + findOrder.Element("GuestRequestKey").Value = updateorder.GuestRequestKey.ToString(); + //findOrder.Element("OrderDate").Value = updateorder.OrderDate.ToString(); + //findOrder.Element("CreateDate").Value = updateorder.CreateDate.ToString(); + findOrder.Element("Status").Value = updateorder.Status.ToString(); + + DataSourceXML.SaveOrders(); + } return true; } - public void UpdateOrder(int OrderKey, OrderStatus status) - { - throw new NotImplementedException(); - } - #region ///// Order ///// @@ -235,10 +324,23 @@ public bool DeleteHostingUnit(HostingUnit hu) { try { - return DataSourceList.HostingUnits.Remove(hu); + XElement hostingUnits = (from o in DataSourceXML.HostingUnits.Elements("HostingUnit") + where Int32.Parse(o.Element("HostingUnitKey").Value) == hu.HostingUnitKey + select o).FirstOrDefault(); + if (hostingUnits != null) + { + + hostingUnits.Remove(); + DataSourceXML.SaveHostingUnits(); + + + } + return true; + } catch (Exception ex) { + throw new Exception("Fail to delete the Hosting-Unit " + ex); } } @@ -250,33 +352,48 @@ public bool DeleteHostingUnit(HostingUnit hu) /// public bool UpdateHostingUnit(HostingUnit hostingUnit) { - //Remove old try { - try - { - DataSourceList.HostingUnits.Remove(DataSourceList.HostingUnits.Find(x => x.HostingUnitKey == hostingUnit.HostingUnitKey)); - } - catch (Exception ex) + XElement hostingUnits = (from o in DataSourceXML.HostingUnits.Elements("HostingUnit") + where Int32.Parse(o.Element("HostingUnitKey").Value) == hostingUnit.HostingUnitKey + select o).FirstOrDefault(); + if (hostingUnits != null) { - throw new Exception("can't remove the old Hosting-Unit " + ex); - } + hostingUnits.Element("Area").Value = hostingUnit.Area.ToString(); + //hostingUnits.Element("SubArea").Value = hostingUnit.SubArea.ToString(); + hostingUnits.Element("HostingType").Value = hostingUnit.HostingType.ToString(); + hostingUnits.Element("Adults").Value = hostingUnit.Adults.ToString(); + hostingUnits.Element("Children").Value = hostingUnit.Children.ToString(); + hostingUnits.Element("Pool").Value = hostingUnit.Pool.ToString(); + hostingUnits.Element("Jacuzzi").Value = hostingUnit.Jacuzzi.ToString(); + hostingUnits.Element("Garden").Value = hostingUnit.Garden.ToString(); + hostingUnits.Element("ChildrensAttractions").Value = hostingUnit.ChildrensAttractions.ToString(); + hostingUnits.Element("SpredBads").Value = hostingUnit.SpredBads.ToString(); + hostingUnits.Element("AirCondsner").Value = hostingUnit.AirCondsner.ToString(); + hostingUnits.Element("frisider").Value = hostingUnit.frisider.ToString(); + hostingUnits.Element("SingogNaerBy").Value = hostingUnit.SingogNaerBy.ToString(); + hostingUnits.Element("NaerPublicTrensportion").Value = hostingUnit.NaerPublicTrensportion.ToString(); + hostingUnits.Element("Diary").Remove(); + var diary = new XElement("Diary", hostingUnit.Diary.Select(x => new XElement("DateTime", x.ToString()))); + hostingUnits.AddFirst(diary); + + DataSourceXML.SaveHostingUnits(); - //insert new - try - { - DataSourceList.HostingUnits.Add(Cloning.Copy(hostingUnit)); return true; } - catch (Exception ex) + else { - throw new Exception("can't add the new Hosting-Unit " + ex); + return false; } } catch (Exception ex) { - throw new Exception("Fail to update Hosting-Unit becuse it " + ex); + + Console.WriteLine(ex.Message); + return false; } + + } /// @@ -382,21 +499,121 @@ public void AddGuestRequestToList(GuestRequest gr) /// Return All Locel Bank /// /// - public IEnumerable ReturnAllLocelBank() + public IEnumerable ReturnAllLocelBank(Func predicate = null) { try { - return new List { "poelim", "marcntil", "laomi", "disceunt", "pagi" }; + if (predicate == null) + return DataSourceList.banks.AsEnumerable(); + return DataSourceList.banks.Where(predicate); } catch (Exception ex) { - throw new Exception("Fail to return the Locel-Bank list " + ex); - } - } + throw new Exception("Fail to retrieve the Guest-Request from the list " + ex); + }} #endregion + /// + /// GetBankInfoFromTheWeb + /// + public void GetAndStoreBankInfo() + { + //C:\Users\ipewz\Documents\GitHub\Mini_project_Windows_system + //const string xmlLocalPath = @"atm.xml"; + const string xmlLocalPath = @"ATM.xml"; + WebClient wc = new WebClient(); + Task.Run(() => + { + try + { + string xmlServerPath = @"http://www.jct.ac.il/~coshri/atm.xml"; + wc.DownloadFile(xmlServerPath, xmlLocalPath); + } + catch (Exception) + { + try + { + string xmlServerPath = + @"http://www.boi.org.il/he/BankingSupervision/BanksAndBranchLocations/Lists/BoiBankBranchesDocs/atm.xml"; + wc.DownloadFile(xmlServerPath, xmlLocalPath); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + + } + } + finally + { + wc.Dispose(); + } + + try + { + + XmlRootAttribute xRoot = new XmlRootAttribute(); + xRoot.ElementName = "ATMs"; + xRoot.IsNullable = true; + + XmlSerializer serializer = new XmlSerializer(typeof(List), xRoot); + + using (FileStream stream = File.OpenRead("ATM.xml")) + { + List dezerializedList = (List)serializer.Deserialize(stream); + stream.Close(); + foreach (var item in dezerializedList) + { + int findBank = DataSourceList.banks.FindIndex((x) => x.BankNumber == Convert.ToInt32(item.קוד_בנק)); + if (findBank == -1) + { + DataSourceList.banks.Add(new BankDetails { + BankName = item.שם_בנק, + BankNumber = Convert.ToInt32(item.קוד_בנק), + Branches = new List() + { + new BankBranch + { + BranchCity = item.ישוב, + BranchNumber = Convert.ToInt32(item.קוד_סניף) + + } + } + + }); + } + else + { + int findBranch = DataSourceList.banks[findBank].Branches.FindIndex((x) => x.BranchNumber == Convert.ToInt32(item.קוד_סניף)); + if (findBranch == -1) + { + DataSourceList.banks[findBank].Branches.Add(new BankBranch + { + BranchNumber = Convert.ToInt32( item.קוד_סניף), + BranchCity = item.ישוב + }); + } + } + } + + + } + } + catch (Exception ex) + { + // throw new Exception("Fail to return the Locel-Bank list " + ex); + //MessageBox.Show("fail to downlode banks file"); + + } + }); + + + } + + } } + + diff --git a/DAL/FactorySingletonDal.cs b/DAL/FactorySingletonDal.cs index 8fd010d..5dc5863 100644 --- a/DAL/FactorySingletonDal.cs +++ b/DAL/FactorySingletonDal.cs @@ -10,11 +10,11 @@ namespace DAL public static class FactorySingletonDal { - private static IDAL instance = null; + private static DalXML instance = null; static FactorySingletonDal() { } - public static IDAL Instance + public static DalXML Instance { get diff --git a/DAL/IDAL.cs b/DAL/IDAL.cs index 002df19..625c788 100644 --- a/DAL/IDAL.cs +++ b/DAL/IDAL.cs @@ -7,16 +7,22 @@ namespace DAL public interface IDAL { bool AddOrderToList(Order order); + bool AddHostingUnitToList(HostingUnit hostingUnit); void UpdateOrder(int OrderKey, OrderStatus status); - bool AddHostingUnitToList(HostingUnit hostingUnit); - bool DeleteHostingUnit(HostingUnit hostingUnit); - bool UpdateHostingUnit(HostingUnit hostingUnit); + bool UpdateHostingUnit(HostingUnit hostingUnit); + + bool DeleteHostingUnit(HostingUnit hostingUnit); + bool DeleteHost(Host host); + IEnumerable ReturnHostingUnitList(Func predicate = null); IEnumerable ReturnGuestRequestList(Func predicate = null); - IEnumerable ReturenAllOrders(Func predicate = null); + IEnumerable ReturenAllOrders(Func predicate = null); + IEnumerable ReturnAllLocelBank(Func predicate = null); + IEnumerable ReturnAllLocelBank(); + } } \ No newline at end of file diff --git a/DataSource/DataSourceList.cs b/DataSource/DataSourceList.cs index 364e620..5e42201 100644 --- a/DataSource/DataSourceList.cs +++ b/DataSource/DataSourceList.cs @@ -31,6 +31,8 @@ static public class DataSourceList + public static List banks = new List(); + public static List Hosts = new List(); public static List HostingUnits = new List(); diff --git a/DataSource/DataSourceXML.cs b/DataSource/DataSourceXML.cs index 5c88075..3e67272 100644 --- a/DataSource/DataSourceXML.cs +++ b/DataSource/DataSourceXML.cs @@ -117,6 +117,7 @@ public static XElement HostingUnits get { hostingUnitRoot = LoadData(hostingUnitPath); + return hostingUnitRoot; } } @@ -130,7 +131,7 @@ public static XElement GuestRequests } } - private static XElement LoadData(string path) + private static XElement LoadData(string path) { XElement root; try diff --git a/DataSource/DataXML/GuestRequestXml.xml b/DataSource/DataXML/GuestRequestXml.xml index d0fec14..b7b4211 100644 --- a/DataSource/DataXML/GuestRequestXml.xml +++ b/DataSource/DataXML/GuestRequestXml.xml @@ -1,7 +1,7 @@  - 10000005 - + 10000010 + Jerusalem old city Hotel @@ -97,4 +97,101 @@ 0001-01-01T00:00:00 0001-01-01T00:00:00 + + South + jhkjh + Zimmer + 0 + 0 + Possible + NotNecessary + Necessary + Possible + Possible + Necessary + Necessary + Possible + Possible + 10000007 + p + p + Open + ipewzner@g.jct.ac.il + 0001-01-01T00:00:00 + 2020-02-02T00:00:00+02:00 + 2020-01-01T00:00:00 + + + North + dfgdf + Zimmer + 0 + 0 + Necessary + Necessary + Necessary + NotNecessary + Necessary + Possible + Necessary + Necessary + Possible + 10000008 + dfgdfggdfg + d + dfg@dd.com + Open + 0001-01-01T00:00:00 + 2020-02-04T00:00:00 + 2020-02-29T00:00:00 + + + North + dfgfd + Zimmer + 0 + 0 + Necessary + Possible + Necessary + Possible + Possible + Necessary + Necessary + Possible + Possible + 10000009 + dfgdf + dfgdf + dfg@dd.com + Open + 0001-01-01T00:00:00 + 2020-02-14T00:00:00 + 2020-02-29T00:00:00 + + + + Jerusalem + ert + Zimmer + 0 + 0 + Possible + Necessary + Possible + NotNecessary + Necessary + Necessary + Necessary + Possible + Possible + 10000010 + meni + wer + meni3a@gmail.com + Open + 0001-01-01T00:00:00 + 2020-02-26T00:00:00 + 2020-02-29T00:00:00 + \ No newline at end of file diff --git a/DataSource/DataXML/HostXml.xml b/DataSource/DataXML/HostXml.xml index e2ce053..8e0042d 100644 --- a/DataSource/DataXML/HostXml.xml +++ b/DataSource/DataXML/HostXml.xml @@ -1,5 +1,6 @@  + 10000077 11111111 david @@ -7,11 +8,11 @@ 054-5555555 sale@gmai.com - 123 - poalim - 432 + 13 + בנק אגוד לישראל בע"מ + 75 jefo 121 - jeruselm + רעננה 11111111 @@ -23,11 +24,11 @@ 054-6666666 hotel@gmai.com - 123 - poalim - 432 + 54 + בנק ירושלים בע"מ + 96 jefo 121 - jeruselm + כרמיאל 11111112 @@ -49,9 +50,9 @@ - 0 - manster - frankinstin + 00000000 + admin + admin 666 hall 0 @@ -64,4 +65,49 @@ 85 + + 10000058 + poster + hoster + 3455 + sdfs@sd.co + -10.104273848989083 + + 14 + בנק אוצר החייל בע"מ + 322 + תל אביב -יפו + 345345 + + + + 10000074 + pewzner + iasayau + 0548410620 + ipewzner@gmail.com + 0.066778548244450411 + + 4 + בנק יהב לעובדי המדינה בע"מ + 125 + אשקלון + 520 + + + + 10000076 + harry + potter + 8 + fds@cd + -2.1442198634214571 + + 14 + בנק אוצר החייל בע"מ + 331 + אילת + 520 + + \ No newline at end of file diff --git a/DataSource/DataXML/HostingUnitXml.xml b/DataSource/DataXML/HostingUnitXml.xml index 0acd880..5162621 100644 --- a/DataSource/DataXML/HostingUnitXml.xml +++ b/DataSource/DataXML/HostingUnitXml.xml @@ -1,39 +1,8 @@  + 10000043 - 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 @@ -67,6 +36,24 @@ hotel hong-kong + + 14/02/2020 00:00:00 + 15/02/2020 00:00:00 + 16/02/2020 00:00:00 + 17/02/2020 00:00:00 + 18/02/2020 00:00:00 + 19/02/2020 00:00:00 + 20/02/2020 00:00:00 + 21/02/2020 00:00:00 + 22/02/2020 00:00:00 + 23/02/2020 00:00:00 + 24/02/2020 00:00:00 + 25/02/2020 00:00:00 + 26/02/2020 00:00:00 + 27/02/2020 00:00:00 + 28/02/2020 00:00:00 + 29/02/2020 00:00:00 + North Zimmer 0 @@ -100,171 +87,7 @@ 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 @@ -298,6 +121,7 @@ zimer of the Jerusalem + South Zimmer 0 @@ -331,27 +155,29 @@ zimer of the South + North - vc - Zimmer - 0 - 0 + + RentingRoom + 5 + 5 Necessary Necessary Necessary - Possible - Possible - Possible + Necessary + Necessary + Necessary Necessary - Possible + Necessary Necessary - 10000040 - + 10000028 + 33333333 dan danon 054-1010101 zimer@gmai.com + 0 525 laomi @@ -361,7 +187,7 @@ 1152582 - -vvvv + + zimer of the north \ No newline at end of file diff --git a/DataSource/DataXML/OrderXml.xml b/DataSource/DataXML/OrderXml.xml index 9a6920c..102ef99 100644 --- a/DataSource/DataXML/OrderXml.xml +++ b/DataSource/DataXML/OrderXml.xml @@ -1,28 +1,60 @@  - 10000009 - - 10000007 + 10000068 + + 10000062 10000003 - 10000001 - 2020-01-27T20:40:58.9922545+02:00 - 2020-01-27T20:40:58.9922545+02:00 + 10000010 + 2020-02-16T01:18:56.1279916+02:00 + 2020-02-16T01:18:56.1279916+02:00 MailSent - - 10000008 + + 10000063 10000003 - 10000001 - 2020-01-27T20:41:17.1073695+02:00 - 2020-01-27T20:41:17.1073695+02:00 + 10000010 + 2020-02-16T01:21:54.9935631+02:00 + 2020-02-16T01:21:54.9935631+02:00 MailSent - - 10000009 - 10000021 - 10000003 - 2020-01-27T21:34:06.2123047+02:00 - 2020-01-27T21:34:06.2123047+02:00 + + 10000064 + 10000003 + 10000010 + 2020-02-16T01:37:16.8911016+02:00 + 2020-02-16T01:37:16.8911016+02:00 + MailSent + + + 10000065 + 10000003 + 10000010 + 2020-02-16T01:44:05.461053+02:00 + 2020-02-16T01:44:05.461053+02:00 + MailSent + + + 10000066 + 10000003 + 10000010 + 2020-02-16T01:45:50.4350622+02:00 + 2020-02-16T01:45:50.4350622+02:00 + MailSent + + + 10000067 + 10000003 + 10000010 + 2020-02-16T01:47:34.6188963+02:00 + 2020-02-16T01:47:34.6188963+02:00 MailSent + + 10000068 + 10000003 + 10000009 + 2020-02-16T01:47:34.6188963+02:00 + 2020-02-16T01:47:34.6188963+02:00 + CloseByClientTimeOut + \ No newline at end of file diff --git a/DataSource/DataXML1/GuestRequestXml.xml b/DataSource/DataXML1/GuestRequestXml.xml index 7b866a5..b7b4211 100644 --- a/DataSource/DataXML1/GuestRequestXml.xml +++ b/DataSource/DataXML1/GuestRequestXml.xml @@ -1,42 +1,197 @@  - 1000001 + 10000010 - 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 + old city + Hotel 2 - 3 + 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 - 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 - 1000001 - dxs - EFG - GR@GG.GG - NotYetApproved + 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 - 2020-01-19T11:53:23.7121693+02:00 - 2020-01-21T11:53:23.7121693+02:00 + 0001-01-01T00:00:00 + 0001-01-01T00:00:00 + + Jerusalem - asd + 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 + + + South + jhkjh Zimmer - 55 - 54 + 0 + 0 + Possible + NotNecessary + Necessary + Possible + Possible + Necessary + Necessary + Possible + Possible + 10000007 + p + p + Open + ipewzner@g.jct.ac.il + 0001-01-01T00:00:00 + 2020-02-02T00:00:00+02:00 + 2020-01-01T00:00:00 + + + North + dfgdf + Zimmer + 0 + 0 Necessary Necessary Necessary - Necessary + NotNecessary + Necessary + Possible + Necessary + Necessary + Possible + 10000008 + dfgdfggdfg + d + dfg@dd.com + Open + 0001-01-01T00:00:00 + 2020-02-04T00:00:00 + 2020-02-29T00:00:00 + + + North + dfgfd + Zimmer + 0 + 0 + Necessary + Possible + Necessary + Possible + Possible + Necessary + Necessary + Possible + Possible + 10000009 + dfgdf + dfgdf + dfg@dd.com + Open + 0001-01-01T00:00:00 + 2020-02-14T00:00:00 + 2020-02-29T00:00:00 + + + + Jerusalem + ert + Zimmer + 0 + 0 + Possible + Necessary + Possible + NotNecessary + Necessary + Necessary + Necessary + Possible + Possible + 10000010 + meni + wer + meni3a@gmail.com + Open + 0001-01-01T00:00:00 + 2020-02-26T00:00:00 + 2020-02-29T00:00:00 \ No newline at end of file diff --git a/DataSource/DataXML1/HostXml.xml b/DataSource/DataXML1/HostXml.xml index 9dfb370..8e0042d 100644 --- a/DataSource/DataXML1/HostXml.xml +++ b/DataSource/DataXML1/HostXml.xml @@ -1,30 +1,113 @@  + 10000077 - 123 - d ca suffit - qwere - 3324 - daas@hhh.jjj - 3123 - Yes + 11111111 + david + cohn + 054-5555555 + sale@gmai.com + + 13 + בנק אגוד לישראל בע"מ + 75 + jefo 121 + רעננה + 11111111 + + - 5555 - qwre - adsa - 232 - fdsf - 12321 - Yes + 22222222 + moses + levi + 054-6666666 + hotel@gmai.com + + 54 + בנק ירושלים בע"מ + 96 + jefo 121 + כרמיאל + 11111112 + + - 1424 - buffalo - Falery Chisqkar Destin - 052 - aaaa@gmail.com - 15141 - Maybe + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + + + 00000000 + admin + admin + 666 + hall + 0 + + 852 + + 852 + + + 85 + + + + 10000058 + poster + hoster + 3455 + sdfs@sd.co + -10.104273848989083 + + 14 + בנק אוצר החייל בע"מ + 322 + תל אביב -יפו + 345345 + + + + 10000074 + pewzner + iasayau + 0548410620 + ipewzner@gmail.com + 0.066778548244450411 + + 4 + בנק יהב לעובדי המדינה בע"מ + 125 + אשקלון + 520 + + + + 10000076 + harry + potter + 8 + fds@cd + -2.1442198634214571 + + 14 + בנק אוצר החייל בע"מ + 331 + אילת + 520 + \ No newline at end of file diff --git a/DataSource/DataXML1/HostingUnitXml.xml b/DataSource/DataXML1/HostingUnitXml.xml index d28178a..5162621 100644 --- a/DataSource/DataXML1/HostingUnitXml.xml +++ b/DataSource/DataXML1/HostingUnitXml.xml @@ -1,2 +1,193 @@  - \ No newline at end of file + + 10000043 + + + 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 + + + + 14/02/2020 00:00:00 + 15/02/2020 00:00:00 + 16/02/2020 00:00:00 + 17/02/2020 00:00:00 + 18/02/2020 00:00:00 + 19/02/2020 00:00:00 + 20/02/2020 00:00:00 + 21/02/2020 00:00:00 + 22/02/2020 00:00:00 + 23/02/2020 00:00:00 + 24/02/2020 00:00:00 + 25/02/2020 00:00:00 + 26/02/2020 00:00:00 + 27/02/2020 00:00:00 + 28/02/2020 00:00:00 + 29/02/2020 00:00:00 + + 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 + + + + 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 + + RentingRoom + 5 + 5 + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + Necessary + 10000028 + + 33333333 + dan + danon + 054-1010101 + zimer@gmai.com + 0 + + 525 + laomi + 852 + gargmel 1010 + heifa + 1152582 + + + + zimer of the north + + \ No newline at end of file diff --git a/DataSource/DataXML1/OrderXml.xml b/DataSource/DataXML1/OrderXml.xml index 00457dc..102ef99 100644 --- a/DataSource/DataXML1/OrderXml.xml +++ b/DataSource/DataXML1/OrderXml.xml @@ -1,28 +1,60 @@  - 25 - - 23 - 10000010 - 10000025 - 30/12/2019 16:52:25 - 02/01/2020 16:52:25 - NotYetApproved + 10000068 + + 10000062 + 10000003 + 10000010 + 2020-02-16T01:18:56.1279916+02:00 + 2020-02-16T01:18:56.1279916+02:00 + MailSent - - 24 - 12123 - 10000005 - 30/12/2019 16:52:25 - 02/01/2020 16:52:25 - NotYetApproved + + 10000063 + 10000003 + 10000010 + 2020-02-16T01:21:54.9935631+02:00 + 2020-02-16T01:21:54.9935631+02:00 + MailSent - - 25 - 12123 - 10000005 - 30/12/2019 16:52:25 - 02/01/2020 16:52:25 - NotYetApproved + + 10000064 + 10000003 + 10000010 + 2020-02-16T01:37:16.8911016+02:00 + 2020-02-16T01:37:16.8911016+02:00 + MailSent + + + 10000065 + 10000003 + 10000010 + 2020-02-16T01:44:05.461053+02:00 + 2020-02-16T01:44:05.461053+02:00 + MailSent + + + 10000066 + 10000003 + 10000010 + 2020-02-16T01:45:50.4350622+02:00 + 2020-02-16T01:45:50.4350622+02:00 + MailSent + + + 10000067 + 10000003 + 10000010 + 2020-02-16T01:47:34.6188963+02:00 + 2020-02-16T01:47:34.6188963+02:00 + MailSent + + + 10000068 + 10000003 + 10000009 + 2020-02-16T01:47:34.6188963+02:00 + 2020-02-16T01:47:34.6188963+02:00 + CloseByClientTimeOut \ No newline at end of file diff --git a/Mini_project_Windows_system.sln b/Mini_project_Windows_system.sln index cc87050..e93b263 100644 --- a/Mini_project_Windows_system.sln +++ b/Mini_project_Windows_system.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.902 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29728.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BE", "BE\BE.csproj", "{6E73959A-2CC3-4F9A-B557-A9A948B98E7D}" ProjectSection(ProjectDependencies) = postProject @@ -29,8 +29,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataSource", "DataSource\Da {6E73959A-2CC3-4F9A-B557-A9A948B98E7D} = {6E73959A-2CC3-4F9A-B557-A9A948B98E7D} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PL", "PL\PL.csproj", "{7F42FED6-B07C-4A84-A4FF-9724DC2F55CF}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PLWPF", "PLWPF\PLWPF.csproj", "{4A8084A7-77A5-4B18-81A2-36400FD55656}" EndProject Global @@ -59,10 +57,6 @@ Global {17B32229-1FE2-45B8-877F-BE87BA1D46EB}.Debug|Any CPU.Build.0 = Debug|Any CPU {17B32229-1FE2-45B8-877F-BE87BA1D46EB}.Release|Any CPU.ActiveCfg = Release|Any CPU {17B32229-1FE2-45B8-877F-BE87BA1D46EB}.Release|Any CPU.Build.0 = Release|Any CPU - {7F42FED6-B07C-4A84-A4FF-9724DC2F55CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7F42FED6-B07C-4A84-A4FF-9724DC2F55CF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7F42FED6-B07C-4A84-A4FF-9724DC2F55CF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7F42FED6-B07C-4A84-A4FF-9724DC2F55CF}.Release|Any CPU.Build.0 = Release|Any CPU {4A8084A7-77A5-4B18-81A2-36400FD55656}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A8084A7-77A5-4B18-81A2-36400FD55656}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A8084A7-77A5-4B18-81A2-36400FD55656}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/PLWPF/App.xaml b/PLWPF/App.xaml index ee20f97..c9ab971 100644 --- a/PLWPF/App.xaml +++ b/PLWPF/App.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PLWPF" - StartupUri="MainWindow.xaml"> + StartupUri="SplashScreenWindow.xaml"> diff --git a/PLWPF/App.xaml.cs b/PLWPF/App.xaml.cs index 7e8cf5a..9733b32 100644 --- a/PLWPF/App.xaml.cs +++ b/PLWPF/App.xaml.cs @@ -1,8 +1,11 @@ -using System; +using BL; +using PLWPF.Windows; +using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -13,5 +16,6 @@ namespace PLWPF /// public partial class App : Application { + } -} +} \ No newline at end of file diff --git a/PLWPF/HostUpdateWindow.xaml b/PLWPF/HostUpdateWindow.xaml index d9aef88..3081225 100644 --- a/PLWPF/HostUpdateWindow.xaml +++ b/PLWPF/HostUpdateWindow.xaml @@ -4,8 +4,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:PLWPF" + Closed="Window_Closed" mc:Ignorable="d" - Title="HostUpdateWindow" Height="500" Width="800"> + Title="HostUpdateWindow" Height="600" Width="800"> diff --git a/PLWPF/HostUpdateWindow.xaml.cs b/PLWPF/HostUpdateWindow.xaml.cs index 557046d..d18915d 100644 --- a/PLWPF/HostUpdateWindow.xaml.cs +++ b/PLWPF/HostUpdateWindow.xaml.cs @@ -1,17 +1,6 @@ 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 { @@ -20,11 +9,27 @@ namespace PLWPF ///
public partial class HostUpdateWindow : Window { - public HostUpdateWindow(Host host) + + public bool HostDeleted { set; get; } + HostUserControl hostUserControl; + + Window mainWindow; + public HostUpdateWindow(Host host,Window mainWindow) { + + this.mainWindow = mainWindow; + mainWindow.Hide(); InitializeComponent(); - UpdateHostFrame.Content = new HostUserControl(host,false); - DeleteHostFrame.Content = new HostUserControl(host,true); + UpdateHostFrame.Content = new HostUserControl(host,false,this); + hostUserControl = new HostUserControl(host, true, this); + DeleteHostFrame.Content = hostUserControl; + + } + + private void Window_Closed(object sender, EventArgs e) + { + HostDeleted = hostUserControl.HostDeleted ; + mainWindow.Visibility = Visibility.Visible; } } } diff --git a/PLWPF/HostUserControl.xaml b/PLWPF/HostUserControl.xaml index de55241..0878d57 100644 --- a/PLWPF/HostUserControl.xaml +++ b/PLWPF/HostUserControl.xaml @@ -8,40 +8,42 @@ d:DesignHeight="450" d:DesignWidth="513.6"> -
public partial class HostUserControl : UserControl { + public bool HostDeleted { set; get; } MyBl myBL = new MyBl(); bool newHost, deleteHost; Host host; BankAccount bankAccount; + Window win; - public HostUserControl(Host hosts, bool deleteHost) + public HostUserControl(Host hosts, bool deleteHost, Window win) { + this.win = win ; InitializeComponent(); + DataContext = this; + Banks = myBL.GetBanks(); + //if this not a new host if (hosts != null) { host = hosts; bankAccount = host.BankAccount; + this.deleteHost = deleteHost; FillTheFeilds(); } else { newHost = true; } - this.deleteHost = deleteHost; - - ContinueButton.Content = (deleteHost==true)?"Delete":"Save"; - - } private void FillTheFeilds() { - FamilyNameTextBox.Text= host.FamilyName; + + FamilyName.Text= host.FamilyName; PrivateName.Text= host.PrivateName; PhoneNumber.Text= host.PhoneNumber ; MailAddress.Text= host.MailAddress ; - - Bank_ComboBox.Text=bankAccount.BankName; - BranchCity_ComboBox.Text= bankAccount.BranchCity; - BranchAddress_ComboBox.Text= bankAccount.BranchAddress; - BankNumber.Text= bankAccount.BankNumber .ToString() ; - BranchNumber.Text= bankAccount.BranchNumber .ToString() ; - BankAccountNumber.Text=bankAccount.BankAccountNumber.ToString() ; + + + BranchCity.Text= bankAccount.BranchCity; + //BranchAddress.Text= bankAccount.BranchAddress; + BankNumber.Text= bankAccount.BankNumber .ToString(); + BranchNumber_ComboBox.SelectedItem = bankAccount.BranchNumber.ToString(); + BankAccountNumber.Text=bankAccount.BankAccountNumber.ToString(); + } + + void bank_loaded(object sender, RoutedEventArgs e) + { + if(!newHost) + SetBankData(); + + } + + void SetBankData() + { + foreach (var item in Banks) + { + //if !new user + if (item.BankName == bankAccount.BankName) + { + Bank_ComboBox.SelectedItem = item; + + foreach (var k in item.Branches) + { + if (k.BranchNumber == bankAccount.BranchNumber) + { + BranchNumber_ComboBox.SelectedItem = k; + } + } + + } + } } -/// -/// check password Match -/// -/// -/// -private void PasswordChanged(object sender, RoutedEventArgs e) + /// + /// check password Match + /// + /// + /// + private void PasswordChanged(object sender, RoutedEventArgs e) { if ((FirstPassword.PasswordHidden.Password) != (SecundPassword.PasswordHidden.Password)) { @@ -82,76 +107,185 @@ private void PasswordChanged(object sender, RoutedEventArgs e) private void CancelChanges_PreviewMouseDown(object sender, MouseButtonEventArgs e) { - if (!newHost) FillTheFeilds(); - else { - FamilyNameTextBox.Text =null; + if (!newHost) + { + FillTheFeilds(); + SetBankData(); + } + else + { + FamilyName.Text = null; PrivateName.Text = null; PhoneNumber.Text = null; MailAddress.Text = null; Bank_ComboBox.Text = null; - BranchCity_ComboBox.Text = null; - BranchAddress_ComboBox.Text =null; - BankNumber.Text = null; - BranchNumber.Text = null; + BranchCity.Text = null; + //BranchAddress_ComboBox.Text =null; + BankNumber.Text = null; + BranchNumber_ComboBox.Text = null; BankAccountNumber.Text = null; } } private void Continue_Click(object sender, RoutedEventArgs e) { - if (deleteHost) + if (!IsValidEmail(MailAddress.Text)) { - try { myBL.RemoveHost(host); } - catch (Exception ex) { throw new Exception(""+ex); } - MessageBox.Show("Host remove seccessfully"); + MessageBox.Show("Error in mail format please try again"); + } + else if (!IsTextValid(PrivateName.Text)) + { + MessageBox.Show("error in Private Name format"); + } + else if (!IsTextValid(FamilyName.Text)) + { + MessageBox.Show("error in Family Name Name format"); + } + else if (!IsPhoneNumberValid(PhoneNumber.Text)) + { + MessageBox.Show("error in Phone Number format"); + } + else if (!IsBankAccountValid(BankAccountNumber.Text)) + { + MessageBox.Show("error in Bank Account Number format"); + } + else if (!IspasswordValid(FirstPassword.Content.ToString())) + { + MessageBox.Show("error in password Number format"); } else { - try + if (deleteHost) { - if (newHost) - { - host = new Host(); - bankAccount = new BankAccount(); - host.FamilyName = FamilyNameTextBox.Text; - + try { + MessageBoxResult result = MessageBox.Show("Are you sure\n?", "Delete Host", MessageBoxButton.YesNo, MessageBoxImage.Warning); + if (result == MessageBoxResult.Yes) + { + myBL.RemoveHost(host); + } } - - host.PrivateName = PrivateName.Text; - host.PhoneNumber = PhoneNumber.Text; - host.MailAddress = MailAddress.Text; - if (FirstPassword.PasswordHidden.Password != null) + catch (Exception ex) { - host.PasswordKey = myBL.KeyForPassword(Int32.Parse(FirstPassword.PasswordHidden.Password)); + MessageBox.Show("Unable to delete host"); + Console.WriteLine("Unable to delete host" + ex.Message); } + MessageBox.Show("Host remove seccessfully"); + HostDeleted = true; + win.DialogResult = true; + win.Close(); + } + else + { + try + { + if (newHost) + { + host = new Host(); + bankAccount = new BankAccount(); + //host.FamilyName = FamilyNameTextBox.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.FamilyName = FamilyName.Text; + host.PrivateName = PrivateName.Text; + host.PhoneNumber = PhoneNumber.Text; + host.MailAddress = MailAddress.Text; + if (FirstPassword.PasswordHidden.Password != null) + { + host.PasswordKey = myBL.KeyForPassword(Int32.Parse(FirstPassword.PasswordHidden.Password)); + } + + bankAccount.BankName = ((BankDetails)Bank_ComboBox.SelectedItem).BankName; + bankAccount.BranchCity = BranchCity.Text; + //bankAccount.BranchAddress = BranchAddress_ComboBox.Text; + bankAccount.BankNumber = Convert.ToInt32(BankNumber.Text); + bankAccount.BranchNumber = ((BankBranch)BranchNumber_ComboBox.SelectedItem).BranchNumber; + bankAccount.BankAccountNumber = Convert.ToInt32(BankAccountNumber.Text); - host.BankAccount = bankAccount; + host.BankAccount = bankAccount; - if (newHost) - { - if (myBL.AddHost(host)) - MessageBox.Show("Recived Seccessfully"); - else MessageBox.Show("Error! Make sure you dont miss any field!"); + if (newHost) + { + if (myBL.AddHost(host)) + { + MessageBox.Show("Recived Seccessfully"); + win.Close(); + + } + + else MessageBox.Show("Error! Make sure you dont miss any field!"); + } + else + { + try { myBL.UpdateHost(host); } + catch (Exception ex) + { + + MessageBox.Show("Unable to update host"); + Console.WriteLine("Unable to update host" + ex.Message); + } + } } - else + catch (Exception ex) { - try { myBL.UpdateHost(host); } - catch (Exception ex) { throw new Exception("" + ex); } + MessageBox.Show("Fail!"); + Console.WriteLine(ex.Message); } } - catch (Exception ex) - { - MessageBox.Show("Fail! "+ex); - } } + + + } + + public IEnumerable Banks { get; set; } + public string selectedBank { get; set; } + + private void Bank_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (Bank_ComboBox.SelectedIndex != -1) + BranchNumber_ComboBox.ItemsSource = (Banks.ElementAt(Bank_ComboBox.SelectedIndex).Branches); + BranchNumber_ComboBox.DisplayMemberPath = "BranchNumber"; + //Branches = new ObservableCollection((Banks.ElementAt(Bank_ComboBox.SelectedIndex).Branches)); + if(Bank_ComboBox.SelectedIndex!=-1) + BankNumber.Text = Banks.ElementAt(Bank_ComboBox.SelectedIndex).BankNumber.ToString(); + } + + private void BranchNumber_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if(Bank_ComboBox.SelectedIndex!=-1&&BranchNumber_ComboBox.SelectedIndex != -1) + BranchCity.Text = Banks.ElementAt(Bank_ComboBox.SelectedIndex).Branches.ElementAt(BranchNumber_ComboBox.SelectedIndex).BranchCity; + } + + + public static bool IsValidEmail(string emailAddress) + { + var regex = @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z"; + bool isValid = Regex.IsMatch(emailAddress, regex, RegexOptions.IgnoreCase); + return isValid; + } + + public static bool IsTextValid(string text) + { + var regex = "^[A-Z][a-zA-Z]*$"; + bool isValid = Regex.IsMatch(text, regex, RegexOptions.IgnoreCase); + return isValid; + } + + public static bool IsPhoneNumberValid(string text) + { + var regex = @"\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})"; + bool isValid = Regex.IsMatch(text, regex, RegexOptions.IgnoreCase); + return isValid; + } + public static bool IsBankAccountValid(string input) + { + double x; + return double.TryParse(input, out x) && x >= 0 && x <= 99999999; + } + public static bool IspasswordValid(string input) + { + double x; + return double.TryParse(input, out x) && x >= 10000000 && x <= 99999999; } } } diff --git a/PLWPF/MainWindow.xaml b/PLWPF/MainWindow.xaml index 3e886f6..b5ebe79 100644 --- a/PLWPF/MainWindow.xaml +++ b/PLWPF/MainWindow.xaml @@ -3,16 +3,24 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:PLWPF" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="800"> + Closed="Window_Closed" + Title="MainWindow" Height="450" Width="800" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> -
public partial class MainWindow : Window { + Host host = null; MyBl myBL = new MyBl(); - + /// + /// c-tor + /// public MainWindow() { - myBL.bootingUp(); - - InitializeComponent(); - //preCode preCode = new preCode(); - //preCode.initialize(); + InitializeComponent (); + } + /// + /// AddRequest_Click event call AddRequestWindow + /// + /// + /// private void AddRequest_Click(object sender, RoutedEventArgs e) { - //Task t = new Task(() => { }); Window win = new AddRequestWindow(); - win.Show(); - + win.Show(); } + /// + /// HostingUnit_Click event call HostingUnitWindow + /// + /// + /// private void HostingUnit_Click(object sender, RoutedEventArgs e) { if (host != null) { - Window win = new HostingUnitWindow(host); - win.Show(); - Window win2 = new HostUpdateWindow(host); - win2.Show(); + Window win = new HostingUnitWindow(host,this); + win.Show(); } else MessageBox.Show("Select User Or Sign Up"); } + /// + /// Orders_Click event call OrdersWindow + /// + /// + /// private void Orders_Click(object sender, RoutedEventArgs e) { if (host != null) @@ -53,14 +65,64 @@ private void Orders_Click(object sender, RoutedEventArgs e) else MessageBox.Show("Select User Or Sign Up"); } + /// + /// Stat_Click event call StatisticsWindow + /// + /// + /// private void Stat_Click(object sender, RoutedEventArgs e) { Window win = new StatisticsWindow(); win.Show(); } + /// + /// ShowInfo_Click event call ShowInfoWindow + /// + /// + /// + private void ShowInfo_Click(object sender, RoutedEventArgs e) + { + Window win = new Windows.ShowInfoWindows.ShowInfoWindow(); + win.Show(); + } - private void Button_Click(object sender, RoutedEventArgs e) + /// + /// editHost_Click event call HostUpdateWindow + /// + /// + /// + private void editHost_Click(object sender, RoutedEventArgs e) + { + HostUpdateWindow win = new HostUpdateWindow(host,this); + win.ShowDialog(); + + if (win.DialogResult == true) + { + if (win.HostDeleted) + LogOut(); + } + } + /// + /// log out and handle visbility acording + /// + public void LogOut() { + host = null; + user.Content = ""; + guestButton.Visibility = Visibility.Visible; + orderButton.Visibility = Visibility.Hidden; + editUnitButton.Visibility = Visibility.Hidden; + editHostButton.Visibility = Visibility.Hidden; + //statButton.Visibility = Visibility.Hidden; + ShowInfoButton.Visibility = Visibility.Hidden; + } + + /// + /// Button_Click event call LogInWindow and handle visibility of some window + /// + /// + /// + private void LogIn_Click(object sender, RoutedEventArgs e) { try { @@ -68,8 +130,29 @@ private void Button_Click(object sender, RoutedEventArgs e) win.ShowDialog(); if (win.DialogResult == true) { + host = win.HostfromLogin; user.Content = host.PrivateName + " " + host.FamilyName; + guestButton.Visibility = Visibility.Hidden; + logout.Visibility = Visibility.Visible; + if (host.HostKey == 00000000) + { + orderButton.Visibility = Visibility.Hidden; + editUnitButton.Visibility = Visibility.Hidden; + editHostButton.Visibility = Visibility.Hidden; + ShowInfoButton.Visibility = Visibility.Visible; + //statButton.Visibility = Visibility.Visible; + } + else + { + ShowInfoButton.Visibility = Visibility.Hidden; + //statButton.Visibility = Visibility.Hidden; + orderButton.Visibility = Visibility.Visible; + editUnitButton.Visibility = Visibility.Visible; + editHostButton.Visibility = Visibility.Visible; + // statButton.Visibility = Visibility.Hidden; + + } } } catch (Exception) @@ -80,5 +163,25 @@ private void Button_Click(object sender, RoutedEventArgs e) } } + + /// + /// LogOut_Click event logOut and change visibility of some windows + /// + /// + /// + private void LogOut_Click(object sender, RoutedEventArgs e) + { + LogOut(); + } + + /// + /// When the main window closed, exit the environment + /// + /// + /// + private void Window_Closed(object sender, EventArgs e) + { + Environment.Exit(Environment.ExitCode); + } } } diff --git a/PLWPF/PLWPF.csproj b/PLWPF/PLWPF.csproj index 1849ebb..cada895 100644 --- a/PLWPF/PLWPF.csproj +++ b/PLWPF/PLWPF.csproj @@ -14,6 +14,21 @@ 4 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -68,10 +83,33 @@ Password.xaml - + + SplashScreenWindow.xaml + HostingUnitUserControl.xaml + + HostInfoPage.xaml + + + OrderInfoPage.xaml + + + RequestInfoPage.xaml + + + ShowInfoWindow.xaml + + + UnitInfoPage.xaml + + + checker.xaml + + + GraphBarsUserControl.xaml + GuestRequestQueryPage.xaml @@ -117,10 +155,42 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -236,5 +306,22 @@ BL + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + + + \ No newline at end of file diff --git a/PLWPF/SplashScreenWindow.xaml b/PLWPF/SplashScreenWindow.xaml new file mode 100644 index 0000000..94bc56d --- /dev/null +++ b/PLWPF/SplashScreenWindow.xaml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/PLWPF/SplashScreenWindow.xaml.cs b/PLWPF/SplashScreenWindow.xaml.cs new file mode 100644 index 0000000..be64855 --- /dev/null +++ b/PLWPF/SplashScreenWindow.xaml.cs @@ -0,0 +1,80 @@ +using BL; +using System; +using System.Threading; +using System.Windows; + +namespace PLWPF +{ + /// + /// Interaction logic for SplashScreenWindow.xaml + /// + public partial class SplashScreenWindow : Window + { + Thread thread; + MainWindow mainwindow = new MainWindow(); + MyBl myBL = new MyBl(); + + /// + /// c-tor + /// + public SplashScreenWindow() + { + InitializeComponent(); + + try + { + thread = new Thread(doWork) { IsBackground = true }; + thread.Start(); + } + catch (Exception ex){MessageBox.Show("" + ex.Message);} + } + + + /// + /// Refresh the Database and close the window when it finise or when 10 sec pass, the leteset + /// + public void doWork() + { + Action closingTheWindow =()=> this.Close(); + Action RefreshingInfoLabel = () => InfoLabel.Content = "Initialize"; + + TimeSpan dalta = new TimeSpan(0, 0, 0, 1); + DateTime bagin = DateTime.Now; + try { myBL.RefreshDatabase(); } + catch (Exception ex) { throw new Exception(""+ex); } + finally + { + Dispatcher.BeginInvoke(RefreshingInfoLabel); + + //Wait for a the minimel time of 10 sec + while (DateTime.Now - bagin < dalta) { } + Dispatcher.BeginInvoke(closingTheWindow); + } + + } + + /// + /// Window Closed event thet show the main window and handle the progres bar (it not properly without it) + /// + /// + /// + private void Window_Closed(object sender, EventArgs e) + { + thread.Abort(); + mainwindow.Show(); + Progress.IsIndeterminate = false; + } + + /// + /// handle the progres bar (it not work without it) + /// + /// + /// + private void Window_ContentRendered(object sender, EventArgs e) + { + Progress.Visibility = Visibility.Visible; + Progress.IsIndeterminate = true; + } + } +} + \ No newline at end of file diff --git a/PLWPF/Windows/AddRequestWindow.xaml b/PLWPF/Windows/AddRequestWindow.xaml index ec67e35..32d21da 100644 --- a/PLWPF/Windows/AddRequestWindow.xaml +++ b/PLWPF/Windows/AddRequestWindow.xaml @@ -12,13 +12,13 @@