private static void prepareLoadingConfirmationMailToCustomer(Common.Agent agent) { List <Common.Order> resultList = new List <Common.Order>(); string outputFileName = string.Empty; // filter only needed customer (all the customers in the list) foreach (Common.Customer customer in Common.customerList) { resultList.AddRange(filterCustomersByName(customer.name, customer.alias)); } // filter only tomorrow's loading dates // filter only loadings sent from the country of the agent // order by consignee resultList = resultList.Where(x => agent.countries.Contains(x.fromCountry) && x.loadingDate.Date == DateTime.Now.AddDays(1).Date) .OrderBy(x => x.consignee) .Distinct() .ToList(); // check if customer has orders if (resultList.Count == 0) { OrdersParser._Form.log(string.Format("no new loadings tomorrow for {0}", agent.name)); return; } OrdersParser._Form.log(string.Format("{0} loading for tomorrow found for {1}", resultList.Count, agent.name)); // not all the columns are needed in the report - remove some List <Common.LoadingReport> targetResList = resultList.ConvertAll(x => new Common.LoadingReport { jobNo = x.jobNo, consignee = x.consignee, loadingDate = x.loadingDate, fromCountry = x.fromCountry, }); string htmlTableStr = addHtmlTable <Common.LoadingReport>(targetResList); // send mail to customer MailDetails mailDetails = new MailDetails(); mailDetails.mailRecepient = agent; mailDetails.mailType = Common.MailType.LoadingConfirmation; mailDetails.bodyParameters = new Dictionary <string, string>() { { "table", htmlTableStr }, { "date", DateTime.Now.AddDays(1).ToString(Common.DATE_FORMAT) }, { "day", DateTime.Now.AddDays(1).DayOfWeek.ToString() }, { "agent", agent.name }, }; mailDetails.subject = "Loading confirmation for tomorrow"; mailDetails.attachments = new List <string>() { }; mailDetails.bHighImportance = false; // send mail sendMail(mailDetails); }
// function goes over the selected rows from the data grid and sends mails to agents private static void prepareDocumentsReceiptsMailToAgent(Common.Agent agent, List <Common.SailsReport> report) { string outputFileName = string.Empty; // filter only shipping sent from the country of the agent // order by consignee report = report.Where(x => agent.countries.Contains(x.fromCountry)) .OrderBy(x => x.sailingDate) .ToList(); // check if customer has orders if (report.Count == 0) { return; } OrdersParser._Form.log(string.Format("Documents receipts are needed from {0} on {1} sailings", agent.name, report.Count)); // not all the columns are needed in the report - remove some List <Common.SailsReport> targetResList = report.ConvertAll(x => new Common.SailsReport { jobNo = x.jobNo, shipper = x.shipper, consignee = x.consignee, tankNum = x.tankNum, fromCountry = x.fromCountry, sailingDate = x.sailingDate, }); string htmlTableStr = addHtmlTable <Common.SailsReport>(targetResList); // send mail to customer MailDetails mailDetails = new MailDetails(); mailDetails.mailRecepient = agent; mailDetails.mailType = Common.MailType.DocumentsReceipts; mailDetails.bodyParameters = new Dictionary <string, string>() { { "table", htmlTableStr }, { "agent", agent.name }, }; mailDetails.subject = "BL is missing"; mailDetails.attachments = new List <string>() { }; mailDetails.bHighImportance = false; // send mail sendMail(mailDetails); }
// function extracts agents list from static DB (excel file) private static void getAgentsDetails() { // got to specific sheet try { excelSheet = workBook.Sheets[AGENTS_SHEE_NAME]; } catch (Exception e) { OrdersParser._Form.log(string.Format("Failed to open excel sheet: {0}. Error: {1}", AGENTS_SHEE_NAME, e.Message), OrdersParser.LogLevel.Error); dispose(); return; } // go over the whole table filling the customerLust // start from 3, since // dynamic array starts from [1,1] // row 1 is full of nulls // row 2 has the column names string val = string.Empty; int col = 1; int effectiveDataOffset = 3; Common.Agent agent = new Common.Agent(); Common.agentList = new List <Common.Agent>(); int totalNumOfRows = excelSheet.UsedRange.Rows.Count - 2; dynamic sheet = excelSheet.UsedRange.Value2; try { for (int row = 0; row < totalNumOfRows; row++) { // name val = sheet[row + effectiveDataOffset, col]; if (string.IsNullOrEmpty(val) == false) { agent.name = val; } // to val = sheet[row + effectiveDataOffset, col + 1]; if (string.IsNullOrEmpty(val) == false) { agent.to.Add(val); } // cc val = sheet[row + effectiveDataOffset, col + 2]; if (string.IsNullOrEmpty(val) == false) { agent.cc.Add(val); } // country val = sheet[row + effectiveDataOffset, col + 3]; if (string.IsNullOrEmpty(val) == false) { agent.countries.Add(val); } // check that last entry for this customer (next should be not empty or out of bounds) if ((row == (totalNumOfRows - 1)) || (string.IsNullOrEmpty(sheet[row + effectiveDataOffset + 1, col]) == false)) { // this is the last customer, add to list and zero struct Common.agentList.Add(agent); // nullify and create new agent = null; agent = new Common.Agent(); } } } catch (Exception e) { OrdersParser._Form.log(string.Format("Failed parsing private DB. Error: {0}", e.Message), OrdersParser.LogLevel.Error); dispose(); return; } // success OrdersParser._Form.log(string.Format("Found {0} agents in the private DB", Common.agentList.Count)); // update global list outside of this APP domain ExcelRemote.RemoteExeclController.DataUpdater.updateAgentList(Common.agentList); excelSheet = null; }