private void OnPlannedItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     // Hack to force 'UnselectedAll' after loading (default: 1st list item selected)
     if (((PlanningViewModel)DataContext).FirstLoading)
     {
         PlannedItems.UnselectAll();
     }
 }
        private void Button_Click_ESR_Filter(object sender, RoutedEventArgs e)
        {
            Button clickedButton = (Button)sender;

            UnselectTextButtons();
            clickedButton.Style = Resources["TextButtonSelectedStyle"] as Style;
            ((PlanningViewModel)DataContext).FilterDisplayedPlants(clickedButton.Name);
            PlannedItems.UnselectAll();
        }
Ejemplo n.º 3
0
        private async Task ProcessSelectedOrderSwap(IDropInfo dropInfo, ProductionOrder selectedItem, string selectedESR)
        {
            int oldIndex = PlannedItems.IndexOf(selectedItem);

            int newIndex = dropInfo.InsertIndex;

            if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem || dropInfo.InsertPosition.Equals(RelativeInsertPosition.AfterTargetItem | RelativeInsertPosition.TargetItemCenter))
            {
                newIndex = dropInfo.InsertIndex - 1; // Hack to guarantee we don't insert after the Target Item position
            }
            // Safety measure considering the "index" is provided by the drag-and-drop used library
            if (newIndex >= PlannedItems.Count)
            {
                newIndex = PlannedItems.Count - 1;
            }

            ProductionOrder targetLocationOrder = PlannedItems[newIndex];

            // Block Swaps that are not allowed
            bool allowed = await CheckIfSwapIsAllowed(selectedESR, targetLocationOrder);

            if (!allowed)
            {
                return;
            }

            // Update the dragged ProductionOrder to the new ESR
            selectedItem.PlantID = targetLocationOrder.PlantID;
            selectedItem.Plant   = targetLocationOrder.Plant;

            // Updating the "Planner"
            UnsetCollectionGroupings(PlannedItems);
            PlannedItems.Move(oldIndex, newIndex);
            SetCollectionGrouping(PlannedItems, "Plant.Name");
            ResetPlannerSelectionState();
            PlannedItems.SortCollectionBy(m => m.Plant.Name);
            RaisePropertyChanged("PlannedItems");
        }
Ejemplo n.º 4
0
        private async Task ProcessSelectedOrdersShift(IDropInfo dropInfo, List <ProductionOrder> draggedItems, string selectedESR)
        {
            int insertIndex = (dropInfo.InsertIndex != dropInfo.UnfilteredInsertIndex) ? dropInfo.UnfilteredInsertIndex : dropInfo.InsertIndex;

            if (dropInfo.VisualTarget is ItemsControl itemsControl)
            {
                IEditableCollectionView editableItems = itemsControl.Items;
                if (editableItems != null)
                {
                    NewItemPlaceholderPosition newItemPlaceholderPosition = editableItems.NewItemPlaceholderPosition;
                    if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtBeginning && insertIndex == 0)
                    {
                        insertIndex++;
                    }
                    else if (newItemPlaceholderPosition == NewItemPlaceholderPosition.AtEnd && insertIndex == itemsControl.Items.Count)
                    {
                        insertIndex--;
                    }
                }

                // Hack to guarantee we don't insert after the Target Item position
                if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem || dropInfo.InsertPosition.Equals(RelativeInsertPosition.AfterTargetItem | RelativeInsertPosition.TargetItemCenter))
                {
                    insertIndex = insertIndex - 1;
                }

                ProductionOrder targetLocationOrder = PlannedItems[insertIndex];

                // Block Swaps that are not allowed
                bool allowed = await CheckIfSwapIsAllowed(selectedESR, targetLocationOrder);

                if (!allowed)
                {
                    return;
                }

                // Removing the "Planner" Groupings
                UnsetCollectionGroupings(PlannedItems);

                // Removal of the Selected Rows
                foreach (ProductionOrder selectedItem in draggedItems)
                {
                    int oldIndex = PlannedItems.IndexOf(selectedItem);
                    PlannedItems.RemoveAt(oldIndex);
                    if (oldIndex < insertIndex)
                    {
                        insertIndex--;
                    }
                }

                // Insertion of the Selected Rows in the new positions
                foreach (ProductionOrder selectedItem in draggedItems)
                {
                    // Update the dragged ProductionOrder to the new ESR before Insertion
                    selectedItem.PlantID = targetLocationOrder.PlantID;
                    selectedItem.Plant   = targetLocationOrder.Plant;
                    PlannedItems.Insert(insertIndex++, selectedItem);
                }

                // Updating the "Planner"
                SetCollectionGrouping(PlannedItems, "Plant.Name");
                ResetPlannerSelectionState();
                PlannedItems.SortCollectionBy(m => m.Plant.Name);
                RaisePropertyChanged("PlannedItems");
            }
        }
Ejemplo n.º 5
0
        public async void ExportPlanner()
        {
            try
            {
                var dialog = new CommonOpenFileDialog
                {
                    IsFolderPicker = true
                };
                CommonFileDialogResult result = dialog.ShowDialog();

                if (result == CommonFileDialogResult.Cancel || result == CommonFileDialogResult.None)
                {
                    return;
                }

                string selectedDirectory = dialog.FileName + @"\";

                DirectoryInfo di = new DirectoryInfo(selectedDirectory);

                if (di.Exists == false)
                {
                    di.Create();
                }

                // Delete previously created file
                var file = di.GetFiles().Where(x => x.Name.Contains("IMAS_Office_Planner_Export")).FirstOrDefault();
                if (file != null)
                {
                    file.Delete();
                }

                StreamWriter sw = new StreamWriter(selectedDirectory + "IMAS_Office_Planner_Export" + ".xls", false)
                {
                    AutoFlush = true
                };

                // HEADER
                sw.Write("\t" + Loc("Plant"));
                sw.Write("\t" + Loc("Count"));
                sw.Write("\t" + Loc("MotherHeatNumber"));
                sw.Write("\t" + Loc("SteelGrade"));
                sw.Write("\t" + Loc("Format"));
                sw.Write("\t" + Loc("DeliveryDate"));
                sw.Write("\t" + Loc("GlowGroup"));
                sw.Write("\t" + Loc("ChargeNumber"));
                sw.WriteLine("\t" + Loc("Comments"));

                // CONTENT
                for (int row = 0; row < PlannedItems.Count; row++)
                {
                    string st1     = "";
                    var    rowItem = PlannedItems[row];

                    int chargesNumber = PlannedItems.Where(x => x.MotherHeatID == rowItem.MotherHeatID).Count();

                    st1 += "\t" + rowItem.Plant.Name;
                    st1 += "\t" + rowItem.Quantity;
                    st1 += "\t" + rowItem.MotherHeat.Name;
                    st1 += "\t" + rowItem.Grade.Name;
                    st1 += "\t" + rowItem.ElectrodeFormat.Name;
                    st1 += "\t" + rowItem.DeliveryDate;
                    st1 += "\t" + rowItem.GlowGroup;
                    st1 += "\t" + chargesNumber;
                    st1 += "\t" + rowItem.Comments;

                    sw.WriteLine(st1);
                }

                sw.Close();

                await facade.Dialog().ShowMessageAsync(this, Loc("SuccessTitle"), Loc("DialogExportToExcelSuccess"));
            }
            catch (Exception e)
            {
                await facade.Dialog().ShowMessageAsync(this, Loc("ErrorTitle"), e.Message);
            }

            /*****************************************************************************************
            *
            *  PURE MICROSOFT EXCEL APPROACH
            *
            *  Requirement: The running machine must have MS Office (Excel) installed
            *
            *  Comment: The code was not tested due to the aforementioned requirement not being met
            *
            *****************************************************************************************/
            /*try
             * {
             *  Excel.Application app = new Excel.Application
             *  {
             *      Visible = true
             *  };
             *
             *  Excel.Workbook wb = app.Workbooks.Add(1);
             *  Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
             *
             *  // HEADER
             *  ws.Cells[1, 1] = Loc("Plant");
             *  ws.Cells[1, 2] = Loc("Count");
             *  ws.Cells[1, 3] = Loc("MotherHeatNumber");
             *  ws.Cells[1, 4] = Loc("SteelGrade");
             *  ws.Cells[1, 5] = Loc("Format");
             *  ws.Cells[1, 6] = Loc("DeliveryDate");
             *  ws.Cells[1, 7] = Loc("GlowGroup");
             *  ws.Cells[1, 8] = Loc("ChargeNumber");
             *  ws.Cells[1, 9] = Loc("Comments");
             *
             *  for (int row = 0; row < PlannedItems.Count; row++)
             *  {
             *      var rowItem = PlannedItems[row];
             *
             *      // CONTENT
             *      ws.Cells[row + 2, 1] = rowItem.Plant.Name;
             *      ws.Cells[row + 2, 2] = rowItem.Quantity;
             *      ws.Cells[row + 2, 3] = rowItem.MotherHeatNumber;
             *      ws.Cells[row + 2, 4] = rowItem.Grade.Name;
             *      ws.Cells[row + 2, 5] = rowItem.RawElectrodeFormat;
             *      ws.Cells[row + 2, 6] = rowItem.DeliveryDate;
             *      ws.Cells[row + 2, 7] = rowItem.GlowGroup;
             *      ws.Cells[row + 2, 8] = rowItem.ChargesNumber;
             *      ws.Cells[row + 2, 9] = rowItem.Comments;
             *  }
             *
             *  // AutoSet Cell Widths to Content Size
             *  ws.Cells.Select();
             *  ws.Cells.EntireColumn.AutoFit();
             *
             *  wb.Save();
             *
             *  await facade.Dialog().ShowMessageAsync(this, Loc("SuccessTitle"), Loc("DialogExportToExcelSuccess"));
             * }
             * catch (Exception e)
             * {
             *  await facade.Dialog().ShowMessageAsync(this, Loc("ErrorTitle"), e.Message);
             * }*/
        }