Ejemplo n.º 1
0
        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            //Confirm password
            if (txtConfirm.Text == txtPass.Text)
            {
                using (DATABASE_KINGFOODEntities2 context = new DATABASE_KINGFOODEntities2())
                {
                    //Check has already this user in account
                    if (context.Personal_Information.Any(o => o.name == txtName.Text))
                    {
                        MessageBox.Show("Has already this user");
                    }
                    else
                    {
                        DATABASE_KINGFOODEntities2 db = new DATABASE_KINGFOODEntities2(); // open connection to database
                        Personal_Information       kf = new Personal_Information();       // create a new student object
                        kf.name     = txtName.Text;
                        kf.password = txtPass.Text;

                        kf.birthday = Convert.ToDateTime(txtBirth.Text);
                        kf.gender   = selectedText;
                        //Check user
                        string pass = txtPass.Text;
                        db.Personal_Information.Add(kf);
                        db.SaveChanges();
                        this.Close(); //
                        MessageBox.Show("Add user successfully!");
                    }
                }
            }
            else
            {
                MessageBox.Show("Wrong Pass");
            }
        }
Ejemplo n.º 2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (lstUsers.SelectedRows.Count == 1)
     {
         var row  = lstUsers.SelectedRows[0];
         var cell = row.Cells["id"];
         int id   = (int)cell.Value;
         DATABASE_KINGFOODEntities2 db = new DATABASE_KINGFOODEntities2();
         Personal_Information       pi = db.Personal_Information.Single(st => st.id == id);
         db.Personal_Information.Remove(pi);
         db.SaveChanges();
         this.LoadStudent();
     }
     else
     {
         MessageBox.Show("You should select a student!");
     }
 }
Ejemplo n.º 3
0
 private void save_Click(object sender, EventArgs e)
 {
     using (var context = new DATABASE_KINGFOODEntities2())
     {
         // Query for the Blog named ADO.NET Blog
         var blog = context.Personal_Information
                    .Where(b => b.name == label2.Text)
                    .FirstOrDefault();
         blog.bmi = float.Parse(label1.Text.ToString());
         context.Entry(blog).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
         this.Close();
         if (blog.bmi > 25)
         {
             MessageBox.Show("Ban nen giam mo!");
         }
         if (blog.bmi <= 25)
         {
             MessageBox.Show("Co the ban rat vua can");
         }
     }
 }