Пример #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 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);
        }
Пример #3
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();
            }));
        }