コード例 #1
0
 private void buttonModify_Click(object sender, EventArgs e)
 {
     if (listBoxShowrooms.SelectedIndex > -1)
     {
         if (checkEntries())
         {
             CarShowrooms sr = dbContext.Set<CarShowrooms>().FirstOrDefault(csr => csr.Id == Int32.Parse(listBoxShowrooms.SelectedItem.ToString().Split(',')[2].Split(':')[1].Substring(1)));
             sr.Name = textBoxShowroomName.Text;
             sr.Address = textBoxShowroomAdress.Text;
             for (int i = 0; i < checkedListBoxWorkers.Items.Count; i++)
             {
                 Employees emp = dbContext.Set<Employees>().Include(em => em.CarShowroom).FirstOrDefault(em => em.Id == Int32.Parse(checkedListBoxWorkers.GetItemText(checkedListBoxWorkers.Items[i]).Split(',')[2].Split(':')[1].Substring(1)));
                 if(checkedListBoxWorkers.GetItemCheckState(i) == CheckState.Checked)
                 {
                     emp.CarShowroom = sr;
                 }
                 else
                 {
                     if (checkedListBoxWorkers.GetItemCheckState(i) == CheckState.Unchecked)
                     {
                         if (emp.CarShowroom == sr)
                             emp.CarShowroom = null;
                     }
                 }
             }
             for (int i = 0; i < checkedListBoxCars.Items.Count; i++)
             {
                 Cars car = dbContext.Set<Cars>().Include(c => c.CarShowroom).FirstOrDefault(cr => cr.Id == Int32.Parse(checkedListBoxCars.GetItemText(checkedListBoxCars.Items[i]).Split(',')[3].Split(':')[1].Substring(1)));
                 if (checkedListBoxCars.GetItemCheckState(i) == CheckState.Checked)
                 {
                     car.CarShowroom = sr;
                 }
                 else
                 {
                     if (checkedListBoxCars.GetItemCheckState(i) == CheckState.Unchecked)
                     {
                         if (car.CarShowroom == sr)
                             car.CarShowroom = null;
                     }
                 }
             }
             dbContext.SaveChanges();
             this.Close();
         }
         else
         {
             MessageBox.Show("Nie wszystkie wymagane pola zostały uzupełnione!", "Błąd modyfikowania salonu.", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
         MessageBox.Show("Nie wybrano salonu do modyfikacji!", "Błąd modyfikowania salonu.", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
コード例 #2
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (listBoxShowrooms.SelectedIndex > -1)
     {
         CarShowrooms sr = dbContext.Set<CarShowrooms>().FirstOrDefault(csr => csr.Id == Int32.Parse(listBoxShowrooms.SelectedItem.ToString().Split(',')[2].Split(':')[1].Substring(1)));
         dbContext.Set<CarShowrooms>().Remove(sr);
         dbContext.SaveChanges();
         this.Close();
     }
     else
     {
         MessageBox.Show("Nie wybrano salonu do usunięcia!", "Błąd usuwania salonu.", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #3
0
        private void listBoxShowrooms_SelectedIndexChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBoxCars.Items.Count; i++)
            {
                checkedListBoxWorkers.SetItemCheckState(checkedListBoxWorkers.Items.IndexOf(checkedListBoxWorkers.Items[i]), CheckState.Unchecked);
            }
            for (int i = 0; i < checkedListBoxCars.Items.Count; i++)
            {
                checkedListBoxCars.SetItemCheckState(checkedListBoxCars.Items.IndexOf(checkedListBoxCars.Items[i]), CheckState.Unchecked);
            }

            var showrooms = dbContext.Set<CarShowrooms>().Include(csr => csr.Employees).Include(csr => csr.Cars);

            CarShowrooms cs = showrooms.FirstOrDefault(csr => csr.Address == listBoxShowrooms.SelectedItem.ToString().Split(',')[0] && csr.Name == listBoxShowrooms.SelectedItem.ToString().Split(',')[1].Substring(1));
            textBoxShowroomAdress.Text = cs.Address;
            textBoxShowroomName.Text = cs.Name;

            for(int i = 0; i < checkedListBoxWorkers.Items.Count; i++)
            {
                Employees emp = cs.Employees.Find(em => em.Id == Int32.Parse(checkedListBoxWorkers.GetItemText(checkedListBoxWorkers.Items[i]).Split(',')[2].Split(':')[1].Substring(1)));
                if(emp != null)
                {
                    checkedListBoxWorkers.SetItemCheckState(checkedListBoxWorkers.Items.IndexOf(checkedListBoxWorkers.Items[i]), CheckState.Checked);
                }
                else
                    checkedListBoxWorkers.SetItemCheckState(checkedListBoxWorkers.Items.IndexOf(checkedListBoxWorkers.Items[i]), CheckState.Unchecked);
            }

                for (int i = 0; i < checkedListBoxCars.Items.Count; i++)
                {
                    Cars car = cs.Cars.Find(cr => cr.Id == Int32.Parse(checkedListBoxCars.GetItemText(checkedListBoxCars.Items[i]).Split(',')[3].Split(':')[1].Substring(1)));

                    if (car != null)
                    {
                        checkedListBoxCars.SetItemCheckState(checkedListBoxCars.Items.IndexOf(checkedListBoxCars.Items[i]), CheckState.Checked);
                    }
                    else
                        checkedListBoxCars.SetItemCheckState(checkedListBoxCars.Items.IndexOf(checkedListBoxCars.Items[i]), CheckState.Unchecked);
                }
        }