コード例 #1
0
ファイル: UserDAL.cs プロジェクト: almda/Kanban-board
        public static void saveUser(UserStruct UserDetails)
        {
            SQLiteCommand command = new SQLiteCommand();

            try
            {
                DAL.OpenConnect();
                command             = new SQLiteCommand(null, DAL.connection);
                command.CommandText = "INSERT INTO Users(UserName, Password)  " +
                                      " VALUES (@User_UserName, @User_Password)";
                SQLiteParameter UserName = new SQLiteParameter("@User_UserName", UserDetails.getUserName());
                SQLiteParameter Password = new SQLiteParameter("@User_Password", UserDetails.getPassword());
                command.Parameters.Add(UserName);
                command.Parameters.Add(Password);
                command.Prepare();
                int changes = command.ExecuteNonQuery();
                command.Dispose();
                DAL.CloseConnect();
                Logger.Log.Info("The registrtion of " + UserDetails.getUserName() + " is Succeeded");
            }
            catch (SQLiteException e)
            {
                Logger.Log.Fatal("while the saving process of " + UserDetails.getUserName() + " accord, there was an error -" + e.Message);
                command.Dispose();
                DAL.CloseConnect();
            }
        }
コード例 #2
0
        public static UserStruct?isPasswordExist(String Email, String Password)
        {
            UserStruct tempUser = new UserStruct();

            String[] arr      = Email.Split('@');
            String   username = arr[0];

            for (int i = 0; i < users.Count; i++)
            {
                tempUser = users[i];
                if (tempUser.getUserName().Equals(username))
                {
                    String tempPass = tempUser.getUser()[username].ToString();
                    if (tempPass.Equals(Password))
                    {
                        return(tempUser);
                    }
                }
            }
            return(null);

            /*
             * if (!File.Exists(UsersFile)) // file exist check
             * {
             *  File.Create(UsersFile);
             * }
             *
             * Stream stream = File.OpenRead(UsersFile);
             * BinaryFormatter formatter = new BinaryFormatter();
             * stream.Position = 0;
             * try
             * {
             *  while (stream.Position < stream.Length)
             *  { // pass on the data in the file
             *      UserStruct UserDetails = (UserStruct)formatter.Deserialize(stream);
             *      String passtry = UserDetails.getUser()[Email].ToString();
             *      if (passtry.Equals(Password))
             *      { // check if the password match to the email
             *          stream.Close();
             *          return UserDetails;
             *      }
             *  }
             * }
             * catch (Exception e)
             * {
             *  MileStone4.DataAcces_Layer.Logger.Log.Fatal("while check if email "+Email+" and password "+Password+" match, an error accord - "+e.Message);
             * }
             * stream.Close();
             * return null;
             */
        }
コード例 #3
0
        public static Boolean isEmailExist(String Email)
        {
            //Hashtable tempHash = new Hashtable();
            //tempHash[Email]
            String[]   arr      = Email.Split('@');
            String     username = arr[0];
            UserStruct tempUser = new UserStruct();

            for (int i = 0; i < users.Count; i++)
            {
                tempUser = users[i];
                if (tempUser.getUserName().Equals(username))
                {
                    return(true);
                }
            }
            return(false);

            /*
             * if (!File.Exists(UsersFile)) // exist file check
             * {
             *  Stream s = File.Create(UsersFile);
             *  s.Close();
             * }
             *
             * Stream stream = File.OpenRead(UsersFile);
             * BinaryFormatter formatter = new BinaryFormatter();
             * Email = Email.Split('@')[0]; // Change to user name
             * stream.Position = 0;
             * try
             * {
             *  while (stream.Position < stream.Length)
             *  { // pass on all the data in te file
             *      UserStruct UserDetails = (UserStruct)formatter.Deserialize(stream);
             *      if (UserDetails.getUser().ContainsKey(Email)) // and check if the email is there
             *      {
             *          stream.Close();
             *          return true;
             *      }
             *  }
             *  stream.Close();
             *  return false;
             * }
             * catch (Exception e)
             * {
             *  MileStone4.DataAcces_Layer.Logger.Log.Fatal("while check the if the email "+Email+" exist, an error accord - "+e.Message);
             *  return false;
             * }
             */
        }
コード例 #4
0
 public static void saveUser(UserStruct UserDetails)
 {
     try
     {
         if (!File.Exists(UsersFile)) // exist file check
         {
             File.Create(UsersFile);
         }
         // open file, and save the user there
         Stream stream = File.OpenWrite(UsersFile);
         stream.Position = stream.Length;
         BinaryFormatter formatter = new BinaryFormatter();
         formatter.Serialize(stream, UserDetails);
         Console.WriteLine("The registrtion of " + UserDetails.getUserName() + " is Succeeded");
         stream.Close();
         users.Add(UserDetails);
     }
     catch (Exception e)
     {
         MileStone4.DataAcces_Layer.Logger.Log.Fatal("while the saving process of " + UserDetails.getUserName() + " accord, there was an error -" + e.Message);
     }
 }