Example #1
0
        public void removeCarById(int id)
        {
            Car c = AutoPark
                    .Where(o => o.Id == id)
                    .FirstOrDefault();

            AutoPark.Remove(c);
        }
Example #2
0
        public void AlterCar(Car car)
        {
            Car c = AutoPark
                    .Where(o => o.Id == car.Id)
                    .FirstOrDefault();

            c.Info         = car.Info;
            c.Price        = car.Price;
            c.Brand        = car.Brand;
            c.Avaliability = car.Avaliability;
        }
Example #3
0
        static void Main(string[] args) //args reprezinta un array de string (eventuali parametrii din command line)
        {
            Car c = new Car()
            {
                Id           = 5,
                Model        = "Focus",
                Manufacturer = "Ford",
                Year         = 2015,
                Pictures     = new List <Picture>()
                {
                    new Picture()
                    {
                        Name     = "Picture1",
                        FilePath = "C:\\Pictures\\5\\Picture1.jpg"
                    },
                    new Picture()
                    {
                        Name     = "Picture2",
                        FilePath = "C:\\Pictures\\5\\Picture2.jpg"
                    }
                }
            };

            var carJsonData = File.ReadAllText("5.json");
            var objCar      = JsonConvert.DeserializeObject <Car>(carJsonData);

            objCar.AddPicture(new Picture()
            {
                Name     = "Picture3",
                FilePath = "C:\\Pictures\\5\\Picture3.jpg"
            });

            var json = JsonConvert.SerializeObject(objCar);

            File.WriteAllText(string.Format("{0}.json", c.Id), json);

            /*
             * string carAsJson = JsonConvert.SerializeObject(c);
             *
             * File.WriteAllText(string.Format("{0}.json", c.Id), carAsJson);
             */
            AutoPark ap = new AutoPark();

            ap.Add(c);


            Console.WriteLine(ap);
            Console.ReadKey();
        }
Example #4
0
        public void LoadView(ViewType typeView)
        {
            switch (typeView)
            {
            case ViewType.Login:
            {
                LoginUC        view = new LoginUC();
                LoginViewModel vm   = new LoginViewModel(this);
                view.DataContext        = vm;
                this.OutputView.Content = view;
                break;
            }

            case ViewType.Registration:
            {
                Registration    viewF = new Registration();
                RegistViewModel vmF   = new RegistViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.Forum:
            {
                Forum_main          viewF = new Forum_main();
                Forum_mainViewModel vmF   = new Forum_mainViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.Forum_topic:
            {
                Forum_topic          viewF = new Forum_topic();
                Forum_topicViewModel vmF   = new Forum_topicViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.User_room:
            {
                User_Room          viewF = new User_Room();
                User_RoomViewModel vmF   = new User_RoomViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.AutoPark:
            {
                AutoPark          viewF = new AutoPark();
                AutoParkViewModel vmF   = new AutoParkViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.AddCar:
            {
                AddCar          viewF = new AddCar();
                AddCarViewModel vmF   = new AddCarViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.Auctions:
            {
                Auctions          viewF = new Auctions();
                AuctionsViewModel vmF   = new AuctionsViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.Auction:
            {
                ver03.Views.Auction viewF = new ver03.Views.Auction();
                AuctionViewModel    vmF   = new AuctionViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.AddAuction:
            {
                AddAuction          viewF = new ver03.Views.AddAuction();
                AddAuctionViewModel vmF   = new AddAuctionViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.MainPage:
            {
                MainPage          viewF = new ver03.Views.MainPage();
                MainPageViewModel vmF   = new MainPageViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }

            case ViewType.Info:
            {
                Info          viewF = new ver03.Views.Info();
                InfoViewModel vmF   = new InfoViewModel(this);
                viewF.DataContext       = vmF;
                this.OutputView.Content = viewF;
                break;
            }
            }

            //void LoadPageAndViewModel<T,V>(T page, V viewModel)
            //    where T: new()
            //    where V: class, new()
            //{
            //    T viewF = new T();
            //    V vmF = new V(this);
            //    viewF.DataContext = vmF;
            //    this.OutputView.Content = viewF;
            //}
        }
Example #5
0
        static void Main(string[] args)
        {
            Figure F;
            int    k;
            double a, b, c, r;

            #region (Task 1)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 1");
            Console.ResetColor();

            Console.WriteLine("What's figure? 1 - Rectangle, 2 - Circle, 3 - Triangle");
            k = Convert.ToInt16(Console.ReadLine());
            switch (k)
            {
                #region (Rectangle)
            case 1:
                Console.WriteLine("Rectangle selected");
                Console.WriteLine("Enter Rectangle's sides: ");
                Console.Write("Length: ");
                a = Convert.ToDouble(Console.ReadLine());
                Console.Write("Width: ");
                b = Convert.ToDouble(Console.ReadLine());
                F = new Rectangle(a, b);
                F.Perimeter();
                F.Area();
                F.Show();
                break;

                #endregion
                #region (Circle)
            case 2:
                Console.WriteLine("Circle selected");
                Console.Write("Enter Circle's radius: ");
                r = Convert.ToDouble(Console.ReadLine());
                F = new Circle(r);
                F.Perimeter();
                F.Area();
                F.Show();
                break;

                #endregion
                #region (Triangle)
            case 3:
                Console.WriteLine("Triangle selected");
                Console.WriteLine("Enter Triangle's sides: ");
                Console.Write("Side А: ");
                a = Convert.ToDouble(Console.ReadLine());
                Console.Write("Side В: ");
                b = Convert.ToDouble(Console.ReadLine());
                Console.Write("Side C: ");
                c = Convert.ToDouble(Console.ReadLine());
                F = new Triangle(a, b, c);
                F.Perimeter();
                F.Area();
                F.Show();
                break;

                #endregion
            default: break;
            }
            #endregion
            #region (Task 2)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 2");
            Console.ResetColor();

            int       i         = 123;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            object o = i;
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedTicks);

            stopwatch.Start();
            i = (int)o;
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedTicks);
            #endregion
            #region (Task 3)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 3");
            Console.ResetColor();

            Car[] cars = new Car[3]
            {
                new Car("Passenger car"),
                new Car("Truck car"),
                new Car("Racing car"),
            };

            AutoPark ap = new AutoPark(cars);
            foreach (Car car in ap)
            {
                Console.WriteLine(car.type);
            }
            #endregion
        }
Example #6
0
 public FormForm()
 {
     InitializeComponent();
     ap = new AutoPark();
 }
Example #7
0
        static void Main(string[] args)
        {
            Figure F;
            int    k;
            double a, b, c, r;

            #region (Task 3)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 3");
            Console.ResetColor();

            Console.WriteLine("What's figure? 1 - Rectangle, 2 - Circle, 3 - Triangle");
            k = Convert.ToInt16(Console.ReadLine());
            switch (k)
            {
                #region (Rectangle)
            case 1:
                Console.WriteLine("Rectangle selected");
                Console.WriteLine("Enter Rectangle's sides: ");
                Console.Write("Length: ");
                a = Convert.ToDouble(Console.ReadLine());
                Console.Write("Width: ");
                b = Convert.ToDouble(Console.ReadLine());
                F = new Rectangle(a, b);
                F.Perimeter();
                F.Area();
                F.Show();
                break;

                #endregion
                #region (Circle)
            case 2:
                Console.WriteLine("Circle selected");
                Console.Write("Enter Circle's radius: ");
                r = Convert.ToDouble(Console.ReadLine());
                F = new Circle(r);
                F.Perimeter();
                F.Area();
                F.Show();
                break;

                #endregion
                #region (Triangle)
            case 3:
                Console.WriteLine("Triangle selected");
                Console.WriteLine("Enter Triangle's sides: ");
                Console.Write("Side А: ");
                a = Convert.ToDouble(Console.ReadLine());
                Console.Write("Side В: ");
                b = Convert.ToDouble(Console.ReadLine());
                Console.Write("Side C: ");
                c = Convert.ToDouble(Console.ReadLine());
                F = new Triangle(a, b, c);
                F.Perimeter();
                F.Area();
                F.Show();
                break;

                #endregion
            default: break;
            }
            #endregion
            #region (Task 6)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 6");
            Console.ResetColor();

            int       y         = 123;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            object o = y;
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedTicks);

            stopwatch.Start();
            y = (int)o;
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedTicks);
            #endregion
            #region (Task 7)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 7");
            Console.ResetColor();

            Car[] cars = new Car[3]
            {
                new Car("Passenger car"),
                new Car("Truck car"),
                new Car("Racing car"),
            };

            AutoPark ap = new AutoPark(cars);
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("'Foreach': ");
            Console.ResetColor();
            foreach (Car car in ap)
            {
                Console.WriteLine(car.type);
            }
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("'While': ");
            Console.ResetColor();
            var getenum = ap.GetEnumerator();
            while (getenum.MoveNext())
            {
                Console.WriteLine(getenum.Current.type);
            }
            #endregion

            #region (Task 8)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 8");
            Console.ResetColor();

            Random    rand     = new Random();
            Storage[] products = new Storage[100];
            for (int i = 0; i < 100; i++)
            {
                products[i] = new Storage(GenerateString(rand, 7), rand.Next(0, 100));
                //Console.WriteLine(products[i]);
            }

            var Availability1 = products.All(product => product.Number > 0);
            var Availability2 = products.Any(product => product.Number == 0);
            if (Availability1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("All products are in Storage");
                Console.ResetColor();
            }
            if (Availability2)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Missing in Storage: ");
                Console.ResetColor();

                var MissingProducts = from product in products
                                      where product.Number == 0
                                      select product;

                foreach (var product in MissingProducts)
                {
                    Console.WriteLine(product.ToString());
                }
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Sort by quantity: ");
            Console.ResetColor();
            var SortProducts = from product in products
                               orderby product.Number
                               group product by product.Number;
            foreach (IGrouping <int, Storage> product in SortProducts)
            {
                Console.Write(product.Key + ": ");
                foreach (var p in product)
                {
                    Console.Write("{0} ", p.Text);
                }
                Console.WriteLine();
            }

            var SumProducts = products.Sum(product => product.Number);
            Console.WriteLine("\nSum of all products in Storage: {0}", SumProducts);

            var MinProducts = products.Min(product => product.Number);
            Console.WriteLine("\nMinimum number of product: {0}", MinProducts);

            var MaxProducts = products.Max(product => product.Number);
            Console.WriteLine("\nMaximum number of product: {0}", MaxProducts);
            Console.WriteLine();
            #endregion
            #region (Task 9)
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Task 9");
            Console.ResetColor();

            ArrayList squares = new ArrayList();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Current ArrayList:");
            Console.ResetColor();
            for (int i = 0; i < 10; i++)
            {
                int    side   = rand.Next(1, 11);
                Square square = new Square(side);
                squares.Add(square);
                Console.WriteLine(squares[i]);
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Sort ArrayList:");
            Console.ResetColor();
            squares.Sort();
            foreach (var square in squares)
            {
                Console.WriteLine(square.ToString());
            }

            CompareTeams <Team> comparerteams = new CompareTeams <Team>();
            List <Team>         teams         = new List <Team>();

            teams.Add(new Team("FC Barcelona", 45));
            teams.Add(new Team("Real Madrid CF", 47));
            teams.Add(new Team("Sevilla FC", 38));
            teams.Add(new Team("Valencia CF", 25));
            teams.Add(new Team("Atletico Madrid", 52));
            teams.Add(new Team("Real Sociedad", 40));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Current TeamList");
            Console.ResetColor();
            foreach (var t in teams)
            {
                Console.WriteLine(t.ToString());
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Sort TeamList by points:");
            Console.ResetColor();
            teams.Sort(comparerteams);
            foreach (var t in teams)
            {
                Console.WriteLine(t.ToString());
            }
            #endregion
        }
Example #8
0
 public Form1()
 {
     InitializeComponent();
     sl = new AutoPark();
 }
Example #9
0
 public Car GetCarById(int id)
 {
     return(AutoPark
            .Where(o => o.Id == id)
            .FirstOrDefault());
 }