示例#1
0
        /// <summary>
        /// Event that calls the method to Generate the NetWork and Grafcet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_GenerateNetNGraf_Click(object sender, RoutedEventArgs e)
        {
            bool importToTia = (bool)cbImportToTia.IsChecked;

            if (FilePath.Contains(".xlsx") || FilePath.Contains(".xlsm") || FilePath.Contains(".xltx") || FilePath.Contains(".xltm"))
            {
                WriteSavingLabelText("Generating NetNGraf...");

                BlocksCreated = new List <string>();
                RetrieveValues();

                // Update lists "SheetsStepS" and "SheetsNameS"
                foreach (WorkSheet ws in workSheets)
                {
                    if (ws.WorkSheetSteps.Count() > 1)
                    {
                        SaveWorksheetIntoMatrix(ws, ws.WorkSheetName);
                    }
                    else
                    {
                        MessageBox.Show("Worksheet \"" + ws.WorkSheetName + "\" will not be generated because it does not have sufficient steps.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                UpdateWorksheetSteps();

                PlcSoftware plcS = null;

                GrafcetManager.SavePath = Path.Combine(savePath, "50_Stationen");

                if (current != null)
                {
                    plcS = (PlcSoftware)(current as PlcBlockUserGroup).Parent.Parent;
                }

                try
                {
                    GrafcetManager.GenerateGrafcet(sheetsStepS, sheetsNameS, plcS);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    WriteSavingLabelText("");
                    return;
                }

                if (importToTia)
                {
                    BlocksCreated = BlocksCreated.Distinct().ToList();
                    using (var access = tiaPortal.ExclusiveAccess("Importing elements"))
                    {
                        ExcelManager.BlocksImporter(savePath, current, "50_Stationen", BlocksCreated);
                    }
                }

                Changes = true;
                WriteSavingLabelText("");
            }
        }
示例#2
0
        /// <summary>
        /// Saves the current DataGrid values in the chosen path
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Save_Click(object sender, RoutedEventArgs e)
        {
            WriteSavingLabelText("Saving...");

            if (ExcelManager.IsOpened(FilePath))
            {
                MessageBox.Show("Please close the current workbook before saving");
            }
            else
            {
                RetrieveValues();

                if (FilePath.Contains(".xlsx") || FilePath.Contains(".xlsm") || FilePath.Contains(".xltx") || FilePath.Contains(".xltm"))
                {
                    Excel.Application xlApp = new Excel.Application
                    {
                        DisplayAlerts = false
                    };
                    Workbook xlWorkbook = xlApp.Workbooks.Open(FilePath);
                    int      row        = 4;
                    var      matrixs    = new List <object[, ]>();
                    var      sheetNames = new List <string>();

                    foreach (Worksheet sheet in xlWorkbook.Worksheets)
                    {
                        string sheetName = sheet.Name;
                        if (!sheetName.Contains("AS_") || sheetName.Equals("AS_000000"))
                        {
                            continue;
                        }

                        object[,] matrix = OpennessHelper.ExcelToMatrix(sheet);
                        if (sheet.Name.Contains(ComboSheet.SelectedItem.ToString()))
                        {
                            Ws = sheet;
                            while (Ws.Cells[row, 3].Value != null)
                            {
                                Ws.Cells[row, 3].Value = null;
                                Ws.Cells[row, 4].Value = null;
                                Ws.Cells[row, 5].Value = null;
                                Ws.Cells[row, 6].Value = null;
                                Ws.Cells[row, 7].Value = null;
                                Ws.Cells[row, 8].Value = null;

                                row += 1;
                            }

                            row = 4;

                            foreach (Step step in steps)
                            {
                                Ws.Cells[row, 2].Value = step.StepNumber;
                                Ws.Cells[row, 3].Value = step.Schritt.Replace(" ", string.Empty);
                                Ws.Cells[row, 4].Value = step.Beschreibung;
                                Ws.Cells[row, 5].Value = step.Aktion.Replace(" ", string.Empty);
                                Ws.Cells[row, 6].Value = step.Vorheriger_Schritt.Replace(" ", string.Empty);
                                Ws.Cells[row, 7].Value = step.Nächster_Schritt.Replace(" ", string.Empty);
                                Ws.Cells[row, 8].Value = step.Zeit_Schritt.ToLower().Replace(" ", string.Empty).Replace("ms", string.Empty);

                                matrix[row, 2] = step.StepNumber;
                                matrix[row, 3] = step.Schritt.Replace(" ", string.Empty);
                                matrix[row, 4] = step.Beschreibung;
                                matrix[row, 5] = step.Aktion.Replace(" ", string.Empty);
                                matrix[row, 6] = step.Vorheriger_Schritt.Replace(" ", string.Empty);
                                matrix[row, 7] = step.Nächster_Schritt.Replace(" ", string.Empty);
                                matrix[row, 8] = step.Zeit_Schritt.ToLower().Replace(" ", string.Empty).Replace("ms", string.Empty);

                                row += 1;
                            }
                        }
                        matrixs.Add(matrix);
                        sheetNames.Add(sheet.Name);
                    }

                    MatrixList(matrixs);
                    SheetNamesList(sheetNames);

                    xlWorkbook.Save();
                    xlWorkbook.Close(0);
                    xlApp.Quit();

                    sheetsStepS = new List <object[, ]>();
                    foreach (var m in matrixs)
                    {
                        sheetsStepS.Add(m);
                    }
                    sheetsNameS = new List <string>();
                    foreach (var n in sheetNames)
                    {
                        sheetsNameS.Add(n);
                    }

                    Saving.Text = "";
                    Saving.Update();

                    if (Ws == null)
                    {
                        System.Windows.MessageBox.Show("This Excel does not contain a usable worksheet", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }

            WriteSavingLabelText("");
        }