コード例 #1
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        ArrayList empList = new ArrayList();

        foreach (RepeaterItem i in empRepeater.Items)
        {
            CheckBox cb = (CheckBox)i.FindControl("ItemSelect");
            if (cb.Checked)
            {
                EEmpPersonalInfo o = (EEmpPersonalInfo)EEmpPersonalInfo.db.createObject();
                WebFormUtils.GetKeys(EEmpPersonalInfo.db, o, cb);
                empList.Add(o);
            }
        }


        string   strEmpList          = string.Empty;
        string   strPayBatchList     = string.Empty;
        string   strPayPeriodRequest = string.Empty;
        DateTime dtPayPeriodFr       = new DateTime();
        DateTime dtPayPeriodTo       = new DateTime();

        if (empList.Count > 0)
        {
            foreach (EEmpPersonalInfo o in empList)
            {
                if (strEmpList == string.Empty)
                {
                    strEmpList = ((EEmpPersonalInfo)o).EmpID.ToString();
                }
                else
                {
                    strEmpList += "_" + ((EEmpPersonalInfo)o).EmpID.ToString();
                }
            }
            if (DateTime.TryParse(PayPeriodFr.Value, out dtPayPeriodFr) && DateTime.TryParse(PayPeriodTo.Value, out dtPayPeriodTo))
            {
                strPayPeriodRequest = "&PayPeriodFr=" + dtPayPeriodFr.Ticks + "&PayPeriodTo=" + dtPayPeriodTo.Ticks;
            }
            else
            {
                errors.addError("Invalid Date Format");
            }


            //            errors.addError("Complete");
            //Response.Write("<script>alert('Completed'); </script>");
        }
        else
        {
            errors.addError("Employee or Payroll Batch not selected");
        }

        if (errors.isEmpty())
        {
            GenericMPFFile mpfFileProcess = getMPFFileObject();
            if (mpfFileProcess == null)
            {
                errors.addError("Generate MPF File is not available for that MPF Scheme");
                return;
            }
            if (mpfFileProcess is HSBCMPFGatewayFileEncrypted)
            {
                string keyFolderPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BankKey");

                string keyPath             = string.Empty;
                string HSBCKeyFileName     = "HSBC.pub";
                string HangSengKeyFileName = "HASE.pub";
                string password            = "******";

                int intMPFPlanID = 0;

                if (int.TryParse(MPFPlanID.SelectedValue, out intMPFPlanID))
                {
                    EMPFPlan mpfPlan = new EMPFPlan();
                    mpfPlan.MPFPlanID = intMPFPlanID;
                    if (EMPFPlan.db.select(dbConn, mpfPlan))
                    {
                        EMPFScheme mpfScheme = new EMPFScheme();
                        mpfScheme.MPFSchemeID = mpfPlan.MPFSchemeID;
                        if (EMPFScheme.db.select(dbConn, mpfScheme))
                        {
                            if (mpfScheme.MPFSchemeTrusteeCode.Equals("HSBC"))
                            {
                                keyPath = System.IO.Path.Combine(keyFolderPath, HSBCKeyFileName);
                                if (Application["MasterDBConfig"] != null)
                                {
                                    DatabaseConnection masterDBConn = ((DatabaseConfig)Application["MasterDBConfig"]).CreateDatabaseConnectionObject();
                                    string             HSBCKeyPath  = HROne.SaaS.Entities.ESystemParameter.getParameter(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_BANKKEY_HSBC_PATH);
                                    string             HSBCPassword = HROne.SaaS.Entities.ESystemParameter.getParameterWithEncryption(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_BANKKEY_HSBC_PASSWORD);
                                    if (!string.IsNullOrEmpty(HSBCKeyPath) && !string.IsNullOrEmpty(HSBCPassword))
                                    {
                                        keyPath  = HSBCKeyPath;
                                        password = HSBCPassword;
                                    }
                                }
                            }
                            else if (mpfScheme.MPFSchemeTrusteeCode.Equals("HangSeng"))
                            {
                                keyPath = System.IO.Path.Combine(keyFolderPath, HangSengKeyFileName);
                                if (Application["MasterDBConfig"] != null)
                                {
                                    DatabaseConnection masterDBConn = ((DatabaseConfig)Application["MasterDBConfig"]).CreateDatabaseConnectionObject();
                                    string             HASEKeyPath  = HROne.SaaS.Entities.ESystemParameter.getParameter(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_BANKKEY_HASE_PATH);
                                    string             HASEPassword = HROne.SaaS.Entities.ESystemParameter.getParameterWithEncryption(masterDBConn, HROne.SaaS.Entities.ESystemParameter.PARAM_CODE_BANKKEY_HASE_PASSWORD);
                                    if (!string.IsNullOrEmpty(HASEKeyPath) && !string.IsNullOrEmpty(HASEPassword))
                                    {
                                        keyPath  = HASEKeyPath;
                                        password = HASEPassword;
                                    }
                                }
                            }
                        }
                    }
                }

                HSBCMPFGatewayFileEncrypted mpfFileEncrypted = (HSBCMPFGatewayFileEncrypted)mpfFileProcess;

                mpfFileEncrypted.publicKeyFile     = keyPath;
                mpfFileEncrypted.publicKeyPassword = password;
            }

            HROneConfig config = HROneConfig.GetCurrentHROneConfig();
            if (config.GenerateReportAsInbox)
            {
                if (EInboxAttachment.GetTotalSize(dbConn, 0) < WebUtils.productLicense(Session).MaxInboxSizeMB * 1000 * 1000)
                {
                    HROne.TaskService.GenerateMPFContributionFileTaskFactory reportTask = new HROne.TaskService.GenerateMPFContributionFileTaskFactory(dbConn, user, lblReportHeader.Text, mpfFileProcess, empList, int.Parse(MPFPlanID.SelectedValue), dtPayPeriodFr, dtPayPeriodTo, ci);
                    AppUtils.reportTaskQueueService.AddTask(reportTask);
                    errors.addError(HROne.Translation.PageMessage.REPORT_GENERATING_TO_INBOX);
                }
                else
                {
                    errors.addError(HROne.Translation.PageMessage.INBOX_SIZE_EXCEEDED);
                }
            }
            else
            {
                try
                {
                    mpfFileProcess.LoadMPFFileDetail(empList, int.Parse(MPFPlanID.SelectedValue), dtPayPeriodFr, dtPayPeriodTo);
                    FileInfo mpfFileInfo = mpfFileProcess.GenerateMPFFile();

                    string mpfFilename = mpfFileProcess.ActualMPFFileName();
                    WebUtils.TransmitFile(Response, mpfFileInfo.FullName, mpfFilename, true);
                }
                catch (Exception ex)
                {
                    errors.addError(ex.Message);
                }
            }
        }
//        emploadData(empInfo, EEmpPayroll.db, empRepeater);
    }
コード例 #2
0
        public override bool Execute()
        {
            try
            {
                mpfFileProcess.LoadMPFFileDetail(empList, MPFPlanID, PayPeriodFr, PayPeriodTo);
                FileInfo mpfFile      = mpfFileProcess.GenerateMPFFile();
                DateTime generateDate = AppUtils.ServerDateTime();

                string strTmpFolder = HROne.Common.Folder.GetOrCreateApplicationTempFolder().FullName;// System.IO.Path.GetTempPath(); //Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);

                string mpfFileName          = mpfFile.FullName;
                string mpfFileNameExtension = mpfFileName.Substring(mpfFileName.LastIndexOf("."));
                string outputMPFFileName    = mpfFileProcess.ActualMPFFileName(); //"MPFFile_" + generateDate.ToString("yyyyMMddHHmmss") + mpfFileNameExtension;
                string strMPFTmpFile        = System.IO.Path.Combine(strTmpFolder, System.IO.Path.GetFileName(mpfFileName));
                System.IO.File.Move(mpfFileName, strMPFTmpFile);

                string ChequeNo = "";   // cheque no for AIA only, not applicable to iMgr

                HROne.MPFFile.MPFRemittanceStatementProcess remittanceStatementProcess = new HROne.MPFFile.MPFRemittanceStatementProcess(dbConn, empList, MPFPlanID, PayPeriodFr, PayPeriodTo, ChequeNo);

                string exportFileName          = remittanceStatementProcess.ReportExportToFile(string.Empty, "PDF", true);
                string exportFileNameExtension = exportFileName.Substring(exportFileName.LastIndexOf("."));
                string outputFileName          = "MPFRemittanceStatement_" + generateDate.ToString("yyyyMMddHHmmss") + exportFileNameExtension;
                string strTmpFile = System.IO.Path.Combine(strTmpFolder, System.IO.Path.GetFileName(exportFileName));
                System.IO.File.Move(exportFileName, strTmpFile);

                string InboxMessageType = string.Empty;
                // currently only gateway format is supported for directly submitted
                if (mpfFileProcess is HSBCMPFGatewayFile && !(mpfFileProcess is HSBCMPFGatewayFileEncrypted))
                {
                    InboxMessageType = EInbox.INBOX_TYPE_MPF_FILE + "|" + EInbox.INBOX_TYPE_FOR_ECHANNEL;
                }

                EInbox inbox = EInbox.CreateAndSaveInboxMessage(dbConn, user.UserID, 0, 0, 0, string.Empty, InboxMessageType, ReportName, string.Empty, new DateTime());

                inbox.AddInboxAttachment(dbConn, outputMPFFileName, strMPFTmpFile);
                inbox.AddInboxAttachment(dbConn, outputFileName, strTmpFile);

                if (mpfFileProcess is HSBCMPFGatewayFileEncrypted)
                {
                    HROne.MPFFile.HSBCMPFGatewayFileEncryptedCoverProcess coverProcess = new HROne.MPFFile.HSBCMPFGatewayFileEncryptedCoverProcess(dbConn, (HSBCMPFGatewayFileEncrypted)mpfFileProcess);

                    string exportCoverFileName          = coverProcess.ReportExportToFile(string.Empty, "PDF", true);
                    string exportCoverFileNameExtension = exportCoverFileName.Substring(exportCoverFileName.LastIndexOf("."));
                    string outputCoverFileName          = "Cover_" + generateDate.ToString("yyyyMMddHHmmss") + exportCoverFileNameExtension;
                    string strCoverTmpFile = System.IO.Path.Combine(strTmpFolder, System.IO.Path.GetFileName(exportCoverFileName));
                    System.IO.File.Move(exportCoverFileName, strCoverTmpFile);

                    inbox.AddInboxAttachment(dbConn, outputCoverFileName, strCoverTmpFile);
                    coverProcess.Dispose();
                }

                dbConn.Dispose();
                remittanceStatementProcess.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                EInbox inbox = EInbox.CreateAndSaveInboxMessage(dbConn, user.UserID, 0, 0, 0, string.Empty, string.Empty, ReportName, ex.Message + "\r\n" + ex.StackTrace, new DateTime());
                dbConn.Dispose();
            }
            return(false);
        }