private void btnCreateOrder_Click(object sender, EventArgs e) { try { Order o = new Order(); o.CustomerID = cmbCustomer.SelectedValue.ToString(); o.EmployeeID = (int)cmbEmployee.SelectedValue; o.OrderDate = dateOrder.Value; o.RequiredDate = dateRequired.Value; o.ShipVia = (int)cmbShipVia.SelectedValue; o.Freight = Convert.ToDecimal(txtFreight.Text); if (txtFreight.Text != null && dateOrder.Value > DateTime.Today && dateRequired.Value > dateOrder.Value) { db.Orders.Add(o); db.SaveChanges(); FormOrderHeaderDetail frm = new FormOrderHeaderDetail(o.OrderID); frm.Show(); this.Hide(); } else { MessageBox.Show("Girilen verilerde hata var"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnInsertDetail_Click(object sender, EventArgs e) { try { Order_Detail od = new Order_Detail(); od.OrderID = Convert.ToInt32(txtOrderID.Text); od.ProductID = (int)cmbProducts.SelectedValue; od.Quantity = Convert.ToInt16(txtQuantity.Text); Product p = db.Products.Find(od.ProductID); od.UnitPrice = (decimal)p.UnitPrice; db.Order_Details.Add(od); db.SaveChanges(); od.Discount = 0; OrderDetDoldur(); MessageBox.Show("Insert is successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }