Creating Variable Consants in Light switch RRS feed

  • Question

  • I want to know if the values for properties I enter in the development data base during debug mode are passed on and stay in the database after I publish so when installing future users will see those values. There are two reasons I want to do this. First is to provide a bit of starting original data when selecting summary property values and make sure there are values to select for summary properties that are required and when present due to relationships. Second there are properties I want to set as constants so this set of properties can be set as a default value using code and some of the properties passed on cannot be edited.

    I have accomplished the later second task by creating a set of properties and entering in one set of values while the add edit and delete buttons were enabled. After doing that the property that marks this set as the default value (a Boolean property marked as true) I made to be un-editable I set as a label only on the screen. Then I removed the add edit and delete buttons -or- left them not present on the screens were you can edit and save the other values in the set(see pictures).

    The other values are times of day that work shifts start and stop and a month value marking the month the spreadsheet will be used for(this is changed by the user every time they want to print). This way when entering the related set of values in this case medication orders the same set of values will always be passed on and when edited on the screen pictured below the times and month will be updated to reflect that. This will also assure that for each Medication there is only one shift time set of vales and one month value for every Medication value essentially giving me constants that I can pass on to an export set of values for a spreadsheet later. While certain constants can be variable and edited from one or more screens.

    The main issue is I can only make the Boolean value non-editable and make it not possible to add multiple sets of shift time values if I can first have the ability to add one set with the add button then take away the privilege to add edit or delete the sets of variables. This is only possible in the debug mode were I can first set up a screen with add edit and delete capabilities. Then add one record to the development database and exit the debugger and change the Boolean value to a label for the screen and remove that screens add edit and delete buttons.

    Shift Times Screen

    Times and MAR(Medication order Details) Screen

    • Edited by reigh7 Saturday, July 19, 2014 11:36 PM
    Saturday, July 12, 2014 11:40 PM


All replies

  • Debug data does not publish to production Db. It sounds like you could use some security allowing admin users to add edit this sat while other uses cannot. Additionally, you can use post deployment script to add data to the deployed database like so:

    Intrinsic Database Management with Database Projects (Chris Rummel)

    • Edited by joshbooker Friday, July 18, 2014 9:22 PM fix link
    • Proposed as answer by Simon Jones [MSDL] Saturday, July 19, 2014 7:40 AM
    • Edited by Yann DuranModerator Sunday, July 20, 2014 9:17 AM Fixed link text & typo
    • Marked as answer by reigh7 Monday, July 21, 2014 8:11 PM
    Sunday, July 13, 2014 12:22 PM
  • Thank you for trying to help but this is not a security problem it is an intuitivity problem. I have already defined security to ‘view’ the “shift times” screen and to add edit and delete shift times. The problem is whoever I give this role to can create problems with the ‘underlying code’ and in the ‘database’. The easiest and most intuitive solution I found was having a table with one and only one (not zero or two or more) set of data. Let’s just take adding as an example for a second. If I allow a user/administrator whomever to add new entries they can cause two problems. 

    First there would be a problem with the code for assigning a ‘single’ default set of values for shift times. In the tables there is a relationship of Many(MedicationOrderDetail)ç=====èOne(ShiftTime). This allows for the medication order detail screen to include the summary property for shift times 

    (The summary property is ‘ShiftScheduleName’ which made sense when originally it was displayed as a non-editable label but now is not visible). The medication orders screen chooses which set of shift time properties to assign to the medication order with the following code.

    code block

    this.ShiftTime = this.DataWorkspace.ApplicationData.ShiftTimeDefault(); 
    //Where ShiftTimeDefault is the query “Where DefaultShiftSchedule = literal true”  
    //and Where DefaultShiftSchedule is a Boolean property  

    The problem this caused with the code is that if you can add multiple sets of properties with the Boolean value as true the query will have multiple results and the code cannot find the default. This is complicated not resolved by making the Boolean properties property be assigned to the unique index. You get non intuitive error messages like "Shift Time (8 Hour Shift): The ShiftTime record has duplicate key values.". This in no way references the Boolean default property either visually or through words. I also tried finding a way to make the Boolean property a radio button. All of the examples I found using radio buttons had been made using multiple properties from the same set and not the same property from multiple sets. This said even solving that problem would leave more problems described below.

    Second is a problem they can cause in the database. Say they get it right and only one set is checked as the default. For every medication order in the database there is one associated set shift time variables. But now it is possible that medications one through three for example are associated with one set of shift times variables (lets name this set “8-hour”). Now let’s change the default set of values as an administrator to an added second set set we will name “12-hour”. Every medication order made and saved after this point will be associated with “12-hour” displaying a completely different month and times when that medication is selected. This may cause the nurse to assign some meds to a time during the wrong shift. The error could go by without ever raising a red flag or displaying any error code to either the administrator or a lower level user.

    Last we could consider the problem caused by giving anyone the capability to delete sets of shift times. If all of the shift times sets are deleted there would be no default defined by the query shown above. If there is no default the users who only have access to adding medication orders and not shift times would receive the following error every time they tried to save a new order. "Shift Time (0): The referenced Shift Time is either not set or no longer exists." This error would not however be an error an administrator saw. In fact the same problem can be caused simply by not checking any set as the default value marking it as true. That I where the edit button would cause a problem except I make the default value a label not a check box in the grid and I unchecked the ‘display by default’ attribute for the DefaultShiftSchedule property on the shift times table. This means when I click the edit button the DefaultShiftSchedule property does not show and it cannot be edited from the datagrid because it is a label not a check box.

    New Medication Order Screen

    • Edited by reigh7 Saturday, July 19, 2014 11:41 PM
    Friday, July 18, 2014 9:06 PM
  • Okay, so you don't want users to edit the data for all the reasons you explain in great length.

    Instead, you want to supply the data with deployment.

    You will find your solution in the article I posted.

    Have a nice day!

    • Edited by joshbooker Friday, July 18, 2014 9:24 PM
    Friday, July 18, 2014 9:22 PM
  • This should be helpful once I upgrade to Visual Studio 2013. For now I see one question with the article. What do I open to write the SQL Statement code as shown in the example.

    Then back in the post-deployment script, you can add this code:

    3.MERGE INTO People AS Target
    5.  (1, 'Chris', 'Rummel', '2013-03-28T08:01:00'), 
    6.  (2, 'Matt', 'Evans', '2013-04-15T11:44:00'), 
    7.  (3, 'Andy', 'Kung', '2013-07-01T09:00:00'), 
    8.  (4, 'Brian', 'Moore', '2013-05-14T08:07:00'), 
    9.  (5, 'Matt', 'Sampson', '2013-05-03T06:07:00'), 
    10.  (6, 'Steve', 'Lasker', '2013-04-22T09:38:00'), 
    11.  (7, 'Heinrich', 'Wendel', '2013-04-10T08:13:00') 
    13.AS Source(Id, FirstName, LastName, LastBlogPost) 
    14.ON Target.Id = Source.Id 
    15.-- update matched rows 
    17.UPDATE SET FirstName = Source.FirstName, LastName = Source.LastName, LastBlogPost = Source.LastBlogPost
    18.-- insert new rows 
    20.INSERT (Id, FirstName, LastName, LastBlogPost) 
    21.VALUES (Id, FirstName, LastName, LastBlogPost) 
    22.-- delete rows that are in the target but not the source 

    Monday, July 21, 2014 7:39 PM
  • After you add a Database Project to your solution the article states:

    "Then you can add items to the database project – start with a post-deployment script."

    The steps which are not written explicitly in the article are:

    In solution explorer: Right-Click on Database Project | New Item | Post-Deployment Script 

    The New Item dialog for a database project is pictured at the end of the article under Build Scripts heading.



    Monday, July 21, 2014 8:08 PM
  • Thanks
    Monday, July 21, 2014 8:11 PM