Ejemplo n.º 1
0
        public bool Update(Moped mopedObj)
        {
            try
            {
                var query = (from mopeds in dataContext.Mopeds
                             where mopeds.ProductID == mopedObj.ProductID
                             select mopeds).First();
                query.ProductID        = mopedObj.ProductID;
                query.ProductName      = mopedObj.ProductName;
                query.Price            = mopedObj.Price;
                query.BrandName        = mopedObj.BrandName;
                query.Photo            = mopedObj.Photo;
                query.GroundClearance  = mopedObj.GroundClearance;
                query.BodyType         = mopedObj.BodyType;
                query.Mileage          = mopedObj.Mileage;
                query.FuelTankCapacity = mopedObj.FuelTankCapacity;
                query.Gears            = mopedObj.Gears;
                query.TubelessTyres    = mopedObj.TubelessTyres;
                query.Weight           = mopedObj.Weight;
                query.CategoryID       = mopedObj.CategoryID;
                query.SubCategoryID    = mopedObj.SubCategoryID;

                int result = dataContext.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                dc.PCErrorLoggers.Add(new PCErrorLogger()
                {
                    ErrorDate    = DateTime.Now,
                    ErrorMessage = ex.Message,
                    ErrorSource  = ex.Source
                });
                dc.SaveChanges();
                throw new DbUpdateException("Please enter valid Foreign keys");
            }
            catch (System.FormatException fe)
            {
                dc.PCErrorLoggers.Add(new PCErrorLogger()
                {
                    ErrorDate    = DateTime.Now,
                    ErrorMessage = fe.Message,
                    ErrorSource  = fe.Source
                });
                dc.SaveChanges();
                throw new System.FormatException();
            }
            catch (Exception q)
            {
                dc.PCErrorLoggers.Add(new PCErrorLogger()
                {
                    ErrorDate    = DateTime.Now,
                    ErrorMessage = q.Message,
                    ErrorSource  = q.Source
                });
                dc.SaveChanges();
                throw new Exception("Incorrect Format");
            }
            return(true);
        }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < 10; i++)
     {
         Moped einMoped = new Moped()
         {
             Hersteller         = "Garelli",
             Farbe              = "Rot",
             Leistung           = 39,
             Modell             = $"SR 50-{i:00}",
             Baujahr            = new DateTime(2018, 11, 11),
             AuspuffEingetragen = false
         };
         bindingSource1.Add(einMoped);
     }
 }
Ejemplo n.º 3
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        CessiPoo cesiOneKenobi = new CessiPoo();
        Cessna   plainCesna    = new Cessna();

        List <IFly> flyList = new List <IFly>()
        {
            cesiOneKenobi, plainCesna
        };

        // With a single `foreach`, have each vehicle Fly()

        foreach (IFly item in flyList)
        {
            item.Fly();
        }

        // Build a collection of all vehicles that operate on roads
        Motorcycle CrotchRocket    = new Motorcycle();
        Moped      SomeKindOfMoped = new Moped();

        // With a single `foreach`, have each road vehicle Drive()
        List <ILand> landList = new List <ILand>()
        {
            CrotchRocket, SomeKindOfMoped
        };

        foreach (ILand item in landList)
        {
            item.Drive();
        }
        // Build a collection of all vehicles that operate on water
        JetSki   imAwesome       = new JetSki();
        SailBoat superSailorMoon = new SailBoat();

        List <IWater> waterList = new List <IWater>()
        {
            imAwesome, superSailorMoon
        };

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IWater item in waterList)
        {
            item.Drive();
        }
    }
Ejemplo n.º 4
0
 public bool Insert(Moped mopedObj)
 {
     try
     {
         dataContext.Mopeds.Add(mopedObj);
         int result = dataContext.SaveChanges();
     }
     catch (DbUpdateException ex)
     {
         dc.PCErrorLoggers.Add(new PCErrorLogger()
         {
             ErrorDate    = DateTime.Now,
             ErrorMessage = ex.Message,
             ErrorSource  = ex.Source
         });
         dc.SaveChanges();
         throw new DbUpdateException("Please enter valid Foreign keys");
     }
     catch (System.FormatException fe)
     {
         dc.PCErrorLoggers.Add(new PCErrorLogger()
         {
             ErrorDate    = DateTime.Now,
             ErrorMessage = fe.Message,
             ErrorSource  = fe.Source
         });
         dc.SaveChanges();
         throw new System.FormatException();
     }
     catch (Exception q)
     {
         dc.PCErrorLoggers.Add(new PCErrorLogger()
         {
             ErrorDate    = DateTime.Now,
             ErrorMessage = q.Message,
             ErrorSource  = q.Source
         });
         dc.SaveChanges();
         throw new Exception("Incorrect Format");
     }
     return(true);
 }
Ejemplo n.º 5
0
 private void button4_Click(object sender, EventArgs e)
 {
     bindingSource1.Clear();
     using (var sr = new StreamReader(fileName))
     {
         while (!sr.EndOfStream)
         {
             var line   = sr.ReadLine();
             var chunks = line.Split(t.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             var m      = new Moped()
             {
                 Hersteller         = chunks[0],
                 Modell             = chunks[1],
                 Farbe              = chunks[2],
                 Baujahr            = DateTime.Parse(chunks[3]),
                 Leistung           = int.Parse(chunks[4]),
                 AuspuffEingetragen = bool.Parse(chunks[5])
             };
             bindingSource1.Add(m);
         }
     }
 }
Ejemplo n.º 6
0
 public void TestInputInvalidString(string model, string make)
 {
     var actual = new Moped(model, "White", make, new Engine(typeEngine.Petrol, 500, 8.7, "NHFAR234DAD"),
                            new Transmission(typeOfTransmission.Combined, 12, "DAF"),
                            new Chassis(8, "NGD5412BND", 20000));
 }