protected bool loadObject() { ECompanyDatabase obj = new ECompanyDatabase(); obj.CompanyDBID = CurID; if (!db.select(dbConn, obj)) { if (CurID <= 0) { return(false); } else { Response.Redirect("~/AccessDeny.aspx"); } } Hashtable values = new Hashtable(); db.populate(obj, values); binding.toControl(values); return(true); }
protected void Delete_Click(object sender, EventArgs e) { ECompanyDatabase c = new ECompanyDatabase(); c.CompanyDBID = CurID; db.select(dbConn, c); db.delete(dbConn, c); Response.Redirect("~/CompanyDB_List.aspx"); }
protected void ResetPassword_Click(object sender, EventArgs e) { PageErrors errors = PageErrors.getErrors(db, Page.Master); errors.clear(); ECompanyDatabase obj = new ECompanyDatabase(); bool isNew = WebFormWorkers.loadKeys(db, obj, DecryptedRequest); if (db.select(dbConn, obj)) { try { ResetLoginIDPasswordWithRandomKey(obj, true); errors.addError("The UserID/Password is reset to\r\nUserID: " + obj.CompanyDBResetDefaultUserLoginID + "\r\nPassword: " + obj.CompanyDBResetDefaultUserPassword); } catch (Exception ex) { errors.addError(ex.Message); } } }
protected void ResetLoginIDPasswordWithRandomKey(ECompanyDatabase obj, bool skipResetLoginID) { DatabaseConnection companyDBConn; try { companyDBConn = new DatabaseConnection(obj.getConnectionString(dbConn), DatabaseConnection.DatabaseType.MSSQL); } catch (Exception ex) { throw new Exception("Fail to connect to database"); } HROne.Lib.Entities.EUser user = new HROne.Lib.Entities.EUser(); user.UserID = 1; if (HROne.Lib.Entities.EUser.db.select(companyDBConn, user)) { string randomPharse = RandomString(16); if (!skipResetLoginID) { obj.CompanyDBResetDefaultUserLoginID = randomPharse.Substring(0, 8); } else { obj.CompanyDBResetDefaultUserLoginID = user.LoginID; } obj.CompanyDBResetDefaultUserPassword = randomPharse.Substring(8); user.LoginID = obj.CompanyDBResetDefaultUserLoginID; user.UserPassword = HROne.CommonLib.Hash.PasswordHash(obj.CompanyDBResetDefaultUserPassword); user.UserAccountStatus = "A"; user.UserChangePassword = true; user.FailCount = 0; HROne.Lib.Entities.EUser.db.update(companyDBConn, user); DBFilter SystemFunctionFilter = new DBFilter(); SystemFunctionFilter.add(new IN("FunctionCode", "'SEC001', 'SEC002'", null)); ArrayList systemFunctionList = HROne.Lib.Entities.ESystemFunction.db.select(companyDBConn, SystemFunctionFilter); foreach (HROne.Lib.Entities.ESystemFunction function in systemFunctionList) { DBFilter userGroupFunctionFilter = new DBFilter(); userGroupFunctionFilter.add(new Match("FunctionID", function.FunctionID)); userGroupFunctionFilter.add(new Match("FunctionAllowWrite", true)); DBFilter userGroupAccessFilter = new DBFilter(); userGroupAccessFilter.add(new Match("UserID", user.UserID)); userGroupAccessFilter.add(new IN("UserGroupID", "SELECT ugf.UserGroupID FROM " + HROne.Lib.Entities.EUserGroupFunction.db.dbclass.tableName + " ugf", userGroupFunctionFilter)); if (HROne.Lib.Entities.EUserGroupAccess.db.count(companyDBConn, userGroupAccessFilter) <= 0) { ArrayList UserGroupFunctionList = HROne.Lib.Entities.EUserGroupFunction.db.select(companyDBConn, userGroupFunctionFilter); if (UserGroupFunctionList.Count > 0) { HROne.Lib.Entities.EUserGroupAccess access = new HROne.Lib.Entities.EUserGroupAccess(); access.UserID = user.UserID; access.UserGroupID = ((HROne.Lib.Entities.EUserGroupFunction)UserGroupFunctionList[0]).UserGroupID; HROne.Lib.Entities.EUserGroupAccess.db.insert(companyDBConn, access); } } } ECompanyDatabase.db.update(dbConn, obj); } else { throw new Exception("Default User does not appear on company database"); } }
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"); }
public string[] CreateOutput() { string outputPathAMPFF_HSBC = System.IO.Path.Combine(m_FileOutputFolder, "APSMPFI." + m_VendorCode + "." + m_SubmissionCutOffDateTime.ToString("yyyyMMdd") + ".M50"); string outputPathAMPFF_HASE = System.IO.Path.Combine(m_FileOutputFolder, "APSMPFI." + m_VendorCode + "." + m_SubmissionCutOffDateTime.ToString("yyyyMMdd") + ".E50"); string outputPathAMCND_HSBC = System.IO.Path.Combine(m_FileOutputFolder, "APSMPFI." + m_VendorCode + "." + m_SubmissionCutOffDateTime.ToString("yyyyMMdd") + ".M23"); string outputPathAMCND_HASE = System.IO.Path.Combine(m_FileOutputFolder, "APSMPFI." + m_VendorCode + "." + m_SubmissionCutOffDateTime.ToString("yyyyMMdd") + ".E23"); HSBCFileExchangeProcess HSBCAMPFFFileExchange = new HSBCFileExchangeProcess(); HSBCAMPFFFileExchange.FileID = HSBCFileIDEnum.AMPFF; HSBCAMPFFFileExchange.Environment = Environment; HSBCAMPFFFileExchange.CreateWriter(outputPathAMPFF_HSBC); HSBCFileExchangeProcess HangSengAMPFFFileExchange = new HSBCFileExchangeProcess(); HangSengAMPFFFileExchange.FileID = HSBCFileIDEnum.AMPFF; HangSengAMPFFFileExchange.Environment = Environment; HangSengAMPFFFileExchange.CreateWriter(outputPathAMPFF_HASE); HSBCFileExchangeProcess HSBCAMCNDFileExchange = new HSBCFileExchangeProcess(); HSBCAMCNDFileExchange.FileID = HSBCFileIDEnum.AMCND; HSBCAMCNDFileExchange.Environment = Environment; HSBCAMCNDFileExchange.CreateWriter(outputPathAMCND_HSBC); HSBCFileExchangeProcess HangSengAMCNDFileExchange = new HSBCFileExchangeProcess(); HangSengAMCNDFileExchange.FileID = HSBCFileIDEnum.AMCND; HangSengAMCNDFileExchange.Environment = Environment; HangSengAMCNDFileExchange.CreateWriter(outputPathAMCND_HASE); DBFilter filter = new DBFilter(); filter.add(new NullTerm("CompanyMPFFileConsolidateDateTime")); filter.add(new Match("CompanyMPFFileConfirmDateTime", "<=", m_SubmissionCutOffDateTime)); ArrayList list = ECompanyMPFFile.db.select(m_dbConn, filter); foreach (ECompanyMPFFile mpfFile in list) { string transactionRefreence = "HREXM" + mpfFile.CompanyMPFFileID.ToString("0000000000"); transactionRefreence += CheckDigit(transactionRefreence); HSBCFileExchangeProcess currentFileProcess = null; if (mpfFile.CompanyMPFFileFileType.Equals("AMPFF")) { if (mpfFile.CompanyMPFFileTrusteeCode.Equals("HSBC")) { currentFileProcess = HSBCAMPFFFileExchange; } else if (mpfFile.CompanyMPFFileTrusteeCode.Equals("HangSeng")) { currentFileProcess = HangSengAMPFFFileExchange; } EHSBCExchangeProfile exchangeProfile = new EHSBCExchangeProfile(); exchangeProfile.HSBCExchangeProfileID = mpfFile.HSBCExchangeProfileID; EHSBCExchangeProfile.db.select(m_dbConn, exchangeProfile); string[] submissionHeader = new string[6]; submissionHeader[0] = "S"; submissionHeader[1] = exchangeProfile.HSBCExchangeProfileRemoteProfileID.PadRight(18).Substring(0, 18); submissionHeader[2] = string.Empty.PadRight(28); submissionHeader[3] = transactionRefreence.PadRight(16).Substring(0, 16); submissionHeader[4] = " "; submissionHeader[5] = mpfFile.CompanyMPFFileConfirmDateTime.ToString("yyyyMMddHHmmss"); string strSubmissionHeader = string.Join(string.Empty, submissionHeader); if (strSubmissionHeader.Length != currentFileProcess.RecordLength) { throw new Exception("Invalid submission header length"); } currentFileProcess.AddLine(strSubmissionHeader); string currentBankFilePath = System.IO.Path.Combine(m_DefaultBankFilePath, mpfFile.CompanyMPFFileDataFileRelativePath); FileInfo fileInfo = new System.IO.FileInfo(currentBankFilePath); StreamReader bankFileStream = fileInfo.OpenText(); char[] charRead = new char[80]; try { while (bankFileStream.Read(charRead, 0, 80) > 0) { string line = new string(charRead); currentFileProcess.AddLine(line); } } catch (Exception ex) { throw ex; } finally { bankFileStream.Close(); } } else if (mpfFile.CompanyMPFFileFileType.Equals("AMCND")) { if (mpfFile.CompanyMPFFileTrusteeCode.Equals("HSBC")) { currentFileProcess = HSBCAMCNDFileExchange; } else if (mpfFile.CompanyMPFFileTrusteeCode.Equals("HangSeng")) { currentFileProcess = HangSengAMCNDFileExchange; } ECompanyDatabase companyDB = new ECompanyDatabase(); companyDB.CompanyDBID = mpfFile.CompanyDBID; ECompanyDatabase.db.select(m_dbConn, companyDB); //string[] submissionHeader = new string[7]; //submissionHeader[0] = "S"; //submissionHeader[1] = companyDB.CompanyDBClientCode.PadRight(18).Substring(0, 18); //submissionHeader[2] = string.Empty.PadRight(28); //submissionHeader[3] = transactionRefreence.PadRight(16).Substring(0, 16); //submissionHeader[4] = " "; //submissionHeader[5] = mpfFile.CompanyMPFFileConfirmDateTime.ToString("yyyyMMddHHmmss"); //submissionHeader[6] = string.Empty.PadRight(1420); //string strSubmissionHeader = string.Join(string.Empty, submissionHeader); //if (strSubmissionHeader.Length != currentFileProcess.RecordLength) // throw new Exception("Invalid submission header length"); //currentFileProcess.AddLine(strSubmissionHeader); string currentBankFilePath = System.IO.Path.Combine(m_DefaultBankFilePath, mpfFile.CompanyMPFFileDataFileRelativePath); FileInfo fileInfo = new System.IO.FileInfo(currentBankFilePath); StreamReader bankFileStream = fileInfo.OpenText(); try { while (!bankFileStream.EndOfStream) { string line = bankFileStream.ReadLine(); if (!line.StartsWith("HEADER ")) { currentFileProcess.AddLine(line.PadRight(currentFileProcess.RecordLength)); } } } catch (Exception ex) { throw ex; } finally { bankFileStream.Close(); } } if (Environment == HSBCEnvironmentIndicatorEnum.Production) { mpfFile.CompanyMPFFileConsolidateDateTime = AppUtils.ServerDateTime(); mpfFile.CompanyMPFFileTransactionReference = transactionRefreence; ECompanyMPFFile.db.update(m_dbConn, mpfFile); } } HSBCAMPFFFileExchange.Close(); HangSengAMPFFFileExchange.Close(); HSBCAMCNDFileExchange.Close(); HangSengAMCNDFileExchange.Close(); return(new string[] { outputPathAMPFF_HSBC, outputPathAMPFF_HASE, outputPathAMCND_HSBC, outputPathAMCND_HASE }); }