Ejemplo n.º 1
0
 private void AddCustomer()
 {
     try
     {
         long id;
         //Specifying id manualy because sqlite has problem with autoincrement
         if (_context.Customers.Count() > 0)
         {
             List <Customer> c = _context.Customers.ToList();
             id = c[_context.Customers.Count() - 1].Id + 1;
         }
         else
         {
             id = 1;
         }
         Customer newCustomer = new Customer
         {
             Id        = id,
             FirstName = FirstNameTB.Text,
             LastName  = LastNameTB.Text
         };
         _context.Customers.Add(newCustomer);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Customer add error: " + ex.Message);
     }
 }
Ejemplo n.º 2
0
        private void AddService()
        {
            try
            {
                long id;
                if (_context.Services.Count() > 0)
                {
                    List <Service> c = _context.Services.ToList();
                    id = c[_context.Services.Count() - 1].Id + 1;
                }
                else
                {
                    id = 1;
                }

                Service newService = new Service
                {
                    Id    = id,
                    Name  = ServiceNameTB.Text,
                    Price = Convert.ToDecimal(PriceTB.Text)
                };
                _context.Services.Add(newService);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Service add error: " + ex.Message);
            }
        }
Ejemplo n.º 3
0
 //Save- Add or Edit Company details
 private void button_Click(object sender, RoutedEventArgs e)
 {
     //Add Company
     if (CheckIfDataInFieldsAreValid())//Validation on form needs to be implemented
     {
         if (_context.Companies.Count() == 0)
         {
             try
             {
                 Company newCompany = new Company
                 {
                     Name     = CompanyNameTB.Text,
                     Adress   = AdressTB.Text,
                     Telefon  = TelephoneTB.Text,
                     Website  = WebSiteTB.Text,
                     FileName = fileName,
                     Data     = imageInBytes
                 };
                 _context.Companies.Add(newCompany);
                 _context.SaveChanges();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Company add error: " + ex.Message);
             }
         }//Edit Company
         else
         {
             try
             {
                 Company existingCompany = _context.Companies.FirstOrDefault();
                 if (existingCompany != null)
                 {
                     existingCompany.Name     = CompanyNameTB.Text;
                     existingCompany.Adress   = AdressTB.Text;
                     existingCompany.Telefon  = TelephoneTB.Text;
                     existingCompany.Website  = WebSiteTB.Text;
                     existingCompany.FileName = fileName;
                     existingCompany.Data     = imageInBytes;
                 }
                 _context.SaveChanges();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Company edit error: " + ex.Message);
             }
         }
     }
 }