Ejemplo n.º 1
0
        public bool FnSendMail(REPORTLOG reportlog, string hostName, string user )
        {
            try
            {
                if (reportlog.EmailAddress !="")
                {
                    var message = new MailMessage();
                    message.To.Add(reportlog.EmailAddress);
                    message.From = new MailAddress(getParams.Parameters("MAILFROM").Paramvalue, "Audit Letters");
                    message.Subject = reportlog.ReportName.Substring(0, reportlog.ReportName.Length - 16) + " Audit Confirmation As At: " + reportlog.Reportdate.ToString("dd MMM yyyy");
                    message.Body = getParams.Parameters("MAILBODY").Paramvalue;

                    SmtpClient mailClient = new SmtpClient(getParams.Parameters("MAILSERVER").Paramvalue);
                    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                    mailClient.UseDefaultCredentials = true;
                    Parameter mailpassword = db.Parameter.Where(b => b.Paramname == "MAILPASSWORD").First();
                    mailClient.Credentials = new NetworkCredential(getParams.Parameters("MAILUSERNAME").Paramvalue, StringCipher.Decrypt(mailpassword.Paramvalue, "S41T" + mailpassword.Osysdate.ToString() + "Th@tS3cr3tS@uc3"));
                    // Create  the file attachment for this e-mail message.
                    Attachment data = new Attachment(reportlog.ReportPath, MediaTypeNames.Application.Octet);
                    // Add time stamp information for the file.
                    ContentDisposition disposition = data.ContentDisposition;
                    disposition.CreationDate = System.IO.File.GetCreationTime(reportlog.ReportPath);
                    disposition.ModificationDate = System.IO.File.GetLastWriteTime(reportlog.ReportPath);
                    disposition.ReadDate = System.IO.File.GetLastAccessTime(reportlog.ReportPath);
                    // Add the file attachment to this e-mail message.
                    message.Attachments.Add(data);
                    mailClient.Send(message);
                    getVals.LogAudit(user, "Emailed", hostName,
                        "Emailed Audit letter: " + reportlog.ReportName + " Report Date: " + reportlog.Reportdate +
                        " Created at: " + reportlog.Osysdate + " Approved By: " + reportlog.ReportChecker, "Email","AuditLetters");

                }
                return true;
            }
            catch (FormatException ex)
            {
                return false;

            }
        }
Ejemplo n.º 2
0
        private bool SaveGeneratedReport(string path, DateTime reportDate, string loggedUser, string emaiAddress, string fpath, string addres,string account,string currency)
        {
            try
            {
                var logReport = new REPORTLOG();
                ClsDatabase getVals = new ClsDatabase();
                var checkIfExist = _repository.CheckExist(Path.GetFileName(path));
                if (checkIfExist != null)
                {
                    logReport =checkIfExist;
                    logReport.State = MyEnums.StatusOptions.Added;
                    logReport.ReportCreator = loggedUser;
                    logReport.ReportName = Path.GetFileName(path);
                    logReport.Reportdate = reportDate;
                    logReport.ReportPath = path;
                    logReport.Osysdate = DateTime.Now;
                    logReport.EmailSent = false;
                    logReport.EmailAddress = emaiAddress;
                    logReport.AccountDebit = account;
                    logReport.AccountCurrency = currency;
                    logReport.Charged = false;
                    _repository.SaveUpdate(logReport);
                }
                else
                {

                    logReport.Id = Guid.NewGuid();
                    logReport.State = MyEnums.StatusOptions.Added;
                    logReport.ReportCreator = loggedUser;
                    logReport.ReportName = Path.GetFileName(path);
                    logReport.Reportdate = reportDate;
                    logReport.ReportPath = path;
                    logReport.Osysdate = DateTime.Now;
                    logReport.EmailSent = false;
                    logReport.EmailAddress = emaiAddress;
                    logReport.AccountDebit = account;
                    logReport.AccountCurrency = currency;
                    logReport.Charged = false;
                    _repository.SaveNew(logReport);
                }

                return true;
            }
            catch (Exception ex)
            {
                _logs.LogError(loggedUser, "PDF - SaveGeneratedReport", "Error: " + ex.Message,
             addres, fpath, "AuditLetters");
                return false;
            }
        }
Ejemplo n.º 3
0
        public string FnF31Two(REPORTLOG rp, string fPath)
        {
            var batch = _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "BatchNo").Paramvalue;
            int Cnt = 0;

            string strDate = string.Format("{0:yyyyMMdd}", DateTime.Now);
            string strSec = string.Format("{0:hhmmss}", DateTime.Now);
            string fccy = rp.AccountCurrency;
            const string ccy = "KES";
            float? rate;
            decimal FCYRate;
            decimal cr = 0;
            decimal dr = 0;
            decimal lcy, fcy;
            string body, tail, account, narrative, f31code,amount,narr;
            int CntOne, CntTwo;

            try
            {
                string cpyFile = fPath + @"F31\F31_" + batch + ".000";
                string directory = fPath + @"\F" + batch + ".000";
                if (!Directory.Exists(Path.GetDirectoryName(directory)))
                    Directory.CreateDirectory(Path.GetDirectoryName(directory));
                string branch = "KE1";
                string head = "HDR" + "KE" + branch + batch.PadLeft(7, '0') + "001" + "0000031" + strDate + strSec + strDate + batch.PadLeft(4, '0') + "LCUP" + "LCUPTEMP       " + "N                                  ";
                File.WriteAllText(directory, "");
                StreamWriter streamF31 = new StreamWriter(directory, true);

                //batch =  _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "BatchNo").Paramvalue;
                account = _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "F31AccountNo").Paramvalue;
                f31code = _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "F31Code").Paramvalue;
                amount = _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "Amount").Paramvalue;
                narr = _repository.Fetch<Parameter>().FirstOrDefault(p => p.Paramname == "Narrative").Paramvalue;
                rate = null;
                if (fccy != "KES")
                {
                    rate = _repository.Fetch<CURRENCY_INFO>().FirstOrDefault(p => p.CURRENCY_CODE == fccy).RATE;
                }
                narrative = "AUDITLETTERS CHARGES";
                streamF31.WriteLine(head);

                    Cnt = Cnt + 1;
                    lcy = Convert.ToDecimal(amount);
                    fcy = Convert.ToDecimal(amount);
                if (fccy!="KES")
                {
                    FCYRate = Convert.ToDecimal(rate);
                    fcy = lcy / FCYRate;
                }

                    //charles change ====Old format 31

                    //body = "ENT" + "~" + "KE" + "~" + brach + "~" + row["Account"].ToString() + "~" + "~" + strDate + "~" + Cnt + "~" +
                    //    row["Reciept"].ToString() + "~" + "C" + "~" + ccy + "~" + fnFormatDec(fcy, 2) +
                    //    "~" + "+" + "~" + "0" + "~" + mdiCommerce.F31Code + "~" + "1" + "~" + rate + "~" + "0" + "~" +
                    //    ccy + "~" + fnFormatDec(lcy, 2) + "~" + "+" + "~" + "0" + "~" + "" + "~" +
                    //    "1077" + "~" + row["CustomerNumber"].ToString() + "" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "^" + "~" +
                    //    "~" + "~" + Cnt + "~" + narrative + " - " + row["MobileNumber"].ToString() +
                    //    "~" + "~~~~~~~~~~~~~~~~~~~~";
                    //streamF31.WriteLine(body);

                    //charles change ====New format 31

                    body = "ENT" + "~" + "KE" + "~" + branch + "~" + rp.AccountDebit + "~" + "~" + strDate + "~" + Cnt + "~" +
                      "" + "~" + "D" + "~" + fccy + "~" + FnFormatDec(fcy, 2) +
                      "~" + "+" + "~" + "0" + "~" + f31code + "~" + "1" + "~" + rate + "~" + "0" + "~" +
                      ccy + "~" + FnFormatDec(lcy, 2) + "~" + "+" + "~" + "0" + "~" + "" + "~" +
                      "1077" + "~" + "" + "" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "~" +
                      "~" + "~" + Cnt + "~" + narr + "  " + "" +
                      "~" + "~~~~~~~~~~~~~~~~~~~~";
                    streamF31.WriteLine(body);

                    //charles change ====Old format 31

                    //Cnt = Cnt + 1;
                    //body = "ENT" + "~" + "KE" + "~" + brach + "~" + account + "~" + "~" + strDate + "~" + Cnt + "~" +
                    //     row["Reciept"].ToString() + "~" + "D" + "~" + ccy + "~" + fnFormatDec(fcy, 2) +
                    //     "~" + "+" + "~" + "0" + "~" + mdiCommerce.F31Code + "~" + "1" + "~" + rate + "~" + "0" + "~" +
                    //     ccy + "~" + fnFormatDec(lcy, 2) + "~" + "+" + "~" + "0" + "~" + "" + "~" +
                    //     "1077" + "~" + row["CustomerNumber"].ToString() + "" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "^" + "~" +
                    //     "~" + "~" + Cnt + "~" + narrative + " - " + row["MobileNumber"].ToString() +
                    //     "~" + "~~~~~~~~~~~~~~~~~~~~";
                    //streamF31.WriteLine(body);

                    //charles change ====New format 31

                    Cnt = Cnt + 1;
                    body = "ENT" + "~" + "KE" + "~" + branch + "~" + account + "~" + "~" + strDate + "~" + Cnt + "~" +
                         "" + "~" + "C" + "~" + fccy + "~" + FnFormatDec(fcy, 2) +
                         "~" + "+" + "~" + "0" + "~" + f31code + "~" + "1" + "~" + rate + "~" + "0" + "~" +
                         ccy + "~" + FnFormatDec(lcy, 2) + "~" + "+" + "~" + "0" + "~" + "" + "~" +
                         "1077" + "~" +""+ "" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "~" + "~" +
                         "~" + "~" + Cnt + "~" + narr + "  " + "" +
                         "~" + "~~~~~~~~~~~~~~~~~~~~";
                    streamF31.WriteLine(body);

                CntTwo = Cnt + 2;
                tail = "TLR" + "KE" + branch + batch.PadLeft(7, '0') + "001" + Right("000000000" + CntTwo, 9) +
                    Right("000000000000000000000000" + lcy, 24) + "+" + Right("000000000000000000000000" + lcy, 24) + "+" +
                    "                ";
                streamF31.WriteLine(tail);
                streamF31.Flush();
                streamF31.Close();
                if (!Directory.Exists(Path.GetDirectoryName(cpyFile)))
                    Directory.CreateDirectory(Path.GetDirectoryName(cpyFile));
                File.Copy(directory, cpyFile, true);
                string filename = Path.GetFileName(directory);
            //    decimal logId = mydb.usp_Log_File(2, directory, filename, mdiCommerce.userId, GetCrc(directory), filename).Single().File_LogId;
            //    Program.fnAudit("Created Format31 file: " + filename);
            //    foreach (DataRow row in dt.Rows)
            //        mydb.usp_Insert_F31Rec(row["Narrative"].ToString(), row["Account"].ToString(), Convert.ToDecimal(row["Amount"]), logId);
            //
            }
            catch (Exception ex)
            {
                //clsLogs.fnErrorLog(ex.Message, "Format31 generation");
                //Notice.SaveEmails(ex.Message, Notice.MessageId("ERROR"));
                return "Failed";
            }
            string msg = "MGen_LS1 " + System.DateTime.Now.ToString("yyyy MMM dd") + "Flex Handoff BatchNo." + batch + " has been Generated";
            //Notice.SaveEmails(msg, Notice.MessageId("NOTIFICATION"));
            //messageParams.Clear();
            //messageParams.Add("MGen_LS1 " + System.DateTime.Now.ToString("yyyy MMM dd"));
            //messageParams.Add(batch);
            //Notice.fnCustommizeNSaveEmails("", "Not:160", messageParams);

            return batch;
        }