Example #1
0
        // function prepares booking mail to shipping company
        private static void prepareBookingMailToAgent(Common.ShippingCompany shippingCompany)
        {
            List <Common.Order> resultList = new List <Common.Order>();
            string outputFileName          = string.Empty;
            int    bookingDays             = 5;

            // 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 => x.sailingDate.Date == DateTime.Now.AddDays(bookingDays).Date&&
                                          x.MBL.ToLower().StartsWith(shippingCompany.id.ToLower()))
                         .OrderBy(x => x.sailingDate)
                         .Distinct()
                         .ToList();

            // check if customer has orders
            if (resultList.Count == 0)
            {
                OrdersParser._Form.log(string.Format("no new bookings in {0} days for {1}", bookingDays, shippingCompany.shippingLine));
                return;
            }

            OrdersParser._Form.log(string.Format("{0} bookings in {1} days found for {2}", resultList.Count, bookingDays, shippingCompany.shippingLine));

            // not all the columns are needed in the report - remove some
            List <Common.BookingsReport> targetResList = resultList.ConvertAll(x => new Common.BookingsReport
            {
                jobNo       = x.jobNo,
                fromCountry = x.fromCountry,
                sailingDate = x.sailingDate,
                toCountry   = x.toCountry,
                toPlace     = x.toPlace,
                vessel      = x.vessel,
                voyage      = x.voyage,
                MBL         = x.MBL,
            });

            string htmlTableStr = addHtmlTable <Common.BookingsReport>(targetResList);

            // send mail to customer
            MailDetails mailDetails = new MailDetails();

            mailDetails.mailRecepient  = shippingCompany;
            mailDetails.mailType       = Common.MailType.BookingConfirmation;
            mailDetails.bodyParameters = new Dictionary <string, string>()
            {
                { "table", htmlTableStr },
                { "agent", shippingCompany.name },
            };
            mailDetails.subject     = string.Format("Booking confirmation for the upcoming {0} days", bookingDays);
            mailDetails.attachments = new List <string>()
            {
            };
            mailDetails.bHighImportance = false;

            // send mail
            sendMail(mailDetails);
        }
Example #2
0
        // function extracts shipping companies (booking) list from static DB (excel file)
        private static void getShippingCompaniesDetais()
        {
            // go to specific sheet
            try
            {
                excelSheet = workBook.Sheets[BOOKING_SHEE_NAME];
            }
            catch (Exception e)
            {
                OrdersParser._Form.log(string.Format("Failed to open excel sheet: {0}. Error: {1}", BOOKING_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.ShippingCompany shippingCompany = new Common.ShippingCompany();
            Common.shippingCompanyList = new List <Common.ShippingCompany>();
            int     totalNumOfRows = excelSheet.UsedRange.Rows.Count - 2;
            dynamic sheet          = excelSheet.UsedRange.Value2;

            try
            {
                for (int row = 0; row < totalNumOfRows; row++)
                {
                    // shipping line
                    val = sheet[row + effectiveDataOffset, col];
                    if (string.IsNullOrEmpty(val) == false)
                    {
                        shippingCompany.shippingLine = val;
                    }

                    // id
                    val = sheet[row + effectiveDataOffset, col + 1];
                    if (string.IsNullOrEmpty(val) == false)
                    {
                        shippingCompany.id = val;
                    }

                    // agent name
                    val = sheet[row + effectiveDataOffset, col + 2];
                    if (string.IsNullOrEmpty(val) == false)
                    {
                        shippingCompany.name = val;
                    }

                    // to
                    val = sheet[row + effectiveDataOffset, col + 3];
                    if (string.IsNullOrEmpty(val) == false)
                    {
                        shippingCompany.to.Add(val);
                    }

                    // cc
                    val = sheet[row + effectiveDataOffset, col + 4];
                    if (string.IsNullOrEmpty(val) == false)
                    {
                        shippingCompany.cc.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.shippingCompanyList.Add(shippingCompany);

                        // nullify and create new
                        shippingCompany = null;
                        shippingCompany = new Common.ShippingCompany();
                    }
                }
            }
            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} shipping companies in the private DB", Common.shippingCompanyList.Count));

            // update global list outside of this APP domain
            ExcelRemote.RemoteExeclController.DataUpdater.updateShippingCompanyList(Common.shippingCompanyList);

            excelSheet = null;
        }