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);
        }
        static Dictionary <short, Dictionary <byte, List <long> > > dTruckCodeToDealerNumbers = new Dictionary <short, Dictionary <byte, List <long> > >();  //TruckCode -> <Seq, List<Orders>>
        public static isaCommand CommandFactory(byte[] cmdBytes)
        {
            isaCommand cmd = new Command().FromArray(cmdBytes);

            switch (cmd.command)
            {
            case eCommand.Broadcast:
                //Broadcast cmdType = Broadcast.FromArray(cmdBytes);
                break;

            case eCommand.DeliveryComplete:
                //Broadcast cmdType = Broadcast.FromArray(cmdBytes);
                break;

            case eCommand.CheckManifest:
            case eCommand.CheckManifestComplete:
                manifestMaster mamr = new manifestMaster();
                cmd = mamr.FromArray(cmdBytes);
                break;

            case eCommand.GenerateManifest:
                manifestRequest mr = new manifestRequest();
                cmd = mr.FromArray(cmdBytes);
                if (cmd == null)
                {
                    manifestMaster mmr = new manifestMaster();
                    cmd = mmr.FromArray(cmdBytes);
                }
                //Call ApplicationServer to return the data requested.
                //UMDManifest.
                break;

            case eCommand.OrdersLoad:
                //orders ords = new orders();
                //cmd = ords.FromArray(cmdBytes);
                orderMaster orm = new orderMaster();
                cmd = orm.FromArray(cmdBytes);
                break;

            case eCommand.Trucks:
                trucks trks = new trucks();
                cmd = trks.FromArray(cmdBytes);
                break;

            case eCommand.Stops:
                stops stps = new stops();
                cmd = stps.FromArray(cmdBytes);
                break;

            case eCommand.OrderDetails:
                orderDetails cmdType = new orderDetails();
                cmd = cmdType.FromArray(cmdBytes);
                break;

            case eCommand.Manifest:
                manifestMaster mm = new manifestMaster();
                cmd = mm.FromArray(cmdBytes);
                break;

            case eCommand.ManifestDetails:
                manifestDetails md = new manifestDetails();
                cmd = md.FromArray(cmdBytes);
                break;

            case eCommand.OrdersUpload:
                orderMaster om = new orderMaster();
                cmd = om.FromArray(cmdBytes);
                OrderMasterData omd = new OrderMasterData(om);
                if (!dStopOrders.ContainsKey(omd.DLR_NO))
                {
                    dStopOrders.Add(omd.DLR_NO, new List <long>()
                    {
                        omd.ORD_NO
                    });
                }
                break;

            case eCommand.ScanFile:
                scanFile sc = new scanFile();
                cmd = sc.FromArray(cmdBytes);
                ScanFileData scd = new ScanFileData(sc);
                break;

            case eCommand.OrderOptions:
                orderOptions oo = new orderOptions();
                cmd = oo.FromArray(cmdBytes);
                //OrderOptionsData ood = new OrderOptionsData(oo);
                break;

            case eCommand.AccountReceivable:
                accountReceivable ar = new accountReceivable();
                cmd = ar.FromArray(cmdBytes);
                // AccountsReceivableData acr = new AccountsReceivableData((accountReceivable)cmd);
                break;

            case eCommand.ManifestLoadComplete:
            case eCommand.TrucksLoadComplete:
            case eCommand.StopsLoadComplete:
            case eCommand.OrdersLoadComplete:
            case eCommand.OrderUpdatesComplete:
            case eCommand.OrderDetailsComplete:
            case eCommand.OrderOptionsComplete:
            case eCommand.ManifestDetailsComplete:
            case eCommand.UploadManifestComplete:
            case eCommand.LoadFilesComplete:
                Logger.Info($"CommandFactory: {Enum.GetName(typeof(eCommand), cmd.command) + Environment.NewLine}");
                manifestRequest req = new manifestRequest();
                Logger.Info($"CommandFactory: {req.ToString()}");
                cmd = req.FromArray(cmdBytes);
                break;

            case eCommand.Ping:
                //Broadcast cmdType = Broadcast.FromArray(cmdBytes);
                //cmd = SendPong();
                break;

            case eCommand.Pong:
                //Broadcast cmdType = Broadcast.FromArray(cmdBytes);
                //Broadcast cmdType = Broadcast.FromArray(cmdBytes);
                break;

            case eCommand.RunQuery:
                //Broadcast cmdType = Broadcast.FromArray(cmdBytes);
                break;

            default:
                break;
            }
            return(cmd);
        }
Beispiel #3
0
        public void HandleClientCmd(byte[] bytes_cmd, Func <byte[], Task> cbsend)
        {
            isaCommand cmd = new Command().FromArray(bytes_cmd);

            switch (cmd.command)
            {
            case eCommand.Ping:
                Logger.Debug("HandleClientCmd -  Received Ping / Replying Pong..");
                cbsend(new Command()
                {
                    command = eCommand.Pong
                }.ToArray());
                break;

            case eCommand.Pong:
                Logger.Debug("HandleClientCmd -  Received Pong");
                break;

            case eCommand.LoadFiles:
                Logger.Info("HandleClientCmd - Copy Files from Winsys Server Paths top App Server Paths:{cmd.ToString()}");
                //CopyFilesToServer(DateTime.Today);
                Logger.Info("HandleClientCmd - Replying LoadFilesComplete...");
                cbsend(new Command()
                {
                    command = eCommand.LoadFilesComplete
                }.ToArray());
                break;

            case eCommand.GenerateManifest:
                Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}");

                manifestMaster mM = (manifestMaster) new manifestMaster().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd Generate Manifest from Winsys and SqlServer:{mM.ToString()}");
                if (mM.LINK != 0)
                {
                    ManifestMasterData mmd = (ManifestMasterData)UMDServer.QueryData(cbsend, mM);
                    Logger.Info($"API Manager GenerateManifest. {mmd.ToString()}");
                }
                else
                {
                    WinSysSM.SendMessage(cmd);
                }
                break;

            case eCommand.CheckManifest:
                Logger.Info($"HandleClientCmd - CheckManifest:{cmd.ToString()}");
                //ManifestMasterData mMstData = (ManifestMasterData)new ManifestMasterData(bytes_cmd);
                manifestMaster mMst = (manifestMaster) new manifestMaster().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd Compare Manifest from Winsys to SqlServer: {mMst.ToString()}");
                ManifestMasterData mamd = (ManifestMasterData)UMDServer.QueryData(cbsend, mMst);
                Logger.Info($"API Manager GenerateManifest. {mamd.ToString()}");
                break;

            case eCommand.RunQuery:
                Logger.Info($"HandleClientCmd - ManifestDetails: {cmd.ToString()}");

                //DriverData dd = (DriverData)GetDrivers(cbsend);
                break;

            case eCommand.Manifest:
                Logger.Info($"HandleClientCmd - Manifest from Winsys and SqlServer:{cmd.ToString()}");
                cbsend(cmd.ToArray());
                break;

            case eCommand.Trucks:
                Logger.Info($"HandleClientCmd - Trucks: {cmd.ToString()}");

                isaCommand req = new manifestRequest().FromArray(bytes_cmd);
                TruckData  td  = (TruckData)UMDServer.QueryData(cbsend, req);
                Logger.Info($"HandleClientCmd - Trucks.  reqId:{req.ToString()}");
                break;

            case eCommand.ManifestDetails:
                Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}");
                isaCommand reqmd = new manifestRequest().FromArray(bytes_cmd);
                // ManifestDetailsData mdd =
                manifestDetails     manDet     = new manifestDetails();
                ManifestDetailsData manDetData = (ManifestDetailsData)manDet.FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd - ManifestDetails:{manDetData.ToString()}");

                foreach (var mmd in UMDServer.Persist(SPCmds.INSERTMANIFESTDETAILS, manDetData))
                {
                    drillDown.GetOrderMasterData((ManifestDetailsData)mmd);
                    mmd.Command   = eCommand.ManifestDetails;
                    mmd.RequestId = new Guid(manDet.requestId);
                    Logger.Info($"HandleClientCmd - ManifestDetails.  Sending GetOrderMasterData:{mmd.ToString()}");
                    cbsend(((manifestDetails)mmd).ToArray());
                }
                break;

            case eCommand.Orders:
                Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}");

                var om = (orderMaster) new orderMaster().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd - Orders.  reqId: {om.ToString()}");
                foreach (var omd in UMDServer.Persist(SPCmds.INSERTORDER, new OrderMasterData(om)))
                {
                    drillDown.GetOrderDetailsData((OrderMasterData)omd);
                }
                break;

            case eCommand.OrderOptions:
                Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}");

                var oo = (orderOptions) new orderOptions().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd - OrderOptions:{cmd.ToString()}");
                foreach (var mmd in UMDServer.Persist(SPCmds.INSERTORDEROPTIONS, new OrderOptionsData(oo)))
                {
                    var oopt = new orderOptions((OrderOptionsData)mmd);
                    oopt.command = eCommand.OrderOptionsComplete;
                    cbsend(oopt.ToArray());
                }
                break;

            case eCommand.OrderDetails:
                Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}");

                var odt = (orderDetails) new orderDetails().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd - OrderDetails: {odt.ToString()}");
                foreach (var mmd in UMDServer.Persist(SPCmds.INSERTORDERDETAILS, new OrderDetailsData(odt)))
                {
                    orderDetails odd = new orderDetails((OrderDetailsData)mmd);
                    odd.command = eCommand.OrderDetailsComplete;
                    cbsend(odd.ToArray());
                }
                break;

            case eCommand.Drivers:
                Logger.Info($"HandleClientCmd - ManifestDetails:{cmd.ToString()}");
                req = new manifestRequest().FromArray(bytes_cmd);
                DriverData dd = (DriverData)UMDServer.QueryData(cbsend, req);
                //drivers drvs = new drivers(dd);
                //drvs.command = eCommand.DriversLoadComplete;
                //cbsend(drvs.ToArray());

                //cbsend(new Command() { command = eCommand.DriversLoadComplete, value = dd.DriverId.ToString() }.ToArray());
                break;

            case eCommand.UploadManifest:
                Logger.Info($"HandleClientCmd - UploadManifest:{cmd.ToString()}");

                manifestRequest mreq = (manifestRequest) new manifestRequest().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd - UploadManifest:  {mreq.ToString()}");
                //ManifestMasterData Mmd = (ManifestMasterData)cmd;
                manifestMaster            mm     = (manifestMaster) new manifestMaster().FromArray(mreq.bData);
                IEnumerable <IMDMMessage> mmdata = UMDServer.Persist(SPCmds.INSERTMANIFEST, new ManifestMasterData(mm, mm.id));
                Logger.Info($"HandleClientCmd - UploadManifest Persisted:{mm.ToString()}");

                try
                {
                    ManifestMasterData mmd = null;
                    foreach (var mmdIt in mmdata)
                    {
                        mmd = (ManifestMasterData)mmdIt;
                        Logger.Info($"HandleClientCmd - UploadManifest - Get ManifestDetails sending ManMastData Trk:{mmd.ToString()}");
                        drillDown.GetManifestDetails(mmd, cbsend);
                    }
                    if (mmd != null)
                    {
                        manifestMaster mmRet = new manifestMaster(mmd);
                        mmRet.command = eCommand.ManifestLoadComplete;
                        Logger.Info($"HandleClientCmd - UploadManifest - Done (ManifestLoadComplete):{mreq.ToString()}");
                        cbsend(mmRet.ToArray());
                    }
                }
                catch (Exception e)
                {
                    Logger.Debug("HandleClientCmd - Error exception = " + e.Message);
                }

                break;

            case eCommand.Stops:
                Logger.Info($"HandleClientCmd - Stops.  reqId:{cmd.ToString()}");
                req = new manifestRequest().FromArray(bytes_cmd);
                StopData sd   = (StopData)UMDServer.QueryData(cbsend, req);
                stops    stps = new stops(sd);
                stps.command = eCommand.StopsLoadComplete;
                cbsend(stps.ToArray());

                break;

            case eCommand.OrdersLoad:
                req = new manifestRequest().FromArray(bytes_cmd);
                Logger.Info($"HandleClientCmd - OrdersLoad (Start QueryData): {req.ToString()}");
                OrderData od   = (OrderData)UMDServer.QueryData(cbsend, req);
                orders    odrs = new orders(od);
                odrs.command = eCommand.OrdersLoadComplete;
                Logger.Info($"HandleClientCmd - OrdersLoad (OrdersLoadComplete): {odrs.ToString()}");
                cbsend(odrs.ToArray());
                break;

            default:
                Logger.Error("HandleClientCmd - ERROR Unknown command.  Parse Error MDM-API");
                break;
            }
        }
Beispiel #4
0
        ///扫描算法(结果是得到站点的stopsList)
        public void scan(string schoolID, double schoolX, double schoolY, SortedList <double, stops> stopsList)
        {
            ///stop和school的坐标范围是[0,211200]英尺,depot在中心,则坐标为[105600,105600]
            ///sin,cos分别是以depot为中心,stop的正弦余弦值
            ///asin是stop的正弦对应的角度,因函数自身原因,其范围是[-90,90]
            ///acos是stop的余弦对应的角度,范围是[0,180]

            double sin, cos, asin, acos,
                   x, y,                       //站点坐标
                   Ox = schoolX, Oy = schoolY, //学校坐标
                   jiaodu;
            string ID;                         //站点ID

            for (int i = 0; stopsArr[i] != null; i++)
            {
                stops stop = new stops();
                x  = double.Parse(stopsArr[i][1]);
                y  = double.Parse(stopsArr[i][2]);
                ID = stopsArr[i][0];
                //以depot为原点,求各stop对应的正弦余弦
                sin = (x - Ox) / Math.Sqrt(Math.Pow((x - Ox), 2) + Math.Pow((y - Oy), 2));
                cos = (y - Oy) / Math.Sqrt(Math.Pow((x - Ox), 2) + Math.Pow((y - Oy), 2));
                ///求正弦值对应的弧度asin(0,pi),实际上也可能是asin+pi,
                ///所以下面再根据acos判断
                asin = Math.Asin(sin) * 180 / Math.PI;//通过乘180/Math.PI转换成角度
                acos = Math.Acos(cos) * 180 / Math.PI;
                if (sin >= 0 && cos >= 0)
                {
                    jiaodu = asin;
                }
                else if (sin >= 0 && cos <= 0)
                {
                    jiaodu = acos;
                }
                else if (sin <= 0 && cos <= 0)
                {
                    jiaodu = 360 - acos;
                }
                else if (sin <= 0 && cos >= 0)
                {
                    jiaodu = 360 + asin;
                }
                else
                {
                    jiaodu = 0;
                }

                stop.stopID       = stopsArr[i][0];
                stop.stopX        = double.Parse(stopsArr[i][1]);
                stop.stopY        = double.Parse(stopsArr[i][2]);
                stop.EP_ID        = stopsArr[i][3];
                stop.studentCount = int.Parse(stopsArr[i][4]);
                //属于目标学校的加入站点列表
                if (stop.EP_ID == schoolID)
                {
                    stopsList.Add(jiaodu, stop);
                }
            }

            //遍历排序列表stopList
            Console.WriteLine("每个学校的站点列表*****************************************************");
            for (int i = 0; i < stopsList.Count; i++)
            {
                Console.WriteLine(i + "\tkey:" + stopsList.ElementAt(i).Key +
                                  "\tstopID:" + stopsList.ElementAt(i).Value.stopID
                                  + "\tstopX:" + stopsList.ElementAt(i).Value.stopX +
                                  "\tstopY:" + stopsList.ElementAt(i).Value.stopY +
                                  "\tEP_ID:" + stopsList.ElementAt(i).Value.EP_ID +
                                  "\tstudentCount:" + stopsList.ElementAt(i).Value.studentCount);
            }
        }//end public void scan()
 public void Join(stops stops)
 {
     this.Values.ToList().ForEach(trip => trip.Values.ToList().ForEach(stop_time => stop_time.stop = stops[stop_time.stop_id]));
 }
        public HttpResponseMessage saveStops(stops s)
        {
            LogTraceWriter traceWriter = new LogTraceWriter();

            traceWriter.Trace(Request, "0", TraceLevel.Info, "{0}", "saveStops credentials....");
            SqlConnection conn = new SqlConnection();

            try
            {
                //connect to database

                //connetionString="Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
                conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["btposdb"].ToString();
                //conn.ConnectionString = "Data Source=localhost;Initial Catalog=MyAlerts;integrated security=sspi;";
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "InsUpdelStops";
                cmd.Connection  = conn;
                conn.Open();


                SqlParameter sId = new SqlParameter("@Id", SqlDbType.Int);
                sId.Value = s.Id;
                cmd.Parameters.Add(sId);

                SqlParameter sName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
                sName.Value = s.Name;
                cmd.Parameters.Add(sName);
                SqlParameter sDescription = new SqlParameter("@Description", SqlDbType.VarChar, 50);
                sDescription.Value = s.Description;
                cmd.Parameters.Add(sDescription);
                SqlParameter Code = new SqlParameter("@Code", SqlDbType.VarChar, 50);
                Code.Value = s.Code;
                cmd.Parameters.Add(Code);
                SqlParameter sActive = new SqlParameter("@Active", SqlDbType.Int);
                sActive.Value = s.Active;
                cmd.Parameters.Add(sActive);

                SqlParameter srcLat = new SqlParameter("@latitude", SqlDbType.VarChar, 15);
                srcLat.Value = s.srcLat;
                cmd.Parameters.Add(srcLat);

                SqlParameter srcLon = new SqlParameter("@longitude", SqlDbType.VarChar, 15);
                srcLon.Value = s.srcLon;
                cmd.Parameters.Add(srcLon);

                SqlParameter insupdflag = new SqlParameter("@insupdflag", SqlDbType.VarChar, 10);
                insupdflag.Value = s.insupdflag;
                cmd.Parameters.Add(insupdflag);


                cmd.ExecuteScalar();

                conn.Close();
                traceWriter.Trace(Request, "0", TraceLevel.Info, "{0}", "saveStops Credentials completed.");

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                string str = ex.Message;
                traceWriter.Trace(Request, "1", TraceLevel.Info, "{0}", "Error in saveStops:" + ex.Message);
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
        }