예제 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            using (StdMng2015NEntities se = new StdMng2015NEntities())
            {
                t_Student std = (from s in se.t_Student
                                 where s.sno == txtID.Text
                                 select s).FirstOrDefault();

                if (std != null)
                {
                    try
                    {
                        IEnumerable <t_SC> stdSC
                            = from sc in se.t_SC where sc.Sno == std.sno
                              select sc;

                        foreach (t_SC tsc in stdSC)
                        {
                            se.DeleteObject(tsc);
                        }

                        se.DeleteObject(std);
                        se.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
예제 #2
0
 private void btnInsert_Click(object sender, EventArgs e)
 {
     using (StdMng2015NEntities se = new StdMng2015NEntities())
     {
         try
         {
             t_Student std = new t_Student();
             std.sno     = txtID.Text;
             std.sname   = txtName.Text;
             std.SGender = cbGender.SelectedItem.ToString();
             std.Sdept   = cbDept.SelectedValue.ToString();
             std.sIDNum  = txtIDCardNums.Text;
             std.SBirth  = dpBirth.Value;
             std.sEmail  = txtEmail.Text;
             std.SImage  = imgBytes;
             //se.AddTot_Student(std);
             se.t_Student.AddObject(std);
             se.SaveChanges();
             MessageBox.Show("保存学生信息成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
예제 #3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            using (StdMng2015NEntities se = new StdMng2015NEntities())
            {
                try
                {
                    t_Student std = se.t_Student.
                                    Where(s => s.sno == txtID.Text).FirstOrDefault();

                    if (std != null)
                    {
                        std.sname   = txtName.Text;
                        std.SGender = cbGender.SelectedItem.ToString();
                        std.Sdept   = cbDept.SelectedValue.ToString();
                        std.sIDNum  = txtIDCardNums.Text;
                        std.SBirth  = dpBirth.Value;
                        std.sEmail  = txtEmail.Text;
                        std.SImage  = imgBytes;
                        se.SaveChanges();
                        MessageBox.Show("修改学生信息成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("查无此人!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }