Beispiel #1
0
        /// <summary>
        /// Metoda zawierająca inicjalizację komend opisanych wyżej
        /// </summary>
        private void InitCommand()
        {
            LoadBaseCommand = new RelayCommand(() => {
                var dialog = new OpenFileDialog()
                {
                    //TODO: filters
                };
                dialog.DefaultExt = ".xls";
                dialog.Filter     = "Excel file (*.xls)|*.xls|Excel file (*.xlsx)|*.xlsx|Excel files (*.xls;*.xlsx)|*.xls;*.xlsx";

                if (dialog.ShowDialog() == true)
                {
                    BaseName = dialog.FileName;
                }
            });

            AcceptBaseCommand = new RelayCommand(() => {
                App.Current.MainWindow.Hide();
                ViewModelLocator.Param        = BaseName;
                ActionLoadedBase ActionWindow = new ActionLoadedBase();
                ActionWindow.ShowDialog();

                App.Current.MainWindow.Show();
            });
        }
        /// <summary>
        /// Metoda InitCommand
        /// Zawiera inicjalizacje koimend występujacych w połączeniu widoku i modelu
        /// Są to komendy dodawania kolumn do zmiennej,sprawdzania poprawnosci wypełnienia pól w widoku
        /// oraz komenda przejścia do następnego okna w aplikacji i dodanie kolumn do pliku
        /// </summary>
        private void InitCommand()
        {
            AddColumnCommand = new RelayCommand(() =>
            {
                if (ColumnName == null || ColumnName.FirstOrDefault() >= '0' && ColumnName.FirstOrDefault() <= '9' || ColumnName == "")
                {
                    MessageBoxResult result = MessageBox.Show("Podaj prawidłową nazwę",
                                                              "Confirmation", MessageBoxButton.OK);
                    AddOrNot = "";
                }
                else if (ColumnType == null)
                {
                    MessageBox.Show("Wybierz typ kolumny",
                                    "Confirmation", MessageBoxButton.OK);
                }
                else
                {
                    for (int indexName = 0; indexName < Dt.Columns.Count; indexName++)
                    {
                        if (ColumnName == Dt.Columns[indexName].ToString())
                        {
                            add = 0;
                            break;
                        }
                        else
                        {
                            add = 1;
                        }
                    }
                    if (add == 0)
                    {
                        MessageBoxResult result = MessageBox.Show("Taka kolumna juz istnieje",
                                                                  "Confirmation", MessageBoxButton.OK);
                        ColumnName = "";
                        AddOrNot   = "";
                    }
                    else if (add == 1)
                    {
                        Dt.Columns.Add(ColumnName);
                        CellType cellType;
                        if (ColumnType == "String")
                        {
                            cellType = CellType.String;
                        }
                        else if (ColumnType == "Numeryczny")
                        {
                            cellType = CellType.Numeric;
                        }
                        else
                        {
                            cellType = CellType.Boolean;
                        }
                        ViewModelLocator.ColumnType.Add(cellType);
                        ColumnName = "";
                        AddOrNot   = "Dodano";
                        ColumnType = null;
                    }
                }
            });

            GoNextCommand = new RelayCommand(() =>
            {
                string path         = navigationService.Parameter.ToString();
                FileStream stream   = new FileStream(path, FileMode.Open, FileAccess.Read);
                IWorkbook woorkbook = new XSSFWorkbook(stream);
                stream.Close();
                string SheetName = woorkbook.GetSheetName(0);
                ISheet sheet     = woorkbook.GetSheet(SheetName);
                IRow row         = sheet.CreateRow(0);


                for (int j = 0; j < Dt.Columns.Count; j++)
                {
                    var cell = row.CreateCell(j);
                    cell.SetCellValue(Dt.Columns[j].ToString());
                }


                stream = new FileStream(path, FileMode.Create, FileAccess.Write);
                woorkbook.Write(stream);

                stream.Close();

                AddOrNot = "";
                Dt.Clear();
                App.Current.MainWindow.Hide();
                ViewModelLocator.Param        = path;
                ActionLoadedBase ActionWindow = new ActionLoadedBase();
                ActionWindow.ShowDialog();

                App.Current.MainWindow.Show();
            });
        }