Update() private method

private Update ( ) : void
return void
Exemplo n.º 1
0
 /// <summary>
 /// Write text on label "Saving"
 /// </summary>
 /// <param name="text"></param>
 private void WriteSavingLabelText(string text)
 {
     Saving.Text = text;
     Saving.Update();
 }
Exemplo n.º 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("");
        }