I need to implement a form tamplate system. The form needs to be very dynamic. It will need:
Multiple textboxes
Multiple dropdown menus
Multiple Number fields
Multiple Date fields
Single Image field
Single Submit button
Any or all of these fields can be blank but must follow the field type. Therefore letters cannot go in number fields.
The form needs to grab all the values and there could be from 1 to 300 fields in one form or more. I could not find any examples of how to implement this online. Once I grap all these values I need to store them in the database. I think I know how to store them in the database but I am puzzled on how to extract the information from the form.
Have you looked into any of the existing options, like XForms? I believe this company produces a fairly nice product: http://www.orbeon.com/
Adobe has a nice product (which even scales to enterprise levels with things like LiveCycle) if you're OK with plugins / non-html-only... although they do offer HTML rendering, but I believe it's limited.
If you are OK with the price of Sharepoint, Microsoft has InfoPath, which is sorta neat.
What are your requirements? I'm assuming ASP.NET/ASP MVC based (based on your tags). I'm also assuming cross-browser. Do you need the data back in a particular format, or as a POST to a page? What about complex validations and field bindings?
Related
This is a stand alone application, and the data doesn't need to be saved for a later time, and data will not be shared between users, it's for one user to input their data and carry out an assessment, the user can then note down the results, but none of this needs to be stored into the app for a later time.
It's a 2 stage assessment, the first stage requires the user to fill out a number of forms with structural details of columns, depending on how many columns they have, and the second stage needs to sum some of those column values and some will need to be averaged, to then display the final values of the assessment, onto a final form.
Only numbers are entered into each form, and results will also be in the form of numbers which are then displayed on a graph. There are around 30 text boxes of user input, which are input into a input form that pops of from a button from the parent form, stage one of the assessment is then carried out for each column on each parent form. Each parent form renderred onto a new tab using this EasyTabs solution Creating a C# Application with Chrome-Style Tabs using EasyTabs in WinForms - YouTube[^] that I found online.
I'm an absolute beginner on C# , so I couldn't figure out how I would take a value from each form and display the sum or average onto the final form, if I don't know how many forms there will be for each user during run time, as each user will have a different amount, I was thinking it's maybe some sort of loop during run time, but I'm just not sure what that would look like.
After speaking to a friend, they recommended a single form, with a save and refresh button, where the data gets saved onto a file, and then gets retrieved would be better, but there are say 10 different user input values that need to be picked up from each form, and then averaged or summed, I started learning about StreamReader and StreamWriter and how files work in C#, but it was really difficult to figure out how to lay out the data in the file, how to get C# to sum the correct values together etc etc.
What would be the best way to approach this problem?
Thank you for your help.
If by "Form" you mean the WinForms definition of Form (Basically a new window), then I advise you to have a look at this post describing how to get data from one Form to the other.
To make a TextBox only accept numbers, you can use the a regular expression validation ^[0-9]*$ if you want to allow empty inputs or ^[0-9]+$ if you want at least one digit. if you want to allow negative numbers as well it is ^(\+|-)?[0-9]$. Note: all those will allow leading zeroes. For decimals you need to allow periods as well. ^(\+|-)?[0-9]*(\.[0-9]+)?$. Read up on regular expressions if you need anythin else. This website can help you design and test them.
To get a number from your text box you need to parse the text in the textbox. dotNet has plenty of functions for that already. For example Int32.TryParse() or if you want it to throw an exception Int32.Parse(). Others are similar. Have a look at the MSDN documentation to see how to use them.
As for averaging: Making a database, connecting to it and then using it to calculate the average of a number does seem like a pretty roundabout way of doing things. In programming you tell the computer what to do. So if someone told you to calculate an average, would you write the numbers in a book an then send them off to someone to calculate for you? Surely not.
You can just add all the numbers together in your code and divide by the amount of numbers. But there is an even easier solution. Add all your numbers to a List<int> and call it's .Sum() method and then divide by the return of it's .Count() method.
Saving the data to a file is only needed if you want to shut off the program between the user inputs or want to document the inputs.
Writing and reading numbers from a file is fairly straight forward though. Have a look at these tutorials provided by Microsoft: Write to file, Read from file, Read file one line at a Time. Writing to files uses the exact same methods as System.Console, just that you use a file stream instead of StdIO.
As for data layouts, there are several sane variants. For something simple you can just make your own (i.e. the position in the file dictates where the data goes, or each data point comes with a descriptor before it, for example inputA: 24). For more complex data, I would consider creating a class for your data and then serialize the data, for example using the popular Newtonsoft JSON library or XML and don't worry about how the file is structured.
I've been learning about obtaining and modifying access data in C# for a few days and I have a pretty good idea on how to do it.
What I find a bit hard to understand is how to efficiently show data in A windows form.
My access table is information on a Supplier, and it has 11 fields in it (name, street etc)
Now I want to be able to have users see all this data as well as modify it in C#.
So far I have tried just having 11 text boxes with corresponding list boxes as well, and the list boxes contained a specific field and when you clicked on any of them, all the data would go into the text box which could be modified.
However I found that this is ridiculously inefficient as I was changing the value of listboxes/Textboxes constantly.
is there a way to efficiently show all the data in a Table? (even if it has many fields, IE upwards of 15), or should I look at an alternative solution.
Thank you.
Use the DataGridView control.
Read C# DataGridView tutorial.
I am creating a new support center and "self-help" customer service module for an application. The CIO really likes the flow of eBay's "Contact Us" pages, that basically work like this:
First, you select a specific topic from a group of topics (e.g. Buying, Selling, Account on eBay)
You're then presented with what appears to be one of three variable types of information, based on the topic you picked (names are just what I'm calling them in some preliminary sketches):
"Descriptive": displays rich text with possible links to other parts of the application.
"Choice": Displays a list of additional topics
"Action": Lets the user look up an item and do some action (e.g. cancel)
From some experimentation, a choice can list to other choices, or to a descriptive block of text, or to an action section.
I'm turning up blanks as to the proper architecture for this. My platform of choice is ASP.NET (WebForms, sadly; we have no desire to touch MVC here) so the "Action" areas would have to be a user control that's dynamically loaded into a placeholder, but I'm more concerned with a possible database structure for this. I would need a way to know if each topic leads to one of the three types above and then on the page dynamically load either the content, list of links, or user control which makes things a bit trickier, nevermind the fact that a non-technical user will have to update and add the information from some kind of administrative panel.
Any suggestions for doing something like this? I'm not on a tight deadline, but I can't take too long or I'll be considered to be wasting time and not producing results.
If you can store the "tree of knowledge" in some way, like a custom XML file which would organize all options / possible actions, descriptions etc. Then you can "walk" it based on user's selections and display appropriate user control with content generated on the fly based on the contents of the XML node you're currently at.
Your "admin tool" would then need to update/modify the XML file, and your "public" CMS would render user controls inside an ASPX form.
One of the projects I worked on used this methodology for intranet's user menu - effectively a knowledge base of hyperlinks / actions split in to categories so they can be drilled-down to. Each element can contain links to other elements - so you have a spider-web like navigatable chain / workflow.
Just make sure each element has a unique ID (trivial to implement) and you can always get at it through xpath.
By having users modify a "working copy" and keeping backups of the live XML file when changes are published you also get versioning / roll-back which would be difficult to do in a DB.
If I personally was doing this I would just roll some MVC3 controllers that handle the work flow steps as needed. That seems to be out for you however.
With webforms, I would most likely consider handling this using Windows Workflow Foundation (the learning curve is moderately steep on this). Here's a pretty good example on using WF Flexible Web UI Workflow application through ASP.NET MVC & Windows Workflow Foundation. It's built on MVC however you could easily replace the return Views() with return UserControls.
Following a model like this would defacto give you the MVC pattern. The controller dictating flow matches very well for a workflow scenario.
Edit: Since this even seems out of the question, at this point you're best option is just writing a controller class that will manage the flow manually (probably a bunch of state / if checks) and then redirect users or return the appropriate user control.
I'm trying to create a very basic web site creator in C#. I already created the templates but have no idea how to get them in the program so the user can pick one and customize it. Is there a certain library I should look into? I've bee told this can be easily created in php but I'd rather not go down that route.
If using .NET you can use WebControl controls to display a preview of your templates and make the user decide which one he wants.
Or a list of templates and single WebControl that parse and display the HTML of the current selected list item (template) and then make the user select.
To edit, just a bunch of controls (one for each template placeholder) that updates the view of the WebControl.
In the top link you found how to do it.
P.S. Templates can be stored on XML, Plain Text, DB or any other mean.
Either store the templates as files on the web-side and use them as templates, or store them in a DB. Unless your app is not web-based, in which case the same advice pretty much applies.
I have a textbox and a button in one page.I want to enter a word in the textbox and click the button. After clicking the button I want to display the name of the web pages containing the word entered in the textbox. So please tell me how to do it? I am using C#.
So you want to create a search engine internal to your website. There are a couple of different options
You can use something like google custom search which requires no coding and uses the google technology which I think we all agree does a pretty good job compared to other search engines. More information at http://www.google.com/cse/
Or you can implement it in .net which I will try to give some pointers about below.
A search engine in general exists out of (some of) the following parts:
a index which is searched against
a query system which allows searches to be specified and results shown
a way to get documents into the index like a crawler or some event thats handled when the documents are created/published/updated.
These are non trivial things to create especially if you want a rich feature set like stemming (returning documents containing plural forms of search terms), highlighting results, indexing different document formats like pdf, rtf, html etc... so you want to use something already made for this purpose. This would only leave the task of connecting and orchestrating the different parts, writing the flow control logic.
You could use Lucene.net a opensource project with a lot of features. http://usoniandream.blogspot.com/2007/10/tutorial-implementing-lucenenet-search.html explains how to get started with it.
The other option is Microsoft indexing service which comes with windows but I would advice against it since it's difficult to tweak to work like you want and the results are sub-optimal in my opinion.
You are going to need some sort of backing store, and full text indexing. To the best of my knowledge, C# alone is not enough.