Esempio n. 1
0
        // Add Car Button --Logg here!
        private void carBtnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(carTbMake.Text))
            {
                MessageBox.Show("Introduceti Marca masinii!");
            }
            else if (string.IsNullOrEmpty(carTbOem.Text))
            {
                MessageBox.Show("Introduceti codul masinii!");
            }
            else if (string.IsNullOrEmpty(carTbPret.Text))
            {
                MessageBox.Show("Introduceti pretul!!!");
            }
            else if (string.IsNullOrEmpty(carTbPower.Text))
            {
                MessageBox.Show("Introduceti puterea masinii!");
            }
            else if (string.IsNullOrEmpty(carTbModel.Text))
            {
                MessageBox.Show("Introduceti modelul masinii!");
            }
            else
            {
                //Matching Parameters
                var _carToBe = new Car
                {
                    Body          = carCbBody.Text,
                    Capacity      = double.Parse(carCbCapacity.Text),
                    Fuel          = carCbFuel.Text,
                    Make          = carTbMake.Text,
                    Model         = carTbModel.Text,
                    Internal_Code = carTbOem.Text,
                    Year          = int.Parse(carCbYear.Text),
                    Power         = double.Parse(carTbPower.Text),
                    Price         = double.Parse(carTbPret.Text),
                    Content       = ImageServices.imageToByteArray(pictureBox1.Image)
                };

                //Add car to DataBase
                db.Cars.Add(_carToBe);
                db.SaveChanges();
                FillUpMyCarTable();
                ClearGUI();

                LoggingService.Log(Enums.ActionsEnum.Adaugare_Masina, _carToBe.Price, "S-a adaugat masina " + _carToBe.Make + " " + _carToBe.Model + " " + _carToBe.Year);

                MessageBox.Show("Masina adaugata cu succes.", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 2
0
        private void AddOrSellPart(bool inStock)
        {
            if (partCbMake.SelectedValue != null && partCbInternalCode.SelectedValue != null && !string.IsNullOrWhiteSpace(partTbName.Text) && !string.IsNullOrWhiteSpace(partTbPrice.Text))
            {
                //      get the car(s) with respect to the filters (3)
                var carsQuery    = db.Cars.AsQueryable();
                var selectedMake = partCbMake.SelectedValue.ToString();
                carsQuery = carsQuery.Where(c => c.Make.Equals(selectedMake));

                if (partCbModel.SelectedValue != null)
                {
                    var selectedModel = partCbModel.SelectedValue.ToString();
                    carsQuery = carsQuery.Where(c => c.Model.Equals(selectedModel));
                }
                if (partCbInternalCode.SelectedValue != null)
                {
                    var selectedCode = partCbInternalCode.SelectedValue.ToString();
                    carsQuery = carsQuery.Where(c => c.Internal_Code.Equals(selectedCode));
                }
                var allReturnedCars = carsQuery.Distinct()
                                      .OrderBy(c => c.Make)
                                      .ThenBy(c => c.Model)
                                      .ThenBy(c => c.Year)
                                      .ThenBy(c => c.Internal_Code)
                                      .ToList();

                var partToBe = new Part
                {
                    Name     = partTbName.Text,
                    Quantity = double.Parse(partTbQty.Text),
                    BarCode  = "gen",
                    Details  = partTbDetails.Text,
                    Price    = double.Parse(partTbPrice.Text),
                    Oem_Code = partTbOem.Text,
                    InStock  = inStock,
                    Color    = partCbColor.Text,
                    Content  = ImageServices.imageToByteArray(pictureBox2.Image)
                };
                //Check if the part is already in stock. If it is, add qty
                var isThePartInStock = db.Parts
                                       .Where(p => p.Name.Equals(partToBe.Name))
                                       .Where(p => p.Price == partToBe.Price)
                                       .Where(p => p.Oem_Code.Equals(partToBe.Oem_Code))
                                       .FirstOrDefault();
                if (isThePartInStock != null)
                {
                    partToBe.Quantity += db.Parts
                                         .Where(p => p.Name.Equals(partToBe.Name))
                                         .Where(p => p.Price == partToBe.Price)
                                         .Where(p => p.Oem_Code.Equals(partToBe.Oem_Code))
                                         .Select(p => p.Quantity)
                                         .FirstOrDefault();
                    isThePartInStock.Quantity = partToBe.Quantity;
                }
                else
                {
                    partToBe.Cars = allReturnedCars;
                    db.Parts.Add(partToBe);
                }
                db.SaveChanges();

                if (inStock)
                {
                    LoggingService.Log(Enums.ActionsEnum.Adaugare_Piesa, partToBe.Price, "S-a adaugat piesa " + partToBe.Name + " la masinile: " +
                                       string.Join(",", allReturnedCars.Select(c => c.Make + " " + c.Model + " " + c.Year).ToList())
                                       );
                    if (isThePartInStock != null)
                    {
                        MessageBox.Show("Piesa exista deja, stoc ul a fost marit.");
                    }
                    else
                    {
                        MessageBox.Show("Piesa adaugata cu succes la " + allReturnedCars.Count + " masini.");
                    }
                }

                else
                {
                    LoggingService.Log(Enums.ActionsEnum.Vanzare_Piesa, partToBe.Price, "S-a vandut piesa " + partToBe.Name);
                    MessageBox.Show("Piesa vanduta cu succes !" + allReturnedCars.Count + " masini.");
                }
                PartGUIReset();
            }
            else
            {
                MessageBox.Show("Toate campurile cu * trebuie completate!");
            }
        }