Page 1 of 2

Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 5:47 am
by jydepower
Hallo.

I need to set a tag if user is logged in.

I tried this with no success.

public partial class Tags
{

void SystemTagCurrentUser_ValueOn(System.Object sender, System.EventArgs e)
{
Globals.Tags.TestBit.Value = 1;
}
}

Basicly i just need to check if the SystemTagCurrentUse string is empty or not.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 9:01 am
by Ron L.
I don't believe the "ValueOn" action works as it's name indicates. I would try using the "ValueChanged" action instead.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 9:10 am
by jydepower
I tried that. But have not clue why it changes. When i start run time it goes 1 right away. When when i login nothing happens. So i actually have no idea what status of SystemUser is.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 9:16 am
by mark.monroe
The current user is a string. The system may change it to a string with nothing in it, which would then trigger the ValueChange event.

You need to check the value of the tag to see if it is empty, or if it has something in it. If it has something in it, then you know that there is a user.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 9:19 am
by jydepower
Yes. That is what i wrote in first post. I basically need help to see if the string is empty.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 9:31 am
by mark.monroe
There are many C# tutorials available online. The best is to look at one of those.

http://csharp.net-tutorials.com/basics/if-statement/

if(Globals.Tags.MyString.Value == "")
//Do something if my string is empty
if(Globals.Tags.MyString.Value != "")
//Do something if my string is not empty

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 11:06 am
by jydepower
I can figure out the basic of checking tags and doing if's etc.

My problem is, if i cant use the "build-in" event handlers like screen opened and closed etc. i don't know how to start a simple if statement.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 11:24 am
by mark.monroe
Why can't you use the built in screen handles? The screen open/closed handles work.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 11:32 am
by jydepower
True.

But when user hits ok after typing username and password the screen is already opened. I would require to somehow refresh the screen or something.

Re: Setting tag if user is logged in.

Posted: Fri Jan 11, 2013 11:38 am
by mark.monroe
When the user logs in, then the tag changes value, which fires its ValueChange event. Therefore put your code in the SystemTagCurrentUser ValueChange event. That tag changes value when the unit turns on because the system is initializing the tag to empty. That is why you need to check the value of the tag in the value change event. If the tag is not a user, then you do nothing because you know that the tag was initialized by the system, and no one logged in.

You can put an AnalogNumeric Box on your screen and associate it with the SystemTagCurrentUser tag and see what is in that tag.