public static bool login(user ExisitingUser, MetroForm ui)
 {
     try
     {
         row = UserDataTable.FindByusername(ExisitingUser.username);
         if (row == null)
         {
             MSG.ERROR(ui, "User Doesn't Exists in the System");
             return(false);
         }
         if ((row.username.ToString() == ExisitingUser.username) && (row.password.ToString() == ExisitingUser.password))
         {
             MSG.SUCCESS(ui, "Login Success.!");
             ui.Hide();
             frm_dashboard n = new frm_dashboard();
             n.ShowDialog();
             ui.Close();
             return(true);
         }
         else
         {
             MSG.ERROR(ui, "Username and Password Doesn't Match!");
             return(false);
         }
     }
     catch (MySql.Data.MySqlClient.MySqlException ex)
     {
         MSG.ERROR(ui, "Login Error.!, " + ex.Message);
         return(false);
     }
 }
        public static void login(MetroForm form)
        {
            try
            {
                usersAdapter.Fill(userTable);
                if ((User.Username == "") || (User.Password == ""))
                {
                    CommonFunctions.ShowError(form, "Please Enter valid username or Password.Fields can not be empty...");
                    CommonFunctions.WriteUserLog("SYSTEM", " Some User Tried to Login with Null username or Password");
                }
                row = userTable.FindByUsername(User.Username);
                if (row == null)
                {
                    //user not exists
                    CommonFunctions.ShowError(form, "User does not Exists.");
                    CommonFunctions.WriteUserLog("SYSTEM", "Failed Login Attemp With Username -> " + User.Username);
                    //return false;
                }

                else if ((row != null) && (User.Password != row.Password))
                {
                    //wrong password

                    CommonFunctions.ShowError(form, "Wrong Password.Please Check and Re enter...");
                    CommonFunctions.WriteUserLog("SYSTEM", User.Username + " Tried to Login with Wrong Password");

                    //return false;
                }
                else if ((User.Username == row.Username) && (row.Password == User.Password) && (row.IsActive == 0))
                {
                    //Disabled User

                    CommonFunctions.ShowError(form, "This User can not Login in to the System. Access Denied...");
                    CommonFunctions.WriteUserLog("SYSTEM", "A Disabled User Tried to Login > " + User.Username);

                    //return false;
                }

                else if ((User.Username == row.Username) && (row.Password == User.Password))
                {
                    //login success
                    CommonFunctions.ShowSuccess(form, "Login Successfully...");
                    Session.Username             = row.Username;
                    Session.BranchId             = row.BranchId;
                    Brow                         = branchTable.FindById(row.BranchId);
                    Session.BranchMasterPassword = Brow.MasterPassword;
                    Session.BranchName           = Brow.BranchName;
                    CommonFunctions.WriteUserLog("SYSTEM", User.Username + " is Log into the System");

                    new UI_DASHBOARD(form).Show();
                    form.Hide();
                    form.ShowInTaskbar = false;


                    //return true;
                }
            }
            catch (Exception ex)
            {
                //show some error and log the original error!
                CommonFunctions.ShowError(form, ex.ToString());
                CommonFunctions.WriteToErrorLog(ex.Message.ToString());
                //return false;
            }
        }