コード例 #1
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            ConstantWindow constantWindow = new ConstantWindow();

            if ((bool)constantWindow.ShowDialog(this))
            {
                long insertedValueId;
                switch (Constant.SelectedIndex)
                {
                case 0:
                    insertedValueId = BusinessEntity.Insert(constantWindow.Value);
                    break;

                case 1:
                    insertedValueId = Activity.Insert(constantWindow.Value);
                    break;

                default:
                    insertedValueId = ActivityDirection.Insert(constantWindow.Value);
                    break;
                }
                UpdateValues();
                Values.SelectItem(Values.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == insertedValueId));
            }
        }
コード例 #2
0
 public FieldValidationDTO(Guid currentActionId, string fieldName, ActivityDirection direction, string manifestType, string crateLabel)
 {
     FieldName         = fieldName;
     CrateLabel        = crateLabel;
     Direction         = direction;
     ManifestType      = manifestType;
     CurrentActivityId = currentActionId;
 }
コード例 #3
0
        private bool ValueExists()
        {
            switch (Constant.SelectedIndex)
            {
            case 0:
                return(BusinessEntity.Exists((long)(Values.SelectedItem as TextBlock).Tag));

            case 1:
                return(Activity.Exists((long)(Values.SelectedItem as TextBlock).Tag));

            default:
                return(ActivityDirection.Exists((long)(Values.SelectedItem as TextBlock).Tag));
            }
        }
コード例 #4
0
        private void UpdateValues()
        {
            Values.Items.Clear();
            switch (Constant.SelectedIndex)
            {
            case 0:
                BusinessEntity.Select().ForEach(x => Values.Items.Add(BusinessEntity.ToTextBlock(x)));
                break;

            case 1:
                Activity.Select().ForEach(x => Values.Items.Add(Activity.ToTextBlock(x)));
                break;

            case 2:
                ActivityDirection.Select().ForEach(x => Values.Items.Add(ActivityDirection.ToTextBlock(x)));
                break;
            }
        }
コード例 #5
0
        private void Delete_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (ValueExists())
            {
                if ((bool)new ConfirmationWindow().ShowDialog(this))
                {
                    if (ValueExists())
                    {
                        if (!DealerExists())
                        {
                            switch (Constant.SelectedIndex)
                            {
                            case 0:
                                BusinessEntity.Delete((long)(Values.SelectedItem as TextBlock).Tag);
                                break;

                            case 1:
                                Activity.Delete((long)(Values.SelectedItem as TextBlock).Tag);
                                break;

                            case 2:
                                ActivityDirection.Delete((long)(Values.SelectedItem as TextBlock).Tag);
                                break;
                            }
                            UpdateValues();
                            Values.SelectItem();
                        }
                        else
                        {
                            ShowErrorWindow(4, false);
                        }
                    }
                    else
                    {
                        ShowErrorWindow(3);
                    }
                }
            }
            else
            {
                ShowErrorWindow(3);
            }
        }
コード例 #6
0
        private void Save_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (TextBox.Text != string.Empty)
            {
                switch ((Owner as ConstantsWindow).Constant.SelectedIndex)
                {
                case 0:
                    e.CanExecute = !ErrorWindow.CriticalError && !BusinessEntity.Exists(TextBox.Text, (long)Tag);
                    break;

                case 1:
                    e.CanExecute = !ErrorWindow.CriticalError && !Activity.Exists(TextBox.Text, (long)Tag);
                    break;

                case 2:
                    e.CanExecute = !ErrorWindow.CriticalError && !ActivityDirection.Exists(TextBox.Text, (long)Tag);
                    break;
                }
            }
        }
コード例 #7
0
        private void Edit_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (ValueExists())
            {
                long           selectedValueId = (long)(Values.SelectedItem as TextBlock).Tag;
                ConstantWindow constantWindow  = new ConstantWindow((Values.SelectedItem as TextBlock).Text, selectedValueId);
                if ((bool)constantWindow.ShowDialog(this))
                {
                    if (ValueExists())
                    {
                        switch (Constant.SelectedIndex)
                        {
                        case 0:
                            BusinessEntity.Update(selectedValueId, constantWindow.Value);
                            break;

                        case 1:
                            Activity.Update(selectedValueId, constantWindow.Value);
                            break;

                        case 2:
                            ActivityDirection.Update(selectedValueId, constantWindow.Value);
                            break;
                        }
                        UpdateValues();
                        Values.SelectItem(Values.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedValueId));
                    }
                    else
                    {
                        ShowErrorWindow(2);
                    }
                }
            }
            else
            {
                ShowErrorWindow(2);
            }
        }
コード例 #8
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Entities.BusinessEntity.Select().ForEach(x => BusinessEntity.Items.Add(Entities.BusinessEntity.ToTextBlock(x)));
     Entities.Activity.Select().ForEach(x => Activity.Items.Add(Entities.Activity.ToTextBlock(x)));
     Entities.ActivityDirection.Select().ForEach(x => ActivityDirection.Items.Add(Entities.ActivityDirection.ToTextBlock(x)));
     Entities.Region.Select().ForEach(x => Region.Items.Add(Entities.Region.ToTextBlock(x)));
     if (Dealer == null)
     {
         Dealer = new Dealer();
         BusinessEntity.SelectItem();
         Activity.SelectItem();
         ActivityDirection.SelectItem();
         Region.SelectItem();
         Title = "Добавление дилера";
     }
     else
     {
         BusinessEntity.SelectItem(BusinessEntity.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.BusinessEntityId));
         _Name.Text = Dealer.Name;
         Activity.SelectItem(Activity.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.ActivityId));
         ActivityDirection.SelectItem(ActivityDirection.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.ActivityDirectionId));
         Rating.SelectItem(selectedIndex: 5 - (int)Dealer.Rating);
         Relevance.SelectItem(selectedIndex: Dealer.IsRelevant ? 0 : 1);
         Region.SelectItem(Region.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == Dealer.RegionId));
         City.Text   = Dealer.City;
         Street.Text = Dealer.Street;
         House.Text  = Dealer.House;
         Block.Text  = Dealer.Block;
         Room.Text   = Dealer.Room;
         UpdateContacts();
         Contacts.SelectItem();
         Note.Text       = Dealer.Note;
         Conditions.Text = Dealer.Conditions;
         UpdateEvents();
         Events.SelectItem(selectedIndex: 1);
         Title = "Правка дилера";
     }
 }
コード例 #9
0
        public void UpdateDealers()
        {
            long selectedRegionId            = (long)(Region.SelectedItem as TextBlock).Tag;
            long selectedActivityId          = (long)(Activity.SelectedItem as TextBlock).Tag;
            long selectedActivityDirectionId = (long)(ActivityDirection.SelectedItem as TextBlock).Tag;

            Region.Items.RemoveRange(1, Region.Items.Count - 1);
            Entities.Region.Select().ForEach(x => Region.Items.Add(Entities.Region.ToTextBlock(x)));
            Region.SelectItem(Region.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedRegionId));
            Activity.Items.RemoveRange(1, Activity.Items.Count - 1);
            Entities.Activity.Select().ForEach(x => Activity.Items.Add(Entities.Activity.ToTextBlock(x)));
            Activity.SelectItem(Activity.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedActivityId));
            ActivityDirection.Items.RemoveRange(1, ActivityDirection.Items.Count - 1);
            Entities.ActivityDirection.Select().ForEach(x => ActivityDirection.Items.Add(Entities.ActivityDirection.ToTextBlock(x)));
            ActivityDirection.SelectItem(ActivityDirection.Items.FirstOrDefault <TextBlock>(x => (long)x.Tag == selectedActivityDirectionId));
            Region.Tag            = (Region.SelectedItem as TextBlock).Tag;
            Activity.Tag          = (Activity.SelectedItem as TextBlock).Tag;
            ActivityDirection.Tag = (ActivityDirection.SelectedItem as TextBlock).Tag;
            Relevance.Tag         = (long)Relevance.SelectedIndex;
            Sort.Tag = (long)Sort.SelectedIndex;
            Dealers.Items.Clear();
            Dealer.Select(new Filter(true)).ForEach(x => Dealers.Items.Add(Dealer.ToTextBlock(x)));
        }
コード例 #10
0
        private FlowDocument GenerateFlowDocument()
        {
            Table table = new Table()
            {
                FontFamily    = new FontFamily("Times New Roman"),
                FontSize      = 12,
                Foreground    = Brushes.Black,
                TextAlignment = TextAlignment.Center
            };
            Style tableCellStyle = new Style(typeof(TableCell));

            tableCellStyle.Setters.Add(new Setter(TableCell.BorderBrushProperty, Brushes.Black));
            tableCellStyle.Setters.Add(new Setter(TableCell.BorderThicknessProperty, new Thickness(1)));
            tableCellStyle.Setters.Add(new Setter(TableCell.PaddingProperty, new Thickness(2)));
            Dealer.Select(new Filter(true)).ForEach(x =>
            {
                Dealer dealer      = Dealer.FromDataRow(x);
                Contact contact    = dealer.Contacts.FirstOrDefault();
                Phone phone        = contact?.Phones.FirstOrDefault();
                TableCell nameCell = new TableCell(new Paragraph(new Run($"{BusinessEntity.Select(dealer.BusinessEntityId).Field<string>("Name")} \"{dealer.Name}\"")))
                {
                    Style = tableCellStyle
                };
                TableCell regionCell = new TableCell(new Paragraph(new Run(Region.Select(dealer.RegionId).Field <string>("Name"))))
                {
                    Style = tableCellStyle
                };
                TableCell activityCell = new TableCell(new Paragraph(new Run(Activity.Select(dealer.ActivityId).Field <string>("Name"))))
                {
                    Style = tableCellStyle
                };
                TableCell activityDirectionCell = new TableCell(new Paragraph(new Run(ActivityDirection.Select(dealer.ActivityDirectionId).Field <string>("Name"))))
                {
                    Style = tableCellStyle
                };
                TableCell ratingCell = new TableCell(new Paragraph(new Run(new string('★', (int)dealer.Rating))))
                {
                    Style = tableCellStyle
                };
                TableCell contactCell = new TableCell(new Paragraph(new Run(contact == null ? "–" : $"{contact.Surname} {contact.Name} {contact.Patronymic}".Trim())))
                {
                    Style = tableCellStyle
                };
                TableCell positionCell = new TableCell(new Paragraph(new Run(contact == null || contact.Position == string.Empty ? "–" : contact.Position)))
                {
                    Style = tableCellStyle
                };
                TableCell phoneCell = new TableCell(new Paragraph(new Run(phone == null ? "–" : phone.Value)))
                {
                    Style = tableCellStyle
                };
                TableRow tableRow = new TableRow();
                tableRow.Cells.Add(nameCell);
                tableRow.Cells.Add(regionCell);
                tableRow.Cells.Add(activityCell);
                tableRow.Cells.Add(activityDirectionCell);
                tableRow.Cells.Add(ratingCell);
                tableRow.Cells.Add(contactCell);
                tableRow.Cells.Add(positionCell);
                tableRow.Cells.Add(phoneCell);
                TableRowGroup tableRowGroup = new TableRowGroup();
                tableRowGroup.Rows.Add(tableRow);
                table.RowGroups.Add(tableRowGroup);
            });
            PrintDialog printDialog = new PrintDialog();

            return(new FlowDocument(table)
            {
                Background = Brushes.White,
                PageWidth = printDialog.PrintableAreaHeight,
                PageHeight = printDialog.PrintableAreaWidth,
                ColumnWidth = printDialog.PrintableAreaHeight
            });
        }
コード例 #11
0
        private void CalculateCriticalPath(IEnumerable <Activity> activities, Activity currentAct, string result,
                                           Activity endingActivity, float?[] deltaLink, Dictionary <int, bool> visited, List <ActivityWithDirection> tempResults,
                                           List <List <ActivityWithDirection> > results, ActivityDirection direction, ActivityDirection previousDirection)
        {
            if (visited[currentAct.Id])
            {
                return;
            }

            visited[currentAct.Id] = true;

            if (deltaLink != null)
            {
                tempResults.Add(new ActivityWithDirection
                {
                    LinkDistance = new LinkDistance
                    {
                        StartingDuration = deltaLink[0],
                        StartingUnit     = deltaLink[1]
                    },
                    Direction = previousDirection
                });
            }

            tempResults.Add(new ActivityWithDirection {
                Activity = currentAct, Direction = direction
            });

            if (currentAct.Id == endingActivity.Id)
            {
                results.Add(tempResults);
                return;
            }

            if (direction == ActivityDirection.Normal)
            {
                foreach (var next in activities.Where(l => Math.Abs(currentAct.ToDuration - l.FromDuration) < 0.02))
                {
                    var delta = currentAct.ToUnit - next.FromUnit;
                    if (delta >= 0 && !visited[next.Id])
                    {
                        float?[] dLink = null;
                        if (delta > 0)
                        {
                            dLink = new float?[] { next.FromDuration, next.FromUnit }
                        }
                        ;

                        CalculateCriticalPath(activities, next, result, endingActivity, dLink,
                                              visited.ToDictionary(entry => entry.Key, entry => entry.Value),
                                              tempResults.CloneLists(), results, ActivityDirection.Normal, ActivityDirection.Normal);
                    }
                }

                foreach (var next in activities.Where(l => Math.Abs(currentAct.ToDuration - l.ToDuration) < 0.02))
                {
                    var delta = currentAct.ToUnit - next.ToUnit;
                    if (delta >= 0 && !visited[next.Id])
                    {
                        float?[] dLink = null;
                        if (delta > 0)
                        {
                            dLink = new float?[] { next.ToDuration, next.ToUnit }
                        }
                        ;

                        CalculateCriticalPath(activities, next, result, endingActivity, dLink,
                                              visited.ToDictionary(entry => entry.Key, entry => entry.Value),
                                              tempResults.CloneLists(), results, ActivityDirection.Reverse, ActivityDirection.Normal);
                    }
                }
            }

            if (direction == ActivityDirection.Reverse)
            {
                foreach (var next in activities.Where(l => Math.Abs(currentAct.FromDuration - l.FromDuration) < 0.02))
                {
                    var delta = currentAct.FromUnit - next.FromUnit;
                    if (delta >= 0 && !visited[next.Id])
                    {
                        float?[] dLink = null;
                        if (delta > 0)
                        {
                            dLink = new float?[] { next.FromDuration, next.FromUnit }
                        }
                        ;

                        CalculateCriticalPath(activities, next, result, endingActivity, dLink,
                                              visited.ToDictionary(entry => entry.Key, entry => entry.Value),
                                              tempResults.CloneLists(), results, ActivityDirection.Normal, ActivityDirection.Reverse);
                    }
                }

                foreach (var next in activities.Where(l => Math.Abs(currentAct.FromDuration - l.ToDuration) < 0.02))
                {
                    var delta = currentAct.FromUnit - next.ToUnit;
                    if (delta >= 0 && !visited[next.Id])
                    {
                        float?[] dLink = null;
                        if (delta > 0)
                        {
                            dLink = new float?[] { next.FromDuration, next.FromUnit }
                        }
                        ;

                        CalculateCriticalPath(activities, next, result, endingActivity, dLink,
                                              visited.ToDictionary(entry => entry.Key, entry => entry.Value),
                                              tempResults.CloneLists(), results, ActivityDirection.Reverse, ActivityDirection.Reverse);
                    }
                }
            }
        }
コード例 #12
0
        public List <List <ActivityWithDirection> > CalculateCriticalPath(IEnumerable <Activity> activities,
                                                                          Activity startingActivity, Activity endingActivity, ActivityDirection direction)
        {
            var results     = new List <List <ActivityWithDirection> >();
            var tempResults = new List <ActivityWithDirection>();
            var result      = "";
            var visited     = new Dictionary <int, bool>();

            activities.ToList().ForEach(l => visited.Add(l.Id, false));
            CalculateCriticalPath(activities, startingActivity, result, endingActivity, null, visited,
                                  tempResults.CloneLists(), results, direction, ActivityDirection.Normal);
            return(results);
        }