/// <summary> /// Deletes order status history. Called when the "Delete history" button is pressed. /// Expects the ChangeOrderStatus method to be run first. /// </summary> private bool DeleteHistory() { // Prepare the parameters string where = "CustomerLastName LIKE N'My New Registered%'"; CustomerInfo customer = null; OrderInfo order = null; // Get the customer DataSet customers = CustomerInfoProvider.GetCustomers(where, null); if (!DataHelper.DataSourceIsEmpty(customers)) { // Create object from DataRow customer = new CustomerInfo(customers.Tables[0].Rows[0]); } if (customer != null) { string whereOrder = "OrderCustomerID = " + customer.CustomerID; // Get the order DataSet orders = OrderInfoProvider.GetOrders(whereOrder, null); if (!DataHelper.DataSourceIsEmpty(orders)) { // Create object from DataRow order = new OrderInfo(orders.Tables[0].Rows[0]); } if (order != null) { // Get the order statuses DataSet statuses = OrderStatusUserInfoProvider.GetOrderStatusHistory(order.OrderID); if (!DataHelper.DataSourceIsEmpty(statuses)) { foreach (DataRow statusDr in statuses.Tables[0].Rows) { // Create object from DataRow OrderStatusUserInfo status = new OrderStatusUserInfo(statusDr); // Delete the order status OrderStatusUserInfoProvider.DeleteOrderStatusUserInfo(status); } return true; } } } return false; }
/// <summary> /// Changes order status. Called when the "Change order status" button is pressed. /// Expects the CreateOrder method to be run first. /// </summary> private bool ChangeOrderStatus() { // Prepare the parameters string where = "CustomerLastName LIKE N'My New Registered%'"; CustomerInfo customer = null; OrderInfo order = null; // Get the customer DataSet customers = CustomerInfoProvider.GetCustomers(where, null); if (!DataHelper.DataSourceIsEmpty(customers)) { // Create object from DataRow customer = new CustomerInfo(customers.Tables[0].Rows[0]); } if (customer != null) { string whereOrder = "OrderCustomerID = " + customer.CustomerID; // Get the order DataSet orders = OrderInfoProvider.GetOrders(whereOrder, null); if (!DataHelper.DataSourceIsEmpty(orders)) { // Create object from DataRow order = new OrderInfo(orders.Tables[0].Rows[0]); } if (order != null) { // Get next enabled order status OrderStatusInfo nextOrderStatus = OrderStatusInfoProvider.GetNextEnabledStatus(order.OrderStatusID); if (nextOrderStatus != null) { // Create new order status user object OrderStatusUserInfo newUserStatus = new OrderStatusUserInfo(); // Set the properties newUserStatus.OrderID = order.OrderID; newUserStatus.ChangedByUserID = CMSContext.CurrentUser.UserID; newUserStatus.FromStatusID = order.OrderStatusID; newUserStatus.ToStatusID = nextOrderStatus.StatusID; newUserStatus.Date = DateTime.Now; // Set the order status user OrderStatusUserInfoProvider.SetOrderStatusUserInfo(newUserStatus); // Set next order status to order order.OrderStatusID = nextOrderStatus.StatusID; // Change the order status OrderInfoProvider.SetOrderInfo(order); return true; } } } return false; }
/// <summary> /// Changes order status. Called when the "Change order status" button is pressed. /// Expects the CreateOrder method to be run first. /// </summary> private bool ChangeOrderStatus() { // Get the customer CustomerInfo customer = CustomerInfoProvider.GetCustomers().WhereStartsWith("CustomerLastName", "My New Registered").FirstOrDefault(); if (customer != null) { var order = OrderInfoProvider.GetOrders().WhereEquals("OrderCustomerID", customer.CustomerID).FirstOrDefault(); if (order != null) { // Get next enabled order status OrderStatusInfo nextOrderStatus = OrderStatusInfoProvider.GetNextEnabledStatus(order.OrderStatusID); if (nextOrderStatus != null) { // Create new order status user object OrderStatusUserInfo newUserStatus = new OrderStatusUserInfo(); // Set the properties newUserStatus.OrderID = order.OrderID; newUserStatus.ChangedByUserID = MembershipContext.AuthenticatedUser.UserID; newUserStatus.FromStatusID = order.OrderStatusID; newUserStatus.ToStatusID = nextOrderStatus.StatusID; newUserStatus.Date = DateTime.Now; // Set the order status user OrderStatusUserInfoProvider.SetOrderStatusUserInfo(newUserStatus); // Set next order status to order order.OrderStatusID = nextOrderStatus.StatusID; // Change the order status OrderInfoProvider.SetOrderInfo(order); return true; } } } return false; }