示例#1
0
        // function updates sails data grid in the last 3 days
        private void updateSailsGrid()
        {
            List <Common.Order> resultList = new List <Common.Order>();
            int    sailingDays             = 3;
            string str = string.Empty;

            // filter only needed customer (all the customers in the list)
            foreach (Common.Customer customer in Common.customerList)
            {
                resultList.AddRange(Outlook.filterCustomersByName(customer.name, customer.alias));
            }

            // filter only yesterday's sailing dates
            // filter only loadings sent from the country of the agent
            // order by sailingDate
            resultList = resultList.Where(x => x.sailingDate.Date >= DateTime.Now.AddDays((-1) * (sailingDays)).Date&&
                                          x.sailingDate.Date <= DateTime.Now.AddDays(-1))
                         .OrderByDescending(x => x.sailingDate)
                         .Distinct()
                         .ToList();

            // check if customer has orders
            if (resultList.Count == 0)
            {
                str = string.Format("No new sailings in the last {0} days", sailingDays);
                log(str);
                updateLabel(sails_lbl, str);

                return;
            }

            // test
            str = string.Format("{0} new sailings in the last {1} days", resultList.Count, sailingDays);
            log(str);
            updateLabel(sails_lbl, str);

            // not all the columns are needed in the report - remove some
            List <Common.SailsReport> targetResList = resultList.ConvertAll(x => new Common.SailsReport
            {
                jobNo       = x.jobNo,
                shipper     = x.shipper,
                consignee   = x.consignee,
                tankNum     = x.tankNum,
                fromCountry = x.fromCountry,
                sailingDate = x.sailingDate,
            });

            // prepare DataTable to fill the grid
            DataTable table = Utils.generateDataTableFromList <Common.SailsReport>(targetResList);

            sailsDataGrid.Invoke(new MethodInvoker(delegate
            {
                sailsDataGrid.DataSource           = table;
                sailsDataGrid.DataBindingComplete += sailsDataGrid_DataBindingComplete;
            }));
        }
示例#2
0
        // function disposes all used classes
        private void cleanResources(bool bSuccess)
        {
            // dispose classes
            Excel.dispose();
            Outlook.dispose();

            animateGif(false);
            buttonsSetVisible(true);

            if (bSuccess == true)
            {
                log("Process done - mails are ready");
            }
        }
示例#3
0
        // function sends document receipts requests from agents
        private void docReceipts_btn_Click(object sender, EventArgs e)
        {
            List <Common.SailsReport> targetResList = new List <Common.SailsReport>();

            buttonsSetVisible(false);
            animateGif(true);

            // sanity check
            if (sailsDataGrid.SelectedRows.Count == 0)
            {
                log("Nothing was selected, you must select at least one sailing", LogLevel.Error);
                cleanResources(false);
                return;
            }

            // go over the selected rows and generate new List<T> for emails
            foreach (DataGridViewRow row in sailsDataGrid.SelectedRows)
            {
                Common.SailsReport report = new Common.SailsReport();

                report.jobNo       = Convert.ToInt32(row.Cells[0].Value);
                report.shipper     = row.Cells[1].Value.ToString();
                report.consignee   = row.Cells[2].Value.ToString();
                report.tankNum     = row.Cells[3].Value.ToString();
                report.fromCountry = row.Cells[4].Value.ToString();
                report.sailingDate = DateTime.Parse(row.Cells[5].Value.ToString());

                targetResList.Add(report);
            }


            // parsing is long, so in order not to block the GUI
            // start in new task
            Task.Factory.StartNew(() =>
            {
                // prepare mails for all customer based on DB data
                Outlook.prepareDocumentsReceiptesMailsToAllAgents(targetResList);
            })
            // when done, call this CB
            .ContinueWith(mailCompleteCB);
        }
示例#4
0
        // function sends emails to all shipping companies with future bookings
        private void bookConfirm_btn_Click(object sender, EventArgs e)
        {
            buttonsSetVisible(false);

            // sanity check that excel file was parsed successfully
            if (Utils.bValidOrders() == false)
            {
                // file doesn't exist
                log("Orders are not valid", LogLevel.Error);
                return;
            }

            animateGif(true);

            // parsing is long, so in order not to block the GUI
            // start in new task
            Task.Factory.StartNew(() =>
            {
                // prepare mails for all customer based on DB data
                Outlook.prepareBookingMailsToAllAgents();
            })
            // when done, call this CB
            .ContinueWith(mailCompleteCB);
        }
示例#5
0
        // function verifies that shipping destination port is correct
        // for this, it compares customer's destination port to the one mentined in the orders excel
        // in case of no match - it alerts
        private void updateDestinationGrid()
        {
            List <Common.Order> resultList = new List <Common.Order>();
            string str = string.Empty;

            // filter only needed customer (all the customers in the list)
            foreach (Common.Customer customer in Common.customerList)
            {
                resultList.AddRange(Outlook.filterCustomersByName(customer.name, customer.alias));
            }

            // filter only loading which haven't sailed yet (sailing date > today)
            // order by sailingDate
            resultList = resultList.Where(x => x.sailingDate.Date > DateTime.Now.Date)
                         .OrderBy(x => x.sailingDate)
                         .Distinct()
                         .ToList();

            // now we are left with customers who ship only to Ashdod or Haifa port
            // generate new list containing only partial details for the report
            List <Common.DestinationReport> targetResList = resultList.ConvertAll(x => new Common.DestinationReport
            {
                jobNo       = x.jobNo,
                shipper     = x.shipper,
                consignee   = x.consignee,
                fromCountry = x.fromCountry,
                sailingDate = x.sailingDate,
                toCountry   = x.toCountry,
                toPlace     = x.toPlace,
                arrivalDate = x.arrivalDate
            });

            // update the bDestinationPortCorrect in the resultList
            // caution: you cannot remove items in foreach, therefore make a copy (ToList)
            foreach (Common.DestinationReport item in targetResList.ToList())
            {
                // get the destination port of this specific customer from local DB
                PortService.PortName port = Utils.getDestinationPortByConsignee(item.consignee);

                // make sure that port is as expcted, and if not, update bDestinationPortCorrect
                if ((port == PortService.PortName.Unknown) || (Utils.strCmp(item.toPlace, port.ToString()) == true))
                {
                    // remove all 'correct' items, meaning that port is unknown or
                    // actual destination port corresponds with desired one
                    targetResList.Remove(item);
                }
            }

            // check if customer has orders
            if (targetResList.Count() == 0)
            {
                str = "Destination port is correct for all orders";
                log(str);
                updateLabel(destination_lbl, str);

                return;
            }

            // inconsistency in destination port was detected
            str = "Destination port inconsistency occurred";
            log(str, LogLevel.Error);
            updateLabel(destination_lbl, str);

            // prepare DataTable to fill the grid
            DataTable table = Utils.generateDataTableFromList <Common.DestinationReport>(targetResList);

            sailsDataGrid.Invoke(new MethodInvoker(delegate
            {
                destinationDataGrid.DataSource           = table;
                destinationDataGrid.DataBindingComplete += destinationDataGrid_DataBindingComplete;
            }));

            tabControl.SelectedIndex = 2;

            // popup message box to draw attention
            MessageBox.Show(str, "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
示例#6
0
        // function updates today's arrivals data grid
        private void updateArrivalsGrid()
        {
            List <Common.Order> resultList = new List <Common.Order>();
            DateTime            now        = DateTime.Now;
            string str = string.Empty;

            // filter only needed customer (all the customers in the list)
            foreach (Common.Customer customer in Common.customerList)
            {
                resultList.AddRange(Outlook.filterCustomersByName(customer.name, customer.alias));
            }

#if OFFLINE
            // for testing purposes, since there might be no arrivals today, take several random arrivals
            resultList = resultList.Where(x => x.arrivalDate.Date >= DateTime.Now.Date)
                         .Take(6)
                         .OrderBy(x => x.consignee)
                         .Distinct()
                         .ToList();
#else
            // filter only today's arrival dates
            // filter only loadings sent from the country of the agent
            // order by consignee
            resultList = resultList.Where(x => x.arrivalDate.Date == DateTime.Now.Date)
                         .OrderBy(x => x.consignee)
                         .Distinct()
                         .ToList();
#endif

            // check if customer has orders
            if (resultList.Count == 0)
            {
                str = "No new arrivals today";
                log(str);
                updateLabel(arrivals_lbl, str);
                initCompleteCB();
                return;
            }

            str = string.Format("{0} new arrivals today", resultList.Count);
            log(str);
            updateLabel(arrivals_lbl, str);

            // start async thread to get data from ports web
            // optimization: downloading data from web takes time, so do not do it
            // in case there are no arrivals today to this specific port
            if (Utils.bArrivalsToPort(resultList, PortService.PortName.Ashdod) == true)
            {
                PortService.getShipsFromPort(PortService.PortName.Ashdod);
            }

            if (Utils.bArrivalsToPort(resultList, PortService.PortName.Haifa) == true)
            {
                PortService.getShipsFromPort(PortService.PortName.Haifa);
            }

            // not all the columns are needed in the report - remove some
            List <Common.ArrivalsReport> targetResList = resultList.ConvertAll(x => new Common.ArrivalsReport
            {
                jobNo       = x.jobNo,
                consignee   = x.consignee,
                toPlace     = x.toPlace,
                vessel      = x.vessel,
                arrivalDate = x.arrivalDate,
            });

            // prepare DataTable to fill the grid
            DataTable table = Utils.generateDataTableFromList <Common.ArrivalsReport>(targetResList);

            arrivalsDataGrid.Invoke(new MethodInvoker(delegate
            {
                arrivalsDataGrid.AutoGenerateColumns = true;
                arrivalsDataGrid.DataSource          = table;
                arrivalsDataGrid.AutoResizeColumns();
                arrivalsDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                arrivalsDataGrid.Refresh();
            }));
        }