C# Help Needed
Aug 17th, 2006 by Brian A. Thomas
If there are any C# programmers out there reading this, perhaps you can help.
First I'll repost a screen shot of the program I am working on:

Under the Action menu, there is an option to change the Standard Work Week (by default set to 40:00). When the user selects that, the standard work week text box changes from read only and a save button (not seen on this shot) becomes visible and active. The user then can edit the standard work week, save it and then have the program calculate what time they are to leave Friday (or whatever their last day of work is). That woks as expected. The problem comes up if they edit the standard work week, but don't save it and then hit calculate. It will calculate based on the last saved (or if never saved, the default) standard work week, which may not be what they typed into the text box.
What I have in place now is a message box that pops up if they try to calculate before saving their work. I currently am using an OK button message box, where if the user selects OK it saves the standard work week and then performs the calculations. Ideally I would like a Cancel button to take the focus back to the text box and wait for them to save it. Then the program could either continue performing the calculations, or the user may need to hit Calculate again.
Here is some code to give an idea of what I am doing:
-
// this is from the global variable section
-
bool standWeekOpen = false;
-
// Note that the save button for saving the standard work week changes
-
// this to true.
-
-
// then this is the click event for the calculate button
-
private void btnCalculate_Click(object sender, EventArgs e)
-
{
-
if (standWeekOpen)
-
{
-
// if the user was editing the standard work week
-
DialogResult button = MessageBox.Show("You are still editing "
-
+ "the Standard Work Week.\n"
-
+ "Press OK to save work week and contine", "Work Week Open");
-
txtWorkWeek.Text = "";
-
if (button == DialogResult.OK)
-
{
-
btnSaveWorkWeek_Click(sender, e);
-
}
-
}
I know that I need to change the MessageBox parameters to add the Cancel button, and I used an else statement to handle the Cancel button. Originally the else statement simply had a txtWorkWeek.Focus(); to send the focus to it, but right after that it continued on with the rest of the actions in the code for the button.
I need a way to stop it from going on until the standWeekOpen is changed back to false. I tried if, while, do/while and try/catch statements without any luck, they either give an infinite loop as expected, or once they are done evaluating, go on just as it does now.
I have a few options that I can see:
- Have the program somehow escape the Cancel event either until the user
standWeekOpenchanges back to false and goes on, or cancels out all together allowing the user to edit and save the standard work week, then click the calculate button again. This is the one I am trying to figure out now, if it is possible. - Have the OK button function as is, that is save the amount in the box and go on. The Cancel button in this case would use the last saved amount. This is perhaps the easiest solution, and didn't occur to me until after I started this entry.
- Change the main window. Get rid of the Save button, and when the user selects the menu option to change the standard work week, have a new window pop up that the user enters the standard work week into. Perhaps the less appealing of the options.
So anyone have any ideas?






