Exemple #1
0
        // Creates a new Order
        public static long SaveOrder(OrderSpec orderSpec)
        {
            try
            {
                // Call the Web Services
                SaveResult[] saveResults = RoutingServiceClient.SaveOrders(
                    SessionHeader, RegionContext,
                    new OrderSpec[] { orderSpec },
                    new SaveOptions
                {
                    InclusionMode = PropertyInclusionMode.All
                });

                if (saveResults[0].Error != null) // Error creating the Order
                {
                    throw new Exception(saveResults[0].Error.Code.ErrorCode_Status);
                }

                return(saveResults[0].EntityKey); // New Order created
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }
Exemple #2
0
        public ISpecification <Schedule> ToSpecification()
        {
            var specification = Spec <Schedule> .New();

            if (DateFrom != null)
            {
                var dateFrom = DateFrom.Value.Date;
                specification = specification.And(Spec <Schedule> .New(x => x.StartTime.Date <= dateFrom));
            }

            if (DateTo != null)
            {
                var dateTo = DateTo.Value.Date;
                specification = specification.And(Spec <Schedule> .New(x => x.StartTime.Date >= dateTo));
            }

            if (SubjectId != null)
            {
                var subjectId = SubjectId.Value;
                specification = specification.And(Spec <Schedule> .New(x => x.SubjectId == subjectId));
            }

            if (GroupId != null)
            {
                var groupId = GroupId.Value;
                specification = specification.And(Spec <Schedule> .New(x => x.Subject.GroupId == groupId));
            }

            if (TeacherId != null)
            {
                var teacherId = TeacherId.Value;
                specification = specification.And(Spec <Schedule> .New(x => x.TeacherId == teacherId));
            }

            if (!string.IsNullOrEmpty(LessonType))
            {
                specification = specification.And(
                    Spec <Schedule> .New(x => EF.Functions.Like(x.LessonType, $"%{LessonType}%"))
                    );
            }

            if (!string.IsNullOrEmpty(AudienceNumber))
            {
                specification = specification.And(
                    Spec <Schedule> .New(x => EF.Functions.Like(x.AudienceNumber, $"%{AudienceNumber}%"))
                    );
            }

            if (Duration != null)
            {
                var duration = Duration.Value;
                specification = specification.And(Spec <Schedule> .New(x => x.Duration == duration));
            }

            specification = specification.OrderBy(OrderSpec <Schedule, DateTime> .New(x => x.StartTime));

            return(specification);
        }
        public void Constructor_InlineExpression_ShouldReturnOrderedList()
        {
            var specification = new OrderSpec <Entity, int>(entity => entity.Value1, Sort.Descending);
            var result        = _fixture.Query.OrderBy(specification).ToList();

            result[0].Value1.ShouldBe(3);
            result[1].Value1.ShouldBe(2);
            result[2].Value1.ShouldBe(1);
        }
        public void Constructor_DefaultExpression_ShouldBeTrue()
        {
            var specification = new OrderSpec <Entity, int>();
            var result        = _fixture.Query.OrderBy(specification).ToList();

            result[0].Value1.ShouldBe(3);
            result[1].Value1.ShouldBe(1);
            result[2].Value1.ShouldBe(2);
        }
Exemple #5
0
        public ISpecification <Teacher> ToSpecification()
        {
            var specification = Spec <Teacher> .New();

            if (FacultyId != null)
            {
                var facultyId = FacultyId.Value;
                specification = specification.And(Spec <Teacher> .New(x => x.FacultyId == facultyId));
            }

            if (!string.IsNullOrEmpty(FirstName))
            {
                specification = specification.And(
                    Spec <Teacher> .New(x => EF.Functions.Like(x.FirstName, $"%{FirstName}%"))
                    );
            }

            if (!string.IsNullOrEmpty(LastName))
            {
                specification =
                    specification.And(Spec <Teacher> .New(x => EF.Functions.Like(x.LastName, $"%{LastName}%")));
            }

            if (!string.IsNullOrEmpty(MiddleName))
            {
                specification = specification.And(
                    Spec <Teacher> .New(x => EF.Functions.Like(x.MiddleName, $"%{MiddleName}%"))
                    );
            }

            if (!string.IsNullOrEmpty(Email))
            {
                specification = specification.And(
                    Spec <Teacher> .New(x => EF.Functions.Like(x.Email, $"%{Email}%"))
                    );
            }

            if (!string.IsNullOrEmpty(AvatarPath))
            {
                specification = specification.And(
                    Spec <Teacher> .New(x => EF.Functions.Like(x.AvatarPath, $"%{AvatarPath}%"))
                    );
            }

            var lastNameAscending = OrderSpec <Teacher, string> .New(p => p.LastName);

            var firstNameAscending = OrderSpec <Teacher, string> .New(p => p.FirstName);

            var orderSpecification = lastNameAscending.ThenBy(firstNameAscending);

            specification = specification.UseOrdering(orderSpecification);

            return(specification);
        }
 public OrderingTerm(Expr term
                     , Identifier collation
                     , OrderSpec orderSpec
                     , NullOrder nullOrder)
 {
     this.Comments  = new Comments();
     this.Term      = term;
     this.Collation = collation;
     this.OrderSpec = orderSpec;
     this.NullOrder = nullOrder;
 }
 internal OrderingTerm(Expr term
                       , Identifier collation
                       , OrderSpec orderSpec
                       , NullOrder nullOrder
                       , Comments comments)
 {
     this.Comments = comments;
     this.Term     = term;
     _collation    = collation;
     _orderSpec    = orderSpec;
     _nullOrder    = nullOrder;
 }
Exemple #8
0
        public static ISpecification <T> ToSpecification <T>(this SearchModel model) where T : Entity
        {
            var parameterExpression = Expression.Parameter(typeof(T));

            var memberExpression = Expression.Property(parameterExpression, model.SortColumn);

            var expression = Expression.Convert(memberExpression, typeof(object));

            var lambda = Expression.Lambda <Func <T, object> >(expression, parameterExpression);

            return(OrderSpec <T, object>
                   .New(lambda, model.SortType)
                   .Paginate(model.PageIndex, model.PageSize));
        }
Exemple #9
0
        // Upload the records to the Web Services
        private void button1_Click(object sender, EventArgs e)
        {
            // Verifies if there are items to be imported
            if (listView1.Items.Count > 0)
            {
                // Initialize the variables
                progressBar1.Value   = 0;
                progressBar1.Maximum = listView1.Items.Count;
                button1.Text         = "Working...";

                // Clear Log
                listBox1.Items.Clear();

                // 1 -> Import orders
                if (Operation == 1)
                {
                    // Add information to the Log
                    listBox1.Items.Add("Importing Orders...");
                    listBox1.Refresh();

                    // Caches order classes to speed up the import process
                    if (Load_Order_Classes())
                    {
                        // Required fileds
                        int Idx_Identifier = ColumnId(listView1, "ID");
                        int Idx_Location   = ColumnId(listView1, "LOCATION");
                        int Idx_Size1      = ColumnId(listView1, "SIZE1");
                        int Idx_Size2      = ColumnId(listView1, "SIZE2");
                        int Idx_Size3      = ColumnId(listView1, "SIZE3");
                        int Idx_Type       = ColumnId(listView1, "TYPE");
                        int Idx_Class      = ColumnId(listView1, "CLASS");
                        int Idx_Begin      = ColumnId(listView1, "BEGIN");
                        int Idx_End        = ColumnId(listView1, "END");

                        // Test if all required columns were found
                        if ((Idx_Identifier != -1) & (Idx_Location != -1) & (Idx_Size1 != -1) & (Idx_Size2 != -1) &
                            (Idx_Size3 != -1) & (Idx_Type != -1) & (Idx_Class != -1) & (Idx_Begin != -1) & (Idx_End != -1))
                        {
                            // Process all Orders in the listview
                            foreach (ListViewItem item in listView1.Items)
                            {
                                // Create the Order object
                                OrderSpec order = new OrderSpec();

                                // Check if the Order Type is Delivery or Pickup
                                if (item.SubItems[Idx_Type].Text == "DELIVERY")
                                {
                                    // Create the Task object
                                    DeliveryTaskSpec Delivery_Task = new DeliveryTaskSpec();

                                    // Retrive the EntityKey of the Service Location cache
                                    Delivery_Task.ServiceLocationEntityKey = Location_EntityKey(item.SubItems[Idx_Location].Text);

                                    // Initialize the quantities object
                                    Delivery_Task.Quantities = new Quantities()
                                    {
                                        Size1 = Convert.ToDouble(item.SubItems[Idx_Size1].Text),
                                        Size2 = Convert.ToDouble(item.SubItems[Idx_Size2].Text),
                                        Size3 = Convert.ToDouble(item.SubItems[Idx_Size3].Text),
                                    };

                                    //Create a Delivery Order
                                    order.TaskSpec = Delivery_Task;
                                }
                                else
                                {
                                    // Create the Task object
                                    PickupTaskSpec Pickup_Task = new PickupTaskSpec();

                                    // Retrive the EntityKey of the Service Location cache
                                    Pickup_Task.ServiceLocationEntityKey = Location_EntityKey(item.SubItems[Idx_Location].Text);

                                    // Initialize the quantities object
                                    Pickup_Task.Quantities = new Quantities()
                                    {
                                        Size1 = Convert.ToDouble(item.SubItems[Idx_Size1].Text),
                                        Size2 = Convert.ToDouble(item.SubItems[Idx_Size2].Text),
                                        Size3 = Convert.ToDouble(item.SubItems[Idx_Size3].Text),
                                    };

                                    // Create a Pickup Order
                                    order.TaskSpec = Pickup_Task;
                                }

                                // Mandatory parameters
                                order.ManagedByUserEntityKey = BUKey;
                                order.RegionEntityKey        = RegionKey;
                                order.SessionEntityKey       = SessionKey;

                                // Retrives the EntityKey of the Order Class
                                order.OrderClassEntityKey = OC_EntityKey(item.SubItems[Idx_Class].Text);

                                // Retrives the Order Id
                                order.Identifier = item.SubItems[Idx_Identifier].Text.Trim();

                                // Checks if the Begin date is empty and uses the Route Session Date
                                string beginDate = item.SubItems[Idx_Begin].Text.Trim();
                                if (beginDate.Length > 0)
                                {
                                    order.BeginDate = beginDate;
                                }
                                else
                                {
                                    order.BeginDate = RouteSessionDate;
                                }

                                // Checks if the End date is empty and uses the Route Session Date
                                string endDate = item.SubItems[Idx_End].Text.Trim();
                                if (beginDate.Length > 0)
                                {
                                    order.EndDate = endDate;
                                }
                                else
                                {
                                    order.EndDate = RouteSessionDate;
                                }

                                try
                                {
                                    // Call the Web Services to upload the new order
                                    long entity_key = RNA.WebServices.SaveOrder(order);

                                    listBox1.Items.Add("Order #" + order.Identifier + " - Added [EntityKey: " +
                                                       entity_key.ToString() + "]");
                                }
                                catch (Exception Ex)
                                {
                                    listBox1.Items.Add("Order #" + order.Identifier + " - Warning: " + Ex.Message);
                                }

                                // Move Log to the last position
                                listBox1.SelectedIndex = listBox1.Items.Count - 1;

                                // Increments the progress bar
                                progressBar1.Value++;

                                // Refresh Form
                                this.Refresh();
                            }

                            listBox1.Items.Add("Finished.");
                        }
                        else
                        {
                            MessageBox.Show("One or more required columns was not found.", "Error");
                        }
                    }
                    else
                    {
                        MessageBox.Show("No Order Class found.", "Error");
                    }
                }
                else
                {
                    // Caches Service Window Types and Service Time Types to speed up the import process
                    if (Load_Service_Windows_Types() && Load_Service_Time_Types())
                    {
                        // Add information to the Log
                        listBox1.Items.Add("Importing Locations...");
                        listBox1.Refresh();

                        // Required fileds
                        int Idx_Identifier  = ColumnId(listView1, "ID");
                        int Idx_Description = ColumnId(listView1, "DESCRIPTION");
                        int Idx_Address     = ColumnId(listView1, "ADDRESS");
                        int Idx_City        = ColumnId(listView1, "CITY");
                        int Idx_State       = ColumnId(listView1, "STATE");
                        int Idx_Zip         = ColumnId(listView1, "ZIP");
                        int Idx_Country     = ColumnId(listView1, "COUNTRY");
                        int Idx_SW          = ColumnId(listView1, "SERVICE_WINDOW");
                        int Idx_ST          = ColumnId(listView1, "SERVICE_TIME");

                        // Test if all required columns were found
                        if ((Idx_Identifier != -1) & (Idx_Description != -1) & (Idx_Address != -1) &
                            (Idx_City != -1) & (Idx_State != -1) & (Idx_Zip != -1) & (Idx_Country != -1) &
                            (Idx_SW != -1) & (Idx_ST != -1))
                        {
                            //Create the Service Location object
                            ServiceLocation SrvLoc = new ServiceLocation();

                            //Create an Address object
                            Address LocAddress = new Address();

                            //Process all Locations in the listview
                            foreach (ListViewItem item in listView1.Items)
                            {
                                if (Location_EntityKey(item.SubItems[Idx_Identifier].Text) > 0)
                                {
                                    //Select Update Mode
                                    SrvLoc.Action = ActionType.Update;
                                }
                                else
                                {
                                    //Select Insert Mode
                                    SrvLoc.Action = ActionType.Add;
                                }

                                //Mandatory parameters
                                SrvLoc.BusinessUnitEntityKey      = BUKey;
                                SrvLoc.RegionEntityKeys           = new long[] { RegionKey };
                                SrvLoc.Identifier                 = item.SubItems[Idx_Identifier].Text;
                                SrvLoc.Description                = item.SubItems[Idx_Description].Text;
                                SrvLoc.StandingDeliveryQuantities = new Quantities {
                                };
                                SrvLoc.StandingPickupQuantities   = new Quantities {
                                };

                                //Build Location Address
                                LocAddress.AddressLine1 = item.SubItems[Idx_Address].Text; //Address 1
                                LocAddress.Locality     = new Locality
                                {
                                    AdminDivision2  = item.SubItems[Idx_City].Text,   //City
                                    AdminDivision1  = item.SubItems[Idx_State].Text,  //State
                                    PostalCode      = item.SubItems[Idx_Zip].Text,    //Postal Code
                                    CountryISO3Abbr = item.SubItems[Idx_Country].Text // Country Code
                                };

                                // Load Address into Location object
                                SrvLoc.Address = LocAddress;

                                // Retrives the EntityKey of the Service Window Type
                                SrvLoc.TimeWindowTypeEntityKey = TW_EntityKey(item.SubItems[Idx_SW].Text);
                                // Retrives the EntityKey of the Service Time Type
                                SrvLoc.ServiceTimeTypeEntityKey = ST_EntityKey(item.SubItems[Idx_ST].Text);

                                try
                                {
                                    // Call the Web Services to upload the new Location
                                    long entity_key = RNA.WebServices.SaveLocation(SrvLoc);

                                    listBox1.Items.Add("Location: " + SrvLoc.Identifier + " - Added [EntityKey: " +
                                                       entity_key.ToString() + "]");
                                }
                                catch (Exception Ex)
                                {
                                    listBox1.Items.Add("Location: " + SrvLoc.Identifier + " - Warning: " + Ex.Message);
                                }

                                // Move Log to the last position
                                listBox1.SelectedIndex = listBox1.Items.Count - 1;

                                // Increments the progress bar
                                progressBar1.Value++;

                                // Refresh Form
                                this.Refresh();
                            }
                        }
                        else
                        {
                            MessageBox.Show("One or more required columns was not found.", "Error");
                        }
                    }
                    else
                    {
                        MessageBox.Show("No Service Windows Type or Service Time Type found.", "Error");
                    }
                }

                button1.Text = "Run";
            }
            else
            {
                MessageBox.Show("No items to import.", "Error");
            }
        }