public override bool Equals(object obj) { Occupancy rental = (Occupancy)obj; if (rental.OccupancyNumber == this.OccupancyNumber) { return(true); } else { return(false); } }
private void btnNewOccupancy_Click(object sender, EventArgs e) { OccupancyEditor editor = new OccupancyEditor(); BinaryFormatter bfmOccupancies = new BinaryFormatter(); Collection <Occupancy> lstOccupancies = new Collection <Occupancy>(); string strFileName = @"C:\Microsoft Visual C# Application Design\Ceil Inn\Occupancies.ocp"; if (File.Exists(strFileName) == true) { using (FileStream fsOccupancies = new FileStream(strFileName, FileMode.Open, FileAccess.Read)) { lstOccupancies = (Collection <Occupancy>)bfmOccupancies.Deserialize(fsOccupancies); } } if (editor.ShowDialog() == DialogResult.OK) { Occupancy occupy = new Occupancy(); occupy.OccupancyNumber = Convert.ToInt32(editor.txtOccupancyNumber.Text); occupy.DateOccupied = editor.dtpDateOccupied.Value; occupy.ProcessedBy = editor.txtEmployeeNumber.Text; occupy.ProcessedFor = editor.txtAccountNumber.Text; occupy.RoomOccupied = editor.txtRoomNumber.Text; occupy.RateApplied = double.Parse(editor.txtRateApplied.Text); occupy.PhoneUse = double.Parse(editor.txtPhoneUse.Text); lstOccupancies.Add(occupy); using (FileStream fsOccupancies = new FileStream(strFileName, FileMode.Create, FileAccess.Write)) { bfmOccupancies.Serialize(fsOccupancies, lstOccupancies); } } ShowOccupancies(); }