public static void Save(EmployeeList empList, DepartmentList depList) { DataContractJsonSerializer JsonFormatterEmp = new DataContractJsonSerializer(typeof(List <Employee>)); DataContractJsonSerializer JsonFormatterDep = new DataContractJsonSerializer(typeof(List <Department>)); var dlg = new System.Windows.Forms.FolderBrowserDialog(); System.Windows.Forms.DialogResult result = dlg.ShowDialog(); string fileName = "Untitled"; int index = 0; if (result == System.Windows.Forms.DialogResult.OK) { fileName = dlg.SelectedPath; index = fileName.LastIndexOf(@"\"); } string empListName = fileName + fileName.Remove(0, index) + "(Employee).json"; string depListName = fileName + fileName.Remove(0, index) + "(Department).json"; using (FileStream fs = new FileStream(empListName, FileMode.OpenOrCreate)) { JsonFormatterEmp.WriteObject(fs, empList.empManager); } using (FileStream fs = new FileStream(depListName, FileMode.OpenOrCreate)) { JsonFormatterDep.WriteObject(fs, depList.depManager); } if (Directory.Exists(fileName)) { ZipFile.CreateFromDirectory(fileName, fileName + ".zip"); Directory.Delete(fileName, true); } }
public static void Load(EmployeeList empList, DepartmentList depList) { DataContractJsonSerializer JsonFormatterEmp = new DataContractJsonSerializer(typeof(List <Employee>)); DataContractJsonSerializer JsonFormatterDep = new DataContractJsonSerializer(typeof(List <Department>)); try { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "*.ZIP | *.zip"; string fileName = ""; int index = 0; bool?result = dlg.ShowDialog(); if (result == true) { fileName = dlg.FileName.Remove(dlg.FileName.Length - 4, 4); index = fileName.LastIndexOf(@"\"); } string empListPath = fileName + fileName.Remove(0, index) + "(Employee).json"; string depListPath = fileName + fileName.Remove(0, index) + "(Department).json"; ZipFile.ExtractToDirectory(fileName + ".zip", fileName); using (FileStream fs = new FileStream(empListPath, FileMode.Open)) { if (fs.Length > 0) { empList.empManager = (List <Employee>)JsonFormatterEmp.ReadObject(fs); } } using (FileStream fs = new FileStream(depListPath, FileMode.Open)) { if (fs.Length > 0) { depList.depManager = (List <Department>)JsonFormatterDep.ReadObject(fs); } } foreach (Employee item in empList.empManager) { if (item.BossIndex != -1) { item.boss = empList.empManager[item.BossIndex]; item.boss.subWorker = new List <Employee>(); item.boss.subWorker.Add(item); } if (item.DepIndex != -1) { item.dep = depList.depManager[item.DepIndex]; } if (item.SubWorkerIndex != null) { foreach (int i in item.SubWorkerIndex) { item.subWorker.Add(empList.empManager[i]); } foreach (Employee sub in item.subWorker) { sub.boss = item; } } } foreach (Department item in depList.depManager) { if (item.BossIndex != -1) { item.boss = empList.empManager[item.BossIndex]; item.boss.dep = item; } } Directory.Delete(fileName, true); } catch { MessageBox.Show("Ошибка при открытии файла!"); } }
public DepartmentWindow(Window _window, MainWindow _mainWindow, EmployeeList _empList, DepartmentList _depList) { InitializeComponent(); //горячие клавиши AppSettingsReader reader = new AppSettingsReader(); KeyGestureConverter gestureConverter = new KeyGestureConverter(); try { string tmp = (string)reader.GetValue("Save", typeof(string)); KeyGesture saveKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding saveKeyBinding = new KeyBinding(new RelayCommand(o => { FileManager.Save(empList, depList); }, o => true), saveKeyGesture); InputBindings.Add(saveKeyBinding); } catch { } try { string tmp = (string)reader.GetValue("Load", typeof(string)); gestureConverter = new KeyGestureConverter(); KeyGesture loadKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding loadKeyBinding = new KeyBinding(new RelayCommand(o => { FileManager.Load(empList, depList); }, o => true), loadKeyGesture); InputBindings.Add(loadKeyBinding); } catch { } try { string tmp = (string)reader.GetValue("Plugins", typeof(string)); gestureConverter = new KeyGestureConverter(); KeyGesture pluginsKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding pluginsKeyBinding = new KeyBinding(new RelayCommand(o => { PluginMenu window = new PluginMenu(mainWindow.pluginList); window.Show(); }, o => true), pluginsKeyGesture); InputBindings.Add(pluginsKeyBinding); } catch { } try { string tmp = (string)reader.GetValue("Esc", typeof(string)); gestureConverter = new KeyGestureConverter(); KeyGesture escKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding escKeyBinding = new KeyBinding(new RelayCommand(o => { MinHeight = 0; var animation = new DoubleAnimation(); animation.From = Height; animation.To = MinHeight; animation.Duration = TimeSpan.FromSeconds(0.5); animation.Completed += Window_Closed; this.BeginAnimation(HeightProperty, animation); }, o => true), escKeyGesture); InputBindings.Add(escKeyBinding); } catch { } empList = _empList; depList = _depList; window = _window; mainWindow = _mainWindow; List <int> year = new List <int>(); int currentDate = DateTime.Today.Year; for (int i = 0; currentDate >= 1982; i++) { year.Add(currentDate); currentDate--; } depYear.ItemsSource = year; depBoss.ItemsSource = empList.empManager; foreach (Department item in depList.depManager) { departmentList.Items.Add(item); } }
public EmployeeWindow(Window _window, MainWindow _mainWindow, EmployeeList _empList, DepartmentList _depList) { InitializeComponent(); //горячие клавиши AppSettingsReader reader = new AppSettingsReader(); KeyGestureConverter gestureConverter = new KeyGestureConverter(); try { string tmp = (string)reader.GetValue("Save", typeof(string)); KeyGesture saveKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding saveKeyBinding = new KeyBinding(new RelayCommand(o => { FileManager.Save(empList, depList); }, o => true), saveKeyGesture); InputBindings.Add(saveKeyBinding); } catch { } try { string tmp = (string)reader.GetValue("Load", typeof(string)); gestureConverter = new KeyGestureConverter(); KeyGesture loadKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding loadKeyBinding = new KeyBinding(new RelayCommand(o => { FileManager.Load(empList, depList); }, o => true), loadKeyGesture); InputBindings.Add(loadKeyBinding); } catch { } try { string tmp = (string)reader.GetValue("Plugins", typeof(string)); gestureConverter = new KeyGestureConverter(); KeyGesture pluginsKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding pluginsKeyBinding = new KeyBinding(new RelayCommand(o => { PluginMenu window = new PluginMenu(mainWindow.pluginList); window.Show(); }, o => true), pluginsKeyGesture); InputBindings.Add(pluginsKeyBinding); } catch { } try { string tmp = (string)reader.GetValue("Esc", typeof(string)); gestureConverter = new KeyGestureConverter(); KeyGesture escKeyGesture = (KeyGesture)gestureConverter.ConvertFromString(tmp); KeyBinding escKeyBinding = new KeyBinding(new RelayCommand(o => { MinHeight = 0; var animation = new DoubleAnimation(); animation.From = Height; animation.To = MinHeight; animation.Duration = TimeSpan.FromSeconds(0.5); animation.Completed += Window_Closed; this.BeginAnimation(HeightProperty, animation); }, o => true), escKeyGesture); InputBindings.Add(escKeyBinding); } catch { } empList = _empList; depList = _depList; window = _window; mainWindow = _mainWindow; int[] day = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; string[] month = new string[] { "Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь" }; List <int> year = new List <int>(); int currentDate = DateTime.Today.Year; for (int i = 0; currentDate >= 1982; i++) { year.Add(currentDate); currentDate--; } employmentDay.ItemsSource = day; employmentMonth.ItemsSource = month; employmentYear.ItemsSource = year; dismissalDay.ItemsSource = day; dismissalMonth.ItemsSource = month; dismissalYear.ItemsSource = year; empDepartment.ItemsSource = depList.depManager; empBoss.ItemsSource = empList.empManager; empSubWorkers.ItemsSource = empList.empManager; foreach (Employee item in empList.empManager) { employeeList.Items.Add(item); } }