8 Replies - 781 Views - Last Post: 12 October 2015 - 06:48 AM Rate Topic: -----

#1 jack_pete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 15

Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:05 PM

I want to display / nodisplay title based on my user access.
I have below code where i determine my access (hasaccess)

bool hasAccess = false;
if (Session.UserRights != null)
{
      if(EngineClient.UserHasAccess(Session.UserRights, doc.AccessL1, doc.Denied1))
      {
         hasAccess= true;
      }
}
if (hasAccess == false) { Display Image }
else { Display No Image }



Can i also use same access (hasaccess) to display title if have access and no title if i have no access.
This is what i have written not sure where i am making mistake.


if (hasAccess == true)
 { Display Preview }
  else 
{ 
   <% return false %>
}

This post has been edited by tlhIn`toq: 11 October 2015 - 03:12 PM
Reason for edit:: Cleaned up post. Added [code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: Can i use hasaccess object twice in my C# Script

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:15 PM

TIP: In the future clean your code before you copy/paste it here. Having 300 spaces at the start of each line plays havoc on the code parser - as well as us reading it.
Control-K, Control-D is the shortcut in Visual Studio for Klean Document.

Quote

This is what i have written not sure where i am making mistake.


Have you looked at your code? Is this *your* code or did you copy it from some other site and not understand it?

Quote

<% return false %>

Was This Post Helpful? 0
  • +
  • -

#3 jack_pete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 15

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:17 PM

Extremely Sorry, I thought i cleaned but seems like my mistake i have just copy pasted it.

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:17 PM

Are those two code blocks in the same method? If they are not, then your bool goes out of scope. Anything made in one method only exists IN that method. Google "C# Scope"
Was This Post Helpful? 0
  • +
  • -

#5 jack_pete   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 03-October 15

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:20 PM

It's an existing code from some 3rd part software which i am trying to modify.
I am not very experienced with C#.

They are 2 code blocks in same script.
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:42 PM

The point I was trying to make with that line I quoted is

<Queue the Seseme Street music>
One of these things is not like the other ones, the other ones the other ones....
One of these things is not like the other ones...

Look at line 5 of your second block. Does it look like C#? Does it even follow the style of all the other lines? Do the other lines start and end with < > ?

It looks like you're grabbing stuff from various languages and trying to kludge them together and expect them to work.

View Postjack_pete, on 11 October 2015 - 04:20 PM, said:

It's an existing code from some 3rd part software which i am trying to modify.
I am not very experienced with C#.

They are 2 code blocks in same script.


C# isn't a 'script' language.
Next I had asked you if they were from the same METHOD. Do you know what a method is in C#.

I'm beginning to think that when you say "I'm not very experienced with C#" you're really saying "I've never seen the language before and have no idea about it."



My standard beginner resources post - Updated June 2013


Plan your study route:
There are three routes people seem to take when learning programming.
  • Just start trying to create programs, commonly text adventures or DnD or some other game. Games are truly the worst thing to start with.
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

  • First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover.
  • Do a dozen on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.
  • Learn to plan before you type.
  • THEN you start designing software with a purpose.


Why are you still building in WinForms?

Quote

"old 1990's WinForms"? i just use visual studio 2015 and started up with a windows form. didn't know there was an option for a newer winform?

WinForms is OLD. Virtually 'legacy' and to many of us nearly considered end-of-life. There are still placing building new projects in it, but I wouldn't work for anyplace that wanted to hold me back by two decades. There are probably tens of thousands of legacy WinForms applications in use in countless companies. "If it ain't broke, don't fix it." in other words: If there isn't a financial gain to be made in re-writing them right now why invest the time and money?

But with decades of WinForms comes developers with decades more experience than you'll have and you have no way to compete with them. Let the legacy developer maintain the legacy applications. Many of them are too stuck in their ways to move forward to WPF. Which is why if you look at job boards, what companies are hiring for and have been looking for, for the last several years its: WPF/MVVM.

So if I were you I would just jump right to WPF. Don't worry about WinForms unless you have a deliberate need for it down the line. Otherwise you spend 10,000 hours getting good at WinForms only to find you need to spend another 7,500 hours bringing your skillset forward several years into WPF - And at the same time break all the bad habits you learned in WinForms.

If some company hires you for WPF development, but would also like it if you could maintain some legacy applications THEN learn WinForms; and take your good habits from WPF with you.




I don't learn from reading books: I learn by doing.
Spoiler


Newbie/Rookie said:

I have little/no programming experience but I need to write a program by Friday that does XYZ.
Spoiler



Resources, references and suggestions for new programmers.
Spoiler

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7463
  • View blog
  • Posts: 25,113
  • Joined: 05-May 12

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:44 PM

Yes, the inexperience is quite telling considering that you don't even know that in C#, source code is called "code", not "script".

Given that, did you happen to draw the short straw and was given the task of modifying this 3rd party code? Do you have a strong test test team to find any regressions you may introduce? If you don't have a strong test team, do you have sufficient unit tests from the 3rd party to make sure you didn't break anything?
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Can i use hasaccess object twice in my C# Script

Posted 11 October 2015 - 03:53 PM

If the kid didn't know the term "method" he sure the heck doesn't know "regression" or "unit test".

I doubt this is for any work project. This is most likely a 14 year old whacking at something he found in an effort to hack a game.
Was This Post Helpful? 0
  • +
  • -

#9 rgfirefly24   User is offline

  • D.I.C Lover
  • member icon


Reputation: 473
  • View blog
  • Posts: 2,221
  • Joined: 07-April 08

Re: Can i use hasaccess object twice in my C# Script

Posted 12 October 2015 - 06:48 AM

To me it looks like he's writing what I used to call "Inline ASP.NET" which basically is the C# code and the ASP.NET code all in a single file. I'm basing that off of the fact that his other post and this one contain angel wings (<%%>) and his other post has what appears to be html controls.

When your writing C# like that, and I would highly suggest you stop, you must have all of the C# code in server tags <% %>. Your pages don't do that. Yes you can Conditionally display titles and images and what ever else you feel like, but you need to understand the flow of C# before you can even attempt it. I would suggest you give back the project to who ever gave it to you, and pick up some C# books. I would also pick up some ASP.NET books as well and learn them. Only after you understand the technologies behind what's been written should you even attempt to work with it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1