示例#1
0
        public cPerson IsValidUser(string useremail, string password)
        {
            var User = new cPerson();

            Get_Connection();
            try
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = connection;
                string pass = converttoencryptedPassword(password);
                cmd.CommandText = string.Format("select * from  RegistrationTable where Email = '{0}'and Password = '******'", useremail, pass);

                MySqlDataReader reader = cmd.ExecuteReader();

                try
                {
                    //var reader1 = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            string tmp = reader["Registration_Id"].ToString();
                            User.Registration_Id = Int32.Parse(tmp);
                            User.email           = reader["Email"].ToString();
                            User.UserName        = reader["Name"].ToString();
                            User.workat          = reader["WorkedAt"].ToString();
                            User.orgname         = reader["OrganizationName"].ToString();
                            User.mobilde         = reader["Mobileno"].ToString();
                            User.role            = reader["Role"].ToString();
                            User.station         = reader["StationedAt"].ToString();

                            var dateTimeRetrieved = Convert.ToDateTime(reader["reg_date"]);;
                            var outputTimeZone    = TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time");
                            var outputDateTime    = TimeZoneInfo.ConvertTime(dateTimeRetrieved, outputTimeZone);
                            User.RegisterationDate = outputDateTime;

                            User.RegistrationStatus = reader["RegistrationStatus"].ToString();
                        }



                        reader.Dispose();
                        cmd.Dispose();
                        connection.Close();
                        return(User);
                    }
                    else
                    {
                        reader.Dispose();
                        cmd.Dispose();
                        connection.Close();
                        return(null);
                    }
                }
                catch (MySqlException e)
                {
                    string MessageString = "Read error occurred  / entry not found loading the Column details: "
                                           + e.ErrorCode + " - " + e.Message + "; \n\nPlease Continue";
                    //MessageBox.Show(MessageString, "SQL Read Error");

                    reader.Close();
                    connection.Close();
                    return(null);
                }
            }
            catch (MySqlException e)
            {
                string MessageString = "The following error occurred loading the Column details: "
                                       + e.ErrorCode + " - " + e.Message;
                connection.Close();
                return(null);
            }
        }