bit of C# .net help needed

  • Thread starter Thread starter fez
  • Start date Start date

fez

fez

Caporegime
Joined
22 Aug 2008
Posts
27,481
Location
Tunbridge Wells
I have been doing a bit of VB .net development for a year or so now but havnt learnt that much if im honest. I really want to start to improve my skills with the idea of moving jobs at some point in the near future. With this in mind I have started to learn C# .net as it seems to be much more popular than VB.

One of the projects at work is being redesigned and I am in charge of this but I have a few questions about what the best way to do this is.

The system stores a large number of records for question answers which relate to an inspection of a property. The system will only store a record if there is an answer present for a question; if not then it will not store a record.

The questionnaire is liable to change over time due to changes in the way properties are assessed. This means that I have to store the questions for a particular years assessment in individual records as opposed to a single record for an assessment.

I have created custom controls for the question types and my plan is to iterate over them and draw them on the form.

My question is how to deal with the saving and updating of the answers to the assessment questions. Some will be updates, some new answers and I need to know which is which.

There are a number of options as to how to do this but how do you test for a value that has changed since loaded. Is there an easy way of automating saving and updating?

Any help, tips etc would be much appreciated.

Thanks
 
This is a windows form application that only wants to save when the user chooses. I dont know why but I always feel like there is a really simple solution staring me in the face that I am missing.

The questions may have a textbox and text field, or just text or just a combo.
 
Not sure I'd have a standard desktop application for this, especially if the questionnaire is set to change.


I'd go really OO on this. Have base objects such as a generic "question" object with all sorts of methods like "AddExtraMultipleChoiceOption".

So you'd be able to say something like
firstQuestion = new Question("Question 1");
firstQuestion.text = "What is the condition of your kitchen";
firstQuestion.addMultipleChoiceOption("Good");
firstQuestion.addMultipleChoiceOption("Bad");
firstQuestion.addMultipleChoiceOption("Medium");

The advantage being, using a reporting system or just a web app, you could process through an array of type "Question" objects and build the form for input or editing without having to redesign any part of the application


So in some sort of confudgimation of all sorts of languages you'd be able to cycle through an array of Question objects:

int i = 0;
while(Questions.hasnext){
print Questions.title();
int j = 0;
while(Questions.hasmoreoptions){
print Questions.multiple[j].MultipleChoiceOption.toString();
j++;
}
i++;
}

Not sure if that makes much sense, but well it does to me :p
 
lol, cheers dangerstat. It does indeed make sense. I am saving this to a database but there is also a mobile version which will run off XML.

To be honest it is rather hard to explain the project in writing without writing a massive spec. I think that I might have to take a good long look at LINQ from what I have seen so far.
 
Something like this would be more mangeable:
Code:
foreach (Question question in Questions) {
  question.renderOn(form);
}
So each type of question knows how to render it self on a form, with something like (and I don't know the API of forms, so bare that in mind before slating this example!)
Code:
public void renderOn(Form form) {
  form.addTextField(this.QuestionText);
  form.addTextbox(this.Name);
}
 
Though you may want to have something like a QuestionRenderer class to avoid tying the questions themselves to a Windows Forms presentation layer.
May be overkill for what is needed here though ;)

As for the new/updated questions stuff you could probably just do that with IsNew and IsDirty flags on the Question class.
 
As far as the real question goes (i.e. how to differentiate between a new and an updated question) you'll need to read from the DB before rendering the question(s) to find a given answer.

Without knowing details of your objects relationships (especially user <-> question) it's hard to tell how it can be done. Assuming someone must login, then you could simply have a question/answer/user relationship to identify an answer. E.g.:

Code:
SELECT Answers.* FROM Answers WHERE User = 'barry' AND QuestionID = 1234
To find Barry's answer to the Question with an id of 1234. If there is no answer, then it must be a new entry.
 
I have decided to screw work to be honest. This was a project that I have had at work for a good while but never had enough time to do it but im pretty ****** off with work at the moment so I will not be doing this in my spare time.

I was going to use it as a useful project to develop my C# skills but I will find something else to do this with.

Cheers for all the help guys and im sure that I will be back soon with questions of another nature.
 
Back
Top Bottom