示例#1
0
 private void LoginEvent2()
 {
     try
     {
         if (!string.IsNullOrEmpty(txtUsername.Text))
         {
             loginpass = loginpass.CheckLogIn(txtUsername.Text, txtpass.Text);
             if (loginpass.is_online)
             {
                 if (MessageBox.Show("This user is online." + Environment.NewLine + "Are you want re-login?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                 {
                     return;
                 }
             }
             loginpass.LogIO(txtUsername.Text, true);
             mesuser            = mesuser.GetUser(loginpass.user_cd);
             UserData.dept      = mesuser.dept_cd;
             UserData.usercode  = mesuser.user_cd;
             UserData.username  = mesuser.user_name;
             UserData.logintime = loginpass.last_login_time;
             //  UserData.role_permision = userrole.GetListRole(loginpass.user_cd);
             //Show main form
             Warehouse wh = new Warehouse();
             this.Hide();
             txtpass.Clear();
             wh.ShowDialog();
             loginpass.LogIO(txtUsername.Text, false);
             this.Show();
             this.Focus();
         }
         else
         {
             MessageBox.Show("Please fill user code!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             txtUsername.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#2
0
 /// <summary>
 /// Check user and password
 /// </summary>
 /// <param name="usercd">user code</param>
 /// <param name="pass">password</param>
 /// <returns></returns>
 public m_login_password CheckLogIn(string usercd, string pass)
 {
     try
     {
         EncryptDecrypt endecrypt = new EncryptDecrypt();
         pass = endecrypt.Encrypt(pass);
         //SQL library
         PSQL   SQL   = new PSQL();
         string query = string.Empty;
         //Open SQL connection
         SQL.Open();
         //SQL query string
         query  = @"SELECT user_cd, registration_user_cd, registration_date_time, factory_cd, last_login_time, is_online ";
         query += "FROM m_login_password WHERE user_cd ='" + usercd + "' and password ='******'";
         //Execute reader for read database
         IDataReader reader = SQL.Command(query).ExecuteReader();
         query = string.Empty;
         reader.Read();
         //Get an item
         m_login_password outItem = new m_login_password
         {
             user_cd                = reader["user_cd"].ToString(),
             factory_cd             = reader["factory_cd"].ToString(),
             is_online              = (bool)reader["is_online"],
             last_login_time        = (DateTime)reader["last_login_time"],
             registration_date_time = (DateTime)reader["registration_date_time"],
             registration_user_cd   = reader["registration_user_cd"].ToString(),
         };
         reader.Close();
         //Close SQL connection
         SQL.Close();
         return(outItem);
     }
     catch
     {
         throw new Exception("Wrong user or password!" + Environment.NewLine + "Please Log In again!");
     }
 }