CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 CUSTOM SESSION VARIABLE (RESOLVED)

Print topic Send  topic

Author Message
abiodunode

Posts: 10
Posted: 07/11/2008, 5:29 PM

I have been having problem creating a custom session variable for some time now.
I followed the example given in the tutorials by copying the cold but i still dint get through.

Basically, i have a user table which contains user login information. 'Branch ID' is also a field on the user table and all i want to do is to add this field as a custom session variable so that when the user logs in, his branch will automatically be set on the form.

I will appreciate ur assistance in resolving this , plssssss.
View profile  Send private message
Oper


Posts: 1195
Posted: 07/11/2008, 7:35 PM

on before show

just use

ASP
sender.value=SESSION("MYSESSIONVARIBALE")


_________________
____________________________
http://www.7bz.com (Free CMS,CRM Developed in CCS)

http://www.PremiumWebTemplate.com
Affiliation Web Site Templates

Please do backup first
View profile  Send private message
ckroon

Posts: 869
Posted: 07/11/2008, 8:31 PM

Walter answered this for me a while back:
this is PHP.
Table: users
Field: users_familyID
Session name: FamID

......>>
How to Lookup a value upon succesful login and store it in a session variable the CCS way.
Based on the table described in this post.
Table: users
Field to lookup: users_familyID
lookup field: currently logged in user
table key field: usersid

Open the properties for the login button, it should already have one action attached: Login.
Add an action: DLookup, it should appear below the Login action, if not right click the Dlookup and select 'move down'
set:

Expression: 'users_familyID'
Domain : 'users'
Criteria: "user_ID=". CCGetUserID()
Connection: <choose from dropdownlist your current connection>
Convert result: Integer
Type of target: Session
Target: FamID

That should do it, tested.
Take care to use correct names and caps!
_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
jjrjr1


Posts: 942
Posted: 07/12/2008, 2:49 AM

Hi

If you want this to happen at login you wil need to modify standard code.

Review this post

http://forums.yessoftware.com/posts.php?post_id=98541

To do what you want to do the code to modify is at the end of Common.php

You will see the login routines. to accomplish what you want is to add the field you want into the database login query. Then follow the example how CCS gets and loads the login session variables and add your new one.

There are many schools of thought as to when someone should change the standard code. I think this is one of them. Why do uneccessary database queries.

Be advised that you need to have your security settings completed at the project level and your login page scripts done before editing this area of Common.php becuase after making this changes CCS will no longer be able to maintain that function thru the IDE. If you need to modify security settings or login settings thru the IDE, you must put the code back to the original configuration, make the change, then put your custom code back.

Hope that helps.



_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/12/2008, 3:08 AM

The post by Ckroon, describes the easiest way to accomplish what the Help file ("Create Custom Session Variables") describes.
There are of course many ways to reach a certain goal.
My personal thought is:
- Do the 'action' method described, use the ections provided in CCS.
- Follow (in this case) the Help files, editing an event in the coding way.
- .....
- Change the Login in Common.php
is the order in which I would advice to do this based on experience level.

Walter

_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
abiodunode

Posts: 10
Posted: 07/12/2008, 4:00 AM

Hey guys,
I am using C# not php, please.
Can i get the guidelines for C# language?
Thanks.
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/12/2008, 4:22 AM

@abiodunode
The Help file subject pointed to above, has a C# Net variant, have you studied that?
Quote :
Create Custom Session Variables
This example shows how to add a custom session variable when a user is logged in. In this case, we will store the user's name in a session variable.

Add an On Click event to the 'Login' button of a Login form.
Within the event, add the code below:
Note: In addition to creating the session variable, you should also clear it when the user logs out.

[....]
  
C#  
//Button Button_DoLogin Event OnClick. Action Custom Code  
  
Session["User_Name"] = Settings.Connection1DataAccessObject.ExecuteScalar("SELECT User_Name FROM Users WHERE User_ID=" +  
Settings.Connection1DataAccessObject.ToSql(DBUtility.UserId.ToString(), FieldType.Integer));  
[...]


Also the Action approach described above might be available and make your day so much easier.

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
abiodunode

Posts: 10
Posted: 07/12/2008, 5:18 AM

Hi wkempees,
I did like u suggested but it still dint work.

I added this code to the login button :

Session["BranchID"] = Settings.Connection1DataAccessObject.ExecuteScalar("SELECT BranchID FROM User WHERE username=" +
Settings.Connection1DataAccessObject.ToSql(DBUtility.UserId.ToString(), FieldType.Integer));

Note the following in the above:
BranchID: is the field from the user database which i wish to display
user :is the table containing user information

I later set the field in the form to retrieve a value from session variable as follows:

Control Name : Branch_ID
Source Type : Session
Source Name: BranchID

The above still did not work.

Is there any other thing am supposed to do?
Please assist further.
Thanks.
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/12/2008, 6:43 AM

Three possibilities:
1. the code example is wrong
try to set the sessionvariable to a known value like
Session["BranchID"]='HereAmI'.
Press F9 start appliction, login and look for ' HereAmI where you expect.
If that works:

2. Your SELECT fails, rewrite it as an alert
see what value is returned
if returned value is as expected and 1. Worked combine them back together as originally intended
most likely reason your select fails is because you connection in project settings connection has a name other than connection1 used in the sample!!


3. i am completely wrong and missing the point

walter



_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
wkempees


Posts: 1679
Posted: 07/12/2008, 6:48 AM

Using the ckroon post suggested Action Dlookup would have helped you as it shows only the fields and connections available......

therefore it is the better solution.



_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
abiodunode

Posts: 10
Posted: 07/12/2008, 6:56 AM

When i used the ckroon suggestion , see the error message i received below:


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'BranchID' does not exist in the current context

Source Error:



Line 266: System.Web.HttpContext.Current.Session["BranchID"]=(string)(new TextField("",Settings.Connection1DataAccessObject.ExecuteScalar("SELECT " + BranchID + " FROM " + user + " WHERE " + "Username=".CCGetUserID()))).Value;
Line 267://End Button Button_DoLogin Event OnClick. Action DLookup
Line 268:
View profile  Send private message
abiodunode

Posts: 10
Posted: 07/12/2008, 7:09 AM

Quote wkempees:
Three possibilities:
1. the code example is wrong
try to set the sessionvariable to a known value like
Session["BranchID"]='HereAmI'.
Press F9 start appliction, login and look for ' HereAmI where you expect.
If that works:

2. Your SELECT fails, rewrite it as an alert
see what value is returned
if returned value is as expected and 1. Worked combine them back together as originally intended
most likely reason your select fails is because you connection in project settings connection has a name other than connection1 used in the sample!!


3. i am completely wrong and missing the point

walter




I tried this option and 'HereAmI' did not appear where i expected.

How else can i achieve this aim, pls guys help me.
View profile  Send private message
tsgroman


Posts: 64
Posted: 07/12/2008, 10:24 AM

There are so many unknowns here, but here are a couple observations...

You should not be getting the results you're looking for. The latest error message is telling you that it doesn't known what the variable BranchID is and if you fixed that problem the next error would say the same about user, or:

SELECT ??????? FROM ???????? WHERE Username = "

Quote :
SELECT " + BranchID + " FROM " + user + " WHERE " + "Username=".CCGetUserID

You need to take the undeclareed variables out of the SQL statement by removing the " and + that are making them variables instead of column names. Something like this:

"SELECT BranchID FROM user WHERE Username = " + whatevervariable

Next, are you using your db column user.Username for both the User_ID and Login in Project Settings -> Security? Are you using the correct column for your compare?
Write code to display the Session[UserID].
Was it what you expected?
Can you use it in your SELECT query from within SQLServer Management Studio to get the desired results?

Also:
Quote :
I tried this option and 'HereAmI' did not appear where i expected.

Make sure the code is placed one line up from the successful login redirect and not in the on error portion of the onclick event of the login button.

Could help more if you post the login button's on click event.




View profile  Send private message
abiodunode

Posts: 10
Posted: 07/12/2008, 4:33 PM

tsgroman,

I tried ur suggestion but i still got some errors.
But i think the problem am having has to do with database retrieval just like u said. But i have followed the CCS examples and guidelines esp on DLookup all but with no avail.

Below is the error i got just now when implementing ur solution:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'string' does not contain a definition for 'CCGetUserID'

Source Error:



Line 264:
Line 265://Button Button_DoLogin Event OnClick. Action DLookup @13-B5A22A72
Line 266: System.Web.HttpContext.Current.Session["BranchID"]=(string)(new TextField("",Settings.Connection1DataAccessObject.ExecuteScalar("SELECT BranchID FROM user WHERE Username=".CCGetUserID()))).Value;
Line 267://End Button Button_DoLogin Event OnClick. Action DLookup
Line 268:


As u can see from the above, i think am having a syntax error which i have tried to resolve but with no result, most esp the placement of function CCGetUserID .

I have tried the 'HereAmI' stuff again and it worked...meaning that i have problem with retrieving required value from the database.

To answer your question correctly, i used username for both the User_id and the login in the project settings.


Basically this is wot i have:

Table User : username, firstname, lastname, email,Phone, BranchID

From a transaction form, i want a situation whereby when the user logs on, his branch will automatically be displayed on the Branch field on the form.
I have been successful in placing the username on a field on d form when the user logs on may be because thatz part of the default session vairable (UserLogin).

My problem has been creating a custom session variable 'BranchID' which will set the branch field on the form when the user logs on.

I will be very grateful, if u guys can help me sort out this.

Thanks.

View profile  Send private message
ckroon

Posts: 869
Posted: 07/12/2008, 7:35 PM

I am by no means an expert but in your code I saw Where username = CCGetUserid.

It should your user_id field that = UserID.

_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
tsgroman


Posts: 64
Posted: 07/12/2008, 8:16 PM

The error you're getting now concerns the use of CCGetUserID.

Try:

"SELECT BranchID FROM user WHERE Username= " + Session[UserID]

Remember you want this to be the last action before the page redirects - this insures that the login action has filled the "standard" login session variables (like Session[UserID]). I had problems with setting session variables on login until I discovered that I was attempting to use Session[UserID] before it had been initiated by the login code.

Looking at your table design, I'm still not seeing a design that is conducive to utilizing CCS's Security/Login features. At a minimum you'd want to use a username and password; and your table design doesn't mention a password.

Feel free to PM me if you're still stuck.
View profile  Send private message
tsgroman


Posts: 64
Posted: 07/13/2008, 1:23 AM

The following is assuming that you're using the Username field in your user table for both the User ID and Login of the security tab of the Project settings and that the BranchID field is an integer.

Place the code to be copied directly under this line of code:
if (!ErrorFlag && Membership.ValidateUser(Loginlogin.Text,Loginpassword.Text)) {
SecurityUtility.SetSecurityCookies(Loginlogin.Text,Loginpassword.Text, LoginautoLogin.Checked);

Code to Copy:
Quote :
System.Web.HttpContext.Current.Session["BranchID"]=(Int64)(new IntegerField("",Settings.Connection1DataAccessObject.ExecuteScalar("SELECT BranchID FROM [User] WHERE Username = '" + Session["UserID"] + "'"))).Value;

I've tested it under the conditions mentioned above and it works.
View profile  Send private message
abiodunode

Posts: 10
Posted: 07/14/2008, 9:05 PM

Hey Guys,
I am pleased to inform you that 'tsgroman.solution' has finally sorted me out. I am so happy for this resolution and many thanks and kudos to him.

Once again, i thank the whole house for resolving this issue for me and most especially tsgroman for always wanting to help despite busy schedules.

I hope he will accept my proposal of him becoming my tutor.

Thanks ALL, cheers.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.