Exemplo n.º 1
0
        private void add_data()
        {
            if (db.Avtos.Any())
            {
                return;
            }
            else
            {
                Engine engine = new Engine();
                engine.EngineID    = 1;
                engine.Type_Engine = "Дизель";
                Engine engine1 = new Engine();
                engine1.EngineID    = 2;
                engine1.Type_Engine = "Бензин";
                Engine engine2 = new Engine();
                engine2.EngineID    = 3;
                engine2.Type_Engine = "Газ";

                Type_Body body = new Type_Body();
                body.Type_BodyID = 1;
                body.NameBody    = "Пикап";
                Type_Body body1 = new Type_Body();
                body1.Type_BodyID = 2;
                body1.NameBody    = "Универсал";
                Type_Body body2 = new Type_Body();
                body2.Type_BodyID = 3;
                body2.NameBody    = "Седан";

                Avto avto = new Avto();
                avto.Model       = "Opel";
                avto.Marka       = "Turbo";
                avto.Color       = "Gold";
                avto.Count_Doors = 2;
                avto.Type_BodyID = 3;
                avto.EngineID    = 1;

                db.Engines.Add(engine);
                db.Engines.Add(engine1);
                db.Engines.Add(engine2);

                db.Type_Bodies.Add(body);
                db.Type_Bodies.Add(body1);
                db.Type_Bodies.Add(body2);

                db.Avtos.Add(avto);

                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void button1_Add_Click(object sender, EventArgs e)
        {
            Avto avto = new Avto
            {
                Model       = textBoxModel.Text,
                Marka       = textBoxMarka.Text,
                EngineID    = getEngine,
                Type_BodyID = getBody,
                Count_Doors = Convert.ToInt32(CountDoors.Text),
                Color       = textBoxColor.Text
            };

            db.Avtos.Add(avto);
            db.SaveChanges();
            this.Close();
        }
Exemplo n.º 3
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows[0].Index > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Avto avto = db.Avtos.Find(id);
                db.Avtos.Remove(avto);

                db.SaveChanges();
                Refresh();
            }
        }
Exemplo n.º 4
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            int index;

            try { index = dataGridView1.SelectedRows[0].Index; }
            catch { index = 0; }

            int  id;
            bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

            if (converted == false)
            {
                return;
            }

            Avto avto = db.Avtos.Find(id);

            Form_Add edit = new Form_Add();


            edit.getModel      = avto.Model;
            edit.getMarka      = avto.Marka;
            edit.getColor      = avto.Color;
            edit.getCountDoors = avto.Count_Doors;
            edit.getEngine     = avto.EngineID;
            edit.getBody       = avto.Type_BodyID;

            edit.buttonUpdate.Visible = true;
            edit.button1_Add.Visible  = false;
            edit.ShowDialog();

            avto.Model       = edit.getModel;
            avto.Marka       = edit.getMarka;
            avto.Color       = edit.getColor;
            avto.Count_Doors = edit.getCountDoors;
            avto.EngineID    = edit.getEngine;
            avto.Type_BodyID = edit.getBody;

            db.SaveChanges();
            Refresh();
        }