public List <OrderDetails> GetAllOrderDetails()
 {
     using (var db = new OrderDB())
     {
         return(db.OrderDetail.ToList <OrderDetails>());
     }
 }
 public void Update(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         List <OrderDetails> odl = GetAllOrderDetails();
         foreach (OrderDetails details in order.orderDetails)
         {
             bool exist = false;
             foreach (OrderDetails detailed in odl)
             {
                 if (detailed.ID == details.ID)
                 {
                     exist = true;
                     break;
                 }
             }
             db.Entry(details).State = EntityState.Modified;
             if (!exist)
             {
                 db.OrderDetail.Add(details);
             }
         }
         //order.orderDetails.ForEach(
         //    item => db.Entry(item).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
 public List <Order> GetAllOrders()
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("orderDetails").ToList <Order>());
     }
 }
 public Order GetOrder(String Id)
 {
     using (var db = new OrderDB()) {
         return(db.Order.Include("Details").
                SingleOrDefault(o => o.Id == Id));
     }
 }
 public List <Order> QueryByCustormer(String custormer)
 {
     using (var db = new OrderDB()) {
         return(db.Order.Include("Details")
                .Where(o => o.Customer.Equals(custormer)).ToList <Order>());
     }
 }
 public void Add(Order order)
 {
     using (var db = new OrderDB()) {
         db.Order.Add(order);
         db.SaveChanges();
     }
 }
Beispiel #7
0
        // validates search text fields, calls for queries, and display results
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if ((comboSearchBy.Text == "OrderID" || comboSearchBy.Text == "CustomerID") &&
                txtValue.Text == "")
            {
                MessageBox.Show("There is no value, please enter a value and try again", "No Value",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtValue.Focus();
            }
            else
            {
                switch (comboSearchBy.Text)
                {
                case "OrderID":
                    Regex regex = new Regex(@"^\d{1,5}");
                    if (regex.IsMatch(txtValue.Text))
                    {
                        try {
                            ordersList = OrderDB.GetOrderByOrderID(txtValue.Text);
                        } catch (Exception ex) {
                            MessageBox.Show(ex.Message.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid value for: " + comboSearchBy.Text +
                                        ", please enter a valid " + comboSearchBy.Text);
                    }
                    break;

                case "CustomerID":
                    if (txtValue.Text.Length <= MAX_VALUE_LENGTH)
                    {
                        ordersList = OrderDB.GetOrderListByCustomerID(txtValue.Text);
                    }
                    break;

                case "OrderDate":     // GetOrderListByOrderDateRange() returns list of Order Objects
                case "RequiredDate":
                case "ShippedDate":
                    if (Convert.ToDateTime(dtpFrom.Text) <= Convert.ToDateTime(dtpTo.Text))
                    {
                        ordersList = OrderDB.GetOrderListByDateRange(
                            comboSearchBy.Text, dtpFrom.Text.Replace("-", ""),
                            dtpTo.Text.Replace("-", ""));
                        break;
                    }
                    else
                    {
                        MessageBox.Show("The date range is invalid, please choose a valid date range (fromDate <= toDate)");
                        dtpFrom.Focus();
                        break;
                    }
                }
            }
            // display listview from order list
            DisplayList(ordersList);
        }
 public void DeleteDetail(String Id)
 {
     using (var db = new OrderDB())
     {
         var orderdetail = db.OrderDetail.SingleOrDefault(o => o.ID == Id);
         db.OrderDetail.Remove(orderdetail);
         db.SaveChanges();
     }
 }
 public List <Order> QueryByGoods(String product)
 {
     using (var db = new OrderDB()) {
         var query = db.Order.Include("Details")
                     .Where(o => o.Details.Where(
                                item => item.Product.Equals(product)).Count() > 0);
         return(query.ToList <Order>());
     }
 }
 public void Delete(String orderId)
 {
     using (var db = new OrderDB()) {
         var order = db.Order.Include("Items").SingleOrDefault(o => o.Id == orderId);
         db.OrderDetail.RemoveRange(order.Details);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
 public void Update(Order order)
 {
     using (var db = new OrderDB()) {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.Details.ForEach(
             item => db.Entry(item).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
Beispiel #12
0
        // show frmAlterShippingDates.cs on button click
        private void btnAlterShipDate_Click(object sender, EventArgs e)
        {
            if (txtOrderID.Text != "")                                                                      // if there's a record, then execute code below
            {
                string oldDate = txtShippedDate.Text;                                                       // store old date in case there's a problem in execution

                frmAlterShippingDate alterShippingDateForm = new frmAlterShippingDate(txtShippedDate.Text); // create a new form to alter shipping date
                if (alterShippingDateForm.ShowDialog() == DialogResult.OK)                                  // open the form
                {
                    string newDate = alterShippingDateForm.ShipDate;                                        // get result from user

                    // check to see if shipping date is within range before changes
                    if (Convert.ToDateTime(newDate) >= Convert.ToDateTime(txtOrderDate.Text) &&
                        Convert.ToDateTime(newDate) <= Convert.ToDateTime(txtRequiredDate.Text) ||
                        alterShippingDateForm.EnterNullShipDate)
                    {
                        // run update query
                        if (OrderDB.UpdateShippedDate(newDate, Convert.ToInt32(txtOrderID.Text)))
                        {
                            MessageBox.Show("Successfully updated ShippingDate for order with ID: " + txtOrderID.Text);
                            txtShippedDate.Text = newDate;
                        }
                        else     // query failed, show error
                        {
                            MessageBox.Show("There was an error updating Shipping Date, please try again");
                            txtShippedDate.Text = oldDate;
                        }
                    }
                    else     // user shipping date is out of range
                    {
                        MessageBox.Show("The ShippedDate is not in range.  Please enter OrderDate <= ShippedDate <= RequiredDate");
                    }
                }
            }
            else
            {
                MessageBox.Show("No record to change. Search for a record before altering Shipping Date");
            }
        }