private void DeserializeData() { XmlSerializer serializer = new XmlSerializer(typeof(HospitalStructure)); if (!File.Exists(Directory.GetCurrentDirectory() + @"\" + filePath)) { createNewMainFile(); } try { StreamReader reader = new StreamReader(filePath); hospitalStructure = (HospitalStructure)serializer.Deserialize(reader); reader.Close(); } catch (Exception e) { MessageBox.Show( $"Error occured: {e.Message}.\nPlease delete or fix {filePath} file in folder with .exe file.", "Something went wrong...", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } }
private void createNewMainFile() { hospitalStructure = new HospitalStructure(); string salt = CryptographyProcessor.CreateSalt(hospitalStructure.SaltLength); Employee admin = new Employee( 1, "Serhii", "Holishevskyi", "dnldcode", CryptographyProcessor.GenerateHash("password", salt), salt, Position.Administration); hospitalStructure.Employees.Add(admin); XmlSerializer xmlSerializer = new XmlSerializer(typeof(HospitalStructure)); try { using (FileStream fs = new FileStream(filePath, FileMode.Create)) { xmlSerializer.Serialize(fs, hospitalStructure); } } catch (Exception e) { MessageBox.Show( $"Error occured: {e.Message}", "Something went wrong...", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } }
public Main(Employee currentUser, HospitalStructure hospitalStructure) { InitializeComponent(); MaterialSkin.MaterialSkinManager manager = MaterialSkin.MaterialSkinManager.Instance; manager.AddFormToManage(this); manager.Theme = MaterialSkin.MaterialSkinManager.Themes.LIGHT; this.Sizable = true; _currentEmployee = currentUser; CurrentUserId = currentUser.Id; HospitalStructure = hospitalStructure; labelPosition.BackColor = Color.FromArgb(55, 71, 79); labelPosition.ForeColor = Color.White; labelPosition.Text = labelPosition.Text.Replace("{pos}", _currentEmployee.TypeOfUser.ToString()); if (!_currentEmployee.IsAdmin()) { labelPosition.Text += $" - {_currentEmployee.Speciality}"; } dateTimePicker.Value = DateTime.Now; loadEmployees(); }