I have search the net but as ASP.NET MVC syntaxing has changed so much I am at a loss never mind that I am still a noob at MVC.
I am using ASP.NET 4.5.1 and MVC 5.
I have the following LatLng fields in the Location table in the DB: Lat, Lng
I am not sure how to go about getting those co-ords out form there and putting them into this format:
//Co-ords for map polygon
var mapCoords = [
new google.maps.LatLng(-36.91353, 175.47578),
new google.maps.LatLng(-36.95565, 175.53483),
new google.maps.LatLng(-36.96309, 175.53603),
new google.maps.LatLng(-36.96944, 175.52556),
new google.maps.LatLng(-36.9717, 175.50633),
new google.maps.LatLng(-36.97321, 175.49363),
new google.maps.LatLng(-36.8898, 175.41553),
new google.maps.LatLng(-36.86936, 175.40866),
new google.maps.LatLng(-36.86728, 175.43612),
new google.maps.LatLng(-36.87668, 175.45054)
];
Thanks all
If you aren't already, you should use an ORM like Entity Framework for the data layer. That will take care of pulling the data from the Location table and providing it as a Location object for you.
Then you have multiple choices on how to set your mapCoords var, but one way is to perform a foreach (var location in Locations){} to iterate through and set the data for the mapCoords. You'll have the latitude and longitude as location.Lat and location.Lng.
Related
I am very new to programming in ActionScript3 and using SQLite. Currently I try to make an AIR application where it will handle from small to large dataset from excel, import into and calculate in AIR using ActionScript3 and stored the calculated data in SQLite.
Right now I have 2 question regarding using array to transfer data into SQLite
1. Is it possible to INSERT data or UPDATE data in SQLite without using looping?
In my AIR application, I have an object called DataInput in which have 62 variables/properties which will contain 62 different values from 62 columns in excel. I do know that if you create new instance of DataInput and push into array e.g arDataInput in loop, you can access each of the data in the array using arDataInput[i].variablename where i is the index of the array and variablename is the variables/properties of the object.
Obviously, right now I do actually using for loop to access the value of each cell in excel then calculate in AIR application before transfer the calculated data into SQLite, row by row within sql transaction.
Is there actually a way to transfer data in array into SQLite (either INSERT new row or UPDATE existing row) without using loop like INSERT INTO tblDataInputUW VALUES arDataInput given that each column name in SQLite table is the same as variables/properties of object within the array eg. SQLite table, tblDataInput have column name namePlat and array have variables/properties of arDataInput.namePlat?
2. Is it possible to split the data array i got from SQLite into multiple array without looping?
Right now, I use the following code to extract data from SQLite and stored as an array;
txtSQL = new String();
arData = new Array();
txtSQL = "SELECT namePlat, platLat, platLong FROM tblDataInput";
arData = getSQLData(txtSQL);
function getSQLData(text: String): Array
{
sqlCon.begin();
sqlStat = new SQLStatement();
sqlStat.sqlConnection = sqlCon;
sqlStat.text = text;
sqlStat.execute();
sqlCon.commit();
var result: SQLResult = new SQLResult();
var arData: Array = new Array();
result = sqlStat.getResult();
if (result != null)
{
arData = result.data;
}
return arData;
}
If my assumption are correct, I can access each of the value in arData by using arData[i].variablename where i is the index of the array and variablename is the table name within the SQLite table tblDataInput.
If there are way to split the data in arData into 3 different array e.g arNamePlat without using looping like arNamePlat = arData.variablename because I have many different chart to draw in my AIR application and each chart will have its own array to get value from.
Right now, I actually using different sql statement for different chart like;
txtSQL = new String();
arData = new Array();
txtSQL = "SELECT namePlat FROM tblDataInput";
arData = getSQLData(txtSQL);
dgNamePlat.dataProvider = new DataProvider(arData);
txtSQL = new String();
arData = new Array();
txtSQL = "SELECT platLat, platLong FROM tblDataInput";
arData = getSQLData(txtSQL);
dgPlatLatLong.dataProvider = new DataProvider(arData);
I use the same arData and txtSQL for each chart as I dont store the value anymore after the chart been drawn.
There are actually no restriction for me to just use for loop, I asking this question as I don't see any topic regarding on this question and as a self-learning programmer, I like to explore different way of coding and way to incorporate that knowledge into my projects.
The best way to send and receive data and do database stuff is through form submissions. AIR can POST regular form submissions like html pages but can also load a response. Regular serverside software like php handles the form submission, does whatever with the database, and returns data or simple success message.
The best way to handle data is to use XML (look into RESTful architecture for reasons why). PHP creates XML for the app. The xml gets loaded and should go into arrays of objects.
Here are some good links to get going on submitting data with forms and reading XML:
republic of code tutorials:
http://www.republicofcode.com/tutorials/flash/as3contactform/2.php
http://www.republicofcode.com/tutorials/flash/as3xml/
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestMethod.html
I have found many sample to create data in dynamics crm from a custom aspx page, but i need to update entity data.
any sample will be helpful.
Thanks
It's quite simple, when you create a record normally you use the following code:
Entity newContact = new Entity("contact");
contact["firstname"] = "John";
contact["lastname"] = "Smith";
service.Create(newContact);
If you need to update a record, you need to retrieve it first (using a Retrieve if you have the Guid, or a RetrieveMultiple if you need to find it using a query), after just update the fields.
Entity retrievedContact = service.Retrieve("contact", GuidOfTheRecord, ColumnsYouWantToRetrieve);
retrievedContact["firstname"] = "My New First Name";
retrievedContact["lastname"] = "My New Last Name";
service.Update(retrievedContact);
I have created a simple stored procedure in SQL Server 2008 as:
CREATE PROCEDURE viewPosts
AS
SELECT * FROM dbo.Post
Now, I have no idea how to use it in controller's action, I have a database object which is:
entities db = new entities();
Kindly tell me how to use stored procedure with this database object in Entity Framework.
For Details check this link:
http://www.entityframeworktutorial.net/data-read-using-stored-procedure.aspx
Hope this will help you.
See article about 30% in:
In the designer, right click on the entity and select Stored Procedure mapping.
Click and then click the drop down arrow that appears. This exposes the list of all Functions found in the DB metadata.
Select Procedure from the list. The designer will do its best job of matching the stored procedure’s parameters with the entity properties using the names. In this case, since all of the property names match the parameter names, it maps every one correctly so you don’t need to make any changes. Note: The designer is not able to automatically detect the name of the field being returned.
Under the Result Column Bindings section, click and enter variable name. The designer should automatically select the entity key property for this final mapping.
The following code is what I use to initialize the stored procedure, then obtain the result into variable returnedResult, which in this case is the record id of a newly created record.
SqlParameter paramResult = new SqlParameter("#Result", -1);
paramResult.Direction = System.Data.ParameterDirection.Output;
var addParameters = new List<SqlParameter>
{
new SqlParameter("#JobID", EvalModel.JobID),
new SqlParameter("#SafetyEvaluator", EvalModel.SafetyEvaluator),
new SqlParameter("#EvaluationGuid", EvalModel.EvaluationGuid),
new SqlParameter("#EvalType", EvalModel.EvalType),
new SqlParameter("#Completion", EvalModel.Completion),
new SqlParameter("#ManPower", EvalModel.ManPower),
new SqlParameter("#EDate", EvalModel.EDate),
new SqlParameter("#CreateDate", EvalModel.CreateDate),
new SqlParameter("#Deficiency", EvalModel.Deficiency.HasValue ? EvalModel.Deficiency.Value : 0),
new SqlParameter("#DeficiencyComment", EvalModel.DeficiencyComment != null ? EvalModel.DeficiencyComment : ""),
new SqlParameter("#Traffic", EvalModel.Traffic.HasValue ? EvalModel.Traffic.Value : 0),
paramResult
};
// Stored procedure name is AddEval
context.Database.ExecuteSqlCommand("AddEval #JobID, #SafetyEvaluator, #EvaluationGuid, #EvalType, #Completion, #ManPower, #EDate, #CreateDate, #Deficiency, #DeficiencyComment, #Traffic, #Result OUTPUT", addParameters.ToArray());
var returnedResult = paramResult.Value;
NewEvaluationID = Convert.ToInt32(returnedResult);
I'm developing an asp.net web-forms application with entity framework. There are two columns in my database table to add Latitude and Longitude. But I don't want to add two TextBoxes in user interface to add them.
I need to add one TextBox to add those data, separated by comma. (ex: 85.06000,25.01200). when user clicks submit button, I need to split this string up and add the result to Latitude and Longitude columns in database table.
I have created the form to insert data using DetailsView with TemplateField.
I'm new to asp.net and C#. How could I do this ?
string[] parts = txtInput.Text.Trim().Split(',');
string Latitude = parts[0];
string Longitude = parts[1];
now you have seperated them and you can send them to your DB.
To separate string on two parts you can use string.Split() method.
if you have variable latitudeandlongitude:
var splittedArray = latitudeandlongitude.Split(',');
if(splittedArray.Length!=2)
throw new ArgumentException();
var latitude = splittedArray[0];
var longitude = splittedArray[1];
But i'm not recommend you to do such things (use one textbox for two different variables). It will be source of user errors and they will hate you.
You can split the value like this :-
string[] arr=TextBox1.Text.Split(',');
and then prepare insert statement like :-
Insert into yourtable("Latitude","Longitude") values(arr[0],arr[1]);
I have created a PHP service in Flex Mobile and binded the result with a List. I want to sort the records from the service based on some calculation on data fields. So, is it possible to perform operations on the resultset from the PHP service ?
Detailed question:
I have created the php service through the built in tool in Flash Builder 4.6. I also had bind the service with a List in my view. (Again using GUI controls). Now I want to rearrange the items in the list based on distance from the current location and coordinates from the rows returned by the service. So the approach I was thinking was to, get the content from the service. Extract lat,lon and calculate the distance. Then update the list again.
I tried the following line in a function:
getAllplacesResult.lastResult[1].lon // lon is a column in the table.
But it returns a blank. Is their a more sane or easier way to do this ?
The better way is to assign it on an Arraycollection and manipulate data from there.
<mx:ArrayCollection id="myAC" source="{ArrayUtil.toArray(myRO.getAllplacesResult.lastResult)}" />
Make sure you bind myAC to your List.
Sort it the way you want to:
var collection:ArrayCollection = new ArrayCollection();
var s:Sort = new Sort();
s.fields = [new SortField("lat"), new SortField("lon")];
s.compareFunction = myCompareFunction;
collection.sort = s;
collection.refresh();
private function myCompareFunction(a:Object, b:Object, fields:Array = null):int {
...
}
Also, AS3 is 0 based index. 1 will actually give you the second row (or throw out of range exception)