private void EndDialog(object sender, RoutedEventArgs e) { if (ValidateOptions()) { DialogResult = true; Order = new Utility.Order { ClientId = (clientBox.SelectedItem as Client).Id, ClientName = (clientBox.SelectedItem as Client).Name, ProductId = (productBox.SelectedItem as Entry).Id, ProductName = (productBox.SelectedItem as Entry).Name, UnitId = (unitBox.SelectedItem as Entry).Id, UnitName = (unitBox.SelectedItem as Entry).Name, CashId = (cashTypeBox.SelectedItem as Entry).Id, CashName = (cashTypeBox.SelectedItem as Entry).Name, Number = long.Parse(numberBox.Text), Cost = Evaluate(costBox.Text), UnitPrice = double.Parse(unitPriceBox.Text), Date = dateBox.SelectedDate.Value, Comment = commentBox.Text }; } else { MessageBox.Show("输入不合法"); } }
internal void UseTemplate(Utility.Order template) { clientBox.SelectedItem = (clientBox.ItemsSource as IEnumerable <Client>).First(x => x.Id == template.ClientId); productBox.SelectedItem = (productBox.ItemsSource as IEnumerable <Entry>).First(x => x.Id == template.ProductId); unitBox.SelectedItem = (unitBox.ItemsSource as IEnumerable <Entry>).First(x => x.Id == template.UnitId); cashTypeBox.SelectedItem = (cashTypeBox.ItemsSource as IEnumerable <Entry>).First(x => x.Id == template.CashId); numberBox.Text = template.Number.ToString(); costBox.Text = template.Cost.ToString(); unitPriceBox.Text = template.UnitPrice.ToString(); dateBox.SelectedDate = template.Date; commentBox.Text = template.Comment; }