protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["CompanyDBID"] == null)
        {
            FileType.Items.FindByValue("D").Enabled = false;
            FileType.Items.FindByValue("E").Enabled = true;
            FileTypeRow.Visible = false;
        }
        else
        {
            if (Application["MasterDBConfig"] != null && Session["CompanyDBID"] != null)
            {
                int CurID = (int)Session["CompanyDBID"];

                HROne.DataAccess.DatabaseConnection masterDBConn = ((DatabaseConfig)Application["MasterDBConfig"]).CreateDatabaseConnectionObject();
                string CommandLineFolder = HROne.SaaS.Entities.ESystemParameter.getParameter(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_HSBC_MRI_DIRECTORY);
                if (string.IsNullOrEmpty(CommandLineFolder))
                {
                    FileType.Items.FindByValue("D").Enabled = false;
                }
                HROne.HSBC.Utility.HSBCMRICommandLineDirectory = CommandLineFolder;
            }
        }
        //HROne.ProductLicense productLicense = WebUtils.productLicense(Session);
        //if (productLicense.ProductType != HROne.ProductLicense.ProductLicenseType.HROneSaaS)
        //{
        //}
    }
    protected void FileType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (FileType.SelectedValue.Equals("D"))
        {
            RemoteProfileID.Visible = true;

            PaymentMethodRow.Visible = false;
            if (Application["MasterDBConfig"] != null && Session["CompanyDBID"] != null)
            {
                int CurID = (int)Session["CompanyDBID"];

                HROne.DataAccess.DatabaseConnection masterDBConn = ((DatabaseConfig)Application["MasterDBConfig"]).CreateDatabaseConnectionObject();
                DBFilter filter = new DBFilter();
                filter.add(new Match("CompanyDBID", (int)Session["CompanyDBID"]));
                filter.add(new Match("HSBCExchangeProfileIsLocked", false));
                ArrayList exchangeProfileList = HROne.SaaS.Entities.EHSBCExchangeProfile.db.select(masterDBConn, filter);
                if (exchangeProfileList.Count > 0)
                {
                    foreach (HROne.SaaS.Entities.EHSBCExchangeProfile exchangeProfile in exchangeProfileList)
                    {
                        if (exchangeProfile.HSBCExchangeProfileBankCode.Equals(BankCode, StringComparison.CurrentCultureIgnoreCase))
                        {
                            txtRemoteProfileID.Text = exchangeProfile.HSBCExchangeProfileRemoteProfileID;
                            RemoteProfileID.Visible = false;
                        }
                    }
                    if (RemoteProfileID.Visible)
                    {
                        txtRemoteProfileID.Text = ((HROne.SaaS.Entities.EHSBCExchangeProfile)exchangeProfileList[0]).HSBCExchangeProfileRemoteProfileID;
                        RemoteProfileID.Visible = false;
                    }
                }
                HROne.HSBC.Utility.HSBCMRICommandLineDirectory = HROne.SaaS.Entities.ESystemParameter.getParameter(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_HSBC_MRI_DIRECTORY);
                //HROne.SaaS.Entities.ECompanyDatabase companyDB = new HROne.SaaS.Entities.ECompanyDatabase();
                //companyDB.CompanyDBID = CurID;
                //if (HROne.SaaS.Entities.ECompanyDatabase.db.select(masterDBConn, companyDB))
                //{
                //    txtRemoteProfileID.Text = companyDB.CompanyDBClientCode;
                //    HROne.HSBC.Utility.HSBCMRICommandLineDirectory = HROne.SaaS.Entities.ESystemParameter.getParameter(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_HSBC_MRI_DIRECTORY);
                //    RemoteProfileID.Visible = false;
                //}
            }
        }
        else
        {
            RemoteProfileID.Visible = false;
            if (FileType.SelectedValue.Equals("AMCND"))
            {
                PaymentMethodRow.Visible = true;
            }
            else
            {
                PaymentMethodRow.Visible = false;
            }
        }
    }
Beispiel #3
0
    protected void Login_Click(object sender, EventArgs e)
    {
        EESSUser user = null;

        Session.Clear();

        HROne.DataAccess.DatabaseConnection  mainDBConn = null;
        HROne.SaaS.Entities.ECompanyDatabase companyDB  = null;
        bool   hasError = false;
        string message  = string.Empty;

        // always check whether companyDB exists after click
        if (Application["MasterDBConfig"] != null)
        {
            DatabaseConfig masterDBConfig = (DatabaseConfig)Application["MasterDBConfig"];
            HROne.DataAccess.DatabaseConnection masterDBConn = masterDBConfig.CreateDatabaseConnectionObject();
            DBFilter companyDatabaseFilter = new DBFilter();
            companyDatabaseFilter.add(new Match("CompanyDBClientCode", txtCustomerID.Text));
            ArrayList companyDatabaseList = HROne.SaaS.Entities.ECompanyDatabase.db.select(masterDBConn, companyDatabaseFilter);
            if (companyDatabaseList.Count > 0)
            {
                companyDB = (HROne.SaaS.Entities.ECompanyDatabase)companyDatabaseList[0];

                DatabaseConfig tempDBConfig = new DatabaseConfig();
                tempDBConfig.ConnectionString = companyDB.getConnectionString(masterDBConn);
                tempDBConfig.DBType           = WebUtils.DBTypeEmun.MSSQL;

                if (tempDBConfig.TestConnection())
                {
                    mainDBConn = tempDBConfig.CreateDatabaseConnectionObject();

                    HROne.Lib.Entities.ESystemParameter.setParameter(mainDBConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_PRODUCTKEY, companyDB.CompanyDBProductKey);
                    HROne.Lib.Entities.ESystemParameter.setParameter(mainDBConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_PRODUCTFEATURECODE, companyDB.getProductFeatureCode(masterDBConn));

                    string[] smtpParameterList = new string[]
                    {
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_SERVER_NAME,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_PORT,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_USERNAME,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_ENABLE_SSL,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_SMTP_OUTGOING_EMAIL_ADDRESS
                    };
                    foreach (string smptParameter in smtpParameterList)
                    {
                        HROne.Lib.Entities.ESystemParameter.setParameter(mainDBConn, smptParameter, ESystemParameter.getParameter(masterDBConn, smptParameter));
                    }
                    HROne.Lib.Entities.ESystemParameter.setParameterWithEncryption(mainDBConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_PASSWORD
                                                                                   , HROne.SaaS.Entities.ESystemParameter.getParameterWithEncryption(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_SMTP_PASSWORD));
                }
                else
                {
                    if (HROne.DataAccess.DBAESEncryptStringFieldAttribute.InvalidRSAKey)
                    {
                        HttpRuntime.UnloadAppDomain();
                    }
                }
            }
        }
        else
        {
            mainDBConn = WebUtils.GetDatabaseConnection();
            if (mainDBConn == null)
            {
                if (multiDBRow.Visible)
                {
                    int idx;
                    if (int.TryParse(cboDatabase.SelectedValue, out idx))
                    {
                        HROneConfig    config   = HROneConfig.GetCurrentHROneConfig();
                        DatabaseConfig dbconfig = config.DatabaseConfigList[idx];
                        if (dbconfig.TestConnection())
                        {
                            mainDBConn = dbconfig.CreateDatabaseConnectionObject();
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "errorMessage", "alert(\"Fail to connect database\");", true);
                            return;
                        }
                    }
                }
            }
        }
        if (mainDBConn != null)
        {
            WebUtils.SetSessionDatabaseConnection(Session, mainDBConn);
        }

        HROne.ProductLicense productLicense = WebUtils.productLicense(Session);
        if (productLicense != null)
        {
            if (companyDB == null && productLicense.ProductType == HROne.ProductLicense.ProductLicenseType.HROneSaaS)
            {
                productLicense.LoadProductKey(string.Empty);
            }
        }

        if (mainDBConn == null && companyDB != null)
        {
            hasError = true;
            message  = "Fail to connect to database. Please contact to customer service.";
        }
        if (!hasError)
        {
            bool ChangePassword = false;
            try
            {
                WebUtils.ValidateUser(mainDBConn, Username.Text, HROne.CommonLib.Hash.PasswordHash(Password.Text), true, out ChangePassword, out user);
            }
            catch (Exception ex)
            {
                hasError = true;
                message  = ex.Message;
            }
            // copy from GAP customization, checking Active Directory ID
            if (user != null)
            {
                DBFilter ADIDFilter = new DBFilter();
                ADIDFilter.add(new Match("EmpExtraFieldName", "AD ID"));
                DBFilter ADIDValueFilter = new DBFilter();
                ADIDValueFilter.add(new IN("EmpExtraFieldID", "Select EmpExtraFieldID from " + EEmpExtraField.db.dbclass.tableName, ADIDFilter));
                ADIDValueFilter.add(new Match("EmpID", user.EmpID));

                ArrayList ADIDList = EEmpExtraFieldValue.db.select(dbConn, ADIDValueFilter);
                if (ADIDList.Count > 0)
                {
                    string remoteUser = Request.ServerVariables["REMOTE_USER"].Trim();
                    string ADID       = ((EEmpExtraFieldValue)ADIDList[0]).EmpExtraFieldValue.Trim();

                    if (!remoteUser.Equals(ADID, StringComparison.CurrentCultureIgnoreCase) && !remoteUser.EndsWith("\\" + ADID, StringComparison.CurrentCultureIgnoreCase) && !remoteUser.EndsWith("/" + ADID, StringComparison.CurrentCultureIgnoreCase))
                    {
                        hasError = true;
                        message  = "This PC is not logged with your network ID!";
                    }
                }
            }
            if (companyDB != null && !hasError)
            {
                if (!companyDB.CompanyDBIsActive)
                {
                    hasError = true;
                    message  = "Subscribed service has been expired; please contact customer service hotline for assistant.";
                }
                if (!productLicense.IsESS)
                {
                    hasError = true;
                    message  = "You are NOT subscribed the service.";
                }
            }

            if (!hasError)
            {
                HROne.Lib.Entities.EESSLoginAudit.CreateLoginAudit(mainDBConn, user.EmpID, Username.Text, Request, AppUtils.ServerDateTime(), false, string.Empty);

                // ADD the Session "User" Value is user
                Session["User"] = user;

                if (ChangePassword)
                {
                    Session.Add("ForceChangePassword", true);
                }
                WebUtils.SetSessionLanguage(Session, user);
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/Default.aspx?LastURL=" + DecryptedRequest["LastURL"]);
            }
        }
        //  Remove all item for release session
        Session.Clear();
        Request.Cookies.Remove(HROne.Common.WebUtility.getDefaultSessionCookieName());
        //if (companyDB != null)
        //{
        //    Session.Remove("DatabaseConnection");
        //}
        {
            if (user != null)
            {
                HROne.Lib.Entities.EESSLoginAudit.CreateLoginAudit(mainDBConn, user.EmpID, Username.Text, Request, AppUtils.ServerDateTime(), true, message);
            }
            else
            {
                HROne.Lib.Entities.EESSLoginAudit.CreateLoginAudit(mainDBConn, 0, Username.Text, Request, AppUtils.ServerDateTime(), true, message);
            }

            //message = message.Replace("\\", "\\\\").Replace("\r", "\\r").Replace("\n", "\\n").Replace("\"", "\\\"");
            //message = message.Replace(HROne.Common.WebUtility.GetLocalizedString("validate.prompt"), "");
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "errorMessage", "alert(\"" + message + "\");", true);
            Prompt.Text = message;
            System.Threading.Thread.Sleep(1000);
        }
    }
Beispiel #4
0
 public int buildSQL(DatabaseConnection dbConn, int index, StringBuilder b)
 {
     b.Append(fieldName1).Append(op).Append(fieldName2);
     return(index);
 }
Beispiel #5
0
    //public bool ValidateUser(string username, string encryptedPassword)
    //{
    //    string message = string.Empty;
    //    DBFilter filter = new DBFilter();
    //    filter.add(new Match("LoginID", username));
    //    filter.add(new Match("UserAccountStatus", "<>", "D"));
    //    ArrayList list = EUser.db.select(dbConn, filter);
    //    if (list.Count == 0)
    //    {
    //        message = "Invalid User Name or Password";
    //        throw new Exception(message);
    //        return;
    //    }
    //    EUser user = (EUser)list[0];
    //    if (user.UserPassword == null)
    //        user.UserPassword = "";
    //    if (!(user.UserAccountStatus == "A"))
    //    {
    //        message = "Account is Inactive/Locked";
    //        throw new Exception(message);
    //        return;
    //    }

    //    if (!user.UserPassword.Equals(encryptedPassword))
    //    {
    //        message = "Invalid User Name or Password";
    //        user.FailCount++;
    //        string maxFailCountParameterString = ESystemParameter.getParameter(ESystemParameter.PARAM_CODE_LOGIN_MAX_FAIL_COUNT);
    //        if (!maxFailCountParameterString.Equals(string.Empty))
    //        {
    //            int MaxFailCount = 0;
    //            if (int.TryParse(maxFailCountParameterString, out MaxFailCount))
    //                if (MaxFailCount > 0)
    //                    if (user.FailCount >= MaxFailCount)
    //                    {
    //                        user.UserAccountStatus = "I";
    //                        user.FailCount = 0;
    //                    }
    //                    else if (user.FailCount - MaxFailCount == 1)
    //                    {
    //                        message += "\r\n" + "The account will be locked if you fail to login 1 more time";
    //                    }

    //        }
    //        EUser.db.update(dbConn, user);
    //        throw new Exception(message);
    //        return;
    //    }

    //    Session["User"] = user;

    //    WebUtils.SetSessionLanguage(Session, user);

    //    user.FailCount = 0;
    //    EUser.db.update(dbConn, user);
    //    //WebUtils.RefreshPermission(Session);
    //    bool isForceChangePassword = false;

    //    if (user.UserChangePasswordUnit == "D")
    //    {
    //        if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddDays(user.UserChangePasswordPeriod))
    //            isForceChangePassword = false;
    //        else
    //            isForceChangePassword = true;
    //    }
    //    else if (user.UserChangePasswordUnit == "M")
    //    {
    //        if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddMonths(user.UserChangePasswordPeriod))
    //            isForceChangePassword = false;
    //        else
    //            isForceChangePassword = true;
    //    }
    //    else if (user.UserChangePasswordUnit == "Y")
    //    {
    //        if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddYears(user.UserChangePasswordPeriod))
    //            isForceChangePassword = false;
    //        else
    //            isForceChangePassword = true;
    //    }
    //    else
    //        isForceChangePassword = false;
    //    if (user.UserChangePassword)
    //        isForceChangePassword = true;

    //    //EInbox.GenerateInboxMessage(user.UserID);
    //    if (isForceChangePassword)
    //        Session["ForceChangePassword"] = true;
    //    if (Session["LastURL"] != null)
    //        Response.Redirect(Session["LastURL"].ToString());
    //    else
    //        HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "Emp_List.aspx");

    //}

    protected void Login_Click(object sender, EventArgs e)
    {
        HROne.Lib.Entities.EUser user = null;

        Session.Clear();

        HROne.DataAccess.DatabaseConnection  mainDBConn = null;
        HROne.SaaS.Entities.ECompanyDatabase companyDB  = null;
        bool   hasError = false;
        string message  = string.Empty;

        // always check whether companyDB exists after click
        if (Application["MasterDBConfig"] != null)
        {
            DatabaseConfig masterDBConfig = (DatabaseConfig)Application["MasterDBConfig"];
            HROne.DataAccess.DatabaseConnection masterDBConn = masterDBConfig.CreateDatabaseConnectionObject();
            DBFilter companyDatabaseFilter = new DBFilter();
            companyDatabaseFilter.add(new Match("CompanyDBClientCode", txtCustomerID.Text));
            ArrayList companyDatabaseList = HROne.SaaS.Entities.ECompanyDatabase.db.select(masterDBConn, companyDatabaseFilter);
            if (companyDatabaseList.Count > 0)
            {
                companyDB = (HROne.SaaS.Entities.ECompanyDatabase)companyDatabaseList[0];

                DatabaseConfig tempDBConfig = new DatabaseConfig();
                tempDBConfig.ConnectionString = companyDB.getConnectionString(masterDBConn);
                tempDBConfig.DBType           = WebUtils.DBTypeEmun.MSSQL;

                if (tempDBConfig.TestConnection())
                {
                    mainDBConn = tempDBConfig.CreateDatabaseConnectionObject();

                    HROne.Lib.Entities.ESystemParameter.setParameter(mainDBConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_PRODUCTKEY, companyDB.CompanyDBProductKey);
                    HROne.Lib.Entities.ESystemParameter.setParameter(mainDBConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_PRODUCTFEATURECODE, companyDB.getProductFeatureCode(masterDBConn));

                    string[] smtpParameterList = new string[]
                    {
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_SERVER_NAME,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_PORT,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_USERNAME,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_ENABLE_SSL,
                        HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_SMTP_OUTGOING_EMAIL_ADDRESS
                    };
                    foreach (string smptParameter in smtpParameterList)
                    {
                        HROne.Lib.Entities.ESystemParameter.setParameter(mainDBConn, smptParameter, HROne.SaaS.Entities.ESystemParameter.getParameter(masterDBConn, smptParameter));
                    }
                    HROne.Lib.Entities.ESystemParameter.setParameterWithEncryption(mainDBConn, HROne.Lib.Entities.ESystemParameter.PARAM_CODE_SMTP_PASSWORD
                                                                                   , HROne.SaaS.Entities.ESystemParameter.getParameterWithEncryption(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_SMTP_PASSWORD));
                }
                else
                {
                    if (HROne.DataAccess.DBAESEncryptStringFieldAttribute.InvalidRSAKey)
                    {
                        HttpRuntime.UnloadAppDomain();
                    }
                }
            }
        }
        else
        {
            mainDBConn = WebUtils.GetDatabaseConnection();
            if (mainDBConn == null)
            {
                if (multiDBRow.Visible)
                {
                    int idx;
                    if (int.TryParse(cboDatabase.SelectedValue, out idx))
                    {
                        HROneConfig    config   = HROneConfig.GetCurrentHROneConfig();
                        DatabaseConfig dbconfig = config.DatabaseConfigList[idx];
                        if (dbconfig.TestConnection())
                        {
                            mainDBConn = dbconfig.CreateDatabaseConnectionObject();
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "errorMessage", "alert(\"Fail to connect database\");", true);
                            return;
                        }
                    }
                }
            }
        }
        if (mainDBConn != null)
        {
            WebUtils.SetSessionDatabaseConnection(Session, mainDBConn);
        }

        HROne.ProductLicense productLicense = WebUtils.productLicense(Session);
        if (productLicense != null)
        {
            if (companyDB == null && productLicense.ProductType == HROne.ProductLicense.ProductLicenseType.HROneSaaS)
            {
                productLicense.LoadProductKey(string.Empty);
            }
        }

        if (mainDBConn == null && companyDB != null)
        {
            hasError = true;
            message  = "Fail to connect to database. Please contact to customer service.";
        }
        if (!hasError)
        {
            try
            {
                WebUtils.ValidateUser(mainDBConn, Username.Text, HROne.CommonLib.Hash.PasswordHash(Password.Text), true, true, out user);
            }
            catch (Exception ex)
            {
                hasError = true;
                message  = ex.Message;
            }
            // Check the database status after login is verified
            if (companyDB != null && !hasError)
            {
                if (!companyDB.CompanyDBIsActive)
                {
                    hasError = true;
                    message  = "Subscribed service has been expired; please contact customer service hotline for assistant.";
                }
            }

            if (!hasError)
            {
                //  Create Login Audit for successfully login
                HROne.Lib.Entities.ELoginAudit.CreateLoginAudit(mainDBConn, user.UserID, Username.Text, Request, AppUtils.ServerDateTime(), false, string.Empty);
                Session["LoginID"]           = user.LoginID;
                Session["PasswordEncrypted"] = user.UserPassword;
                if (companyDB != null)
                {
                    Session["CompanyDBID"] = companyDB.CompanyDBID;
                }

                if (mainDBConn is HROne.DataAccess.DatabaseConnectionWithAudit)
                {
                    ((HROne.DataAccess.DatabaseConnectionWithAudit)mainDBConn).UserID = user.UserID;
                }
                WebUtils.SetSessionLanguage(Session, user);

                //WebUtils.RefreshPermission(Session);
                bool isForceChangePassword = false;

                if (user.UserChangePasswordUnit == "D")
                {
                    if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddDays(user.UserChangePasswordPeriod))
                    {
                        isForceChangePassword = false;
                    }
                    else
                    {
                        isForceChangePassword = true;
                    }
                }
                else if (user.UserChangePasswordUnit == "M")
                {
                    if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddMonths(user.UserChangePasswordPeriod))
                    {
                        isForceChangePassword = false;
                    }
                    else
                    {
                        isForceChangePassword = true;
                    }
                }
                else if (user.UserChangePasswordUnit == "Y")
                {
                    if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddYears(user.UserChangePasswordPeriod))
                    {
                        isForceChangePassword = false;
                    }
                    else
                    {
                        isForceChangePassword = true;
                    }
                }
                else
                {
                    isForceChangePassword = false;
                }
                if (user.UserChangePassword)
                {
                    isForceChangePassword = true;
                }

                //EInbox.GenerateInboxMessage(user.UserID);
                if (isForceChangePassword)
                {
                    Session["ForceChangePassword"] = true;
                }

                WebUtils.SetSessionLanguage(Session, WebUtils.GetCurUser(Session));
                //RegenerateSessionId();
                HROne.Lib.Entities.EInbox.DeleteAllDeletedUserID(mainDBConn);
                HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "~/Default.aspx?LastURL=" + DecryptedRequest["LastURL"]);
            }
        }
        //  Remove all item for release session
        Session.Clear();
        Request.Cookies.Remove(HROne.Common.WebUtility.getDefaultSessionCookieName());
        //if (companyDB != null)
        //{
        //    Session.Remove("DatabaseConnection");
        //}
        {
            //  Create Login Audit for fail login
            if (user != null)
            {
                HROne.Lib.Entities.ELoginAudit.CreateLoginAudit(mainDBConn, user.UserID, Username.Text, Request, AppUtils.ServerDateTime(), true, message);
            }
            else
            {
                HROne.Lib.Entities.ELoginAudit.CreateLoginAudit(mainDBConn, 0, Username.Text, Request, AppUtils.ServerDateTime(), true, message);
            }

            message = message.Replace("\\", "\\\\").Replace("\r", "\\r").Replace("\n", "\\n").Replace("\"", "\\\"");
            message = message.Replace(HROne.Common.WebUtility.GetLocalizedString("validate.prompt"), "");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "errorMessage", "alert(\"" + message + "\");", true);
            System.Threading.Thread.Sleep(1000);
        }
    }
Beispiel #6
0
 public SearchBinding(DatabaseConnection DBConn, DBManager db)
 {
     this.DBConn = DBConn;
     this.db     = db;
 }
Beispiel #7
0
    //public bool ValidateUser(string username, string encryptedPassword)
    //{
    //    string message = string.Empty;
    //    DBFilter filter = new DBFilter();
    //    filter.add(new Match("LoginID", username));
    //    filter.add(new Match("UserAccountStatus", "<>", "D"));
    //    ArrayList list = EUser.db.select(dbConn, filter);
    //    if (list.Count == 0)
    //    {
    //        message = "Invalid User Name or Password";
    //        throw new Exception(message);
    //        return;
    //    }
    //    EUser user = (EUser)list[0];
    //    if (user.UserPassword == null)
    //        user.UserPassword = "";
    //    if (!(user.UserAccountStatus == "A"))
    //    {
    //        message = "Account is Inactive/Locked";
    //        throw new Exception(message);
    //        return;
    //    }

    //    if (!user.UserPassword.Equals(encryptedPassword))
    //    {
    //        message = "Invalid User Name or Password";
    //        user.FailCount++;
    //        string maxFailCountParameterString = ESystemParameter.getParameter(ESystemParameter.PARAM_CODE_LOGIN_MAX_FAIL_COUNT);
    //        if (!maxFailCountParameterString.Equals(string.Empty))
    //        {
    //            int MaxFailCount = 0;
    //            if (int.TryParse(maxFailCountParameterString, out MaxFailCount))
    //                if (MaxFailCount > 0)
    //                    if (user.FailCount >= MaxFailCount)
    //                    {
    //                        user.UserAccountStatus = "I";
    //                        user.FailCount = 0;
    //                    }
    //                    else if (user.FailCount - MaxFailCount == 1)
    //                    {
    //                        message += "\r\n" + "The account will be locked if you fail to login 1 more time";
    //                    }

    //        }
    //        EUser.db.update(dbConn, user);
    //        throw new Exception(message);
    //        return;
    //    }

    //    Session["User"] = user;

    //    WebUtils.SetSessionLanguage(Session, user);

    //    user.FailCount = 0;
    //    EUser.db.update(dbConn, user);
    //    //WebUtils.RefreshPermission(Session);
    //    bool isForceChangePassword = false;

    //    if (user.UserChangePasswordUnit == "D")
    //    {
    //        if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddDays(user.UserChangePasswordPeriod))
    //            isForceChangePassword = false;
    //        else
    //            isForceChangePassword = true;
    //    }
    //    else if (user.UserChangePasswordUnit == "M")
    //    {
    //        if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddMonths(user.UserChangePasswordPeriod))
    //            isForceChangePassword = false;
    //        else
    //            isForceChangePassword = true;
    //    }
    //    else if (user.UserChangePasswordUnit == "Y")
    //    {
    //        if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddYears(user.UserChangePasswordPeriod))
    //            isForceChangePassword = false;
    //        else
    //            isForceChangePassword = true;
    //    }
    //    else
    //        isForceChangePassword = false;
    //    if (user.UserChangePassword)
    //        isForceChangePassword = true;

    //    //EInbox.GenerateInboxMessage(user.UserID);
    //    if (isForceChangePassword)
    //        Session["ForceChangePassword"] = true;
    //    if (Session["LastURL"] != null)
    //        Response.Redirect(Session["LastURL"].ToString());
    //    else
    //        Response.Redirect("Emp_List.aspx");

    //}

    protected void Login_Click(object sender, EventArgs e)
    {
        Session.Clear();

        //  re-assign the connection
        HROne.DataAccess.DatabaseConnection mainDBConn = WebUtils.GetDatabaseConnection();
        if (mainDBConn != null)
        {
            WebUtils.SetSessionDatabaseConnection(Session, mainDBConn);
        }

        HROne.SaaS.Entities.EUser user = null;
        string message  = string.Empty;
        bool   hasError = false;

        try
        {
            WebUtils.ValidateUser(mainDBConn, Username.Text, HROne.CommonLib.Hash.PasswordHash(Password.Text), true, true, out user);
        }
        catch (Exception ex)
        {
            hasError = true;
            message  = ex.Message;
        }
        if (!hasError)
        {
            Session["LoginID"]           = user.LoginID;
            Session["PasswordEncrypted"] = user.UserPassword;
            if (mainDBConn is HROne.DataAccess.DatabaseConnectionWithAudit)
            {
                ((HROne.DataAccess.DatabaseConnectionWithAudit)mainDBConn).UserID = user.UserID;
            }

            //WebUtils.RefreshPermission(Session);
            bool isForceChangePassword = false;

            if (user.UserChangePasswordUnit == "D")
            {
                if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddDays(user.UserChangePasswordPeriod))
                {
                    isForceChangePassword = false;
                }
                else
                {
                    isForceChangePassword = true;
                }
            }
            else if (user.UserChangePasswordUnit == "M")
            {
                if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddMonths(user.UserChangePasswordPeriod))
                {
                    isForceChangePassword = false;
                }
                else
                {
                    isForceChangePassword = true;
                }
            }
            else if (user.UserChangePasswordUnit == "Y")
            {
                if (AppUtils.ServerDateTime() < user.UserChangePasswordDate.AddYears(user.UserChangePasswordPeriod))
                {
                    isForceChangePassword = false;
                }
                else
                {
                    isForceChangePassword = true;
                }
            }
            else
            {
                isForceChangePassword = false;
            }
            if (user.UserChangePassword)
            {
                isForceChangePassword = true;
            }

            //EInbox.GenerateInboxMessage(user.UserID);
            if (isForceChangePassword)
            {
                Session["ForceChangePassword"] = true;
            }

            Response.Redirect("~/Default.aspx");
        }
        //  Remove all item for release session
        Session.Clear();
        Request.Cookies.Remove(HROne.Common.WebUtility.getDefaultSessionCookieName());

        {
            message = message.Replace("\\", "\\\\").Replace("\r", "\\r").Replace("\n", "\\n").Replace("\"", "\\\"");
            message = message.Replace(HROne.Common.WebUtility.GetLocalizedString("validate.prompt"), "");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "errorMessage", "alert(\"" + message + "\");", true);
            System.Threading.Thread.Sleep(1000);
        }
    }
Beispiel #8
0
        public void loadData(DatabaseConnection DBConn, DataSet ds, string tableName, ListInfo info, string select, string from, string distinct)
        {
            StringBuilder s = new StringBuilder();

            s.Append("SELECT ");
            if (!string.IsNullOrEmpty(distinct))
            {
                s.Append("DISTINCT ");
            }
            s.Append(select).Append(" ");
            s.Append(from).Append(" ");
            //s.Append(getWhereClause());
            //s.Append(getGroupCluase());
            //s.Append(getOrderClause(info));



            DbCommand     command = DBConn.CreateSelectCommand(s.ToString(), this, info);
            DbDataAdapter adapter = DBConn.CreateAdapter();

            adapter.SelectCommand = command;
            try
            {
                //conn.Open();


                if (info != null)
                {
                    StringBuilder cs = new StringBuilder();
                    cs.Append("SELECT ");
                    if (!string.IsNullOrEmpty(distinct))
                    {
                        cs.Append("COUNT(DISTINCT ").Append(distinct).Append(") ");
                    }
                    else
                    {
                        cs.Append("COUNT(*) ");
                    }
                    cs.Append(from);
                    cs.Append(getWhereClause(DBConn));
                    //cs.Append(getGroupCluase());
                    DbCommand ccommand = DBConn.CreateCommand();
                    ccommand.CommandText = cs.ToString();
                    setParams(ccommand);
                    info.numRecord = Convert.ToInt32(DBConn.ExecuteScalar(ccommand));

                    if (info.recordPerPage > 0)
                    {
                        info.numPage = (int)Math.Ceiling((double)info.numRecord / info.recordPerPage);
                        if (info.page >= info.numPage)
                        {
                            info.page = info.numPage - 1;
                        }
                        if (info.page < 0)
                        {
                            info.page = 0;
                        }
                        int rowIndex = info.page * info.recordPerPage;
                        adapter.Fill(ds, rowIndex, info.recordPerPage, "table");
                    }
                    else
                    {
                        info.numPage = 1;
                        info.page    = 0;
                        adapter.Fill(ds, tableName);
                    }
                }
                else
                {
                    adapter.Fill(ds, tableName);
                }
                //DataTable table=ds.Tables["table"];
                //ds.Tables.Clear();
                //return table;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString() + "\r\n" + select + from);
            }
            finally
            {
                adapter.Dispose();
                //conn.Close();
                //conn.Dispose();
            }
        }
Beispiel #9
0
        public DataTable loadData(DatabaseConnection DBConn, string SelectQuery)
        {
            DataSet ds = new DataSet();

            return(DBConn.ExecuteToDataTable(DBConn.CreateSelectCommand(SelectQuery, this)));
        }
Beispiel #10
0
 public DataTable loadData(DatabaseConnection DBConn, ListInfo info, string select, string from)
 {
     return(loadData(DBConn, info, select, from, null));
 }
Beispiel #11
0
        public string getWhereClause(DatabaseConnection dbConn, bool first)
        {
            int out_index;

            return(getWhereClause(dbConn, first, 0, out out_index));
        }
Beispiel #12
0
 public string getWhereClause(DatabaseConnection dbConn)
 {
     return(getWhereClause(dbConn, false));
 }