예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            btnSaveEnbaled(false);

            if (opration == OP_ADD)
            {
                HRJob job = new HRJob();
                job.Id   = txtId.Text;
                job.Name = txtName.Text;
                int ret = dao.Add(job);
                if (ret > 0)
                {
                    jobListSource.Add(job);
                }
            }
            else if (opration == OP_UPDATE)
            {
                HRJob job = jobList[grid.CurrentRow.Index];
                job.Name = txtName.Text;
                dao.Update(job);
                grid.Refresh();
            }

            CleanData();
        }
예제 #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (grid.CurrentRow.Index < 0)
            {
                MessageBoxEx.Show("请选择一条数据,在进行操作");
                return;
            }
            DialogResult result = MessageBoxEx.Show(this, "确认要删除吗?", "操作提示", MessageBoxButtons.YesNo);

            //如果点击的是"YES"按钮,将form关闭.
            if (result == DialogResult.Yes)
            {
                HRJob job = jobList[grid.CurrentRow.Index];
                try
                {
                    dao.Delete(job.Id);
                }
                catch (Exception ex)
                {
                    MessageBoxEx.Show(this, "删除失败!" + ex.StackTrace, "报错提示", MessageBoxButtons.YesNo);
                    return;
                }

                jobList.RemoveAt(grid.CurrentRow.Index);
                InitData();
            }
        }
예제 #3
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <returns></returns>
 public int Update(HRJob vo)
 {
     return(conn.Execute(@"update HR_JOB SET NAME=@Name WHERE id = @Id",
                         new
     {
         Id = vo.Id,
         Name = vo.Name
     }));
 }
예제 #4
0
        // 新增
        public int Add(HRJob vo)
        {
            int ret = conn.Execute(@"insert HR_JOB(ID,NAME) values (@Id,@Name)",
                                   new[] { new { Id   = vo.Id,
                                                 Name = vo.Name } });

            Console.WriteLine(string.Format("插入数据库成功{0}", ret));

            return(ret);
        }
예제 #5
0
        private void dataGridJob_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            HRJob job = jobList[e.RowIndex];

            Console.WriteLine(job.Id);
            txtId.Text   = job.Id;
            txtName.Text = job.Name;

            btnDelete.Enabled = true;
            btnUpdate.Enabled = true;
        }