Show and hide switch in C# database applications - c#

I have a small one line application and recently I have been instruct to remove all persons form it. That is I have several fields and one of it is a owner field. I am not going to move the owners from the database but only hide them and I need to be able to show some fields again when I will be contacted by that person saying: "You can show my name". This is an Visual Studio application with underlying SQL database. My dream solution would be a switch that make this name field true or false so I will be able to show only those name which I am allowed to show with a click of a button.
What do you think would be the easiest way to accomplish this.

There are lots of ways to do this, since you didn't specify what type of C# application you have (ASP.NET C#, WinForms, WCF, WPF), I'll assume you mean either Winforms or WPF. The easiest way is a checkbox, and then on change, hide or show the other fields that you want to hide. Then do your database calls. That's all I can give you without more info.

There are many ways to achieve that. One way is to introduce an extra bit field/column in your ‘User’ (or whatever it is) database table that would represent whether to show or hide a user name. Based on this field you would show or hide the user name within your application. This could be checked/unchecked directly in your database (by you), or via an application UI. You could implement ‘Admin’ page/view/form that would be dedicated to admins (you) that would have enough privileges to update the above specified column.

Related

Get new Messagebox style - WPF

I am currently working on a Windows Presentation Foundation app and I need to make use of Message boxes. I want to get few information from user inside Message Box popup.
But they appear always like this:
But I think the actual look of it should be like that:
Does anybody know, why this is, and how to solve it? I tried all everything listed
here
, but nothing worked.
I agree with Keithernet, build your own. Its more of an Input Dialog box. You may want to plan it to create a window, create it with ex: 4 parameters which you could override so you can apply them in the form including
The title,
The prompt you want the user to fill in
optional default button 1 text
optional default button 2 text.
have the input value stored into a public property in the window for the text to be bound to during entry.
If the user clicks the cancel button (or similar), clear the text entry and close the window. If ok button, just close the window.
Then, when you call it with a YourWindow.ShowDialog(), upon return, you can look at the public property for that input text value.
You could even do with a property / flag if the user cancelled directly or not. I have done similar in a couple of my WPF apps.
MessageBox is very limited. Based on your screenshot, you should just create your own child Window with your own XAML so you can get the user input.
You can find sample service implementations/NuGets for this on GitHub. Here is one I've created sometime ago: https://github.com/Dirkster99/MsgBox
Just create your own is an oversimplifying statement in my opinion because this is usually a dialog that you want to show in different parts of the application. Therefore, you have to settle for a software design pattern (I chose a service implementation as suggested here).
Likewise, there are other design decisions that should be taken. I have for instance made sure that the API has a compatible subset of Show API calls with the standard .Net MessageBox to make its application as flexible as possible. I also settled for light and dark themes hoping this will make its application easy in any other theme...

How to read and change text in a TextBox control in another process in a .NET application?

I need the following for a specific corporate application that we use in our office. The goal is to create something similar to what password managers do with forms in a web browser -- fill out the login credentials automatically. I need it only for this specific application.
When the application loads, it shows a login window:
My goal is to read Corp Code, Location Code and User Name & fill out the Password accordingly from my application that I'm writing.
I do not have the source code for the corporate application in question. I know that it is a .NET 4.0 process:
From Windows Spy++ I can see what those text boxes are:
So they have this WindowsForms10.EDIT.app.* class name, where * I believe can be changed from build to build:
My first instinct was to use native EnumWindows API with conjunction with GetClassName and GetWindowText to locate those text boxes and get their text, but the issue is telling them apart.
So I was hoping that their Control ID properties could be used for that:
but unfortunately their Control ID value seems to change every time the application runs.
So my only hope in this case is to identify these TextBox controls by their name, natively like .NET does:
Is there a way to do it from another .NET process?
I do not believe it is possible to expose the .NET names of the textboxes that way. You are going down the correct path with p/invoking the EnumWindows, GetClassName, etc.
You might have luck checking the Z-Order of the child windows, which would be the effective tab order, which is probably consistent for each run.

Is WPF adequate for creating such a form or am I missing something?

Intro:
I am quite new to C#.
It is my job to create a certain simulation program.
I can't ask other programers, I'm an intern with a nonprogramer adviser and should not nother them. (I'm doing more of a fun project.)
So before spending a week or two to get really into WPF, I wanted to make sure it fits my needs.
If not, I want to use something else.
What I need:
Show the user a range of radio buttons to decide wether a simulation/plot/opening_of_svg should be done or not. (Can be done.)
A button "Add Task" where the user can choose one. (Can be done.)
Depending on the choice, add a certain form into the existing one, where parameters can be set. (Not found.)
Some of them radio buttons. (Can be done.)
Some of them text box, for integers and doubles only. (Can be done.)
All of them with default values. (Can be done.)
After adding a task, another "Add Task" button should be created, for adding more of them. (Not found.)
If for example a second simulation is added, it should take the values of the first one as default. (Can be done.)
Save the choices and data to a text file in a certain syntax like "Gnuplot Add Restriction = Time" which is used by the rest of the program. (Can probably be done.)
Question:
The biggest uncertainty is the one with adding forms into the forms.
Can this be done in WPF?
If there is any other framework (if this is the right name) specially made for this, feel free to comment.
I can't add many links due to my reputation. I might do it later. Just in case someone will find this later and wants to know about how.
Rather than creating Forms, consider creating UserControls and arranging them within a single Window. This is the same pattern you might use when creating composite windows in WinForms. I'd recommend the Grid or DockPanel layout panels.
In this respect, WPF is quite similar.
In addition, it sounds to me like you are doing a feasibility study for a new requirement. Are you sure it is not appropriate to speak to more senior staff? If I was them, I'd want to know your findings!
On reflection...
It seems like you are trying to create a branching Wizard workflow, like an installer might give you, i.e. Next, Next, I Agree, Next, Finish. WPF Can absolutely do this and some open source solutions already exist. For example, Avalon Wizard.

How to make a user dependant localizable treeview menu?

I need to develop a winform with a treeview menu, localizable and with different options in case of each user (role and single-user based).
The only solution I can imagine is really unmaintainable:
Everything loaded and watched from database.
A table to define the menu (child-of...).
Every option in the menu should have a Form name to find and open it with reflection.
A table with translations to each language related to each option in the menu.
A table with permissions for each user and option (to show or hide it).
Is there any simpler solution??? I really don't want to do this kind of stuff 8-)
Thanks in advance.
We have actually implemented exactly what you are describing here (with the only difference being that we are using one language) and it works quite well. The fact that the menu can be altered at runtime has been used multiple times where any other implementation would have required a code release.
I am not sure why you say that it is not maintainable - the system has been in use for years now and we hardly ever need to spend time on the code that makes it all work.
A different system that I am involved in we build the menu at design time and then just have a lookup table with all the menu buttons in the database - it actually feels a lot easier to get something wrong there than when everything is in the DB.

usercontrol to connect to a SqlServer database

I've been writing some small maintenance/viewer tools that each connect to a SQLServer (2005) database via System.Data.SqlClient classes.
(C# - .NET 3.5 - Windows.Forms)
For each of these tools I had to write the UI and dialog to let the user choose the right db and server: I connect to my test-db, my colleague uses my tools too and connects his test-db.
I'm looking for a plugable usercontrol that lets the user select a server, db and the rest of the connection parameters and that provides a SqlClient.SqlConnection to the rest of the application.
I've tried writing a usercontrol myself now, but I'm sure there must be others ,better ones and better tested ones. I've been Googling and looking at CodeProject, but found none.
There must be some better than one I wrote recently, because that one's so bad:
Just
Create a user control
drag a couple of buttons to it, anchor bottom center, make them ok and cancel
drag a Property Grid control onto it, dock fill
Add a read-only property to the control of type SqlConnectionStringBuilder, back it with a field
Initialize the field to a new SqlConnectionStringBuilder instance
In the Load event, set the Object property of the property grid to the SqlConnectionStringBuilder
That's pretty much that. The user just gets to fill in the properties. If you like, you can also create a ConnectionString property on the control and have it return the .ConnectionString property of the SqlConnectionStringBuilder.
What you're describing here is simple enough that I doubt there's something out there that does only this. You'd probably be better off sticking with your own code here.

Categories

Resources