Exemple #1
0
        protected void Application_Start(Object sender, EventArgs e)
        {
            Application["ActiveUsers"] = 0;

            HROneSaaSConfig configure = HROneSaaSConfig.GetCurrentConfig();
            //if (perspectivemind.common.DBUtil.type != null)
            //if (dbConn != null)
            //{
            //    HROne.DataAccess.DatabaseConnection.SetDefaultDatabaseConnection(dbConn);
            //    if (!ProductVersion.UpdateDatabaseVersion(true))
            //        Application["NeedDBUpgrade"] = true;
            //    else
            //    {
            //        try
            //        {
            //            WebUtils.ClearTempTable(string.Empty);
            //            //System.Diagnostics.Debug.WriteLine("Clear Upload Claims and Deduction Table...");
            //            //ImportClaimsAndDeductionsProcess.ClearTempTable(string.Empty);
            //            //System.Diagnostics.Debug.WriteLine("Clear Upload Employee Table...");
            //            //ImportEmpPersonalInfoProcess.ClearTempTable(string.Empty);
            //        }
            //        catch
            //        {
            //            System.Diagnostics.Debug.WriteLine("Fail to clear temp table");
            //        }
            //    }
            //}
        }
Exemple #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     config = HROneSaaSConfig.GetCurrentConfig();
     if (!System.IO.File.Exists(config.HROneConfigFullPath))
     {
         Response.Redirect("~/HROneConfiguration.aspx");
     }
 }
Exemple #3
0
    public static DatabaseConnection GetDatabaseConnection()
    {
        HROneSaaSConfig config = HROneSaaSConfig.GetCurrentConfig();

        if (System.IO.File.Exists(config.HROneConfigFullPath))
        {
            HROneConfig HROneConfig = new HROneConfig(config.HROneConfigFullPath);
            return(HROneConfig.GetDatabaseConnection());
        }
        return(null);
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        HROne.CommonLib.RSACrypto rsa = null;
        if (cbxEncryptedDataBy.SelectedValue.Equals("buildin", StringComparison.CurrentCultureIgnoreCase))
        {
            rsa = new HROne.CommonLib.RSACrypto("HROneSaaS");
        }
        //else
        //{
        //    rsa = new HROne.CommonLib.RSACrypto();
        //    rsa.FromXMLString(txtPublicKeyXMLString.Text);
        //}
        string          encryptedString = rsa.Encrypting(txtPasspharse.Text);
        HROneSaaSConfig SaaSconfig      = HROneSaaSConfig.GetCurrentConfig();
        HROneConfig     config          = new HROneConfig(SaaSconfig.HROneConfigFullPath);

        config.databaseEncryptKey = encryptedString;
        config.Save();
    }
    protected void OK_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtPhysiclPath.Text))
        {
            Message.Text      = "Physcal Path cannot be empty";
            Message.ForeColor = System.Drawing.Color.Red;
            return;
        }

        if (System.IO.File.Exists(txtPhysiclPath.Text))
        {
            HROneSaaSConfig config = HROneSaaSConfig.GetCurrentConfig();
            config.HROneConfigFullPath = txtPhysiclPath.Text;
            config.Save();

            Response.Redirect("~/Default.aspx");
        }
        else
        {
            Message.Text      = "File not found: " + txtPhysiclPath.Text;
            Message.ForeColor = System.Drawing.Color.Red;
            return;
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        HROneSaaSConfig SaaSconfig = HROneSaaSConfig.GetCurrentConfig();
        string          HROnePath  = new System.IO.FileInfo(SaaSconfig.HROneConfigFullPath).Directory.FullName;

        ECompanyDatabase c      = new ECompanyDatabase();
        Hashtable        values = new Hashtable();

        binding.toValues(values);

        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();


        db.validate(errors, values);

        if (!errors.isEmpty())
        {
            return;
        }

        db.parse(values, c);

        if (!chkAutoCreateID.Checked && string.IsNullOrEmpty(c.CompanyDBClientCode))
        {
            errors.addError("Client ID is required");
            return;
        }



        HROne.ProductKey key = new HROne.ProductKey();
        key.ProductType    = HROne.ProductKey.ProductLicenseType.HROneSaaS;
        key.NumOfCompanies = Convert.ToUInt16(c.CompanyDBMaxCompany);
        key.NumOfUsers     = Convert.ToUInt16(c.CompanyDBMaxUser);
        if (c.CompanyDBHasIMGR)
        {
            key.IsLeaveManagement = true;
            key.IsPayroll         = true;
            key.IsTaxation        = true;
        }
        if (c.CompanyDBHasIStaff)
        {
            key.IsESS = true;
        }

        if (string.IsNullOrEmpty(c.CompanyDBClientCode))
        {
            const int MAX_LENGTH = 8;
            string    prefix     = CreateClientCodePrefix(c.CompanyDBClientName);
            //if (c.CompanyDBClientBank.Equals("HSBC", StringComparison.CurrentCultureIgnoreCase))
            //    prefix = "H";
            //else if (c.CompanyDBClientBank.Equals("HangSeng", StringComparison.CurrentCultureIgnoreCase))
            //    prefix = "X";
            int idx = 0;
            if (prefix.Length >= MAX_LENGTH)
            {
                prefix = prefix.Substring(0, MAX_LENGTH);
            }
            else
            {
                idx++;
                string idxString = idx.ToString().Trim();
                prefix = prefix.PadRight(MAX_LENGTH - idxString.Length, '0') + idxString;
            }
            c.CompanyDBClientCode = prefix;
            while (!AppUtils.checkDuplicate(dbConn, ECompanyDatabase.db, c, new PageErrors(), "CompanyDBClientCode"))
            {
                idx++;
                string idxString = idx.ToString().Trim();
                c.CompanyDBClientCode = prefix.Substring(0, MAX_LENGTH - idxString.Length) + idxString;
            }
        }
        if (!AppUtils.checkDuplicate(dbConn, ECompanyDatabase.db, c, errors, "CompanyDBClientCode"))
        {
            return;
        }

        EDatabaseServer dbServer = new EDatabaseServer();

        dbServer.DBServerID = c.DBServerID;
        if (EDatabaseServer.db.select(dbConn, dbServer))
        {
            if (dbServer.DBServerDBType.Equals("MSSQL"))
            {
                System.Data.SqlClient.SqlConnectionStringBuilder saConnStringBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();
                saConnStringBuilder.DataSource = dbServer.DBServerLocation;
                saConnStringBuilder.UserID     = dbServer.DBServerSAUserID;
                saConnStringBuilder.Password   = dbServer.DBServerSAPassword;

                DatabaseConfig dbConfig = new DatabaseConfig();
                dbConfig.DBType           = WebUtils.DBTypeEmun.MSSQL;
                dbConfig.ConnectionString = saConnStringBuilder.ConnectionString;
                if (dbConfig.TestServerConnectionWithoutDatabase())
                {
                    string DBSchemaName = c.CompanyDBSchemaName.Trim();
                    if (DBSchemaName.Equals(string.Empty))
                    {
                        DBSchemaName = c.CompanyDBClientCode;
                    }
                    System.Data.SqlClient.SqlConnectionStringBuilder connStringBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();
                    connStringBuilder.DataSource     = dbServer.DBServerLocation;
                    connStringBuilder.InitialCatalog = DBSchemaName;
                    connStringBuilder.UserID         = dbServer.DBServerUserID;
                    connStringBuilder.Password       = dbServer.DBServerPassword;
                    dbConfig.ConnectionString        = connStringBuilder.ConnectionString;
                    if (!dbConfig.TestConnection())
                    {
                        if (chkCreateDB.Checked)
                        {
                            try
                            {
                                HROne.ProductVersion.Database.CreateSchema(saConnStringBuilder.ConnectionString, DBSchemaName, dbServer.DBServerUserID);
                                //c.CompanyDBSchemaName = DBSchemaName;
                                saConnStringBuilder.InitialCatalog = DBSchemaName;
                                HROne.ProductVersion.Database.CreateTableAndData(HROnePath, saConnStringBuilder.ConnectionString);
                                // drop all the connection so that new "normal user" connection to database is accepted
                                System.Data.SqlClient.SqlConnection.ClearAllPools();
                            }
                            catch (Exception ex)
                            {
                                errors.addError(ex.Message);
                                return;
                            }
                        }
                        else
                        {
                            errors.addError("Fail to connect to database");
                            return;
                        }
                    }
                }
                else
                {
                    errors.addError("Fail to connect to server");
                    return;
                }
            }
        }
        if (CurID < 0)
        {
            //            Utils.MarkCreate(Session, c);

            db.insert(dbConn, c);
            CurID = c.CompanyDBID;
            HSBCExchangeProfile_List1.CompanyDBID = CurID;
            //            url = Utils.BuildURL(-1, CurID);
        }
        else
        {
            //            Utils.Mark(Session, c);
        }

        key.SerialNo          = Convert.ToUInt16(c.CompanyDBID);
        c.CompanyDBProductKey = key.GetProductKey();
        db.update(dbConn, c);

        HROne.ProductVersion.Database databaseProcess = new HROne.ProductVersion.Database(new DatabaseConnection(c.getConnectionString(dbConn), DatabaseConnection.DatabaseType.MSSQL), HROnePath);
        databaseProcess.UpdateDatabaseVersion(true);
        errors.addError("Saved");
        loadObject();
        //Response.Redirect("~/CompanyDB_List.aspx");
    }