private void Change1_Click(object sender, RoutedEventArgs e)
 {
     if (lb == 1)
     {
         Add_Window wnd = new Add_Window(this);
         wnd.Show();
         try {
             foreach (var item in lr.Lorries)
             {
                 if (item.Name == ((Lorry)Table1.SelectedItem).Name)
                 {
                     wnd.Name.Text      = item.Name;
                     wnd.Mass.Text      = item.FreightMass.ToString();
                     wnd.Prod_Year.Text = item.ProductionYear.ToString();
                     wnd.Power.Text     = item.Horsepower.ToString();
                     wnd.Type_eng.Text  = item.EngineType;
                     wnd.Capacity.Text  = item.EngineСapacity.ToString();
                 }
             }
             lr.Lorries.Remove((Lorry)Table1.SelectedItem);
             Search_result.Items.Remove(Table1.SelectedItem);
             Serializing.Serialize_l(lr);
             Table1.Items.Remove(Table1.SelectedItem);
         }catch (Exception a)
         { MessageBox.Show(a.ToString()); }
     }
     else
     {
     }
     if (lb == 2)
     {
         Add_Window wnd = new Add_Window(this);
         wnd.Show();
         try
         {
             foreach (var item in lr.Lorries)
             {
                 if (item.Name == ((Lorry)Search_result.SelectedItem).Name)
                 {
                     wnd.Name.Text      = item.Name;
                     wnd.Mass.Text      = item.FreightMass.ToString();
                     wnd.Prod_Year.Text = item.ProductionYear.ToString();
                     wnd.Power.Text     = item.Horsepower.ToString();
                     wnd.Type_eng.Text  = item.EngineType;
                     wnd.Capacity.Text  = item.EngineСapacity.ToString();
                 }
             }
             lr.Lorries.Remove((Lorry)Search_result.SelectedItem);
             Table1.Items.Remove(Search_result.SelectedItem);
             Serializing.Serialize_l(lr);
             Search_result.Items.Remove(Search_result.SelectedItem);
         }
         catch (Exception a)
         { MessageBox.Show(a.ToString()); }
     }
     else
     {
     }
 }
 private void Delete_Button1_Click(object sender, RoutedEventArgs e)
 {
     if (lb == 1)
     {
         Serializing.Deserialize_l(lr);
         lr.Lorries.Remove((Lorry)Table1.SelectedItem);
         Search_result.Items.Remove(Table1.SelectedItem);
         Serializing.Serialize_l(lr);
         Table1.Items.Remove(Table1.SelectedItem);
     }
     if (lb == 2)
     {
         Serializing.Deserialize_l(lr);
         lr.Lorries.Remove((Lorry)Search_result.SelectedItem);
         Table1.Items.Remove(Search_result.SelectedItem);
         Serializing.Serialize_l(lr);
         Search_result.Items.Remove(Search_result.SelectedItem);
     }
 }
Пример #3
0
 private void Add_L_L_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (File.Exists("../../lorries.xml"))
         {
             wnd.lr = Serializing.Deserialize_l(wnd.lr);
         }
         else
         {
             wnd.lr.Lorries = new List <Lorry>();
         }
         Lorry lry = new Lorry(Name.Text, int.Parse(Prod_Year.Text), Type_eng.Text, int.Parse(Capacity.Text), int.Parse(Mass.Text), int.Parse(Power.Text));
         wnd.lr.Lorries.Add(lry);
         Serializing.Serialize_l(wnd.lr);
         wnd.Table1.Items.Add(lry);
         this.Close();
     }
     catch (Exception a)
     {
         MessageBox.Show(a.ToString());
     }
 }