private void btnSignup_Click(object sender, EventArgs e)
 {
     //insert on Account.
     if (!TM.AddAccount(txtUsername.Text, MD5.CreateMD5(txtPassword.Text), 2, 1))
     {
         //if add faild, show notification
         MessageBox.Show("Failed");
     }
     else
     {
         //get id of it
         var rs = TM.GetListOfAccount().OrderByDescending(s => s.ID).First();
         //insert on Driver.
         if (!TM.AddDriver((int)rs.ID, txtFullname.Text, txtIDCard.Text, txtAddress.Text, txtPhone.Text))
         {
             //if add failed. show notification
             MessageBox.Show("Add info failed, please sign in and update your profile");
         }
         else
         {
             //if 2 success, show notification
             MessageBox.Show("Sign up successed");
         }
     }
 }
 private void btnChange_Click(object sender, EventArgs e)
 {
     //when click change pass button
     //check empty textbox
     if (String.IsNullOrEmpty(txtPass.Text) || String.IsNullOrEmpty(txtPassRepeat.Text))
     {
         MessageBox.Show("Please don't let empty");
     }
     else
     {
         //compare password and passrepeat
         if (String.Compare(txtPassRepeat.Text, txtPass.Text) != 0)
         {
             MessageBox.Show("Password and Repeat-Password are not matched");
         }
         else
         {
             //update
             if (TM.UpdatePasswordAccount(id, MD5.CreateMD5(txtPass.Text.Trim())))
             {
                 MessageBox.Show("Update successed");
                 Close();
             }
             else
             {
                 MessageBox.Show("Update failed! Please try again");
             }
         }
     }
 }
Beispiel #3
0
 private void btnDangNhap_Click(object sender, EventArgs e)
 {
     //Check textbox Empty
     if (string.IsNullOrEmpty(txtUser.Text) | string.IsNullOrEmpty(txtPassword.Text))
     {
         //if empty, show error
         MessageBox.Show("Don't empty username or password.");
     }
     else
     {
         //if not empty
         //check valid account
         var acc = TM.GetListOfAccount();
         var rs  = acc.Where(s => (s.USERNAME.Trim() == txtUser.Text) & (s.PASSWORD.Trim() == MD5.CreateMD5(txtPassword.Text))).SingleOrDefault();
         if (rs != null)
         {
             //1: is Admin, 2: is Driver
             if (rs.TYPEID == 1)
             {
                 //1: status actived, 2: blocked
                 if (rs.STATUS == 1)
                 {
                     //Show notification
                     MessageBox.Show("Sign in success as Admin");
                     //call form admin manage
                     Menu fmn = new Menu((int)rs.ID);
                     fmn.StartPosition = FormStartPosition.CenterScreen;
                     fmn.FormClosed   += new FormClosedEventHandler(fmn_FormClosed);
                     Hide();
                     fmn.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Account is blocked");
                 }
             }
             else if (rs.TYPEID == 2)
             {
                 //1: status actived, 2: blocked
                 if (rs.STATUS == 1)
                 {
                     //Show notification
                     MessageBox.Show("Sign in success as Driver");
                     //call form admin manage
                     FormDriver fd = new FormDriver((int)rs.ID);
                     fd.StartPosition = FormStartPosition.CenterScreen;
                     fd.FormClosed   += new FormClosedEventHandler(fd_FormClosed);
                     Hide();
                     fd.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("Account is blocked");
                 }
             }
         }
         else
         {
             //Show Exception
             MessageBox.Show("Username or Password is incorrect!");
         }
     }
 }