public override bool Equals(object obj) { if (obj == null) { return(false); } if (this.GetType() != obj.GetType()) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (this.GetHashCode() != obj.GetHashCode()) { return(false); } System.Diagnostics.Debug.Assert(base.GetType() != typeof(object)); // check base.Equals() if base overides Equals() if (!base.Equals(obj)) { return(false); } Zbor zbor = obj as Zbor; return(this.cost == zbor.cost && this.nrLocuriDisponibile == zbor.nrLocuriDisponibile && this.NumarLocuri == zbor.NumarLocuri); }
public void SetZbor(Zbor zbor) { dateAterizare.Value = zbor.TimpAterizare; dateDecolare.Value = zbor.TimpDecolare; numericCost.Value = (decimal)zbor.Cost; numericNrLocuri.Value = zbor.LocuriDisponibile; }
public bool AdaugaZbor(RutaAeriana rutaAeriana, Zbor zbor, Hashtable rezervari) { if (rutaAeriana == null || zbor == null || rezervari == null) { throw new ArgumentNullException(); } if (rute.TryGetValue(rutaAeriana, out var zboruri)) { if (zboruri.ContainsKey(ExtractDate(zbor.TimpDecolare))) { try { zboruri[ExtractDate(zbor.TimpDecolare)].Add(zbor, rezervari); return(true); } catch (ArgumentException) { return(false); } } else { zboruri.Add(ExtractDate(zbor.TimpDecolare), new SortedDictionary <Zbor, Hashtable>()); zboruri[ExtractDate(zbor.TimpDecolare)].Add(zbor, rezervari); return(true); } } else { return(false); } }
public object Clone() { Rezervare rez = (Rezervare)this.MemberwiseClone(); rez.RutaAeriana = (RutaAeriana)RutaAeriana.Clone(); rez.Zbor = (Zbor)Zbor.Clone(); rez.Rezervant = (Persoana)Rezervant.Clone(); return(rez); }
public virtual float ApplyDiscount(Rezervare rezervare, Zbor zbor) { if (rezervare == null || zbor == null) { throw new ArgumentNullException(); } else { return(Discount(rezervare, zbor)); } }
protected override float Discount(Rezervare rezervare, Zbor zbor) { if (this.motivDiscount == MotivDiscount.CLIENT && !rezervare.Rezervant.EsteClient) { return(zbor.Cost); } float SumaDeDecontat = zbor.Cost; if (zbor.TimpDecolare >= dataInceput && zbor.TimpDecolare <= dataInceput + durata) { SumaDeDecontat -= SumaDeDecontat * procentDiscount; SumaDeDecontat -= sumaAditionala; } return(SumaDeDecontat); }
protected override float Discount(Rezervare rezervare, Zbor zbor) { var sumaDeDecontat = zbor.Cost; for (int i = 1; i <= rezervare.NumarBilete; i++) { if (i == 1) { sumaDeDecontat -= sumaDeDecontat * procentDiscount; } else { sumaDeDecontat -= sumaDeDecontat * (procentDiscount / i); } } return(sumaDeDecontat); }
public int CompareTo(object obj) { if (obj == null) { return(1); } Rezervare rezervare = obj as Rezervare; if (rezervare != null) { if (numarBilete == rezervare.numarBilete) { if (Rezervant.CompareTo(rezervare.Rezervant) == 0) { if (RutaAeriana.CompareTo(rezervare.RutaAeriana) == 0) { if (Zbor.CompareTo(rezervare.Zbor) == 0) { return(0); } else { return(Zbor.CompareTo(rezervare.Zbor)); } } else { return(RutaAeriana.CompareTo(rezervare.RutaAeriana)); } } else { return(Rezervant.CompareTo(rezervare.Rezervant)); } } else { return(numarBilete.CompareTo(rezervare.numarBilete)); } } else { throw new ArgumentException("Object is not a " + this.GetType()); } }
public float ApplyDiscount(Rezervare rezervare, Zbor zbor) { float sumaMinima = zbor.Cost - zbor.Cost * discountMaxim; var zborCopie = (Zbor)zbor.Clone(); var rezervareCopie = (Rezervare)rezervare.Clone(); foreach (IDiscount discount in discounts) { zborCopie.Cost = discount.ApplyDiscount(rezervareCopie, zborCopie); } if (zborCopie.Cost < sumaMinima) { return(sumaMinima); } else { return(zborCopie.Cost); } }
public override int CompareTo(object obj) { if (obj == null) { return(1); } Zbor zbor = obj as Zbor; if (zbor != null) { int baseComp = base.CompareTo(zbor); if (baseComp != 0) { return(baseComp); } else if (this.cost > zbor.cost) { return(1); } else if (this.cost < zbor.cost) { return(-1); } else if (this.nrLocuriDisponibile > zbor.nrLocuriDisponibile) { return(1); } else if (this.nrLocuriDisponibile < zbor.nrLocuriDisponibile) { return(-1); } else { return(0); } } else { throw new ArgumentException("Object is not a " + this.GetType().ToString()); } }
protected abstract float Discount(Rezervare rezervare, Zbor zbor);
public override float ApplyDiscount(Rezervare rezervare, Zbor zbor) { return(base.ApplyDiscount(rezervare, zbor)); }
public void CitesteRuteXML() { if (!DBRepositoriesManager.OpenAirCompanyDB()) { System.Windows.Forms.MessageBox.Show("Eroare la deschiderea bazei de date", "Eroare deschidere baza de date", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } XmlDocument document = new XmlDocument(); try { document.Load(@Properties.Settings.Default.SerializationFilesPath + "RuteAeriene.xml"); } catch (FileNotFoundException) { System.Windows.Forms.MessageBox.Show("Unnable to open rute.xml"); return; } this.rute.Clear(); RutaAeriana ruta; Hashtable TabelaRezervari; SortedDictionary <DateTime, SortedDictionary <Zbor, Hashtable> > DicInfoRute; DateTime data; SortedDictionary <Zbor, Hashtable> DicZboruri; //nivelul cu rute foreach (XmlNode rutaNode in document.DocumentElement.ChildNodes) { //alocare dictionar pentru ruta DicInfoRute = new SortedDictionary <DateTime, SortedDictionary <Zbor, Hashtable> >(); //alocare ruta ruta = new RutaAeriana(new Aeroport(rutaNode.Attributes["numeAeropDec"]?.InnerText, rutaNode.Attributes["orasDec"]?.InnerText, rutaNode.Attributes["taraDec"]?.InnerText, rutaNode.Attributes["codIATAAeropDec"]?.InnerText, rutaNode.Attributes["codICAOAeropDec"]?.InnerText), new Aeroport(rutaNode.Attributes["numeAeropAter"]?.InnerText, rutaNode.Attributes["orasAter"]?.InnerText, rutaNode.Attributes["taraAter"]?.InnerText, rutaNode.Attributes["codIATAAeropAter"]?.InnerText, rutaNode.Attributes["codICAOAeropAter"]?.InnerText)); //nivelul cu zboruri pentru o data anumita foreach (XmlNode dataNode in rutaNode.ChildNodes) { //alocare data data = DateTime.ParseExact(dataNode.Attributes["data"]?.InnerText, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); DicZboruri = new SortedDictionary <Zbor, Hashtable>(); //nivelul cu zboruri foreach (XmlNode zborNode in dataNode.ChildNodes) { //alocam tabela de rezervari pentru zborul curent TabelaRezervari = new Hashtable(); Zbor zbor = new Zbor(DateTime.ParseExact(zborNode.Attributes["dataPlecare"]?.InnerText, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture) , DateTime.ParseExact(zborNode.Attributes["dataSosire"]?.InnerText, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture) , float.Parse(zborNode.Attributes["cost"]?.InnerText), int.Parse(zborNode.Attributes["nrLocuriDisponibile"]?.InnerText)); zbor.NumarLocuri = int.Parse(zborNode.Attributes["nrLocuriTotal"]?.InnerText); foreach (XmlNode rezervareNode in zborNode.ChildNodes) { var rezervare = new Rezervare( ruta, zbor, int.Parse(rezervareNode.Attributes["nrBilete"]?.InnerText), //new Persoana(rezervareNode.Attributes["persoana"]?.InnerText)); DBRepositoriesManager.AirCompanyDBGetPersoana(rezervareNode.Attributes["persoana"]?.InnerText)); TabelaRezervari.Add(rezervare.Rezervant.CNP, rezervare); } DicZboruri.Add(zbor, TabelaRezervari); } DicInfoRute.Add(data, DicZboruri); } //adauga ruta cu dictionarul ei in Rutele Companiei this.rute.Add(ruta, DicInfoRute); } DBRepositoriesManager.CloseAirCompanyDB(); }