コード例 #1
0
        public OperationResult SaveRoute(Route route)
        {
            OperationResult result = new OperationResult();

            var routeDetails = new DataTable();

            routeDetails.Columns.Add("RouteID", typeof(int));
            routeDetails.Columns.Add("Username", typeof(string));
            routeDetails.Columns.Add("Title", typeof(string));
            routeDetails.Columns.Add("Description", typeof(string));
            routeDetails.Columns.Add("Speed", typeof(float));
            routeDetails.Columns.Add("StartTime", typeof(string));
            routeDetails.Columns.Add("EndTime", typeof(string));
            routeDetails.Columns.Add("Distance", typeof(float));
            routeDetails.Columns.Add("WeatherInfo", typeof(string));

            var routePoints = new DataTable();
            routePoints.Columns.Add("latitude", typeof(Double));
            routePoints.Columns.Add("longitude", typeof(Double));

            routeDetails.Rows.Add(new Object[] {route.routeid,route.username,route.title,route.description,route.speed,route.starttime,route.endtime,route.distance,route.weatherinfo});
            foreach (RoutePoint point in route.pointCollection)
            {
                routePoints.Rows.Add(new Object[] {point.latitude,point.longitude});
            }
            try
            {
                using (con = new SqlConnection(connectionString))
                {
                    con.Open();
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "sp_insertRoute";
                        var routeParam = cmd.Parameters.AddWithValue("@route", routeDetails);
                        var routePointsParams = cmd.Parameters.AddWithValue("@routePoints", routePoints);

                        routeParam.SqlDbType = SqlDbType.Structured;
                        routePointsParams.SqlDbType = SqlDbType.Structured;

                        SqlParameter result_param = new SqlParameter("@result", SqlDbType.Int);
                        result_param.Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(result_param);

                        cmd.ExecuteNonQuery();
                        int status = Convert.ToInt32(result_param.Value);
                        if (status == 1)
                        {
                            result.status = true;
                            result.Message = "Saved Route Successfully";
                        }
                        else if (status == 0)
                        {
                            result.status = false;
                            result.Message = "Exception in Procedure";
                        }
                        else if (status == 2)
                        {
                            result.status = false;
                            result.Message = "Duplicate";
                        }
                        else if (status == 3)
                        {
                            result.status = false;
                            result.Message = "Invalid User";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.status = false;
                result.Message = ex.Message;
                sEvent = ex.Message;
                if (!EventLog.SourceExists(sSource))
                    EventLog.CreateEventSource(sSource, sLog);
                EventLog.WriteEntry(sSource, sEvent);
                EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Error, 234);
            }
            return result;
        }
コード例 #2
0
 public string getRoutesNew(Route route)
 {
     return route.title;
 }