Ejemplo n.º 1
0
        public CarColorForm(int id = 0)
        {
            InitializeComponent();

            namePictureBox.Visible = false;

            if (id != 0)
            {
                this.id = id;
                CarColor color = CarColorRepository.Get(id);
                carcolorTextBox.Text = color.Name;
            }
        }
Ejemplo n.º 2
0
        private void CarColorDelete_Click(object sender, EventArgs e)
        {
            int index = carcolorGridView.SelectedCells.Count > 0 ? carcolorGridView.SelectedCells[0].RowIndex : -1;

            index = index != -1 ? Int32.Parse(carcolorGridView.Rows[index].Cells[0].Value.ToString()) : 0;
            if (index == 0)
            {
                MessageBox.Show("Please select row!", "No record selected?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            DialogResult result = MessageBox.Show("Сигурни ли сте, че искате да изтриете записа?", "Изтриване?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                CarColorRepository.Remove(index);
                this.getRecords();
            }
        }
Ejemplo n.º 3
0
        private void CarColorAddButton_Click(object sender, System.EventArgs e)
        {
            namePictureBox.Visible = false;
            if (carcolorTextBox.Text.Length == 0)
            {
                namePictureBox.Visible = true;
                return;
            }

            string name = carcolorTextBox.Text;

            if (this.id != 0)
            {
                CarColorRepository.Update(new CarColor(this.id, name));
            }
            else
            {
                CarColorRepository.Add(new CarColor(0, name));
            }

            this.Close();
        }
Ejemplo n.º 4
0
        public CarForm(int id = 0)
        {
            InitializeComponent();

            this.hideErrors();

            Car car = null;

            if (id != 0)
            {
                this.id = id;
                car     = CarRepository.Get(id);
            }

            colors = CarColorRepository.GetAll();
            foreach (CarColor c in colors)
            {
                colorDropdown.Items.Add(c.Name);
            }

            brands = BrandRepository.GetAll();
            foreach (Brand b in brands)
            {
                brandDropdown.Items.Add(b.Name);
            }

            if (car == null)
            {
                if (brands.Count > 0)
                {
                    models = ModelRepository.GetForBrand(brands[0].Id);
                }
                else
                {
                    models = new List <Model>();
                }
            }
            else
            {
                models = ModelRepository.GetForBrand(car.Model.Brand.Id);
            }

            foreach (Model m in models)
            {
                modelDropdown.Items.Add(m.Name);
            }

            if (car != null)
            {
                regTextbox.Text          = car.RegistrationNumber;
                yearTextbox.Text         = car.Year.ToString();
                engineTextbox.Text       = car.EngineNumber;
                frameTextbox.Text        = car.FrameNumber;
                engineVolumeTextbox.Text = car.EngineVolume;
                descriptionTextbox.Text  = car.Description;
                ownerTextbox.Text        = car.CarOwnerName;
                phoneTextbox.Text        = car.ContactNumber;

                brandDropdown.Text = car.Model != null ? car.Model.Brand.Name : "";
                modelDropdown.Text = car.Model != null ? car.Model.Name : "";
                colorDropdown.Text = car.Color != null ? car.Color.Name : "";
            }
            else
            {
                brandDropdown.Text = this.brands.Count > 0 ? this.brands[0].Name : "";
                modelDropdown.Text = this.models.Count > 0 ? this.models[0].Name : "";
                colorDropdown.Text = this.colors.Count > 0 ? this.colors[0].Name : "";
            }
        }