public static bool DeleteOrder(Order SelectedOrder) { try { DataAccessLayer.DeleteObject(SelectedOrder); DataAccessLayer.SaveChanges(System.Data.Objects.SaveOptions.None); } catch (Exception ex) { string s = ex.ToString(); DataAccessLayer.Refresh(System.Data.Objects.RefreshMode.StoreWins, SelectedOrder); return false; } DataAccessLayer.Refresh(System.Data.Objects.RefreshMode.StoreWins, SelectedOrder); return true; }
public static Order GetOrderById(int? id) { if (id != null) { IQueryable<Order> OrderQuery = from p in DataAccessLayer.Orders where p.OrderId == id select p; return OrderQuery.ToList()[0]; } else { Order o = new Order(); o.OrderName = ""; return o; } }
private void btnDelete_Click(object sender, EventArgs e) { if (OrderDataAccess.DeleteOrder(SelectedOrder) == false) { MessageBox.Show("Cannot delete, child nodes still exist", "Delete Fail", MessageBoxButtons.OK, MessageBoxIcon.Warning); } SelectedOrder = null; LoadData(); try { dgOrders.CurrentCell = dgOrders.Rows[0].Cells[0]; dgOrders.Rows[0].Selected = true; } catch { btnFamily.Enabled = false; txtOrderId.Text = ""; txtOrderName.Text = ""; } }
/// <summary> /// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrders(Order order) { base.AddObject("Orders", order); }
/// <summary> /// Create a new Order object. /// </summary> /// <param name="orderId">Initial value of the OrderId property.</param> public static Order CreateOrder(global::System.Int32 orderId) { Order order = new Order(); order.OrderId = orderId; return order; }
private void SelectOrder(int id) { try { SelectedOrder = OrderDataAccess.GetOrderById(id); txtOrderName.Text = SelectedOrder.OrderName; txtOrderId.Text = SelectedOrder.OrderId.ToString(); txtNumberinOrder.Text = SelectedOrder.NumberInOrder.ToString(); txtNotes.Text = SelectedOrder.Notes; btnFamily.Enabled = true; } catch { } }
public static int SaveOrder(Order SelectedOrder) { return DataAccessLayer.SaveChanges(); }