I have two Tables where one specifies a parent - child relationship among records of the other.
I would like to have a view where I have a grid with all entries of the main table and when I select an entry I would like to get a second grid with all the child entries.
I can't link the two datasources in form or I get the error "menu item could not be shown". What I've researched is that I need to "clear the link and build it manually in the init method". I can't figure out how though.
If I do this:
QueryBuildDataSource dsRole;
QueryBuildDataSource dsSubRole;
dsRole = securityRole_ds.query().dataSourceTable(tableNum(SecurityRole));
dsSubRole = dsRole.addDataSource(tableNum(SecuritySubRole));
dsSubRole.addLink(fieldNum(SecurityRole, RecId), fieldNum(SecuritySubRole, SecurityRole));
dsSubRole.joinMode(JoinMode::InnerJoin);
dsSubRole.fetchMode(QueryFetchMode::One2Many);
it runs but I get duplicate entries in the main grid.
I've also tried various variations on this:
QueryBuildDataSource dsRole;
QueryBuildDataSource dsSubRole;
dsRole = securityRole_ds.query().dataSourceTable(tableNum(SecurityRole));
dsSubRole = SecuritySubRole_ds.query().dataSourceTable(tableNum(SecuritySubRole));
dsSubRole.clearLinks();
dsSubRole.addLink(fieldNum(SecurityRole, RecId), fieldNum(SecuritySubRole, SecurityRole));
dsSubRole.joinMode(JoinMode::InnerJoin);
dsSubRole.fetchMode(QueryFetchMode::One2Many);
But these always produce the error
Related
I have the following LINQ to Entities call to fill a collection variable:
var insuredFamily = db.Insureds.Where(x => x.ssn.Split('-')[0] == tmp[MemberId])
.OrderBy(x => x.fk_relation);
How would I go about looping through the items in the collection printing out both the item header and the item value for each row?
I'm new to LINQ to Entities, so all I'm trying to do is loop through a built collection and output the headers and rows to a log file so that I can quickly see what is being returned in the collection without resorting to stepping through each row in the debugger. Is this possible?
If a generic loop is not possible, is it possible to set the data source of a data grid to the collection variable and view the collection in a grid?
For starters, this can't be a LINQ-to_Entities statement. There's no way to translate x.ssn.Split('-')[0] == tmp[MemberId] into SQL. Unless this is EF-Core, that automatically switches to client-side evaluation when the expression contain not-supported part. You're not explicit about that.
Anyway, it's overkill to add logging just to see the content of a collection while debugging. You can use the immediate window in Visual Studio to output data when the code stops at a break point.
To make this really helpful, override the Insured class's ToString method. When I do this with just some Product class ...
public override string ToString()
{
return string.Format("{0}, {1}", this.Name, this.UnitPrice);
}
... and break in the debugger right after a line like ...
var prod = context.Products;
.. then in the immediate window I can type ...
?prod.ToList()
... which gives me:
Count = 6
[0]: {Nike Air, 150.00}
[1]: {Web cam, 23.00}
[2]: {Mouse, 7.00}
[3]: {Cool pack, 4.50}
[4]: {Keyboard, 47.30}
[5]: {Action cam, 73.00}
(and some SQL logging)
Note that this is invasive debugging. By calling ToList, the query is forced to execute. This may change the state in a way that it affects the code's behavior. The same would hold for logging though.
Thank you for all the advice, but it looks like the following two lines of code will do what I need. I just wanted to visualize the results of my LINQ to SQL queries.
var nationalities = db.Nationalities.OrderBy(x => x.pk_Nationality);
dgvResults.DataSource = nationalities;
This code will simply put the collection into the data source of my data grid view allowing me to see all the contents.
Zoho Creator is a great system for quickly creating simple cloud applications. I've run into a problem with sub-forms, though: currently, Zoho Creator does not provide functionality for sorting sub-form records by a specified column. Instead, it sorts records in the order in which they were added.
My sub-form is a Creator Form that's linked to another Creator Form (basically, 2 different tables). The forms are linked with a bi-directional lookup relationship.
I've seen and tried implementing these "hacks", but none of them work for my situation:
[Zoho Forums, "Subforms sorting rows"][1]
[Zoho Forums, "Hack to sort rows of a subform and pre-populate row fields that I want to preset"][2]
I also called Zoho tech support, and after looking at my application, they said that sorting sub-form records is not currently possible.
Any other ideas?
My tested solution is still a hack, but until Zoho implements a method to sort sub-form records via the GUI, this will have to do.
First, create a function that you can call from anywhere (e.g. when a new sub-form record is added or changed)--for details on that, go here: http://www.zoho.com/creator/help/script/functions.html
This function will first duplicate the sub-form records by the parent record ID (sorting by the appropriate column) and then delete all sub-form records that were inserted before the script started:
int SubFormRecords_SortByAnything_ReturnCount(int ParentRecordID)
{
scriptStartTime = zoho.currenttime;
for each rSubFormRecord in SubFormRecords [ParentFieldName = input.ParentRecordID] sort by FieldName1, FieldName3, FieldName2
{
NewSubFormRecordID = insert into SubFormRecords
[
FieldName1 = rSubFormRecord.FieldName1
FieldName2 = rSubFormRecord.FieldName2
FieldName3 = rSubFormRecord.FieldName3
];
}
delete from SubFormRecords[ (Series == input.ParentRecordID && Added_Time < scriptStartTime) ];
return SubFormRecords[ParentFieldName == input.EventID].count();
}
Once the above sorting function is in place (customized for your application), call it when appropriate. I call it when adding a record associated with the sub-form, or when I change the sorting column values.
That works well, and as long as you don't have complex logic associated with adding and deleting records, it should have minimal impact on application performance.
Please let me know whether that works for you, and if you have any better ideas.
Caveat: This solution is not suitable for forms containing additional sub-form records because deleting the records will delete linked sub-form values.
Thanks.
I have a a very simple workaround:
1) You have to add a Form Workflow
2)Record Event - Create OR Edit OR Create/Edit (As per your requirement)
3)Form Event - On successful form submission
4)Let Main_Form be the link name of the Main Form
4)Let Sub_Form be the Link name of the Sub Form (Not the link name you specify in the main form for the same sub form)
4)Let Field1 and Field2 are fields of subform on which you want to sort subform records
5)Let Link_ID be lookup field of Mainform ID in the subform
Workflow
1)Sub_Records = Sub_Form[Link_ID == input.ID] sort by Field1,Field2;
(sort by multiple fields, add asc/desc as per requirement)
2)delete from Sub_Form[Link_ID == input.ID];
3)for each sub_record in Sub_Records
{
insert into Sub_Form
[
Added_User = zoho.loginuser
Link_ID = input.ID
Field1 = sub_record.Field1
Field2 = sub_record.Field2
]
}
//Now you check the results in edit view of the main form
I have a "task" table, which has a "sub category". The sub category is related to a Category. A category has many sub categories, but my task item only stored the sub category id (The category can be deduced from this).
So, my entity framework seems to understand this relationship.
But, my link is failing.
public TaskObject GetTask(int taskId)
{
var item = (from t in _te.tasks.Include("r_sub_category").Include("r_category").Include("r_priority").Include("r_state").Include("assigned_person").Include("create_person").Include("update_person") where t.task_id == taskId select t).FirstOrDefault();
return Transformer.UnpackTask(item);
}
There is a r_category table, and entity object, but when I run this, it tells me:
A specified Include path is not valid. The EntityType 'taskerModel.task' does not declare a navigation property with the name 'r_category'.
And that's correct - r_category is linked to my r_sub_category table... and not directly to task. Is there a way to load the r_category?
Or, maybe this Include is lazy, and I should be doing some sort of Joining myself? Maybe more efficient?
You need to show the full path with dot Notation so im guessing it would be
"r_sub_category.r_category".
And so forth
On my grid, after a user enters text on the bottom row, I am adding another row so they can fill out another row if needed. The grid will grow as needed by the user. This is working fine, however after a page reload and populating from db, the addrowdata() function does not honor existing row ids and creates duplicates, starting from 1 again, e.g. jqg1. It should look at existing row ids and create new unique ids. So if I have 5 rows already, it might start at jqg6. Here is the relevant code inside onCellSelect:
var records = jQuery("#table-1").jqGrid('getGridParam', 'records');
var lastRowId = jQuery("#table-1").jqGrid('getDataIDs')[records - 1];
if (lastRowId == id)
{
jQuery('#table-1').addRowData(undefined, {}, 'last');
}
I have also tried $.jgrid.randId() instead of undefined, same results as expected.
Thanks
Ryan
I think that the error is in the part where you fill grid with the data from the database. The data saved in the database has unique ids. The ids are not in the form jqg1, jqg2, ... So if should be no conflicts. You should just fill the id fields of the JSON with the ids from the database.
One more possibility is that you just specify the rowid parameter (the first parameter) of addRowData yourself. In the case you will have full control on the new ids of the rows added in the grid.
The code of $.jgrid.randId function is very easy. There are $.jgrid.uidPref initialized as 'jqg' and $.jgrid.guid initialized to 1. The $.jgrid.randId function do the following
$.jgrid.randId = function (prefix) {
return (prefix? prefix: $.jgrid.uidPref) + ($.jgrid.guid++);
}
If it is really required you can increase (but not decrease) the $.jgrid.guid value without any negative side effects.
I am attempting to make an online store that sells DVDs, VHSs, CDs and Digital Products. The Digital Products will be broken down into singles.
I have created two (2) Product Parents: "Product" and "Product Singles"
"Product" has three (3) Children: "DVD", "CD" and "Download"
"Product Singles" has three (4) Children: "Track1", "Track2", "Track3" and "Track4"
In "Product"s Extra IDs field I input the Product ID of "Product Singles".
Now, my AddtoCart Form is listing all seven (7) Children.
I created a 2nd AdtoCart Form titled addtocart_form2.tpl.php which is an exact copy of addtocart_form.tpl.php
In the ps_product_attribute.php file, I created a duplicate function called list_attribute_list2 which controls the list that appears in the AddtoCart Form.
I had my Flypage show addtocart_form.tpl.php in the top right and blocked out the code that would add the Extra IDs. It worked.
I had my Flypage show addtocart_form.tpl.php at the bottom. It worked.
Now, I'd like to change the code on addtocart_form2.tpl.php to allow for ONLY the Extra ID Children to appear.
But this is where I'm stuck, I don't know how to change the code to ONLY show the Extra IDs Children and NOT the Parent "Product"s Children.
Any help would be appreciated.
In the shop.product_details.php file:
I created a second instance of the variable $q and caled it $q2
after $db_product->query( $q ); ran the query on the Database, $db_product was now set as the entire row where 'product_id' = $product_id
Then I inserted the following code:
$product_id2_str = $db_product->f("child_option_ids");
$product_id2_arr = explode(",",$product_id2_str);
$product_id2 = intval($product_id2_arr[0]);
$db_product2 = new ps_DB;
In other words, I fetched 'child_option_ids' as a string, then created an array. Then, I transferred the first number in the array to $product_id2.
After that, I pretty much just made copies of anything where $product_id was important.
If you need more help, I guess just comment and I'll write the rest, but this was the main problem I was having.