private void Button_Click(object sender, RoutedEventArgs e) { try { Model1 db = new Model1(); int a = Convert.ToInt32(idtxt.Text); var orderr = db.Orders .Where(c => c.id_order == a) .FirstOrDefault(); orderr.order_status = Convert.ToInt32(LogicStatus.GetIdStatus(status.Text)); orderr.client = Convert.ToInt32(LogicClient.GetIdClient(client.Text)); orderr.master = Convert.ToInt32(LogicMaster.GetIdMaster(master.Text)); orderr.date_of_acceptance = accept.DisplayDate; orderr.date_of_return = @return.DisplayDate; orderr.cost = Convert.ToInt32(price.Text); orderr.description = description.Text; db.SaveChanges(); MessageBox.Show("Заказ изменён!"); ViewOrder vo = new ViewOrder(); vo.Show(); Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Button_Click(object sender, RoutedEventArgs e) { try { if (@return.Text == "") { var dt = DateTime.Now; @return.SelectedDate = dt.AddDays(7); } if (price.Text == "") { price.Text = "0"; } if (description.Text == "") { description.Text = "Не указано"; } Model1 db = new Model1(); Orders order = new Orders { order_status = statusnew, //order_status = Convert.ToInt32(LogicStatus.GetIdStatus(status.Text)), client = Convert.ToInt32(LogicClient.GetIdClient(client.Text)), master = Convert.ToInt32(LogicMaster.GetIdMaster(master.Text)), date_of_acceptance = accept.SelectedDate, date_of_return = @return.SelectedDate, cost = Convert.ToInt32(price.Text), description = description.Text }; db.Orders.Add(order); //string connectionString = @"data source=MAX-PC\SQLEXPRESS;initial catalog=ComputerService;integrated security=True;"; //string sqlExpression = "SELECT IDENT_CURRENT('dbo.Orders')+1"; //using (SqlConnection connection = new SqlConnection(connectionString)) //{ // connection.Open(); // SqlCommand command = new SqlCommand(sqlExpression, connection); // var ident_current = command.ExecuteScalar(); // globalid = ident_current; // LogicOrders.globalidorder = Convert.ToInt32(globalid); //} //Details details = new Details //{ // Order = Convert.ToInt32(globalid), // Parts = Convert.ToInt32(LogicComputers.GetIdMark(pc.Text)), //}; //db.Details.Add(details); db.SaveChanges(); MessageBox.Show("Заказ добавлен!"); ViewOrder vo = new ViewOrder(); vo.Show(); Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }