//сериализация и десериализация проектов public static void Serialize_proj(ListOfProjects lp) { using (FileStream fs = new FileStream(file_proj, FileMode.Create)) { serializer_proj.Serialize(fs, lp); }; }
private void AddProject_Click(object sender, RoutedEventArgs e) { try { if (AllPrListBox.SelectedItem.ToString() != NameText.Text) { Customer customer = null; lc.Cust = new List <Customer>(); lc = Serialization.Deserialze(lc); foreach (var item in lc.Cust) { if (CustomerComboBox.SelectedItem.ToString() == item.Name) { customer = item; } } Project proj = new Project(NameText.Text, Description.Text, ManagerComboBox.Text, customer, int.Parse(People.Text), int.Parse(Money.Text), Date.Text); lp.Proj.Add(proj); Log.logging("Добавлен проект: " + proj.Name + " " + DateTime.Now); Serialization.Serialize_proj(lp); lp = Serialization.Deserialze_proj(lp); MessageBox.Show("Сохранено!"); AllPrListBox.Items.Clear(); foreach (var item in lp.Proj) { AllPrListBox.Items.Add(item.Name); } } else { MessageBox.Show("Такой проект уже существует"); } AllPrListBox.SelectedItem = -1; NameText.Clear(); Description.Clear(); ManagerComboBox.SelectedIndex = -1; CustomerComboBox.SelectedIndex = -1; People.Clear(); Money.Clear(); Date.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); Log.logging("Ошибка: " + ex); } }
public Projects_Page1() { InitializeComponent(); try { //десериализация для проектов //lp.Proj = new List<Project>(); lp = Serialization.Deserialze_proj(lp); foreach (var item in lp.Proj) { AllPrListBox.Items.Add(item.Name); } //чтение из текстового файла и вывод информации в поле "Руководитель" using (FileStream fs = new FileStream(@"../../input_managers.txt", FileMode.Open, FileAccess.Read)) { string[] data_txt; Manager mg; StreamReader sr = new StreamReader(fs, Encoding.Default); while (!sr.EndOfStream) { data_txt = sr.ReadLine().Split(' '); mg = new Manager(data_txt[0], data_txt[1]); managers.Add(mg); } sr.Close(); fs.Close(); } foreach (Manager mg in managers) { string emp = mg._name + ' ' + mg._lastName; ManagerComboBox.Items.Add(emp); } //вывод информации в поле "Заказчик" lc.Cust = new List <Customer>(); lc = Serialization.Deserialze(lc); foreach (var item in lc.Cust) { CustomerComboBox.Items.Add(item.Name); } } catch (Exception ex) { MessageBox.Show(ex.Message); Log.logging("Ошибка: " + ex); } }
public static ListOfProjects Deserialze_proj(ListOfProjects lp) { ListOfProjects data_proj = null; using (FileStream fs = new FileStream(file_proj, FileMode.Open)) { data_proj = (ListOfProjects)serializer_proj.Deserialize(fs); }; return(data_proj); }