Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            employee   empp = new employee();
            department dep  = new department();

            using (empDBContext emp2 = new empDBContext())
            {
                dep.Name        = comboBox1.SelectedItem.ToString();
                dep             = emp2.departments.Where(data => data.Name == dep.Name).SingleOrDefault();
                empp.FirstName  = textBox1.Text.ToString();
                empp.LastName   = textBox2.Text.ToString();
                empp.Gender     = textBox3.Text.ToString();
                empp.Salary     = Int32.Parse(textBox4.Text);
                empp.Department = dep;
                emp2.employees.Add(empp);
                int count = emp2.SaveChanges();
                if (count > 0)
                {
                    MessageBox.Show("Add successfully added to db");
                }
                else
                {
                    MessageBox.Show("Data not edited to db");
                }

                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";

                dataGridView1.DataSource = repo.getGridData();
            }
        }
Exemplo n.º 2
0
 public object getGridData()
 {
     using (empDBContext emp = new empDBContext())
     {
         return((from employee in emp.employees
                 join department in emp.departments
                 on employee.Department.Id equals department.Id
                 select new { firstname = employee.FirstName, lastname = employee.LastName, name = department.Name }).ToList());
     }
 }
Exemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            department dp = new department();

            using (empDBContext emp = new empDBContext())
            {
                //dp.Name = "hr";
                //dp.Location = "kota";
                //emp.departments.Add(dp);
                //emp.SaveChanges();
                List <department> d = emp.departments.ToList();
                foreach (department x in d)
                {
                    comboBox1.Items.Add(x.Name);
                }
                dataGridView1.DataSource = repo.getGridData();
            }
        }