public AppointmentDialog(int appointmentId) : this() { using (var db = new BizeeBirdDbContext()) { this.AppointmentId = appointmentId; Appointment appointment = db.Appointments.Find(AppointmentId); setActiveCustomerCombo(appointment.Customer.CustomerId); StartDateSelector.Date = appointment.StartTime; EndDateSelector.Date = appointment.EndTime; SetAppointmentStatus(appointment.Status); notesTextView.Buffer.Text = appointment.Notes; foreach (var appointmentBird in appointment.AppointmentBirds) { foreach (AppointmentDialogBirdRow row in birdHBox.Children) { if (appointmentBird.Bird.BirdId == row.Bird.BirdId) { row.BirdSelected = true; row.Wings = appointmentBird.GroomingWings; row.Nails = appointmentBird.GroomingNails; row.CageNeeded = appointmentBird.CageNeeded; } } } } }
public CustomerDialog(int customerId) : this() { this.CustomerId = customerId; using (var db = new BizeeBirdDbContext()) { Customer customer = db.Customers.Find(customerId); customerNameEntry.Text = customer.Name; boardingRateSpinButton.Value = customer.BoardingRate; customerNotesTextView.Buffer.Text = customer.Notes; emailEntry.Text = customer.Email; if (customer.PhoneNumbers != null && customer.PhoneNumbers.Count() > 0) { RemovePhoneNumberRow(PhoneNumberRows[0]); foreach (CustomerPhoneNumber phoneNumber in customer.PhoneNumbers) { if (PhoneNumberRows.Count() <= 0) { AddPhoneNumberRow(true, phoneNumber); } else { AddPhoneNumberRow(false, phoneNumber); } } } Birds = customer.Birds.ToList(); ResetBirdWidgetsAndRefreshBirdsList(); } }
private void UpdatePhoneNumbers(BizeeBirdDbContext db, Customer customer) { for (int idx = customer.PhoneNumbers.Count() - 1; idx >= 0; idx--) { var dbPhoneNumber = customer.PhoneNumbers[idx]; //TODO I'm not sure this is a very reliable check for new records. shouldn't we add a foreign key to CustomerPhoneNumbers and iterate on that //instead of using customer.PhoneNumbers? if (dbPhoneNumber.PhoneNumberId != 0) { bool inPhoneNumberRows = PhoneNumberRows.Where(pn => pn.PhoneNumberId == dbPhoneNumber.PhoneNumberId).Count() > 0; if (!inPhoneNumberRows) { db.CustomerPhoneNumbers.Remove(dbPhoneNumber); } } } foreach (CustomerDialogPhoneNumberRow row in PhoneNumberRows) { if (row.PhoneNumberId.HasValue) { CustomerPhoneNumber customerPhoneNumber = db.CustomerPhoneNumbers.Find(row.PhoneNumberId.Value); customerPhoneNumber.PhoneNumber = row.getPhoneNumber(); } else { customer.PhoneNumbers.Add(new CustomerPhoneNumber() { PhoneNumber = row.getPhoneNumber() }); } } }
private void UpdateHistoryTreeview() { string searchTerm = historySearchEntry.Text.Trim().ToLower(); HistoryListStore.Clear(); using (var db = new BizeeBirdDbContext()) { IQueryable set; if (searchTerm.Length > 0) { set = db.Appointments.Where( a => a.Customer.Name.ToLower().Contains(searchTerm) || a.Customer.Email.ToLower().Contains(searchTerm) || a.Customer.Notes.ToLower().Contains(searchTerm) || a.Customer.PhoneNumbers.Any(p => p.PhoneNumber.ToLower().Contains(searchTerm)) || a.AppointmentBirds.Any(b => b.Bird.Name.ToLower().Contains(searchTerm))).OrderByDescending(a => a.EndTime); } else { set = db.Appointments.OrderByDescending(a => a.EndTime); } foreach (Appointment row in set) { HistoryListStore.AppendValues(row.AppointmentId, row.Customer.Name, row.Customer.BoardingRate.ToString("C2"), row.AppointmentBirds.First().Bird.Name, row.StartTime.ToShortDateString() + " - " + row.EndTime.ToShortDateString(), row.Status.ToString(), row.AppointmentBirds.First().GroomingWings, row.AppointmentBirds.Exists(a => a.GroomingNails), row.AppointmentBirds.Exists(a => a.CageNeeded)); } } }
private void updateCustomerCombo(string searchTerm) { customerCombobox.Clear(); CellRendererText cell = new CellRendererText(); customerCombobox.PackStart(cell, false); customerCombobox.AddAttribute(cell, "text", 0); ListStore store = new ListStore(typeof(string), typeof(int)); customerCombobox.Model = store; using (var db = new BizeeBirdDbContext()) { IQueryable set; if (searchTerm != null && searchTerm.Length > 0) { set = db.Customers.Where( c => c.Name.ToLower().Contains(searchTerm) || c.Email.ToLower().Contains(searchTerm) || c.Notes.ToLower().Contains(searchTerm) || c.PhoneNumbers.Any(p => p.PhoneNumber.ToLower().Contains(searchTerm)) || c.Birds.Any(b => b.Name.ToLower().Contains(searchTerm))).OrderByDescending(c => c.Name); } else { set = db.Customers; } foreach (Customer row in set) { store.AppendValues(row.Name, row.CustomerId); } } }
private void onCustomerSelected(int customerId) { while (birdHBox.Children.Length > 0) { birdHBox.Remove(birdHBox.Children[0]); } using (var db = new BizeeBirdDbContext()) { Customer customer = db.Customers.Find(customerId); boardingRateEntry.Text = customer.BoardingRate.ToString("C2"); foreach (Bird row in customer.Birds) { if (row.Deleted) { continue; } AppointmentDialogBirdRow birdRow = new AppointmentDialogBirdRow(row, customer); birdHBox.Add(birdRow); } } }
private void UpdateUpcomingPickupsTreeview() { UpcomingPickupsListStore.Clear(); using (var db = new BizeeBirdDbContext()) { var appointments = from a in db.Appointments where a.EndTime >= DateTime.Today && a.Status == AppointmentStatus.CheckedIn orderby a.EndTime ascending select a; foreach (var row in appointments) { string birdsString = ""; string breedString = ""; if (row.AppointmentBirds.Count() == 1) { birdsString = row.AppointmentBirds.First().Bird.Name; breedString = row.AppointmentBirds.First().Bird.Breed; } TreeIter parent = UpcomingPickupsListStore.AppendValues(row.AppointmentId, row.EndTime.ToShortDateString(), row.Customer.Name, birdsString, breedString, row.AppointmentBirds.Exists(a => a.GroomingWings == true), row.AppointmentBirds.Exists(a => a.GroomingNails == true), row.Customer.BoardingRate.ToString("C2"), row.Notes); if (row.AppointmentBirds.Count() > 1) { foreach (var bird in row.AppointmentBirds) { UpcomingPickupsListStore.AppendValues(parent, null, null, null, bird.Bird.Name, bird.Bird.Breed, bird.GroomingWings, bird.GroomingNails, null, null); } } } } }
private void SaveNewAppointment(BizeeBirdDbContext db) { TreeIter iter; if (!customerCombobox.GetActiveIter(out iter)) { //TODO error customer not selected return; } int customerId = (int)customerCombobox.Model.GetValue(iter, 1); if (!HasBirdSelected()) { //TODO error no birds selected return; } List <AppointmentBird> appointmentBirds = new List <AppointmentBird>(); foreach (AppointmentDialogBirdRow row in birdHBox.Children) { if (row.BirdSelected) { appointmentBirds.Add(new AppointmentBird() { Bird = db.Birds.Find(row.Bird.BirdId), CageNeeded = row.CageNeeded, GroomingNails = row.Nails, GroomingWings = row.Wings }); } } if (appointmentBirds.Count < 1) { //TODO error no birds selected return; } var appointment = new Appointment { Customer = db.Customers.Find(customerId), AppointmentBirds = appointmentBirds, StartTime = StartDateSelector.Date, EndTime = EndDateSelector.Date, Status = GetAppointmentStatus(statusCombobox.ActiveText), Notes = notesTextView.Buffer.Text }; db.Appointments.Add(appointment); }
private void SaveExistingAppointment(BizeeBirdDbContext db) { TreeIter iter; if (!customerCombobox.GetActiveIter(out iter)) { //TODO error customer not selected return; } int customerId = (int)customerCombobox.Model.GetValue(iter, 1); if (!HasBirdSelected()) { //TODO error no birds selected return; } Appointment appointment = db.Appointments.Find(AppointmentId); appointment.Customer = db.Customers.Find(customerId); appointment.StartTime = StartDateSelector.Date; appointment.EndTime = EndDateSelector.Date; appointment.Status = GetAppointmentStatus(statusCombobox.ActiveText); appointment.Notes = notesTextView.Buffer.Text; for (int idx = appointment.AppointmentBirds.Count() - 1; idx >= 0; idx--) { db.AppointmentBirds.Remove(appointment.AppointmentBirds[idx]); } var appointmentBirds = new List <AppointmentBird>(); foreach (AppointmentDialogBirdRow row in birdHBox.Children) { if (row.BirdSelected) { appointmentBirds.Add(new AppointmentBird() { Bird = db.Birds.Find(row.Bird.BirdId), CageNeeded = row.CageNeeded, GroomingNails = row.Nails, GroomingWings = row.Wings }); } } appointment.AppointmentBirds = appointmentBirds; }
protected void onOkButtonClicked(object sender, EventArgs e) { using (var db = new BizeeBirdDbContext()) { if (!AppointmentId.HasValue) { SaveNewAppointment(db); } else { SaveExistingAppointment(db); } db.SaveChanges(); } Destroy(); }
private void UpdateExistingCustomer(BizeeBirdDbContext db) { Customer customer = db.Customers.Find(CustomerId); if (customer != null) { customer.Name = customerNameEntry.Text; customer.BoardingRate = boardingRateSpinButton.Value; customer.Notes = customerNotesTextView.Buffer.Text; customer.Email = emailEntry.Text; UpdatePhoneNumbers(db, customer); UpdateBirds(db, customer); } else { //TODO ERROR } }
public AppointmentDialogBirdRow(Bird bird, Customer customer) { Bird = bird; EnableCheckbutton = new CheckButton(bird.Name); EnableCheckbutton.Toggled += OnToggled; Add(EnableCheckbutton); WingsCheckButton = new CheckButton("Wings"); WingsCheckButton.Sensitive = false; Add(WingsCheckButton); NailsCheckButton = new CheckButton("Nails"); NailsCheckButton.Sensitive = false; Add(NailsCheckButton); using (var db = new BizeeBirdDbContext()) { var previousAppointments = db.Appointments.Where(x => x.Customer.CustomerId == customer.CustomerId); bool cageNeededCheckBox = false; foreach (var appointment in previousAppointments) { var appointmentBird = appointment.AppointmentBirds.FirstOrDefault(x => x.Bird.BirdId == bird.BirdId); if (appointmentBird != null) { cageNeededCheckBox = appointmentBird.CageNeeded; break; } } CageNeededCheckButton = new CheckButton("Cage Needed"); CageNeededCheckButton.Sensitive = false; CageNeededCheckButton.Active = cageNeededCheckBox; Add(CageNeededCheckButton); } ShowAll(); }
private void UpdateCombo(ComboBox comboBox, Dictionary <int, string> values) { comboBox.Clear(); CellRendererText cell = new CellRendererText(); comboBox.PackStart(cell, false); comboBox.AddAttribute(cell, "text", 0); ListStore store = new ListStore(typeof(string), typeof(int)); comboBox.Model = store; using (var db = new BizeeBirdDbContext()) { IQueryable set = db.Customers; foreach (KeyValuePair <int, string> kvp in values) { store.AppendValues(kvp.Value, kvp.Key); } } }
private void UpdateUpcomingDropOffsTreeview() { UpcomingDropOffsListStore.Clear(); using (var db = new BizeeBirdDbContext()) { var appointments = from a in db.Appointments where a.StartTime >= DateTime.Today && a.Status == AppointmentStatus.Scheduled orderby a.StartTime ascending select a; foreach (var row in appointments) { string birdsString = ""; string breedString = ""; if (row.AppointmentBirds.Count() == 1) { birdsString = row.AppointmentBirds.First().Bird.Name; breedString = row.AppointmentBirds.First().Bird.Breed; } TreeIter parent = UpcomingDropOffsListStore.AppendValues(row.AppointmentId, row.StartTime.ToShortDateString(), row.Customer.Name, birdsString, breedString, row.AppointmentBirds.Exists(a => a.CageNeeded == true)); if (row.AppointmentBirds.Count() > 1) { foreach (var bird in row.AppointmentBirds) { UpcomingDropOffsListStore.AppendValues(parent, "", "", "", bird.Bird.Name, bird.Bird.Breed, bird.CageNeeded); } } } } //uncommenting this will automaticly expand all the nested rows //upcomingDropOffsTreeView.ExpandAll(); }
private void UpdateBirds(BizeeBirdDbContext db, Customer customer) { foreach (Bird bird in Birds) { //TODO should we check for new records this way? if (bird.BirdId != 0) { Bird dbBird = db.Birds.Find(bird.BirdId); dbBird.Deleted = bird.Deleted; dbBird.Name = bird.Name; dbBird.Breed = bird.Breed; dbBird.Color = bird.Color; dbBird.Age = bird.Age; dbBird.Gender = bird.Gender; dbBird.Notes = bird.Notes; } else { customer.Birds.Add(bird); } } }
protected void onOkButtonClicked(object sender, EventArgs e) { if (birdNameEntry.Text.Trim() != "") { onBirdAddButtonClicked(sender, e); } using (var db = new BizeeBirdDbContext()) { if (CustomerId.HasValue) { UpdateExistingCustomer(db); } else { CreateNewCustomer(db); } db.SaveChanges(); } Destroy(); }
private void CreateNewCustomer(BizeeBirdDbContext db) { List <CustomerPhoneNumber> phoneNumbers = new List <CustomerPhoneNumber>(); foreach (CustomerDialogPhoneNumberRow row in PhoneNumberRows) { phoneNumbers.Add(new CustomerPhoneNumber() { PhoneNumber = row.getPhoneNumber() }); } Customer customer = new Customer { Name = customerNameEntry.Text, BoardingRate = boardingRateSpinButton.Value, Notes = customerNotesTextView.Buffer.Text, PhoneNumbers = phoneNumbers, Email = emailEntry.Text, Birds = Birds }; customer = db.Customers.Add(customer); }
private void UpdateCustomerList() { string searchTerm = customerSearchEntry.Text.Trim(); CustomersListStore.Clear(); using (var db = new BizeeBirdDbContext()) { IQueryable set; if (searchTerm.Length > 0) { set = db.Customers.Where( c => c.Name.ToLower().Contains(searchTerm.ToLower()) || c.Email.ToLower().Contains(searchTerm.ToLower()) || c.Notes.ToLower().Contains(searchTerm.ToLower()) || c.PhoneNumbers.Any(p => p.PhoneNumber.ToLower().Contains(searchTerm.ToLower())) || c.Birds.Any(b => b.Name.ToLower().Contains(searchTerm.ToLower()))).OrderBy(c => c.Name); } else { set = db.Customers.OrderBy(c => c.Name); } foreach (Customer row in set) { string phoneNumber = ""; if (row.PhoneNumbers != null && row.PhoneNumbers.Count() > 0) { phoneNumber = row.PhoneNumbers.First().PhoneNumber; } CustomersListStore.AppendValues(row.CustomerId, row.Name, phoneNumber, row.Email, row.BoardingRate.ToString("C2"), row.Notes); } } }