Page 1 of 1
How to Display all fields/records of a Recipe on a Grid
Posted: Fri Jan 25, 2013 2:45 am
by andrea
Hello,
we are creating a receipt with addtional fields as you can see in attached image (Recipe.jpg).
Then we would like to display and eventually modify all fields (name, date, note, watchdog) of the receipt on a grid in a screen.
Is it possible? How?
Thank you
Re: How to Display all fields/records of a Recipe on a Grid
Posted: Fri Jan 25, 2013 2:53 am
by andrea
We are writing a code like this
List<string> myRecipeNames;
myRecipeNames = Globals.Constant1.FieldNames;
//List<Receipt> listReceipt1;
Recipe myRecipe = Globals.Constant1;
List<Receipt> listReceipt = new List<Receipt>();
foreach( string i in myRecipeNames) {
listReceipt.Add(new Receipt(){
Name = i,
Note = "Programming C#",
Date = new DateTime(1982, 4, 12),
WatchDog = true
});
}
I can scroll and update the name but cannot read and update other fields created by us...
I know that that there is this possibility (using Intellisense)
Globals.Constant1.Date;
Globals.Constant1.Note;
Globals.Constant1.WatchDog;
but not how to integrate it in my cycle.
Thank you
Re: How to Display all fields/records of a Recipe on a Grid
Posted: Fri Jan 25, 2013 9:49 am
by mark.monroe
In the Recipe Tag configuration you associate a Recipe Item with a tag. In your case "Date" has been associated with SystenTagDateTime. Which means that when you save a Recipe, the value at that point in time will be saved to a column in a database called "Date".
You can create recipes during design time by adding them to the Runtime Data tab. The Runtime Recipe Title is the name of the recipe that shows up when the operator runs the Load Recipe action.
If you want to create recipes at runtime through script you would set the value of the tags associated with your recipe items, then save the recipe using a name.
Code: Select all
Globals.Tags.WatchDog_Recipe.Value = 12344;
//Now save the recipe and it will add the new recipe and the Watchdog
//recipe item will have a value of 12344 in the recipe called MyNewRecipe
Globals.Recipe1.SaveRecipe("MyNewRecipe");
Re: How to Display all fields/records of a Recipe on a Grid
Posted: Fri Jan 25, 2013 10:03 am
by andrea
My main problem is not to add a new receipt programmatically but to display all fields compiled in a grid as in attached image.
Re: How to Display all fields/records of a Recipe on a Grid
Posted: Fri Jan 25, 2013 12:19 pm
by mark.monroe
To get at the values of each individual recipe saved, you are going to need to access the database where all the recipes are stored. Here is a
forum thread on how to write SQL queries. The recipes are stored in the same database, the table is named the same as your recipe group is named, table name would be "Constant1".
You might also want to take a look at the iX
database viewer, it allows you to list the values in a table on a iX HMI.
Re: How to Display all fields/records of a Recipe on a Grid
Posted: Mon Jan 28, 2013 8:31 am
by andrea
Thank you, is this the only one solution?
Do I have in some properties/tag the entire connection string of local SQL database or do I have create a new tag for it?
Re: How to Display all fields/records of a Recipe on a Grid
Posted: Mon Jan 28, 2013 8:59 am
by mark.monroe
There is no connection string tag. If you want one you will have to create it and populate it with the correct information.
This is the connection string code from the Database script example provide in the previously mentioned thread.
Code: Select all
// Create a new sql connection object.
m_SqlConnection = new SqlCeConnection();
// Specify the connectionstring, with the full path to the database.
m_SqlConnection.ConnectionString = string.Format("data source={0}", Path.Combine(ExcecutingPath, "Database.sdf"));