public static isaCommand MyQueryReader_Driver(SqlDataReader reader, Func <byte[], Task> cb)
        {
            drivers md = new drivers();

            try
            {
                int    did;
                string fname;
                string lname;

                did   = reader.GetInt32(reader.GetOrdinal("DriverId"));
                fname = reader.GetString(reader.GetOrdinal("FirstName"));
                lname = reader.GetString(reader.GetOrdinal("LastName"));
                if (did != 0)
                {
                    md.DriverId  = did;
                    md.FirstName = fname;
                    md.LastName  = lname;
                }
                cb(md.ToArray());
            }
            catch (Exception ex) { }
            return(md);
        }
        public IMDMMessage QueryData(Func <byte[], Task> cb, isaCommand dat)
        {
            IMDMMessage     retVal = null;
            SPCmds          SP;
            manifestRequest req; // (manifestRequest)dat;

            switch (dat.command)
            {
            case eCommand.Drivers:
                SP = SPCmds.GETAVAILABLEDRIVERS;
                break;

            case eCommand.Manifest:
                SP = SPCmds.GETDRIVERMANIFEST;
                break;

            case eCommand.Trucks:
                SP = SPCmds.GETTRUCKS;
                break;

            case eCommand.Stops:
                SP = SPCmds.GETSTOPS;
                break;

            case eCommand.Orders:
            case eCommand.OrdersLoad:
                SP = SPCmds.GETORDERS;
                break;

            case eCommand.GenerateManifest:
                SP = SPCmds.GETMANIFEST;
                break;

            default:
                throw new Exception("Not handled");
            }

            using (SqlConnection cnn = new SqlConnection(UMDDB.connectionString))
            {
                using (var adapter = new SqlDataAdapter())
                {
                    using (var command = new SqlCommand(SP.ToString(), cnn))
                    {
                        command.CommandType = CommandType.StoredProcedure;

                        switch (dat.command)
                        {
                        case eCommand.Drivers:
                            req = (manifestRequest)dat;
                            command.Parameters.AddWithValue("@SHP_DTE", SqlDbType.Date).Value = DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd");
                            dat.command = eCommand.DriversLoadComplete;
                            retVal      = new DriverData()
                            {
                                RequestId = new Guid(req.requestId)
                            };
                            Logger.Info($"QueryData Drivers. Cmd:{retVal.Command.ToString()}  reqId: {retVal.RequestId.ToString()} SHP_DTE: {DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd")}");
                            break;

                        case eCommand.Manifest:
                            req = (manifestRequest)dat;
                            command.Parameters.AddWithValue("@DriverId", SqlDbType.Int).Value = req.id;
                            retVal = new ManifestMasterData()
                            {
                                RequestId = new Guid(req.requestId)
                            };
                            Logger.Info($"QueryData Manifest. Cmd:{retVal.Command.ToString()}  reqId: {retVal.RequestId.ToString()}  DriverId: {req.id} ");
                            dat.command = eCommand.ManifestLoadComplete;
                            break;

                        case eCommand.Trucks:
                            req = (manifestRequest)dat;
                            command.Parameters.AddWithValue("@SHP_DTE", SqlDbType.Date).Value = DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd");
                            dat.command = eCommand.TrucksLoadComplete;
                            Logger.Info($"QueryData Trucks. Cmd:{req.command.ToString()}  reqId: {new Guid(req.requestId).ToString()} SHP_DTE: {DateTime.Parse(req.date).Date.ToString("yyyy-MM-dd")}");

                            retVal = new TruckData()
                            {
                                RequestId = new Guid(req.requestId)
                            };
                            break;

                        case eCommand.Stops:
                            req = (manifestRequest)dat;
                            command.Parameters.AddWithValue("@ManifestId", SqlDbType.Int).Value = req.id;
                            dat.command = eCommand.StopsLoadComplete;
                            Logger.Info($"QueryData Stops. Cmd:{req.command.ToString()}  reqId: {new Guid(req.requestId).ToString()}  manId: {req.id}");
                            retVal = new StopData()
                            {
                                RequestId = new Guid(req.requestId)
                            };
                            break;

                        case eCommand.Orders:
                        case eCommand.OrdersLoad:
                            req = (manifestRequest)dat;
                            command.Parameters.AddWithValue("@ManifestId", SqlDbType.Int).Value = req.id;
                            dat.command = eCommand.OrdersLoadComplete;
                            command.Parameters.AddWithValue("@Stop", SqlDbType.Int).Value = req.Stop;
                            Logger.Info($"QueryData Orders. Cmd:{req.command.ToString()}  reqId: {new Guid(req.requestId).ToString()}  stop: {req.Stop.ToString()}");
                            retVal = new OrderMasterData()
                            {
                                RequestId = new Guid(req.requestId)
                            };
                            break;

                        case eCommand.GenerateManifest:
                            // req = (manifestRequest)dat;
                            command.Parameters.AddWithValue("@Link", SqlDbType.BigInt).Value = ((manifestMaster)dat).LINK;
                            dat.command = eCommand.ManifestLoadComplete;

                            Logger.Info($"QueryData GenerateManifest. " +
                                        $"Cmd:{dat.command.ToString()}  " +
                                        $"reqId: {new Guid(dat.requestId).ToString()}" +
                                        $"link: { ((manifestMaster)dat).LINK}");

                            retVal = new ManifestMasterData()
                            {
                                LINK = ((manifestMaster)dat).LINK, RequestId = new Guid(dat.requestId)
                            };
                            break;

                        default:
                        {
                            Logger.Error($"QueryData Unkonwn Command. " +
                                         $"Cmd:{retVal.Command.ToString()}  " +
                                         $"reqId: {retVal.RequestId.ToString()}");

                            throw new Exception("Not handled");
                        }
                        }
                        adapter.SelectCommand = command;
                        SqlDataReader reader = null;
                        try
                        {
                            cnn.Open();
                            reader = adapter.SelectCommand.ExecuteReader();
                        }
                        catch (Exception ex) { }

                        while (reader.Read())
                        {
                            switch (retVal.Command)
                            {
                            case eCommand.Drivers:
                                drivers drv = (drivers)MyQueryReader_Driver(reader, cb);
                                drv.requestId = dat.requestId;
                                drv.command   = eCommand.Drivers;
                                Logger.Info($"QueryData Manifest. Cmd:{drv.command.ToString()}  reqId: {new Guid(drv.requestId).ToString()}  Link: {drv.DriverId}  manId: {drv.LastName}, {drv.FirstName} ");
                                cb(drv.ToArray());
                                break;

                            case eCommand.Manifest:
                            case eCommand.GenerateManifest:
                                manifestMaster micmd = (manifestMaster)myQueryData_GetManifest(reader, cb);
                                micmd.requestId = dat.requestId;
                                micmd.command   = eCommand.Manifest;
                                Logger.Info($"QueryData Manifest. Cmd:{micmd.command.ToString()}  reqId: {new Guid(micmd.requestId).ToString()}  Link: {micmd.LINK}  manId: {micmd.id} ");
                                cb(micmd.ToArray());
                                break;

                            case eCommand.Trucks:
                                trucks tcmd = (trucks)MyQueryReader_Trucks(reader, cb);
                                tcmd.requestId = dat.requestId;
                                tcmd.command   = eCommand.Trucks;
                                Logger.Info($"QueryData Trucks. Cmd:{tcmd.command.ToString()}  reqId: {new Guid(tcmd.requestId).ToString()}  TRK_CDE: {tcmd.TruckCode}  ManId: {tcmd.ManifestId}");
                                cb(tcmd.ToArray());
                                break;

                            case eCommand.Stops:
                                stops scmd = (stops)MyQueryReader_Stops(reader, cb);
                                scmd.requestId = dat.requestId;
                                scmd.command   = eCommand.Stops;
                                Logger.Info($"QueryData Stops. Cmd:{scmd.command.ToString()} reqId: {new Guid(scmd.requestId).ToString()} manId: {scmd.ManifestId}");
                                cb(scmd.ToArray());
                                break;

                            case eCommand.Orders:
                            case eCommand.OrdersLoad:
                                var ocmd = (orders)MyQueryReader_Orders(reader, cb);
                                ocmd.requestId = dat.requestId;
                                ocmd.command   = eCommand.OrdersLoad;
                                Logger.Info($"QueryData Orders. Cmd:{ocmd.command.ToString()} reqId: {new Guid(ocmd.requestId).ToString()}");
                                cb(ocmd.ToArray());
                                break;

                            default:
                                throw new Exception("Not handled");
                            }
                        }

                        Logger.Info($"QueryData Completed. Cmd:{dat.command.ToString()} reqId: {new Guid(dat.requestId).ToString()}");
                        cb(dat.ToArray());
                    }
                }
            }

            return(retVal);
        }