• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

My first C# - cleaning up document types

oynaz

Platinum Member
Hi guys,

I am a supporter turned sysadmin who is now turning developer. I am currently starting work on my first app, and it wanted to make this post to ask for your advice and guidance.
Now, I could figure most of this out for myself, or ask some colleagues, but posting this gives a number of boons. First, writing things down is a great way to organize one's thoughts. Second, your guy's opinions might differ from my collegues', thus lessening group thinking. Third, other aspiring programmers might find this interesting as well.

So, here is my task:

We have a document handling system with a lot of features. One of them is creating document types, thus enabling customers to organize templates easier. So, for instance a .docx document can be of ducoment type Letter to Government, type Schedule, type Letter to Customer, and so on. A .xlsx sheet can have type Budget for IT, type Budget for HR, etc. You get the point.
Another feature is enabling the customers to upload documents by drag and drop. When they do this, the document type is assigned a default type. This default type is controlled by a boolean in the database. Thus, the customers can set that all .docx documents are by default uploaded as Letter, all .xlsx documents as Generic Excel 2010 - whatever.
Now, the administration module has in the past allowed the default document type boolean to be set to True for any number of documenttypes with the same extension. On top of that, the admin module did not really tell what setting a document type to default actually did. As as a result, our customers has set the default document types all over the place. This menas that drag n' dropping a .docx document might for instance by default upload the document as type List of Christmas Presents for Customers. Not good.

I can change it ie the database with some simple SQL, ie:

Code:
select * from dbo.documentTypes where isDefault = true order by docExtension

update dbo.documentTypes 
set is Default = false where docExtension = docxForExample and documentTypeID <> whaterverTheCorrectDIsTheCorrectOne

but I would rather make an application for it.

As I see it, I need four parts.

1. The UI. WinForms or WPF?
2. Something to handle the database connection. I can get it from a bunch of config files which is referred by an environment variable. I think I can figure this out. It makes sense to make this part into a separate class, right?
3. Selecting and presenting the data. The select is straight forward, but presenting it is harder. Is there a built in list view in C# which presents data in a tree form? Like this:

Extension
--Documenttype
--Documenttype
--Documenttype
Extension
--Documenttype
--Documenttype

4. A way to make the user select which types to keep as default and write it to the database. I imagines a radio button type which enables the user to select only one documenttype from each extension. It would then be relatively simple, I hope, to update the database.

So, opinions and advice? What do you guys think?
 
WPF is a newer framework than winforms, although as far as I know winforms is still fully supported. There are treeview controls available in both as far as I recall. It's been a few years since I did any .NET development.

I'm not sure I understand the requirement, though.

This menas that drag n' dropping a .docx document might for instance by default upload the document as type List of Christmas Presents for Customers. Not good.

Is this not the behavior the customer intended when they set the document type? Are the instructions simply unclear, or are they encouraging people to do the wrong thing?
 
1.) Up to you. If you've got the time and ambition (for learning), go ahead and do it in WPF. Otherwise WinForms is perfectly fine too. If you haven't done any WinForms or WPF dev before, then flip a coin! Haha.

2.) I'd just use an App.config file for the database connection. This file is typically created by default when you create a new project in Visual Studio.

3.) There is a TreeView in C# that displays data like you showed. There are a lot of different ways you could present the data in the UI; a GridView is another way.

4.) You just need to code the logic in the application to only allow one default for a particular file extension. This kinda goes with #3, there's a lot of ways to do this.

Here's one simple, easy way to it:

documenttypesexample.png


Just two ListBox controls, one for the file extensions and the other for document types. When a user clicks on the left ListBox, on a file extension, it populates the right ListBox with the document types for that extension. The ListBox control has a "SelectionMode" property that you can set to "Single" so only one thing can be selected at a time. Then have a button somewhere that when clicked does the logic of updating the database.

Good luck; hope that helps a bit.
 
Thanks for the replies, guys.

@MarkBNJ:
The users can drag n drop multiple documents at a time, and tend to grasp entire projects and stuff it somewhere in the system. Not that I blame them. However, this means that the default documenttypes need to be OK.
There is definitely room for improvement, but right now I will be concentrating on fixing the issue at the customers.

@Clamum:

1: Decision, decision. I think I will actually flip a coin.
2: This solution is deployed at multiple customers, all using different names from the database server and different service accounts. I can of course use a prompt to get this information from the user, but I would rather do it automatically, since the needed information is already available through environment variable and shared config files.
I have already got this to work in Powershell, so I should be able to get it to work in C# 🙂
3 and 4: Good idea with the 2 ListBoxes. I will use that instead 🙂

Back to coding as soon as I have explained to another customer that setting your SQL servers to automatically install Windows updates, including restart of the machine, is a bad idea in a production environment.

I will be back soon with more n00b questions 🙂
 
Hmm, I have trouble getting data from an XML file. Hope you guys can help. I have tried in 2 ways:

Code:
            XmlDocument loadConfigInfo = new XmlDocument();
            loadConfigInfo.Load(@"\\server\Configuration.xml");

            XmlNode node = loadPluginConfig.DocumentElement.SelectSingleNode("/configuration/systemModuleSection/systemAccessSettings/connectionString");
           
            if (node == null)
            {
                Console.WriteLine("node is null");
                Console.ReadLine();
            }

            else
            {
                string text = node.InnerText;
                Console.WriteLine(text);
                Console.ReadLine();
            }

I get non errors, but the node is always null. It shouldn't be.

I have also tried using LINQ:

Code:
// Loading from a file, you can also load from a stream
            var xml = XDocument.Load(@"\\server\Configuration.xml");


            // Query the data and write out a subset of contacts
            var query = from c in xml.configuration.systemModuleSection("systemAccessSettings")
                                                select c.Element("connectionString").Value;


            foreach (string name in query)
            {
                Console.WriteLine("{0}", name);

This cannot compile - Visual Studio throws a No Definition for the configuration in xml.configuration.systemModuleSection

Any tips?
 
Hmm, it seems like I am doing it right in my first example, but the XML file I am using has a namespace, and I have to modify my code accordingly. I will post back when I find a solution.
 
Back
Top