internal string ReportAccident(string AccLoc)
        {
            string Response = "Failed";


            using (SqlConnection con = new SqlConnection(SqlConnect.GetConnectionString()))
            {
                try
                {
                    con.Open();

                    SqlCommand cmd = new SqlCommand("INSERT Into Accident (Location,DriverName,DriverId,VehicleId,VehicleNO) Values (@Location,'Varun',1,1,'KL-0167')", con);
                    cmd.Parameters.AddWithValue("@Location", AccLoc);
                    cmd.ExecuteNonQuery();
                    Response = "Accident reported successfully";
                }
                catch (Exception ex)
                {
                    Response = ex.Message;
                }
                finally
                {
                    con.Close();
                }
            }

            return(Response);
        }
        internal string ReportAccident(string Longitude, string Latitude)
        {
            string Response = "Failed";
            string AccLoc   = "Thiruvanathapuram";//Default set to Trivandrum,We are not considering location here ,we use latitude and longtitude

            //So we basically not want to leave the location as blank

            using (SqlConnection con = new SqlConnection(SqlConnect.GetConnectionString()))
            {
                try
                {
                    con.Open();

                    SqlCommand cmd = new SqlCommand("INSERT Into Accident (Location,Latitude,Longitude,DriverName,DriverId,VehicleId,VehicleNO) Values (@Location,@Latitude,@Longitude,'Varun',1,1,'KL-0167')", con);
                    cmd.Parameters.AddWithValue("@Latitude", Latitude);
                    cmd.Parameters.AddWithValue("@Longitude", Longitude);
                    cmd.Parameters.AddWithValue("@Location", AccLoc);
                    cmd.ExecuteNonQuery();
                    Response = "Accident reported successfully";
                }
                catch (Exception ex)
                {
                    Response = ex.Message;
                }
                finally
                {
                    con.Close();
                }
            }

            return(Response);
        }
        public Location Get()
        {
            string localLoc     = "NIL";
            int    AccidentId   = 0;
            string GetLongitude = "NIL";
            string GetLatitude  = "NIL";

            using (SqlConnection con = new SqlConnection(SqlConnect.GetConnectionString()))
            {
                try
                {
                    con.Open();
                    //currently we are taking top 1 but later we will take particular driver location accidents only
                    SqlCommand    cmd = new SqlCommand("select TOP 1 Location,Accident,Longitude,Latitude from Accident WHERE IsExpired=0 order by 1 desc", con);
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            localLoc     = rdr["Location"].ToString();
                            AccidentId   = Convert.ToInt32(rdr["Accident"]);
                            GetLongitude = rdr["Longitude"].ToString();
                            GetLatitude  = rdr["Latitude"].ToString();
                        }
                    }
                    rdr.Close();
                    rdr.Dispose();
                    DeleteAfterPLot(AccidentId, con);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    con.Close();
                }
            }


            Location objLocation = new Location
            {
                Latitude  = GetLatitude,
                Longitude = GetLongitude,
                Address   = localLoc
            };

            return(objLocation);
        }
        public string Get()
        {
            string Location   = "NIL";
            int    AccidentId = 0;

            using (SqlConnection con = new SqlConnection(SqlConnect.GetConnectionString()))
            {
                try
                {
                    con.Open();
                    //currently we are taking top 1 but later we will take particular driver location accidents only
                    SqlCommand    cmd = new SqlCommand("select TOP 1 Location,Accident from Accident order by 1 desc", con);
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        while (rdr.Read())
                        {
                            Location   = rdr["Location"].ToString();
                            AccidentId = Convert.ToInt32(rdr["Accident"]);
                        }
                    }
                    rdr.Close();
                    rdr.Dispose();
                    //Delete once we plot the location
                    var cmdDelete = new SqlCommand("Delete from Accident Where Accident=@Accident ", con);
                    cmdDelete.Parameters.AddWithValue("@Accident", AccidentId);
                    cmdDelete.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    con.Close();
                }
            }

            return(Location);
        }
 public bool UserAuthenticate(string Username, string Password)
 {
     using (SqlConnection con = new SqlConnection(SqlConnect.GetConnectionString()))
     {
         try
         {
             con.Open();
             SqlCommand cmd = new SqlCommand("Select * from AddDriver Where DriverName=@Username and Password=@Password", con);
             cmd.Parameters.AddWithValue("@Username", Username);
             cmd.Parameters.AddWithValue("@Password", Password);
             SqlDataReader rdr = cmd.ExecuteReader();
             return(rdr.HasRows);
         }
         catch (Exception)
         {
             throw;
         }
         finally
         {
             con.Close();
         }
     }
 }