示例#1
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     #region Add_New_Subproduct
     if (this.Title == "Add Subproduct")
     {
         for (int i = 0; i < subprod.Length; i++)
         {
             if (subprod[i] == null)
             {
                 subprod[i] = new Subproduct
                 {
                     ValueOnProduct = 5,
                     Product = new DatabaseClass
                     {
                         IDProduct = Guid.NewGuid().ToString(),
                         Name = NameTB.Text,
                         ValueInDatabase = int.Parse(ValueTB.Text),
                         Unit = UnitTB.Text
                     }
                 };
             }
             break;
         }
         Close();
     }
        #endregion
        #region Add_Existing_Subproduct
     else
     {
         try
         {
             if (DetailsDict.Count == 0 && subprod[0] == null)
             {
                 addToBase.AddToDatabaseFunct(NameTB.Text, int.Parse(ValueTB.Text), UnitTB.Text);
             }
             else if (DetailsDict.Count != 0 && subprod[0] == null)
             {
                 addToBase.AddToDatabaseFunct(NameTB.Text, int.Parse(ValueTB.Text), UnitTB.Text, DetailsDict);
             }
             else if (DetailsDict.Count != 0 && subprod[0] != null)
             {
                 addToBase.AddToDatabaseFunct(NameTB.Text, int.Parse(ValueTB.Text), UnitTB.Text, DetailsDict, subprod);
             }
             MessageBox.Show("Dodano do bazy", "Dodano", MessageBoxButton.OK);
             MainWindow mw = (MainWindow)Application.Current.Windows[0];
             mw.ShowData();
             Close();
         }
         catch (Exception a)
         {
             MessageBox.Show(a.Message);
         }
     }
        #endregion
 }
示例#2
0
 public void AddToDatabaseFunct(string Name, int ValueInDatabase, string Unit, Subproduct[] Subprod)
 {
     addStoreComm(new DatabaseClass()
                                 {
                                     IDProduct = Guid.NewGuid().ToString(),
                                     Name = Name,
                                     ValueInDatabase = ValueInDatabase,
                                     Unit = Unit,
                                     Subprod = Subprod
                                 });
 }