Please tell what approach should be used for desktop application - c#

I am planing to develop desktop application that will have multiple logins and according to that login type options/From view will be displayed.
I have done database login part now its turn of view
How can i establish that what i have in my mind that
Drag and drop all required controls and make them visible = false and check which type of login is that and display accordingly
Create separate forms and display one by one as required

You sound like you are new to C# forms programming. I suggest looking at some tutorials or a book like this Windows Forms Programming

For me it depends on numbers.
If u have many diffrent user roles and they share only a few controls then it would be easier to make diffrent form / panel for each user type. This approach is quite dangerous since when you want to change common control u would be forced to do it in all forms / panels.
Thats why i would recommend to group application logic into custom controls and then build GUI from them. For example: if you have two user types ( let's say boss and employee ) then you can build form with shared controls / logic and two user controls (bossControl, employeeControl) with functions for boss and employee. Then after login check you add matching user control to GUI.

You need to make one form and make control visible/invisible or enable/disable control.
Create separate forms and display one
by one as required
it will be very difficult for you to manage and extend in future.

Related

How to create multiple pages in windows forms without creating multiple forms

I have a program were creating at school in c# and I need to create multiple pages which display information on certain things but I'm not quite sure how to do this without creating over 50 new forms in my program. I know parameters have to be used but I'm not quite sure how to go about doing it.
Try to use TabControl
You can add pages and name them how you want.
Controls, you are adding to a tab, are still active, even if you move to another tab.

What technology to use to write a modular C# desktop program?

Question:
Is there some effective way to hide some portions of the WinForm/WPF desktop program based on user settings/permissions?
Why I need this?
I'm starting a big accounting project which will contain hundreds of forms/dialogs.
The program is going to launch a main window which shows 1 to 4 divisions. The user selects each of those and it will then launch the a window which contains a sidebar with a bunch of buttons on sidebar (something like Microsoft Outlook). Now, when the user clicks on each of these buttons, it will open that section of the program and the user will work with that part. Based on the user permissions/settings, there's a need to sometimes hide some of these buttons though. For instance suppose I have 4 main divisions A, B, C and D. When you launch A, you'll get a sidebar containing A1, A2, ..., A100. A user might opt to see only A1 & A50!
Our initial approach was to use WinForms for this because the team was very familiar with it. I suspect that for doing so, we have to build some sort of model which contains information about user preferences and write lines of code like btnA1.Visible = false; a lot.
Frankly just thinking about doing that disgusts me. That's why I'm looking for a better way to achieve such result. I've searched around and found PRISM.
I'm not sure just yet but I think to use PRISM I need to make each of those buttons or their dialog a module and load them after I decide which of them is needed for the user.
It seems like a nice way to do this but considering the fact that this project is very urgent and we don't need to load different modules for different users (we just need to load them - ideally on demand - and sometimes hide some), I have some concerns:
My team might need some time to learn WPF
All of us don't know much about Unity and PRISM.
This might be overly complex, i.e. there might be a more simple way to achieve this without going into such lengths.
Also, I'm watching Prism & Silverlight Series and PRISM5 for WPF from Channel9.
a window which contains a sidebar with a bunch of buttons on sidebar (something like Microsoft Outlook). Now, when the user clicks on each of these buttons, it will open that section of the program and the user will work with that part.
That sounds to me like a TabControl. You'd rather not try to reinvent the wheel as it's already been invented.
The only difference between that example and your requirement is that instead of hard coding the tabs you're going to bind to a collection of ViewModels, like this, and then have each instance of TabViewModel toggle it's own IsVisible property depending on user permissions / user selections.
Simple as that. No need for complex MVVM frameworks. No need for silly obsolete useless winforms stuff.

Why do we use UserControl?

ı have been serching this for a while but I couldn't come up with a conclusion. What is UserControl? For me we can do everything with creating new windows forms instead of User Control. I know there is a reason to use but it is not clear right now. If someone illuminates the mystery that would be great.
A user control is basically a grouping of other existing control, intended as a reusable component (i.e. composite control). If you need to place the same group of controls on different windows you'd rather group them in a user control, adding things like data validation for instance, and then reuse this control whenever you need it.
Here is some more reading.
UserControls allow you to reuse your code. For example if you need a small component that displays two values (code and description), with UserControls you can design it only one time and then reuse it in other forms.
Also, you can add your custom properties\methods to the UserControl; in this way you can define simple (or even more complex) functions associated to the GUI control.
Hope this helps.
imagine you have a GridView with some new methods you create, and which you want to use on several pages. There you go. A UserControl is useful. That's just one example
As the others have explained a UserControl groups 'real' Controls and the logic that makes them work together as one component.
Imagine an application where the user can decide wether it runs in MDI mode or with separate windows or with tabbed pages. You can add the UCs of your application to any of these easily.
Think of a MP3 player with various controls, buttons, labels and sliders and user drawn-gauges. If it's in a UC you can re-use it directly. If it is all on a window, how do you re-use it?
So UCs are about flexibilty and re-using visual components.

Simple and advanced layout

I'm currently developing an application in C# that will have two layouts: simple and advanced.
The simple layout would have 4 objects (2 buttons and 2 text controls) and the advanced layout would have 8 objects.
What would be the best way to do this? Having two forms? Or set the button.visible to true/false (and for each object?).
If you follow a UI pattern that allows for separation of model, view and controller (e.g. MVVM or MVC), you will find it is very straightforward to have two separate forms that can be evolved over time as needed, with only minimal changes to the rest of your code.
Trying to make a single form work for two different presentations tends to get complex over time (compared to the alternative of just making two forms that share the same model and controller) as user requirements evolve.
UPDATE
Based on your comment... you can also do MVC with WinForms
http://www.codeproject.com/Articles/383153/The-Model-View-Controller-MVC-Pattern-with-Csharp
I would propose a third option, having two user controls that share the same form. Then all you have to do is set the appropriate user control visible. And you get the benefit of being able to share any code between the two.

Proper Windows Forms multi screen program

I'm trying to build a rather simple Windows Application for the employees that process our payroll (currently it's a vbscript/terminal combination). The logic is mostly worked out, but I'm trying to find out what the best way build a Windows Forms application that has multiple screens (login/etc). I've been using the TabControl container for this, but just wasn't sure if this was correct...or 'common'.
If this is what is normally done are the contents of the tabs generally made up of User Control object or are they just filled with different layouts on the tab?
I doubt I need much in the way of help on the coding side, but more the "how a gui" is normally laid out in the visual designer.
EDIT: Just to provide a basis of the screens that I'm needing to build. I'm currently planning on having a Login Screen and the three screens that guide the user through processing two different types of payroll and then certain accounts receivables work. Primarily I will have two user types. The ones that process payroll and the ones that do accounts receivable work. I'm wanting to make this easily expandable so that as I build in more functionality it's not a major pain to add screens and limit who can see them.
What I ended up doing is removing the "Login Screen" as hinted to in the question. Instead of a Login Screen and the corresponding logic being required I ended up doing integration with our Active Directory Server.
Once this integration was done I simply design the Screens as UserControl elements and then add each one to a tab based on if the user is in a specific group or not.
Doing this solved my main concern of having a heavy main form containing logic. Now the only logic in the main form is whether or not to add a tab based on Active Directory groups.

Categories

Resources