Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        // function updates arrivals data grid with data taken from port websites
        // function should be called when data reading from all ports is complete
        // and the following lists are filled with data:
        // Common.ashdodAnchoringList
        // Common.haifaAnchoringList
        // function colors rows according to arrival status and adds tooltips with additional data
        public void arrivalsDataGrid_WebSyncComplete()
        {
            // get columns based on Common.ArrivalsReport
            PortService.PortName portName = PortService.PortName.Unknown;
            int    toPlaceIndex           = arrivalsDataGrid.Columns["toPlace"].Index;
            int    vesselIndex            = arrivalsDataGrid.Columns["vessel"].Index;
            string portNameStr            = string.Empty;
            string toolTipStr             = string.Empty;

            // go over each rows
            foreach (DataGridViewRow row in arrivalsDataGrid.Rows)
            {
                string vesselName = string.Empty;
                portNameStr = row.Cells[toPlaceIndex].Value.ToString();

                if (portNameStr.ToLower() == "ashdod")
                {
                    portName = PortService.PortName.Ashdod;
                }

                if (portNameStr.ToLower() == "haifa")
                {
                    portName = PortService.PortName.Haifa;
                }

                vesselName = row.Cells[vesselIndex].Value.ToString();

                if (string.IsNullOrEmpty(vesselName) == false)
                {
                    // colorize according to arrival status
                    // get tool tip as well during parsing
                    switch (PortService.shipStatusInPort(vesselName, portName, out toolTipStr))
                    {
                    case PortService.ShipStatus.Arrived:
                        row.DefaultCellStyle.BackColor = Color.LightGreen;
                        break;

                    case PortService.ShipStatus.Expected:
                        row.DefaultCellStyle.BackColor = Color.LightPink;
                        break;

                    case PortService.ShipStatus.Unknown:
                        row.DefaultCellStyle.BackColor = Color.LightYellow;
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    // vessel name is empty, this can happen if excel has not been updated yet
                    // in such case, mark as unknown
                    row.DefaultCellStyle.BackColor = Color.LightYellow;
                    toolTipStr = "Vessel not found";
                }

                // add tool tip with additional data about this ship
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.ToolTipText = toolTipStr;
                }
            }

            //sailsDataGrid.DefaultCellStyle.Font = new Font(new FontFamily("Calibri"), 10f);
            arrivalsDataGrid.AutoGenerateColumns = true;
            arrivalsDataGrid.AutoResizeColumns();
            arrivalsDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            arrivalsDataGrid.Invoke(new MethodInvoker(delegate
            {
                arrivalsDataGrid.Refresh();
            }));

            initCompleteCB();
        }
Ejemplo n.º 3
0
 // function verifies is there are arrivals to certain ports
 public static bool bArrivalsToPort(List <Common.Order> resultList, PortService.PortName portName)
 {
     return(resultList.Any(x => x.toPlace.ToLower() == portName.ToString().ToLower()));
 }