/// <summary> /// Metoda uloží kolekce v modelu do XAML souborů (MaterialCollection, EmployeeCollection, ContractCollection, OverviewModel, TransactionCollection, DeletedMaterialCollection, DeletedEmployeeCollection, DeletedContractCollection). /// </summary> public void Save() { // K ukládání je využit serializér XmlSerializer materialSerializer = new XmlSerializer(MaterialCollection.GetType()); using (StreamWriter sw = new StreamWriter(materialTrack)) { materialSerializer.Serialize(sw, MaterialCollection); } XmlSerializer employeeSerializer = new XmlSerializer(EmployeeCollection.GetType()); using (StreamWriter sw = new StreamWriter(employeeTrack)) { employeeSerializer.Serialize(sw, EmployeeCollection); } XmlSerializer contractSerializer = new XmlSerializer(ContractCollection.GetType()); using (StreamWriter sw = new StreamWriter(contractTrack)) { contractSerializer.Serialize(sw, ContractCollection); } XmlSerializer overviwSerializer = new XmlSerializer(OverviewModel.GetType()); using (StreamWriter sw = new StreamWriter(overviewTrack)) { overviwSerializer.Serialize(sw, OverviewModel); } XmlSerializer accountSerializer = new XmlSerializer(TransactionCollection.GetType()); using (StreamWriter sw = new StreamWriter(transactionTrack)) { accountSerializer.Serialize(sw, TransactionCollection); } XmlSerializer deletedMaterialSerializer = new XmlSerializer(DeletedMaterialCollection.GetType()); using (StreamWriter sw = new StreamWriter(deletedMaterialTrack)) { deletedMaterialSerializer.Serialize(sw, DeletedMaterialCollection); } XmlSerializer deletedEmployeeSerializer = new XmlSerializer(DeletedEmployeeCollection.GetType()); using (StreamWriter sw = new StreamWriter(deletedEmployeeTrack)) { deletedEmployeeSerializer.Serialize(sw, DeletedEmployeeCollection); } XmlSerializer deletedContractSerializer = new XmlSerializer(DeletedContractCollection.GetType()); using (StreamWriter sw = new StreamWriter(deletedContractTrack)) { deletedContractSerializer.Serialize(sw, DeletedContractCollection); } FillingAllCollections(); }
/// <summary> /// Metoda naplní kolekce v modelu z XAML souborů (MaterialCollection, EmployeeCollection, ContractCollection, OverviewModel, TransactionCollection, DeletedMaterialCollection, DeletedEmployeeCollection, DeletedContractCollection). /// </summary> public void Load() { // Využití deserializace XmlSerializer materialSerializer = new XmlSerializer(MaterialCollection.GetType()); if (File.Exists(materialTrack)) { using (StreamReader sr = new StreamReader(materialTrack)) { MaterialCollection = (ObservableCollection <Material>)materialSerializer.Deserialize(sr); } } else { MaterialCollection = new ObservableCollection <Material>(); } XmlSerializer employeeSerializer = new XmlSerializer(EmployeeCollection.GetType()); if (File.Exists(employeeTrack)) { using (StreamReader sr = new StreamReader(employeeTrack)) { EmployeeCollection = (ObservableCollection <Employee>)employeeSerializer.Deserialize(sr); } } else { EmployeeCollection = new ObservableCollection <Employee>(); } XmlSerializer contractSerializer = new XmlSerializer(ContractCollection.GetType()); if (File.Exists(contractTrack)) { using (StreamReader sr = new StreamReader(contractTrack)) { ContractCollection = (ObservableCollection <Contract>)contractSerializer.Deserialize(sr); } } else { ContractCollection = new ObservableCollection <Contract>(); } XmlSerializer overviewSerializer = new XmlSerializer(OverviewModel.GetType()); if (File.Exists(overviewTrack)) { using (StreamReader sr = new StreamReader(overviewTrack)) { OverviewModel = (OverviewFactory)overviewSerializer.Deserialize(sr); } } else { OverviewModel = new OverviewFactory(); } XmlSerializer accountSerializer = new XmlSerializer(TransactionCollection.GetType()); if (File.Exists(transactionTrack)) { using (StreamReader sr = new StreamReader(transactionTrack)) { TransactionCollection = (ObservableCollection <Transaction>)accountSerializer.Deserialize(sr); } } else { TransactionCollection = new ObservableCollection <Transaction>(); } RearrangeMaterialCollection(); XmlSerializer deletedMaterialSerializer = new XmlSerializer(DeletedMaterialCollection.GetType()); if (File.Exists(deletedMaterialTrack)) { using (StreamReader sr = new StreamReader(deletedMaterialTrack)) { DeletedMaterialCollection = (ObservableCollection <Material>)deletedMaterialSerializer.Deserialize(sr); } } else { DeletedMaterialCollection = new ObservableCollection <Material>(); } XmlSerializer deletedEmployeeSerializer = new XmlSerializer(DeletedEmployeeCollection.GetType()); if (File.Exists(deletedEmployeeTrack)) { using (StreamReader sr = new StreamReader(deletedEmployeeTrack)) { DeletedEmployeeCollection = (ObservableCollection <Employee>)deletedEmployeeSerializer.Deserialize(sr); } } else { DeletedEmployeeCollection = new ObservableCollection <Employee>(); } XmlSerializer deletedEontractSerializer = new XmlSerializer(DeletedContractCollection.GetType()); if (File.Exists(deletedContractTrack)) { using (StreamReader sr = new StreamReader(deletedContractTrack)) { DeletedContractCollection = (ObservableCollection <Contract>)deletedEontractSerializer.Deserialize(sr); } } else { DeletedContractCollection = new ObservableCollection <Contract>(); } FillingAllCollections(); }