private void btnSave_Click(object sender, EventArgs e)
        {
            bool check = ValidationFeild();

            if (check == true)
            {
                tblCar car  = new tblCar();
                CarIF  data = new CarIF();
                car.carName = txtCarName.Text;
                if (txtLicensePlate.Text == null || txtLicensePlate.Text == "")
                {
                    if (readLicense(PicBoxCarLicence.Image) == null)
                    {
                        MessageBox.Show("Can't read license.Please give another picture");
                    }
                    else
                    {
                        car.licensePlate = readLicense(PicBoxCarLicence.Image);
                    }
                }
                else
                {
                    car.licensePlate = txtLicensePlate.Text;
                }
                MemoryStream ms = new MemoryStream();
                PicBoxCarLicence.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                car.nearestPhoto = ms.ToArray();
                car.status       = "activated";
                car.userID       = cbUser.SelectedItem.ToString();
                CarDAO dao = new CarDAO();
                dao.AddNewCar(car);
                data = CarDAO.GetCarfullInforByName(car.carName);
                parent.Getdata(data);
                MessageBox.Show("Add car success!");
                this.Close();
            }
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string model         = txtModel.Text.Trim();
            string sPrice        = txtPrice.Text.Trim();
            string sProducedYear = txtProduceYear.Text.Trim();
            string sEngine       = txtEngine.Text.Trim();
            string sQuantity     = txtQuantity.Text.Trim();
            string manufacturer  = cbManufacturer.Text.Trim();
            string tranmission   = cbTranmission.Text.Trim();
            string type          = cbType.Text.Trim();
            string category      = cbCategory.Text.Trim();
            string fuel          = cbFuel.Text.Trim();

            //Check null or empty
            if (string.IsNullOrEmpty(model))
            {
                MessageBox.Show("Please input Model name!");
                return;
            }

            if (string.IsNullOrEmpty(sPrice))
            {
                MessageBox.Show("Please input Price!");
                return;
            }

            if (string.IsNullOrEmpty(sProducedYear))
            {
                MessageBox.Show("Please input Produced Year!");
                return;
            }

            if (string.IsNullOrEmpty(sEngine))
            {
                MessageBox.Show("Please input Engine!");
                return;
            }

            if (string.IsNullOrEmpty(sQuantity))
            {
                MessageBox.Show("Please input Quantity!");
                return;
            }

            if (string.IsNullOrEmpty(manufacturer))
            {
                MessageBox.Show("Please input Manufacturer!");
                return;
            }

            if (string.IsNullOrEmpty(tranmission))
            {
                MessageBox.Show("Please input Tranmission!");
                return;
            }

            if (string.IsNullOrEmpty(type))
            {
                MessageBox.Show("Please input Type!");
                return;
            }

            if (string.IsNullOrEmpty(category))
            {
                MessageBox.Show("Please input Category!");
                return;
            }

            if (string.IsNullOrEmpty(fuel))
            {
                MessageBox.Show("Please input Fuel!");
                return;
            }

            int Price        = -1;
            int ProducedYear = -1;
            int Engine       = -1;
            int Quantity     = -1;

            try
            {
                Price = int.Parse(sPrice);
            } catch
            {
                MessageBox.Show("Please input valid Price!");
                return;
            }

            try
            {
                ProducedYear = int.Parse(sProducedYear);
            }
            catch
            {
                MessageBox.Show("Please input valid Produced Year!");
                return;
            }

            try
            {
                Engine = int.Parse(sEngine);
            }
            catch
            {
                MessageBox.Show("Please input valid Engine!");
                return;
            }

            try
            {
                Quantity = int.Parse(sQuantity);
            }
            catch
            {
                MessageBox.Show("Please input valid Quantity!");
                return;
            }

            if (Price <= 0)
            {
                MessageBox.Show("Price must be greater than 0!");
                return;
            }

            if (ProducedYear <= 0)
            {
                MessageBox.Show("Produced Year must be greater than 0!");
                return;
            }

            if (Engine <= 0)
            {
                MessageBox.Show("Engine must be greater than 0!");
                return;
            }

            if (Quantity <= 0)
            {
                MessageBox.Show("Quantity must be greater than 0!");
                return;
            }
            //End validation.

            CarDTO carDTO = new CarDTO()
            {
                Model_Name              = model,
                Price                   = Price,
                Produced_Year           = ProducedYear,
                Engine                  = Engine,
                Quantity                = Quantity,
                Manufacturer_Name       = manufacturer,
                Tranmission_Description = tranmission,
                Type_Description        = type,
                Category_Description    = category,
                Fuel_Description        = fuel
            };

            CarDAO carDAO = new CarDAO();
            bool   result = carDAO.AddNewCar(carDTO);

            if (result)
            {
                MessageBox.Show("Add new car successfully!");
            }
            else
            {
                MessageBox.Show("Add new car failed!");
            }
            this.DialogResult = DialogResult.OK;
        }