private void TransferFile(string pvtFileName) { Event clsEvent = new Event(); try { if (!string.IsNullOrEmpty(pvtFileName)) { if (string.IsNullOrEmpty(mclsAyalaDetails.FTPIPAddress)) { clsEvent.AddEventLn("Cannot transfer file " + pvtFileName + ". FTP IPAddress is empty Automatic File transfer is disabled.", true); return; } else clsEvent.AddEventLn("Transferring " + pvtFileName + " to " + mclsAyalaDetails.FTPIPAddress, true); } else { clsEvent.AddEventLn("Cannot transfer an blank file.", true); return; } int intPort = 21; if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"] != null) { try { intPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"]); } catch { } } FtpClient ftpClient = new FtpClient(); ftpClient.Host = mclsAyalaDetails.FTPIPAddress; ftpClient.Port = intPort; ftpClient.Credentials = new NetworkCredential(mclsAyalaDetails.FTPUsername, mclsAyalaDetails.FTPPassword); IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(mclsAyalaDetails.FTPDirectory, FtpListOption.Modify | FtpListOption.Size); bool bolIsFileExist = false; clsEvent.AddEventLn("Checking file if already exist...", true); try { foreach (FtpListItem ftpListItem in lstFtpListItem) { if (ftpListItem.Name.ToUpper() == Path.GetFileName(pvtFileName).ToUpper()) { bolIsFileExist = true; break; } } } catch (Exception excheck) { clsEvent.AddEventLn("checking error..." + excheck.Message, true); } if (bolIsFileExist) { clsEvent.AddEventLn("exist...", true); clsEvent.AddEventLn("uploading now...", true); } else { clsEvent.AddEventLn("does not exist...", true); clsEvent.AddEventLn("uploading now...", true); } using (var fileStream = File.OpenRead(pvtFileName)) using (var ftpStream = ftpClient.OpenWrite(string.Format("{0}/{1}", Path.GetFileName(pvtFileName), Path.GetFileName(pvtFileName)))) { var buffer = new byte[8 * 1024]; int count; while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0) { ftpStream.Write(buffer, 0, count); } clsEvent.AddEventLn("Upload Complete: TotalBytes: " + buffer.ToString(), true); } ftpClient.Disconnect(); ftpClient.Dispose(); ftpClient = null; clsEvent.AddEventLn("Done.", true); } catch (Exception ex) { clsEvent.AddEventLn("Error encountered: " + ex.Message, true); throw new IOException("Sales file is not sent to RLC server. Please contact your POS vendor"); } }
public void CreateAndTransferFile(int BranchID, string TerminalNo, DateTime pvtDateInitialized) { DateTime dteDateToprocess = pvtDateInitialized; Event clsEvent = new Event(); try { clsEvent.AddEventLn("Starting Ayala FILE CREATOR.", true); clsEvent.AddEventLn("==================================================", true); clsEvent.AddEventLn("= Ayala FILE CREATOR =", true); clsEvent.AddEventLn("==================================================", true); /*********************************************************************** * Check the destination dir if existing. * ********************************************************************/ clsEvent.AddEventLn("Checking directory settings.", true); string dir = mclsAyalaDetails.OutputDirectory; dir = dir.Replace("{YYYY}", DateTime.Now.ToString("yyyy")); dir = dir.Replace("{MM}", DateTime.Now.ToString("MM")); dir = dir.Replace("{MMM}", DateTime.Now.ToString("MMM")); dir = dir.Replace("{MMMM}", DateTime.Now.ToString("MMMM")); if (!System.IO.Directory.Exists(dir)) { clsEvent.AddEventLn("Directory [" + dir + "] does not exist.", true); System.IO.Directory.CreateDirectory(dir); } else { clsEvent.AddEventLn("Directory [" + dir + "] exist.", true); } mclsAyalaDetails.OutputDirectory = dir; /*********************************************************************** * GET The report of Current Terminal using Specified InitializationDate * ********************************************************************/ Data.TerminalReportHistory clsTerminalReportHistory = new Data.TerminalReportHistory(); Data.TerminalReportDetails clsTerminalReportDetail = clsTerminalReportHistory.Details(BranchID, TerminalNo, dteDateToprocess); string stDailyTableName = CreateDailySales(dteDateToprocess, clsTerminalReportDetail); string stHourlyTableName = CreateHourlySales(BranchID, TerminalNo, dteDateToprocess); clsTerminalReportHistory.UpdateTerminalReportBatchCounter(TerminalNo, dteDateToprocess); clsTerminalReportHistory.CommitAndDispose(); clsEvent.AddEventLn("Record for [" + dteDateToprocess.ToString("yyyy-MM-dd HH:mm:ss") + "] BacthCounter:" + clsTerminalReportDetail.BatchCounter.ToString() + " has been created for Ayala.", true); TransferFile(stDailyTableName); TransferFile(stHourlyTableName); } catch (Exception ex) { clsEvent.AddErrorEventLn(ex); throw ex; } clsEvent.AddEventLn("Ayala FILE CREATOR exited.", true); }
private string CreateHourlySales(Int32 BranchID, string TerminalNo, DateTime ProcessDate, Data.TerminalReportDetails TerminalReportDetails) { string strRetValue = ""; DateTime dteDateFrom = ProcessDate; Data.TerminalReportHistory clsTerminalReportHistory = new Data.TerminalReportHistory(); DateTime dteDateTo = DateTime.MinValue; try { dteDateTo = clsTerminalReportHistory.NEXTDateLastInitialized(BranchID, TerminalNo, ProcessDate); } catch { } if (dteDateTo == DateTime.MinValue) { Event clsEvent = new Event(); clsEvent.AddEventLn("HourlySales: Did not found MAXDateLastInitialized from Terminal Report History. Using the MAXDateLastInitialized from terminal report", true); Data.TerminalReport clsTerminalReport = new Data.TerminalReport(clsTerminalReportHistory.Connection, clsTerminalReportHistory.Transaction); dteDateTo = clsTerminalReport.MAXDateLastInitialized(BranchID, TerminalNo, ProcessDate); } System.Data.DataTable dtHourlyReport = clsTerminalReportHistory.HourlyReport(BranchID, TerminalNo, dteDateFrom, dteDateTo); clsTerminalReportHistory.CommitAndDispose(); string stHourlyTableName = mclsFSIDetails.OutputDirectory + "\\H" + mclsFSIDetails.TenantName.Substring(0, 4) + TerminalReportDetails.TerminalNo + TerminalReportDetails.BatchCounter.ToString() + "." + TerminalReportDetails.DateLastInitializedToDisplay.ToString("MM").Replace("10", "A").Replace("11", "B").Replace("12", "C").Replace("0", "") + TerminalReportDetails.DateLastInitializedToDisplay.ToString("dd"); if (File.Exists(stHourlyTableName)) File.Delete(stHourlyTableName); writer = File.AppendText(stHourlyTableName); writer.WriteLine("01{0}", mclsFSIDetails.TenantCode); writer.WriteLine("02{0}", TerminalNo); DateTime dtePreviousTransactionDate = DateTime.MinValue; foreach (System.Data.DataRow dr in dtHourlyReport.Rows) { if (dtePreviousTransactionDate != Convert.ToDateTime(dr["TransactionDate"])) { writer.WriteLine("03{0}", Convert.ToDateTime(dr["TransactionDate"]).ToString("MMddyyyy")); dtePreviousTransactionDate = Convert.ToDateTime(dr["TransactionDate"]); } writer.WriteLine("04{0}", dr["Time"].ToString().Substring(0,2)); writer.WriteLine("05{0}", Convert.ToDecimal(Convert.ToDecimal(dr["Amount"]) - Convert.ToDecimal(dr["VAT"])).ToString("####.#0").Replace(".", "")); writer.WriteLine("06{0}", Convert.ToInt64(dr["TranCount"]).ToString("####")); } writer.WriteLine("07{0}", TerminalReportDetails.DailySales.ToString("####.#0").Replace(".", "")); writer.WriteLine("08{0}", TerminalReportDetails.NoOfClosedTransactions.ToString("####")); writer.Flush(); writer.Close(); strRetValue = stHourlyTableName; return strRetValue; }
private string CreateHourlySales(int BranchID, string TerminalNo, DateTime pvtProcessDate) { string strRetValue = ""; DateTime dteDateFrom = pvtProcessDate; Data.TerminalReportHistory clsTerminalReportHistory = new Data.TerminalReportHistory(); DateTime dteDateTo = DateTime.MinValue; try { dteDateTo = clsTerminalReportHistory.NEXTDateLastInitialized(BranchID, TerminalNo, pvtProcessDate); } catch { } if (dteDateTo == DateTime.MinValue) { Event clsEvent = new Event(); clsEvent.AddEventLn("HourlySales: Did not found MAXDateLastInitialized from Terminal Report History. Using the MAXDateLastInitialized from terminal report", true); Data.TerminalReport clsTerminalReport = new Data.TerminalReport(clsTerminalReportHistory.Connection, clsTerminalReportHistory.Transaction); dteDateTo = clsTerminalReport.MAXDateLastInitialized(Constants.TerminalBranchID, TerminalNo, pvtProcessDate); } System.Data.DataTable dthreport = clsTerminalReportHistory.HourlyReport(BranchID, TerminalNo, dteDateFrom, dteDateTo); clsTerminalReportHistory.CommitAndDispose(); string stHourlyTableName = mclsAyalaDetails.TenantCode.Substring(0, 3) + pvtProcessDate.ToString("MMdd") + "H"; string stHourlyFileName = mclsAyalaDetails.OutputDirectory + "\\" + stHourlyTableName + ".dbf"; if (File.Exists(stHourlyFileName)) File.Delete(stHourlyFileName); CreateHourlySalesTable(stHourlyTableName); InsertHourlySales(stHourlyTableName, dthreport); strRetValue = stHourlyFileName; return strRetValue; }
public bool CreateAndTransferFile(Int32 BranchID, string TerminalNo, DateTime pvtDateInitialized) { bool bolRetValue = false; DateTime dteDateToprocess = pvtDateInitialized; Event clsEvent = new Event(); try { clsEvent.AddEventLn("Starting RLC FILE CREATOR.", true); clsEvent.AddEventLn("==================================================", true); clsEvent.AddEventLn("= RLC FILE CREATOR =", true); clsEvent.AddEventLn("==================================================", true); /*********************************************************************** * Check the destination dir if existing. * ********************************************************************/ clsEvent.AddEventLn("Checking directory settings.", true); string dir = mclsRLCDetails.OutputDirectory; dir = dir.Replace("{YYYY}", DateTime.Now.ToString("yyyy")); dir = dir.Replace("{MM}", DateTime.Now.ToString("MM")); dir = dir.Replace("{MMM}", DateTime.Now.ToString("MMM")); dir = dir.Replace("{MMMM}", DateTime.Now.ToString("MMMM")); if (!System.IO.Directory.Exists(dir)) { clsEvent.AddEventLn("Directory [" + dir + "] does not exist.", true); System.IO.Directory.CreateDirectory(dir); } else { clsEvent.AddEventLn("Directory [" + dir + "] exist.", true); } mclsRLCDetails.OutputDirectory = dir; /*********************************************************************** * GET The report of Current Terminal using Specified InitializationDate * ********************************************************************/ Data.TerminalReportHistory clsTerminalReportHistory = new Data.TerminalReportHistory(); Data.TerminalReportDetails clsTerminalReportDetail = clsTerminalReportHistory.Details(BranchID, TerminalNo, dteDateToprocess); Data.SalesTransactions clsSalesTransactions = new Data.SalesTransactions(clsTerminalReportHistory.Connection, clsTerminalReportHistory.Transaction); long lngSeniorCitizenDiscountCount = 0; decimal decSeniorCitizenDiscount = clsSalesTransactions.SeniorCitizenDiscounts(clsTerminalReportDetail.BranchID, clsTerminalReportDetail.TerminalNo, clsTerminalReportDetail.BeginningTransactionNo, clsTerminalReportDetail.EndingTransactionNo, out lngSeniorCitizenDiscountCount); long lngPWDDiscountCount = 0; decimal decPWDDiscount = clsSalesTransactions.PersonWithDisabilityDiscounts(clsTerminalReportDetail.BranchID, clsTerminalReportDetail.TerminalNo, clsTerminalReportDetail.BeginningTransactionNo, clsTerminalReportDetail.EndingTransactionNo, out lngPWDDiscountCount); string stDailyTableName = CreateDailySales(dteDateToprocess, clsTerminalReportDetail, decSeniorCitizenDiscount, lngSeniorCitizenDiscountCount, decPWDDiscount, lngPWDDiscountCount); clsTerminalReportHistory.CommitAndDispose(); bool bolTransferFile = TransferFile(stDailyTableName); if (bolTransferFile ) { clsTerminalReportHistory = new Data.TerminalReportHistory(); clsTerminalReportHistory.UpdateTerminalReportBatchCounter(clsTerminalReportDetail.TerminalNo, dteDateToprocess); clsTerminalReportHistory.UpdateTerminalReportIsMallFileUploadComplete(clsTerminalReportDetail.TerminalNo, dteDateToprocess, true); if (clsTerminalReportDetail.BatchCounter == 1) clsTerminalReportHistory.UpdateTerminalReportMallForwarderFileName(clsTerminalReportDetail.TerminalNo, dteDateToprocess, stDailyTableName); clsTerminalReportHistory.CommitAndDispose(); bolRetValue = true; } clsEvent.AddEventLn("Record for [" + dteDateToprocess.ToString("yyyy-MM-dd HH:mm:ss") + "] BacthCounter:" + clsTerminalReportDetail.BatchCounter.ToString() + " has been created for RLC.", true); } catch (Exception ex) { clsEvent.AddErrorEventLn(ex); throw ex; } clsEvent.AddEventLn("RLC FILE CREATOR exited.", true); return bolRetValue; }