This topic is locked
[SOLVED]

 Disable Record Editing and Additon of Child Tables

2/6/2018 7:11:25 PM
ASPRunner.NET General questions
I
i.NoLim author

I have 3 tables: Family, Applicant, Charges. All these tables contain a column called "Status." Their relationship is a follows:
Master | Child | Linked Field

Family - Applicant - Family_ID

Applicant - Charges - Applicant_ID
Right now I have so that when the "Status" changes for the master table the "Status" for the child tables also changes.
For example, if the "Status" for Applicant C changes from 'Active' to 'Inactive' all the "Charges" that share that same 'Applicant_ID' become 'Inactive' as well.
Now I would like it so that when the status of the Master table is set to 'Inactive' the "Edit," "Inline Add," and "Add new" buttons for the child entries that have that same "Family_ID" and/or "Applicant_ID" are disabled.
For example if I set the "Status" for the Jones family, I would not be able to edit or add new Applicants or Charges to this family.
I saw this, but I'm not sure how to apply it to the child tables.
https://xlinesoft.com/asprunnerpro/docs62/disable_record_editing.htm

jadachDevClub member 2/7/2018

On the Is Record Editable for your table you can add code similar to this:

if (values["Status"] == "Inactive")

return false;

else

return true;


As far as adding new reocrds, you will need to do something like this on your child list pages:
ListPage Before Process

XVar data = pageObject.getMasterRecord();

if (data != null)

{

string strSQLExists = "select * from dbo.Family where Family_ID='"+data["Family_ID"].ToString()+"' and Status='Inactive'";

XVar rsExists = CommonFunctions.db_query(strSQLExists, null);

XVar data1 = CommonFunctions.db_fetch_array(rsExists);

if(data1)

{

pageObject.setProxyValue("AddRecord", 1);

}

else

{

pageObject.setProxyValue("AddRecord", 0);

}

}


ListPage JavaScript Onload

var id = "addButton";

var button = $("[id^=" + id + "]");

if (proxy['AddRecord']==1){

button.hide();

}
var id = "inlineAdd";

var button1 = $("[id^=" + id + "]");

if (proxy['AddRecord']==1){

button1.hide();

}


This may not work exactly for you as is, but it should get you going in the right direction.

I
i.NoLim author 2/7/2018



On the Is Record Editable for your table you can add code similar to this:

if (values["Status"] == "Inactive")

return false;

else

return true;


As far as adding new reocrds, you will need to do something like this on your child list pages:
ListPage Before Process

XVar data = pageObject.getMasterRecord();

if (data != null)

{

string strSQLExists = "select * from dbo.Family where Family_ID='"+data["Family_ID"].ToString()+"' and Status='Inactive'";

XVar rsExists = CommonFunctions.db_query(strSQLExists, null);

XVar data1 = CommonFunctions.db_fetch_array(rsExists);

if(data1)

{

pageObject.setProxyValue("AddRecord", 1);

}

else

{

pageObject.setProxyValue("AddRecord", 0);

}

}


ListPage JavaScript Onload

var id = "addButton";

var button = $("[id^=" + id + "]");

if (proxy['AddRecord']==1){

button.hide();

}
var id = "inlineAdd";

var button1 = $("[id^=" + id + "]");

if (proxy['AddRecord']==1){

button1.hide();

}


This may not work exactly for you as is, but it should get you going in the right direction.


Thank you very much! As usual, you are a lifesaver jadach!
I modified the first code to look like this,


string strSQLExists = "select * from dbo.Family where Family_ID='"+values["Family_ID"].ToString()+"' and Status='Inactive'";

XVar rsExists = CommonFunctions.db_query(strSQLExists, null);

XVar data1 = CommonFunctions.db_fetch_array(rsExists);

if(data1)

{

  return false;

}

else

{

  return true;

}


I'm leaving it open until tomorrow, hopefully I don't run into issues.

I
i.NoLim author 2/8/2018

There's is an issue when disabling "Add New" and "Inline Add". If I select an 'Inactive' "Applicant" not only does it disable adding new "Charges" (which is perfect) but it also disables the addition of a new "Family."

I added a few screen shots for clarity.
"Add New" and "Inline Add" for "Family" when an 'Active' "Applicant" is selected.


"Add New" and "Inline Add" are disabled for "Family" when an 'Inactive' "Applicant" is selected.


The following two pictures show the actual "id" is different for those buttons.


A
Arkie 2/8/2018

Take a look at your line of code:

string strSQLExists = "select * from dbo.Family where Family_ID='"+values["Family_ID"].ToString()+"' and Status='Inactive'";

======

It appears to me that you should be comparing the inactive status to the Applicant ID, not the Family ID. Or perhaps even both IDs. Otherwise your code is doing exactly as it is programmed to do.
I could be reading this wrong, so just go about your biz and ignore this if I am... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=84302&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

I
i.NoLim author 2/8/2018



Take a look at your line of code:

string strSQLExists = "select * from dbo.Family where Family_ID='"+values["Family_ID"].ToString()+"' and Status='Inactive'";

======

It appears to me that you should be comparing the inactive status to the Applicant ID, not the Family ID. Or perhaps even both IDs. Otherwise your code is doing exactly as it is programmed to do.
I could be reading this wrong, so just go about your biz and ignore this if I am... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=84303&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />



I do have

string strSQLExists = "select * from dbo.Applicant where Applicant_ID='"+data["Applicant_ID"].ToString()+"' and Status='Inactive'";


but in the Charges' "List page: Before process" event. I cant compare it to Applicant_ID in the Applicant's "List page: Before process" event because the Family table doesn't have a "Applicant_ID" field.