private void addItem() { if ( Inspection.CheckNumeric(OrderWindowViewModel.AddItem.txtIdContractor.Text, 18, 0) && Inspection.CheckNumeric(OrderWindowViewModel.AddItem.txtSumm.Text, 18, 2) && Inspection.CheckDateTime(OrderWindowViewModel.AddItem.txtDateOrder.Text) && Inspection.CheckDateTime(OrderWindowViewModel.AddItem.txtDateImport.Text) ) { Order n = new Order() { id_contractor = decimal.Parse(OrderWindowViewModel.AddItem.txtIdContractor.Text), summ = decimal.Parse(OrderWindowViewModel.AddItem.txtSumm.Text), date_order = DateTime.Parse(OrderWindowViewModel.AddItem.txtDateOrder.Text), date_import = DateTime.Parse(OrderWindowViewModel.AddItem.txtDateImport.Text), id_user = AdministratorWindowViewModel.Current_User.id }; Order m; using (var context = new WarehouseEntities()) { context.Order.Add(n); context.SaveChanges(); m = context.Order.ToList().Last(); var orderTable = (OrderWindowViewModel)Application.Current.Resources["OrderWindowViewModel"]; orderTable.Orders = context.Order.ToList(); } MessageBox.Show("Запись создана успешно."); MerchendiseWindowViewModel f = (MerchendiseWindowViewModel)Application.Current.Resources["MerchendiseWindowViewModel"]; var carMerch = f.AddItem1(f); carMerch.txtConsignment.Text = m.consigment.ToString(); carMerch.txtConsignment.IsEnabled = false; Card addmerch = carMerch; addmerch.Show(); } else { MessageBox.Show("Некорректные данные!"); } }
private void addItem() { var merchTable = (MerchendiseWindowViewModel)Application.Current.Resources["MerchendiseWindowViewModel"]; if ( Inspection.CheckString(merchTable.AddItem.Name.Text, 50) && Inspection.CheckNumeric(merchTable.AddItem.txtConsignment.Text, 18, 0) && Inspection.CheckNumeric(merchTable.AddItem.txtCountBooked.Text, 18, 0) && Inspection.CheckNumeric(merchTable.AddItem.txtCountStored.Text, 18, 0) && Inspection.CheckNumeric(merchTable.AddItem.txtCountOrder.Text, 18, 0) && Inspection.CheckNumeric(merchTable.AddItem.txtCost.Text, 18, 2) && Inspection.CheckNumeric(merchTable.AddItem.txtMargin.Text, 18, 2) ) { var context = new WarehouseEntities(); Merchandise n = new Merchandise() { brand = merchTable.AddItem.Name.Text, consignment = decimal.Parse(merchTable.AddItem.txtConsignment.Text), arrived = merchTable.AddItem.chkArrived.IsEnabled, count_booked = decimal.Parse(merchTable.AddItem.txtCountBooked.Text), count_stored = decimal.Parse(merchTable.AddItem.txtCountStored.Text), count_order = decimal.Parse(merchTable.AddItem.txtCountOrder.Text), count_send = decimal.Parse(merchTable.AddItem.txtCountSend.Text), specif_n = merchTable.AddItem.Descr.Text, cost = decimal.Parse(merchTable.AddItem.txtCost.Text), id_type = ((Types)merchTable.AddItem.comboType.SelectedValue).id_type, margin = decimal.Parse(merchTable.AddItem.txtMargin.Text) }; context.Merchandise.Add(n); context.SaveChanges(); merchTable.Merchandises = context.Merchandise.ToList(); MessageBox.Show("запись создана"); } else { MessageBox.Show("Некорректные данные!"); } }