public AddOperationViewModel() { operation = new Operation(); dentalChartViewModel = new DentalChartViewModel() { TreatmentRecordViewModel = null }; copyOperation = (Operation)operation.Clone(); AddCommand = new DelegateCommand(new Action(addTooth)); RemoveCommand = new DelegateCommand(new Action(removeTooth)); ClearCommand = new DelegateCommand(new Action(clearTeeth)); MedicineViewModel = new MedicineViewModel(); MedicineViewModel.LoadMedicines(); ProviderViewModel = new ProviderViewModel(); ProviderViewModel.LoadProviders(); AddItemCommand = new DelegateCommand(AddItem); RemoveItemCommand = new DelegateCommand(RemoveItem); ClearItemsCommad = new DelegateCommand(ClearItems); Consumables = new List <ConsumableItem>(); AddBillingViewModel = new AddBillingViewModel(); AllPermanentCommand = new DelegateCommand(AllPermanent); UpperPermanentCommand = new DelegateCommand(UpperPermanent); LowerPermanentCommand = new DelegateCommand(LowerPermanent); AllTemporaryCommand = new DelegateCommand(AllTemporary); UpperTemporaryCommand = new DelegateCommand(UpperTemporary); LowerTemporaryCommand = new DelegateCommand(LowerTemporary); DeselectCommand = new DelegateCommand(Deselect); }
public void finishTreatment() { if (ToothList != null && ToothList.Count > 0) { if (MessageBox.Show("Are you sure you want to save this treatment?", "Save Treatment", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { foreach (ToothViewModel toothViewModel in ToothList) { AddTreatmentRecordViewModel treatmentRecord = new AddTreatmentRecordViewModel(); treatmentRecord.Treatment = Appointment.Treatment; treatmentRecord.Appointment = Appointment; treatmentRecord.Tooth = toothViewModel.Tooth; treatmentRecord.Patient = Appointment.Patient; treatmentRecord.Notes = toothViewModel.Remarks; treatmentRecord.ActiveUser = ActiveUser; treatmentRecord.saveTreatmentRecord(); if (!Appointment.Treatment.Output.Equals("None")) { toothViewModel.Tooth.Condition = Appointment.Treatment.Output; } toothViewModel.saveTooth(); toothViewModel.loadTooth(); } foreach (ConsumableItem consumable in Consumables) { AddUsedItemViewModel addUsedItemViewModel = new AddUsedItemViewModel(); addUsedItemViewModel.Appointment = Appointment; addUsedItemViewModel.Medicine = consumable.Medicine; addUsedItemViewModel.Quantity = Int32.Parse(consumable.Consumed); addUsedItemViewModel.ActiveUser = ActiveUser; consumable.ViewModel.ActiveUser = ActiveUser; consumable.consume(); addUsedItemViewModel.SaveUsedItem(); } AddBillingViewModel.Billing.Provider = ProviderViewModel.Provider; if (AddBillingViewModel.Billing.Provider == null) { AddBillingViewModel.Billing.Provider = new Provider(); } AddBillingViewModel.ActiveUser = ActiveUser; AddBillingViewModel.Appointment = Appointment; AddBillingViewModel.Billing.AmountCharged = Double.Parse(AmountCharge); AddBillingViewModel.Billing.Balance = Double.Parse(AmountCharge); AddBillingViewModel.saveBilling(); MessageBox.Show("Treatment was successfully saved.", "Treatment Saved", MessageBoxButton.OK, MessageBoxImage.Information); MySqlConnection connection = CreateConnection(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "update allaboutteeth_appointments set appointment_status='Completed' where appointment_no = '" + Appointment.No + "'"; command.ExecuteNonQuery(); connection.Close(); connection = null; MySqlConnection connection2 = CreateConnection(); MySqlCommand command2 = connection2.CreateCommand(); command2.CommandText = "update allaboutteeth_patients set patient_status='Active', patient_addedby='" + ActiveUser.No + "' where patient_no='" + Appointment.Patient.No + "'"; command2.ExecuteNonQuery(); connection2.Close(); connection2 = null; AddActivityLogViewModel addActivityLog = new AddActivityLogViewModel(); addActivityLog.ActivityLog = new ActivityLog(); addActivityLog.ActiveUser = ActiveUser; addActivityLog.ActivityLog.Activity = "User performed treatment for " + Operation.Appointment.Patient.FirstName + " " + Operation.Appointment.Patient.LastName + "."; addActivityLog.saveActivityLog(); try { var appointment = Appointments.OrderBy(x => x.No).First(x => x.Patient.No == Appointment.Patient.No && x.No != Appointment.No); Appointment = appointment; Appointments.Remove(appointment); Teeth = new List <ToothViewModel>(); ToothList = new List <ToothViewModel>(); ClearItems(); } catch (Exception) { MenuViewModel.gotoBillings(); } //MenuViewModel.gotoBillings(); } } else { MessageBox.Show("No tooth is selected.", "Selection Error", MessageBoxButton.OK, MessageBoxImage.Error); } }