Exemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // list all employees
            var empService = new EmpService();
            var employees  = empService.ListAll();

            bindingSource1.DataSource       = employees;
            dataGridView1.DataSource        = bindingSource1;
            bindingNavigator1.BindingSource = bindingSource1;
        }
Exemplo n.º 2
0
        public void SaveEntity()
        {
            bindingSource1.EndEdit();
            var emp        = this.bindingSource1.Current as Employee;
            var empService = new EmpService();

            if (isAddNew)
            {
                empService.Insert(emp);
            }
            else
            {
                empService.Update(emp);
            }
        }
Exemplo n.º 3
0
        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (bindingSource1.Current == null)
            {
                return;
            }

            var result = MessageBox.Show("确定删除此笔记录吗?",
                                         "删除确认",
                                         MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                var emp        = bindingSource1.Current as Employee;
                var empService = new EmpService();
                int count      = empService.Delete(emp.Emp_Id);

                if (count > 0)
                {
                    bindingSource1.RemoveCurrent();
                }
            }
        }