Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (Functions.AllowedPlate(plate.Text))
            {
                cars Car = new cars
                {
                    Make         = make.Text,
                    Model        = model.Text,
                    Comment      = comment.Text,
                    Number_plate = plate.Text,
                    Carry        = (int)carry.Value,
                    IsUsed       = false.ToString(),
                    Sold         = false.ToString()
                };
                projektEntities context = new projektEntities();
                context.cars.Add(Car);
                context.SaveChanges();

                LoadData();
                dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
                id.Text = Car.Id.ToString();
            }
            else
            {
                MessageBox.Show("Istnieje już auto o takiej rejestracji");
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var             query   = (from car in context.cars
                                       where car.Id == Id
                                       select new
            {
                Car = car
            }).First();

            if (query.Car == null)
            {
                MessageBox.Show("Nie znaleziono auta o takim Id");
                return;
            }
            if (!Functions.AllowedPlate(plate.Text) && plate.Text != query.Car.Number_plate)
            {
                MessageBox.Show("Taki numer rejestracji już występuje");
                return;
            }

            query.Car.Make         = make.Text;
            query.Car.Model        = model.Text;
            query.Car.Comment      = comment.Text;
            query.Car.Number_plate = plate.Text;
            query.Car.Carry        = (int)carry.Value;
            query.Car.Sold         = sold.Checked.ToString();

            context.Entry(query.Car).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }