/// <summary> /// Fill bill form /// </summary> private void fillBillForm() { tbBillNumber.Text = selectedBill.BillNumber; tbReferenceNumber.Text = selectedBill.ReferenceNumber; tbReference.Text = selectedBill.Reference; tbOverdueRate.Text = selectedBill.OverdueRate; dueDate.SelectedDate = selectedBill.DueDate; billDate.SelectedDate = selectedBill.BillDate; // Select customer (stupid way, but I don't have time to make it better) List <UI.ComboBoxItem> list = new List <UI.ComboBoxItem>(); foreach (var item in cbCustomers.ItemsSource) { UI.ComboBoxItem it = (UI.ComboBoxItem)item; list.Add(it); } cbCustomers.SelectedItem = list.Where(x => x.Id == selectedBill.CustomerId).FirstOrDefault(); // Fill bill rows dgBillRows.ItemsSource = selectedBill.BillRows; }
/// <summary> /// Fill bill object /// </summary> /// <param name="bill"></param> /// <param name="action"></param> private void fillBillObject(ref Bill bill, Enums.Action action) { bill.BillNumber = tbBillNumber.Text; if (dueDate.SelectedDate != null) { bill.DueDate = DateTime.Parse(dueDate.SelectedDate.Value.ToShortDateString()); } else { validationErrors.Add("- Laskulle pitää syöttää eräpäivä."); } if (billDate.SelectedDate != null) { bill.BillDate = DateTime.Parse(billDate.SelectedDate.Value.ToShortDateString()); } else { validationErrors.Add("- Laskulle pitää syöttää laskutuspäivä."); } bill.ReferenceNumber = tbReferenceNumber.Text; bill.Reference = tbReference.Text; bill.OverdueRate = tbOverdueRate.Text; bill.BIC = company.BIC; bill.IBAN = company.IBAN; // Get selected customer UI.ComboBoxItem item = (UI.ComboBoxItem)cbCustomers.SelectedItem; if (item != null) { bill.CustomerId = item.Id; } else { validationErrors.Add("- Laskulle pitää valita asiakas."); } // Bill rows bill.BillRows = dgBillRows.ItemsSource as List <BillRow>; }