예제 #1
0
 private void Form4_Load(object sender, EventArgs e)
 {
     using (var db = new police_dbContext())
     {
         double avgamount = (double)db.Fine.Average(a => a.Ammount);
         var    fines     = db.Fine.Where(a => a.Ammount > avgamount).ToList();
         dataGridView1.DataSource = fines;
     }
 }
예제 #2
0
 public void EditCitizen()//изменеие граждан
 {
     using (var db = new police_dbContext())
     {
         var edit = db.Citizen.Single(a => a.CitizenId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
         edit.CitizenFio = dataGridView1.CurrentRow.Cells[1].Value.ToString();
         db.SaveChanges();
     }
 }
예제 #3
0
 public void EditLicense()//изменеие прав
 {
     using (var db = new police_dbContext())
     {
         var edit = db.License.Single(a => a.LicenseId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
         edit.FromData   = DateTime.Parse(dataGridView1.CurrentRow.Cells[2].Value.ToString());
         edit.BeforeData = DateTime.Parse(dataGridView1.CurrentRow.Cells[3].Value.ToString());
         db.SaveChanges();
     }
 }
예제 #4
0
 //public void EditFine()//изменеие штрафа
 //{
 //    using (var db = new police_dbContext())
 //    {
 //        var edit = db.Fine.Single(a => a.VialatorId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
 //        edit.VialatorId = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
 //        edit.Ammount = int.Parse(dataGridView1.CurrentRow.Cells[1].Value.ToString());
 //        edit.VialatorId = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
 //        db.SaveChanges();
 //    }
 //}
 public void EditInsurance()//изменеие страховки
 {
     using (var db = new police_dbContext())
     {
         var edit = db.Insurance.Single(a => a.InsuranceSerialnumber == dataGridView1.CurrentRow.Cells[0].Value.ToString());
         edit.InsuranceFrom   = DateTime.Parse(dataGridView1.CurrentRow.Cells[2].Value.ToString());
         edit.InsuranceBefore = DateTime.Parse(dataGridView1.CurrentRow.Cells[3].Value.ToString());
         db.SaveChanges();
     }
 }
예제 #5
0
        public void EditTechPasport()//изменеие тех паспорта
        {
            using (var db = new police_dbContext())
            {
                var edit = db.TechPasport.Single(a => a.TechPassId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                edit.Color    = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                edit.CarModel = dataGridView1.CurrentRow.Cells[3].Value.ToString();

                db.SaveChanges();
            }
        }
예제 #6
0
 public void EditEmployee()//изменеие работников
 {
     using (var db = new police_dbContext())
     {
         var edit = db.Employee.Single(a => a.EmpId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
         edit.EmpFio = dataGridView1.CurrentRow.Cells[1].Value.ToString();
         //edit.WorkDate = DateTime.Parse(dataGridView1.CurrentRow.Cells[2].Value.ToString());
         //edit.WorkStatus = dataGridView1.CurrentRow.Cells[3].Value.ToString();
         //edit.LeaveDate = DateTime.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
         edit.EmpPosition = int.Parse(dataGridView1.CurrentRow.Cells[5].Value.ToString());
         db.SaveChanges();
     }
 }
예제 #7
0
 public void GetMeTechPasport()//метод для получения списка тех паспортов
 {
     using (police_dbContext db = new police_dbContext())
     {
         if (db.Citizen.Count() == 0)
         {
             MessageBox.Show("Таблица пуста");
         }
         else
         {
             var ctz = db.TechPasport.FromSqlRaw("select * from tech_pasport").ToList();
             dataGridView1.DataSource = ctz;
         }
     }
 }
예제 #8
0
 public void GetMeLicense()//метод для получения списка прав
 {
     using (police_dbContext db = new police_dbContext())
     {
         if (db.Citizen.Count() == 0)
         {
             MessageBox.Show("Таблица пуста");
         }
         else
         {
             var ctz = db.License.FromSqlRaw("select * from license").ToList();
             dataGridView1.DataSource = ctz;
         }
     }
 }
예제 #9
0
 public void GetMeCopyTechPasport()
 {
     using (var db = new police_dbContext())
     {
         if (db.Citizen.Count() == 0)
         {
             MessageBox.Show("Таблица пуста");
         }
         else
         {
             var ctz = db.CopyTechPasport.ToList();
             dataGridView1.DataSource = ctz;
         }
     }
 }
예제 #10
0
 public void GetMeCopyCitizen()//метод для получения списка граждан
 {
     using (var db = new police_dbContext())
     {
         if (db.Citizen.Count() == 0)
         {
             MessageBox.Show("Таблица пуста");
         }
         else
         {
             var ctz = db.CopyCitizen.ToList();
             dataGridView1.DataSource = ctz;
         }
     }
 }
예제 #11
0
        private void button2_Click(object sender, EventArgs e)//удаление
        {
            using (var db = new police_dbContext())
            {
                string choice = comboBox1.Text;
                switch (choice)
                {
                case "":
                    MessageBox.Show("не выбрана таблица");
                    break;

                case "Citizen":
                    try
                    {
                        var delete = db.Citizen.Single(a => a.CitizenId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                        db.Citizen.Remove(delete);
                        db.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("От этого зависят значения других таблиц");
                    }
                    break;

                case "Employee":
                    try
                    {
                        var delete = db.Employee.Single(a => a.EmpId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                        db.Employee.Remove(delete);
                        db.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("От этого зависят значения других таблиц");
                    }
                    break;

                case "Fine":
                    try
                    {
                        var delete = db.Fine.Single(a => a.VialatorId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                        db.Fine.Remove(delete);
                        db.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("От этого зависят значения других таблиц");
                    }
                    break;

                case "Insurance":
                    try
                    {
                        var delete = db.Insurance.Single(a => a.InsuranceSerialnumber == dataGridView1.CurrentRow.Cells[1].Value.ToString());
                        db.Insurance.Remove(delete);
                        db.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("От этого зависят значения других таблиц");
                    }
                    break;

                case "License":
                    try
                    {
                        var delete = db.License.Single(a => a.LicenseId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                        db.License.Remove(delete);
                        db.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("От этого зависят значения других таблиц");
                    }
                    break;

                case "TechPasport":
                    try
                    {
                        var delete = db.TechPasport.Single(a => a.TechPassId == int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()));
                        db.TechPasport.Remove(delete);
                        db.SaveChanges();
                    }
                    catch
                    {
                        MessageBox.Show("От этого зависят значения других таблиц");
                    }
                    break;
                }
            }
        }
예제 #12
0
        private void button1_Click(object sender, EventArgs e)//подтверждение
        {
            using (var db = new police_dbContext())
            {
                string n = comboBox1.Text;
                switch (n)
                {
                case "":
                    MessageBox.Show("не выбрана таблица");
                    break;

                case "Citizen":
                    int    id  = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    string fio = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    db.Citizen.Add(new Citizen {
                        CitizenId = id, CitizenFio = fio
                    });
                    db.SaveChanges();
                    break;

                case "Employee":
                    int    empid      = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    string empfio     = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    string workdate   = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    string workstatus = dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    //string leavedate = dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    int empposition = int.Parse(dataGridView1.CurrentRow.Cells[5].Value.ToString());
                    db.Employee.Add(new Employee {
                        EmpId = empid, EmpFio = empfio, WorkDate = DateTime.Parse(workdate), WorkStatus = workstatus, LeaveDate = null, EmpPosition = empposition
                    });
                    db.SaveChanges();
                    break;

                case "Fine":

                    int    vid    = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    int    amount = int.Parse(dataGridView1.CurrentRow.Cells[1].Value.ToString());
                    int    vtpid  = int.Parse(dataGridView1.CurrentRow.Cells[2].Value.ToString());
                    int    koap   = int.Parse(dataGridView1.CurrentRow.Cells[3].Value.ToString());
                    string vdate  = dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    string vplace = dataGridView1.CurrentRow.Cells[5].Value.ToString();
                    db.Fine.Add(new Fine {
                        VialatorId = vid, Ammount = amount, VialatorTechPasportId = vtpid, Koap12 = koap, VialationDate = DateTime.Parse(vdate), VialationPlace = vplace
                    });
                    db.SaveChanges();
                    break;

                case "Insurance":
                    int    itpid   = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    string isn     = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    string ifrom   = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    string ibefore = dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    int    icid    = int.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
                    db.Insurance.Add(new Insurance {
                        InsuranceTechPasportId = itpid, InsuranceSerialnumber = isn, InsuranceFrom = DateTime.Parse(ifrom), InsuranceBefore = DateTime.Parse(ibefore), InsuranceCivilianId = icid
                    });
                    db.SaveChanges();
                    break;

                case "License":
                    int    lid   = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    int    oid   = int.Parse(dataGridView1.CurrentRow.Cells[1].Value.ToString());
                    string fdata = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    string bdata = dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    db.License.Add(new Models.License {
                        LicenseId = lid, OwnerId = oid, FromData = DateTime.Parse(fdata), BeforeData = DateTime.Parse(bdata)
                    });
                    db.SaveChanges();
                    break;

                case "TechPasport":
                    int    tpid  = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
                    int    ctpid = int.Parse(dataGridView1.CurrentRow.Cells[1].Value.ToString());
                    string color = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                    string model = dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    string vin   = dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    db.TechPasport.Add(new TechPasport {
                        TechPassId = tpid, CivTechPassportId = ctpid, Color = color, CarModel = model, Vin = vin
                    });
                    db.SaveChanges();
                    break;
                }
            }

            Form2 form2 = new Form2();

            form2.Close();
        }
예제 #13
0
 private void Form2_Load(object sender, EventArgs e)
 {
     using (var db = new police_dbContext())
     {
     }
 }