コード例 #1
0
ファイル: UserInfoForm.cs プロジェクト: biduong/KingFood
        private void Form3_Load(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 == textBox1.Text)
                           .FirstOrDefault();
                int current = Int32.Parse(DateTime.Now.Year.ToString());

                DateTime birth = Convert.ToDateTime(blog.birthday.ToString());
                int      year  = birth.Year;
                int      age2  = current - year;
                lbAge.Text = age2.ToString();
                lbAge.Text = age2.ToString();
                if (txtBmi.Text == "")
                {
                    txtBmi.Text = "Not calculated";
                }
                else
                {
                    String s = blog.bmi.ToString();
                    //Lay 3 chu so thap phan
                    double db = Math.Round(Double.Parse(s), 3);
                    txtBmi.Text = db.ToString();
                }
            }
        }
コード例 #2
0
ファイル: SignUp.cs プロジェクト: biduong/KingFood
        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");
            }
        }
コード例 #3
0
        public void LoadStudent()
        {
            DATABASE_KINGFOODEntities2 db = new DATABASE_KINGFOODEntities2(); // create connection to your database

            this.lstUsers.DataSource                  = db.Personal_Information.ToList();
            this.lstUsers.DefaultCellStyle.Font       = new Font("Tahoma", 11);
            this.lstUsers.Columns["password"].Visible = false;
        }
コード例 #4
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!");
     }
 }
コード例 #5
0
ファイル: bmi.cs プロジェクト: biduong/KingFood
 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");
         }
     }
 }
コード例 #6
0
ファイル: LoginForm.cs プロジェクト: biduong/KingFood
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string user = txtUser.Text;
            string pass = txtPass.Text;

            using (DATABASE_KINGFOODEntities2 context = new DATABASE_KINGFOODEntities2())
            {
                var users = context.Personal_Information.FirstOrDefault(u => u.name == user);
                if (users != null)
                {
                    if (users.password == pass)
                    {
                        MessageBox.Show("Login Sucessfully");
                        this.Hide();
                        UserInfoForm f3 = new UserInfoForm();
                        f3.textBox1.Text = user;
                        f3.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Wrong Password");
                    }
                }
                else if (user == "admin" && pass == "123456")
                {
                    MessageBox.Show("Login Sucessfully with admin account");
                    this.Hide();
                    ManageAdmin f3 = new ManageAdmin();
                    f3.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("No user name call " + user + " found");
                }
            }
        }
コード例 #7
0
ファイル: SignUp.cs プロジェクト: biduong/KingFood
 private void Form2_Load(object sender, EventArgs e)
 {
     DATABASE_KINGFOODEntities2 db = new DATABASE_KINGFOODEntities2();
 }