Loop in Visual Query (or other solution) - 2sxc

Hello 2sxc / SIC fans!
A little help would be appreciated on that ...
I use JavaScript Kendo UI components to display data in a grid. These data are transcribed in Json in order to benefit from the connection on the data source of a hierarchical grid.
On the one side, I have an "employees" table with their attributes { id, lastName, firstName, email }. On the other hand, I have a list of training "events" { id, date, title, level }.
So, I would like to add the date and title of the last training received into the attributes of each person. So I would like the output Json to be after processing { id, lastName, firstName, email, dateLastTraining, titleLastTraining }.
One solution would be to re-manipulate the Json objects once I retrieve them in Razor but I would like to know if it was possible to do it directly at the source in the Visual Query.
I doubt this can be done because there should be a concept of loop (for each employee, filter the trainings according to the Id, sort them in order of date and take the Top1) and I think that there is no such possibility.
Am I wrong or would there be a solution to do that in Visual Query?
Thanks for your help !

Basically what you want is a kind of join-operation. ATM (2sxc 9.14) this isn't possible in visual query.

Related

Jdeveloper query form

I'm trying to create an adf query panel with table but I need to limit the search values as also the result values in the table.
For example:
- I have a table with FName, LName, Dateofbirth, address, phone
- I want that the values presented in the search form are FName, Lname
- the values in the result table Fname, Lname, address, phone
I've checked several links including this one enter link description here
But I can't understand how to limit the values.
There are lot of resources available on the internet on how to implement search functionality in ADF. here are few for your reference:
http://www.baigzeeshan.com/2010/04/creating-simple-search-form-in-oracle.html
https://www.youtube.com/watch?v=LAWSfO-7xR8
http://adfnote.blogspot.com/2013/02/create-simple-search-form-in-oracle-adf.html
Normally a search functionality is implemented using a View Critreia, which is created on a View Object. It shows up in Data Control as a Named Criteria under your View Object instance.
While creating the view criteria you can specify the items that you would want to see in the panel as search fields.
When you use (drag and drop) your view criteria as an 'ADF Query Panel with Table' on a page, you get the option to specify the columns you want to see in the results table. You can restrict the number of columns there, or even afterwards by just removing the unwanted columns from your page.
I was able to make it work, by not checking the attribute option 'Queryable'.
This way the it does not appear in the query form,only in the results table.
Thank you all for your help

Storing item currencies in SQLite database

I'm building out a schema for a site that will need to store a product's currency. I'm not sure whether I'll be needing to be able to convert from one currency to another, however, I'm presuming that will probably be necessary. My db schema is below. (this is for a mobile app btw). My question is, should I just simplify things by adding an additional column called currency to my item table? Does my design make sense? Thank you.
Edit (based on reply from Victor below): the items have a many-to-many relationship with order table. How about putting the currency id on order table since most likely all items in an order will be in the same currency?
exchange_rates
id
currency_from
currency_to
ex_rate
item_currencies
currency_id
item_id (from items/products table)
currencies
id
code
symbol
The schema looks good but I think that the *item_currencies* table is not necessary.
In your items table you can just add the currency_id column. Keep it together with all the item properties :)

help designing autocomplete response's

I want my autocomplete to be very user friendly.
I have products that people will search for by:
part#
manufacturer
e.g. searches
HND123
Honda 123
So basically each manufacturer has a short form and a long form.
How should I build my search index so when the autocomplete needs to fetch the data from the db, it will return results for both types of queries?
I would do this as a UNION, even if you have the same table. Assuming that you are searching in two different columns.
SELECT PartNumber AS Term FROM Parts WHERE PartNumber LIKE 'input%'
UNION
SELECT Manufaturer AS Term FROM Parts WHERE Manufactuer LIKE 'input%

Passing Lists as a QueryString - should I use JSON

Lets say I've got an online dating site, users can filter the user list based on various criteria, Height, Age, BodyType, Ethnic Origin....
I want to pass the criteria to the pager, via QueryString. Height and Age are easy as these are ranges, and I would use
MinHeight=3&MaxHeight=12&MinAge=21&MaxAge=30
However other Criteria like BodyType and Ethnic orgins are Lists of ForeignKey values e.g:
Ethnitity:2,3,5
What is the best way to pass these as a QueryString? Should I convert it to a Json string eg:
www.site.com?filterjson={\"minage\":0,\"maxage\":0,\"minheight\":0,\"maxheight\":0,\"bodytypelist\":[1,2,3],"ethnicitylist\":[2,3,4],\"eyecolorlist\":[],\"haircolorlist\":[],\"orientationlist\":[]}
Or is this not-valid/overkill/too complex?
Maybe something like this:
MinHeight=3&MaxHeight=12&bodytypes=1,2,3&
and parse the list values by splitting the ','?????
I don't know the ups and downs of all these ideas. So how would you pass a list of values in a querystring?
Using comma-separated values is the most pragmatic approach in my opinion. You can use this code to split values:
if (!string.IsNullOrEmpty(Request.QueryString["bodytypes"]))
{
string[] rgs = Request.QueryString["bodytypes"].Split(new char[] { ',' });
}
Both will work, though querystring is much easier to be 'hacked'. However if you have it well protected from malicious/unexpected values, I say it's fine.
Consuming data via querystring is relatively more straightforward than from JSON.

Asp.Net Sql Auto-Increment for Wall Post

I have a table that contains three columns.
"UserId" type-nvarchar
"PostAuthorId" type-nvarchar
"Post" type-text
This table will contain "wall" posts like in facebook for each user's page. I am going to use a gridview on each user's page to display the posts. The issue is I want to display them with the latest(most current) post being first and the earliest post being last.
I have never used autoincrement before and I am not sure if that is the answer. If it is, I do not know how to use it. I thought about adding a date posted column and then ordering by date.
If I end up using the date column, I could also display the date on the post. Is there a way to convert the date to a readable format?
What is the best way of implementing this type of ordering?
If you use AutoIcrement the first record will start with 1 and each record will increment from there. (default setting)
If you want to sort them by newest first do an ORDER BY ID DESC
I would suggest making a column called wallPostID then setting that to AutoIncrement and also your Primary Key
Date Formating:
If you are displaying this data in a gridView
Go to Edit Columns on your grid view
CLick on the Date field under "Selected Fields" on the bottom left
Under "BoundField properties" on the right Go to Data -> DataFormatString
{0:d} will display as 1/1/2010
This site has more info in string formatting
http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
A datetime column would definitely work for something like this. Assuming you are using MS-SQL, you can also attach a default value to the column using a built-in function like GETDATE(). That way, you only have to input the data that matters and the database will take care of adding the datetime column.
For converting a datetime to a readable format try:
DateTime postDate;
string value = postDate.ToShortDateString();
You should always use an ID field that auto increments. Can also be used as your PK
I would suggest the DateTime field rather than the autoincrement simply because it will not only serve as an effective Sort field, it also preserves information that you may well want to display. If you want the most recent first you'll sort using the Date and a "DESC" modifier:
Select ... Order By [Date] DESC;
When you retrieve the data, you can retrieve it as a DateTime and modify it using C#. You can use "ToShortDateString()" as suggested by mdresser if you just wish to show the date or ToString("...") if you wish to show the time as well. You can also use SQL to convert it into a string before retrieving it:
convert(Varchar(10), #mydatetime, 101)
If you look in MSDN you'll see the various conversion codes (101 is the code used above) that can be used to translate the date in various ways.
UPDATE: You may want to use an autoincrementing field for your application for reasons other than your expressed need to sort wall entries. They are easy to use - just mark the field as an Identity if using SQL Server (other DBs are similar). As far as using them in your program, just think of the field as an Int field that you never have to set.
Now, why would you use a auto-incrementing field? Perhaps the most straightforward reason is so that they give you have an easy way to identify each record. For example, if you permit people to alter or delete their wall entries, the auto-incrementing field is ideal as it gives you a way to easily look up each record (each record will be assigned its own, unique value). You might put an "x" next to the record like StackOverflow does and make it a call back with the UID (auto-increment) value. Note that you should set up your primary key on the UID field if you'll be doing this.
Now, if you find them useful for this reason then you could also sort by the UID. I would still store the date so that you can provide Date and Time feedback as to when an entry was made on the wall but this would no longer be your indexed or sorted field.

Resources