Example #1
0
        private void btn_Update_Click(object sender, EventArgs e)
        {
            using (Student_DBEntities db = new Student_DBEntities())
            {
                var Stud = db.tbl_Student.Find(Convert.ToInt32(tb_ID.Text));

                if (Stud != null)
                {
                    Stud.Name      = tb_Name.Text;
                    Stud.Mobile_No = Convert.ToInt64(tb_Mobile_No.Text);
                    Stud.City      = cmb_City.Text;
                    Stud.DOB       = dtp_DOB.Value;
                    if (rbtn_male.Checked)
                    {
                        Stud.Gender = rbtn_male.Text;
                    }
                    else
                    {
                        Stud.Gender = rbtn_Female.Text;
                    }
                    db.SaveChanges();

                    MessageBox.Show("Information Deleted Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearControls();
                }
                else
                {
                    MessageBox.Show("Invalid Student ID Can't Delete", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
        private void btn_Search_Click(object sender, EventArgs e)
        {
            using (Student_DBEntities db = new Student_DBEntities())
            {
                var Stud = db.tbl_Student.Find(Convert.ToInt32(tb_ID.Text));

                if (Stud != null)
                {
                    tb_Name.Text      = Stud.Name;
                    tb_Mobile_No.Text = Stud.Mobile_No.ToString();
                    cmb_City.Text     = Stud.City.ToString();
                    dtp_DOB.Value     = Stud.DOB;
                    if (Stud.Gender.Contains(rbtn_male.Text))
                    {
                        rbtn_male.Checked = true;
                    }
                    else
                    {
                        rbtn_Female.Checked = true;
                    }

                    MessageBox.Show("Information Found Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Invalid Student ID", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 private void frm_View_All_Student_Details_Load(object sender, EventArgs e)
 {
     //lbl_Header.Text = "Update";
     using (Student_DBEntities db = new Student_DBEntities())
     {
         dgv_Student_Details.DataSource = (from s in db.tbl_Student select s).ToList();
     }
 }
Example #4
0
 void Autoincreament()
 {
     using (Student_DBEntities db = new Student_DBEntities())
     {
         var CntID = (from s in db.tbl_Student select s.Id).Count();
         if (CntID != 0)
         {
             var MaxID = (from s in db.tbl_Student select s.Id).Max();
             tb_ID.Text = (Convert.ToInt32(MaxID += 1)).ToString();
         }
         else
         {
             tb_ID.Text = (Convert.ToInt32(CntID = 1001)).ToString();
         }
     }
 }
Example #5
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            using (Student_DBEntities db = new Student_DBEntities())
            {
                var Stud = db.tbl_Student.Find(Convert.ToInt32(tb_ID.Text));

                if (Stud != null)
                {
                    db.tbl_Student.Remove(Stud);
                    db.SaveChanges();

                    MessageBox.Show("Information Deleted Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearControls();
                }
                else
                {
                    MessageBox.Show("Invalid Student ID Can't Delete", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #6
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            string gender = null;

            if (tb_ID.Text != "" && tb_Name.Text != "" && tb_Mobile_No.Text != "" && cmb_City.Text != "" && (rbtn_male.Checked || rbtn_Female.Checked))
            {
                using (Student_DBEntities db = new Student_DBEntities())
                {
                    if (rbtn_male.Checked)
                    {
                        gender = rbtn_male.Text;
                    }
                    else
                    {
                        gender = rbtn_Female.Text;
                    }
                    db.tbl_Student.Add(new tbl_Student()
                    {
                        Id        = Convert.ToInt32(tb_ID.Text),
                        Name      = tb_Name.Text,
                        Mobile_No = Convert.ToInt64(tb_Mobile_No.Text),
                        City      = cmb_City.Text,
                        DOB       = dtp_DOB.Value,
                        Gender    = gender
                    }
                                       );
                    db.SaveChanges();
                    MessageBox.Show("Information Save Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Autoincreament();
                    ClearControls();
                }
            }
            else
            {
                MessageBox.Show("1st Fill All The Fields", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }