prevent duplicate entries in C1TrueDBGrid - c#

I am working with my C# Windows application, and this is my first time to use tdbgrid(component1). I want to prevent users from inputting duplicated values after validating them with the database.
Below is the code which I am using for it in (BeforeColUpdate)Event:
bool ExitValue = false;
private void C1TrueDBGrid_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
{
if (e.Column.Name == "Groups Code")
{
for (int currentRow = 0; currentRow < this.C1TrueDBGrid.Rows.Count - 1;currentRow++)
{
string rowToCompare = this.C1TrueDBGrid.Splits[0].DisplayColumns[C1TrueDBGrid.Col].DataColumn.CellValue(currentRow).ToString();
for (int otherRow = currentRow+1 ; otherRow < this.C1TrueDBGrid.Rows.Count; otherRow++)
{
bool DuplicatedRow = true;
string Row = this.C1TrueDBGrid.Splits[0].DisplayColumns[C1TrueDBGrid.Col].DataColumn.CellValue(otherRow).ToString();
if (Row!=rowToCompare)
{
ExitValue = false;
break;
}
if (DuplicatedRow)
{
C1TrueDBGrid.Splits[0].DisplayColumns[tgdGroupsUsers.Col].DataColumn.Value = DBNull.Value;
MessageBox.Show("Sorry: but this item(s) is already Exists ", "Error Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
ExitValue = true;
e.Cancel = true;
}
}
}
}
else
{
//Clear Fields
C1TrueDBGrid.Splits[0].DisplayColumns[C1TrueDBGrid.Col].DataColumn.Value = null;
e.Cancel = true;
}
}
if not duplicated below is the code which I am using in (AfterColUpdate)Event:
private void C1TrueDBGrid_AfterColUpdate(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e)
{
if (!ExitValue)
{
int indexRow = this.C1TrueDBGrid.RowBookmark(this.C1TrueDBGrid.Row);
this.C1TrueDBGrid[indexRow, 0] = CSystemUsers.GroupsCode;
this.C1TrueDBGrid[indexRow, 0] = CSystemUsers.EngName;
}
}

componentone answer me the question:
private void c1TrueDBGrid1_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
{
if (e.ColIndex == 1)
{
for (int i = 0; i < c1TrueDBGrid1.RowCount; i++)
{
if (c1TrueDBGrid1.Editor.Text == c1TrueDBGrid1[i, e.ColIndex].ToString())
{
MessageBox.Show("Sorry: but this item(s) already Exists", "Error Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Cancel = true;
}
}
}
}
link:
http://our.componentone.com/groups/topic/how-do-i-prevent-duplicate-entries-in-c1truedbgrid/
hope this helps someone else in future:

Related

Some rows remains in a DataGrid when deleting multiple rows

I have a WPF triggered (TextChanged) function which calls two other function whose subroutine deletes rows from a DataGrid object when certain conditions are met.
I have a feeling I might be encountering race conditions on the delete of multiple rows. When I place a MessageBox.Show("somethings'); in between the two functions, 2 rows from DataGrid are deleted as expected with the message box popping up in between delete actions.
deleteFunction("item1");
MessageBox.Show("something");
deleteFunction("item2");
However if I remove the MessageBox only the first function deletes a single row (item1)from DataGrid.
deleteFunction("item1");
deleteFunction("item2");
I have tried all sorts of ways to resolve this, Thread.Sleep(500) in between function calls, setting up a Queue to FIFO the requests, thread locking. async ... Nothing seems to work for me.
I'm not even sure it is actually a race condition issue anymore. I am starting to wonder if there is some Thread connection to the DataGrid object that the MessageBox is severing when invoked and releasing the control for another function to interact with.
Code below:
private void streamCode_TextChanged(object sender, TextChangedEventArgs e)
{
if (configurationSectionLoaded == true)
{
streamCodeAlphanumeric(streamCode.Text);
streamCodeIsChar128(streamCode.Text);
}
formEdited = true;
}
private bool streamCodeAlphanumeric(string value)
{
dataValidation dv = new dataValidation();
if (dv.isAlphanumeric(value))
{
streamCode.Background = Brushes.LightGreen;
editStreamcode.Background = Brushes.LightGreen;
editStreamcode.IsEnabled = true;
//MessageBox.Show("scE01 Deleting");
//q.Enqueue(new UILogDeleteQueue() { qEntryType = "scE01" });
try
{
UILogRemoveRow("scE01");
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
return true;
}
else
{
editStreamcode.IsEnabled = false;
streamCode.Background = Brushes.LightPink;
UILogAddRow("scE01", "Stream Code", "Non-Alphanumeric Characters Detected!");
return false;
}
}
private bool streamCodeIsChar128(string value)
{
dataValidation dva = new dataValidation();
if (dva.isChar128(value))
{
streamCode.Background = Brushes.LightGreen;
editStreamcode.Background = Brushes.LightGreen;
editStreamcode.IsEnabled = true;
//MessageBox.Show("scE02 Deleting");
try
{
UILogRemoveRow("scE02");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return true;
}
else
{
editStreamcode.IsEnabled = false;
streamCode.Background = Brushes.LightPink;
UILogAddRow("scE02", "Stream Code", "Invalid Length Detected!");
return false;
}
}
Finally here is the delete row code:
private void UILogRemoveRow(string entryCode)
{
int rowCount;
rowCount = UILog.Items.Count;
if (rowCount > 0)
{
for (int i = 0; i < rowCount; i++)
{
DataGridRow row = (DataGridRow)UILog.ItemContainerGenerator.ContainerFromIndex(i);
var selectedItem = UILog.ItemContainerGenerator.ContainerFromIndex(i);
if (row != null)
{
UILogObject theItem = (UILogObject)row.DataContext;
if (theItem.entryType == entryCode)
{
UILog.Items.RemoveAt(i);
}
}
}
}
}
Any assistance would be greatly appreciated.
UPDATE: included UILogAddRow function
private void UILogAddRow(string entryCode, string entryIdentifier, string entryDetail)
{
bool itemExists = false;
int rowCount;
rowCount = UILog.Items.Count;
if (rowCount > 0)
{
for (int i = 0; i < rowCount; i++)
{
DataGridRow row = (DataGridRow)UILog.ItemContainerGenerator.ContainerFromIndex(i);
if (row != null)
{
UILogObject theItem = (UILogObject)row.DataContext;
if (theItem.entryType == entryCode)
{
itemExists = true;
}
}
}
}
else
{
//MessageBox.Show(rowCount.ToString());
}
if (itemExists != true)
{
UILog.Items.Add(new UILogObject() { entryType = entryCode, identifier = entryIdentifier, detail = entryDetail });
}
UILog.Items.Refresh();
}
instead of working with low-level container elements (DataGridRow), cast items to your known type, and then search and remove
private void UILogRemoveRow(string entryCode)
{
var item = UILog.Items.OfType<UILogObject>()
.FirstOrDefault(x => x.entryType == entryCode);
if (item != null)
UILog.Items.Remove(item);
}

Why are the values still adding up after i clear the output label?

I'm not sure what is going on. I thought I had it set up to clear the output label at the end. Everytime I clear it, the program still remembers the previous number and adds to it. I honestly have no idea what is going on.
Also on a side note, how do I put set up radiobuttons to be used in the this method?
First coding class so i'm still kind of a beginner.
private double oilandlube()
{
if (checkBox1.Checked == true)
{
Oil_change = 26;
}
if (checkBox2.Checked == true)
{
Lube_job = 18;
}
return Oil_change + Lube_job;
}
private void Oiltype ()
{
if (radioButton1.Checked)
{
Regular = 0;
}
if (radioButton2.Checked)
{
Mixed = 10;
}
else
{
Mixed = 0;
}
if (radioButton3.Checked)
{
Full_Synthetic = 18;
}
else
{
Full_Synthetic = 0;
}
}
private void carwash()
{
if (radioButton4.Checked)
{
none = 0;
}
if (radioButton5.Checked)
{
complimentary = 0;
}
if (radioButton6.Checked)
{
Full_service = 6;
}
else
{
Full_service = 0;
}
if (radioButton7.Checked)
{
Premium = 9;
}
else
{
Premium = 0;
}
}
private double flushes()
{
if (checkBox3.Checked == true)
{
Radiator_flush = 30;
}
if (checkBox4.Checked == true)
{
Transmission_flush = 80;
}
return Radiator_flush + Transmission_flush;
}
private double misc()
{
if (checkBox5.Checked == true)
{
inspection = 15;
}
if (checkBox6.Checked == true)
{
replace_muffler = 100;
}
if (checkBox7.Checked == true)
{
tire_rotation = 20;
}
return inspection + replace_muffler;
}
private double partsandlabor()
{
double.TryParse(textBox1.Text, out parts);
double.TryParse(textBox2.Text, out labor);
return parts + labor;
}
private double tax()
{
return partsandlabor() * taxes;
}
private void summary()
{
service = oilandlube() + flushes() + misc();
total_parts = partsandlabor();
double total_tax = tax();
double grand_total = service + total_parts + total_tax;
label7.Text = service.ToString("c");
label8.Text = total_parts.ToString("c");
label9.Text = total_tax.ToString("c");
label10.Text = grand_total.ToString("c");
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
oilandlube();
carwash();
flushes();
misc();
partsandlabor();
summary();
}
private void ClearOilandlube()
{
checkBox1.Checked = false;
checkBox2.Checked = false;
}
private void ClearMisc()
{
checkBox5.Checked = false;
checkBox6.Checked = false;
checkBox7.Checked = false;
}
private void ClearFlushes()
{
checkBox3.Checked = false;
checkBox4.Checked = false;
}
private void ClearSummary()
{
label7.Text = "";
label8.Text = "";
label9.Text = "";
label10.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
ClearOilandlube();
ClearMisc();
ClearFlushes();
ClearSummary();
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;
radioButton4.Checked = false;
radioButton5.Checked = false;
radioButton6.Checked = false;
radioButton7.Checked = false;
textBox1.Text = "0";
textBox2.Text = "0";
}
}
}
When you clear the contents of your controls, you should also clear the values of the backing variables, so they don't retain their previous values. You should be able to just set them back to zero in your Clear methods.
For example, oil and lube might look like:
private void ClearOilandlube()
{
checkBox1.Checked = false;
checkBox2.Checked = false;
Oil_change = 0;
Lube_job = 0;
Mixed = 0;
Regular = 0;
Full_Synthetic = 0;
}
It looks like you're holding state of some your variables globally so you can access them elsewhere.
Mixed = 10;
You'll have to reset that to some default value as well.

Online Exam Test splits when test taken by multiple users simultaniously

My online exam application test in asp.net gets split when multiple users take the test. my 20 question test gets split into 10 10 question to each user who is taking the test simultaniously. I am using session in my appliaction here is the code please help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BAL;
namespace OnlineExamDesign
{
public partial class Exam : System.Web.UI.Page
{
static int index = 0;
static int selection = 0;
static int QuestionNums = 0;
clsExam examObj = new clsExam();
DataSet ds; DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
index = 0;
selection = 0;
string set = Session["CandidateSet"].ToString();
ds = examObj.getQuestion(set);
Session["Ques"] = ds;
displayQuestion(index);
btnPrevious.Enabled = false;
if (Session["candidateName"] != null)
lblCandidateName.Text = Session["candidateName"].ToString();
clearResultData();
}
}
private void clearRadioButtons()
{
rbtnOption1.Checked = false;
rbtnOption2.Checked = false;
rbtnOption3.Checked = false;
rbtnOption4.Checked = false;
}
private void clearResultData()
{
for (int n = 0; n < clsExam.AnsList.Length; n++)
{
clsExam.AnsList[n] = 0;
}
}
private void saveCandidateData()
{
Candidate obj = new Candidate();
obj.Fname = Session["CandidateFName"].ToString();
obj.Lname = Session["CandidateLName"].ToString();
obj.Contact = Session["CandidateContact"].ToString();
obj.Domain = Session["CandidateDomain"].ToString();
obj.Team = Session["CandidateTeam"].ToString();
obj.Set = Session["CandidateSet"].ToString();
obj.ExamStartTime = (DateTime)Session["strttime"];
obj.ExamEndTime = System.DateTime.Now;
obj.Score = examObj.score;
obj.actionCandidateDetails("save");
Session["Score"] = obj.Score;
}
private int displayQuestion(int index)
{
ds = (DataSet)Session["Ques"];
dt = ds.Tables[0];
int num = dt.Rows.Count;
if (index <= num)
{
lblQuestionNum.Text = Convert.ToString((index+1));
lblQuestion.Text = dt.Rows[index]["questions_question_nvc"].ToString();
rbtnOption1.Text = dt.Rows[index]["questions_option1_nvc"].ToString();
rbtnOption2.Text = dt.Rows[index]["questions_option2_nvc"].ToString();
rbtnOption3.Text = dt.Rows[index]["questions_option3_nvc"].ToString();
rbtnOption4.Text = dt.Rows[index]["questions_option4_nvc"].ToString();
}
else if (index > num - 1)
btnNext.Enabled = false;
else if (index <= 0)
btnPrevious.Enabled = false;
return num;
}
private void retainChoice()
{
if ((clsExam.AnsList[index]).Equals(1))
{
rbtnOption1.Checked = true;
}
else if ((clsExam.AnsList[index]).Equals(2))
{
rbtnOption2.Checked = true;
}
else if ((clsExam.AnsList[index]).Equals(3))
{
rbtnOption3.Checked = true;
}
else if ((clsExam.AnsList[index]).Equals(4))
{
rbtnOption4.Checked = true;
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
btnPrevious.Enabled = true;
rbtnOptionCheckedChanged(sender, e);
examObj.storeAns(index, selection);
selection = 0;
clearRadioButtons();
index++;
int QuestionNums = displayQuestion(index);
retainChoice();
if (index >= QuestionNums - 1)
btnNext.Enabled = false;
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
if (index > 0)
{
rbtnOptionCheckedChanged(sender, e);
examObj.storeAns(index, selection);
selection = 0;
clearRadioButtons();
index--;
displayQuestion(index);
retainChoice();
btnNext.Enabled = true;
}
else if (index <= 0)
{
btnPrevious.Enabled = false;
}
else if (index < QuestionNums - 1)
{
btnNext.Enabled = true;
}
else
{
btnPrevious.Enabled = false;
btnNext.Enabled = true;
}
}
protected void btnExit_Click(object sender, EventArgs e)
{
int i = 0;
examObj.storeAns(index, selection);
ds = (DataSet)Session["Ques"];
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["questions_answer_nvc"].Equals(clsExam.AnsList[i]))
{
examObj.countScore();
i++;
}
}
Response.Write(examObj.score);
saveCandidateData();
index = 0;
clearResultData();
Response.Redirect("ThankYou.aspx");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int i = 0;
examObj.storeAns(index, selection);
ds = (DataSet)Session["Ques"];
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["questions_answer_nvc"].Equals(clsExam.AnsList[i]))
{
examObj.countScore();
i++;
}
}
Response.Write(examObj.score);
saveCandidateData();
index = 0;
clearResultData();
Response.Redirect("ThankYou.aspx");
}
protected void rbtnOptionCheckedChanged(object sender, EventArgs e)
{
if (rbtnOption1.Checked)
selection = 1;
else if (rbtnOption2.Checked)
selection = 2;
else if (rbtnOption3.Checked)
selection = 3;
else if (rbtnOption4.Checked)
selection = 4;
}
}
}
I am going to repeat the sentence I am famous for in our company: Static is evil!
And yes, it is. static in a web application means it is shared across all users, meaning that the index of user 1 is the same as the index for user 2.
You can fix this quite easily by storing your static variables in the session object. I would simply hide that in a property:
public int Index
{
get
{
return (Session["Exam_Index"] as int?) ?? 0;
}
set
{
Session["Exam_Index"] = value;
}
}

Stopping the calculations because of predicted error

I am unsure how to ask this question as I can't quite well translate it.
I am currently working on my own Windows Form Application that will calculate the dimensions of a given package in inches (written all together in string format) and calculate the dimensions in centimeters, milimeters or even meters and at this point I was wondering what if someone entered wrong dimensions and given measures can not be parsed.
Something like Environment.Exit(), but without closing the application just stopping calculations and writing a message that an error has occured.
If there is a question like this answered, please do link it because I haven't been able to find it.
namespace PretvaranjeDimenzija
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public double mjera = 1;
public bool pogreska = false;
public string mjeraKratica = " cm";
public string dimenzijeIspis = "";
private void buttonIzracunaj_Click(object sender, EventArgs e)
{
string dim = textBoxDimenzije.Text;
if (dim.Contains('.'))
{
dim = dim.Replace('.', ',');
}
if (dim.Length != 0)
{
if (dim.IndexOf('x') != -1)
{
string[] multiDim = dim.Split('x');
double[] multiDimCentimetara = new double[multiDim.Length];
bool[] uspjeh = new bool[multiDim.Length];
for (int i = 0; i < multiDim.Length; i++)
{
uspjeh[i] = double.TryParse(multiDim[i], out multiDimCentimetara[i]);
if (uspjeh[i] == false)
{
pogreska = true;
goto kraj;
}
}
kraj:
if (pogreska == true)
{
MessageBox.Show("Doslo je do pogreske!");
pogreska = false;
}
else
{
double[] dimenzije = new double[multiDim.Length];
for (int i = 0; i < dimenzije.Length; i++)
{
dimenzije[i] = multiDimCentimetara[i] * 2.54 * mjera;
if (i == dimenzije.Length - 1)
{
dimenzijeIspis += dimenzije[i].ToString() + mjeraKratica;
}
else
{
dimenzijeIspis += dimenzije[i].ToString() + "x";
}
}
textBoxIspisDimenzija.Text = dimenzijeIspis;
dimenzijeIspis = "";
}
}
else
{
double dimCentimetara;
if(double.TryParse(dim, out dimCentimetara))
{
double dimenzija = dimCentimetara * 2.54 * mjera;
dimenzijeIspis = dimenzija.ToString() + mjeraKratica;
textBoxIspisDimenzija.Text = dimenzijeIspis;
dimenzijeIspis = "";
}
else
{
MessageBox.Show("Doslo je do pogreske!");
return;
}
}
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
mjera = 0.01;
mjeraKratica = " m";
if (radioButton2.Checked == true)
{
radioButton2.Checked = false;
radioButton1.Checked = true;
}
if (radioButton3.Checked == true)
{
radioButton3.Checked = false;
radioButton1.Checked = true;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
mjera = 1;
mjeraKratica = " cm";
if (radioButton1.Checked == true)
{
radioButton1.Checked = false;
radioButton2.Checked = true;
}
if (radioButton3.Checked == true)
{
radioButton3.Checked = false;
radioButton2.Checked = true;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
mjera = 10;
mjeraKratica = " mm";
if (radioButton2.Checked == true)
{
radioButton2.Checked = false;
radioButton3.Checked = true;
}
if (radioButton1.Checked == true)
{
radioButton1.Checked = false;
radioButton3.Checked = true;
}
}
}
It should be pretty simple, depending on your requirements. For example, you could just use a basic if block in your method.
void CalculateStuff()
{
// Get input. Do stuff.
if (IsInvalid)
{
MessageBox.Show("You did a bad thing.");
return; // exit the method.
}
// now that we know the input is good, do other stuff.
}
Substitute IsInvalid with whatever check condition you want that will return true if the input is not valid.

How do I stop a program from calculating if no radio button is selected?

I'm really new to programming. C# is the first class I've taken and I'm stuck on this a project. We had to create a program that will calculate the cost of workshop after selecting a workshop radiobutton and a location radio button. I've got everything working the way it's supposed to except for one thing.
Let's say you select a workshop, but you don't select a location. I have it to where a MessageBox will show up saying to "select a location," but how do I stop the program from calculating if this happens? As of now, it will just calculate and give the location amount 0. I need it to not calculate at all.
public partial class frmWorkshopSelector : Form
{
public frmWorkshopSelector()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close(); //When clicking the exit button, the program will close
}
private void btncalc_Click(object sender, EventArgs e)
{
int wsregistration = 0;
int lcost = 0;
const decimal DAYS = 3;
//For the following if statements, depending on what workshop and location is selected,
//their correstponding registration and lodging fees will be displayed
{
if (rbtHandlingStress.Checked == true)
{
wsregistration = 1000;
}
else if (rbtSupervisionSkills.Checked == true)
{
wsregistration = 1500;
}
else if (rbtTimeManagement.Checked == true)
{
wsregistration = 800;
}
else
MessageBox.Show("Please Select a Workshop");
lblTotalCost.Text = "";
lblLodgingCost.Text = "";
lblRegistrationCost.Text = "";
}
{
if (rbtAustin.Checked == true)
{
lcost = 150;
}
else if (rbtChicago.Checked == true)
{
lcost = 225;
}
else if (rbtDallas.Checked == true)
{
lcost = 175;
}
else
{
MessageBox.Show("Please Select a Location");
lblRegistrationCost.Text = " ";
lblTotalCost.Text = " ";
lblLodgingCost.Text = " ";
}
}
lblRegistrationCost.Text = wsregistration.ToString("C");
lblLodgingCost.Text = lcost.ToString("C");
lblTotalCost.Text = (wsregistration + (lcost * DAYS)).ToString("C");
}
private void btnReset_Click(object sender, EventArgs e)
{
//unchecks all radio buttons as well as clears out the previous calculations
lblRegistrationCost.Text = "";
lblLodgingCost.Text = "";
lblTotalCost.Text = "";
rbtHandlingStress.Checked = false;
rbtSupervisionSkills.Checked = false;
rbtTimeManagement.Checked = false;
rbtAustin.Checked = false;
rbtChicago.Checked = false;
rbtDallas.Checked = false;
}
}
You have to exit from the method. Added return statement in else block.
private void btncalc_Click(object sender, EventArgs e)
{
int wsregistration = 0;
int lcost = 0;
const decimal DAYS = 3;
//For the following if statements, depending on what workshop and location is selected,
//their correstponding registration and lodging fees will be displayed
if (rbtHandlingStress.Checked == true)
{
wsregistration = 1000;
}
else if (rbtSupervisionSkills.Checked == true)
{
wsregistration = 1500;
}
else if (rbtTimeManagement.Checked == true)
{
wsregistration = 800;
}
else
{
lblTotalCost.Text = "";
lblLodgingCost.Text = "";
lblRegistrationCost.Text = "";
MessageBox.Show("Please Select a Workshop");
return;
}
if (rbtAustin.Checked == true)
{
lcost = 150;
}
else if (rbtChicago.Checked == true)
{
lcost = 225;
}
else if (rbtDallas.Checked == true)
{
lcost = 175;
}
else
{
lblRegistrationCost.Text = " ";
lblTotalCost.Text = " ";
lblLodgingCost.Text = " ";
MessageBox.Show("Please Select a Location");
return;
}
lblRegistrationCost.Text = wsregistration.ToString("C");
lblLodgingCost.Text = lcost.ToString("C");
lblTotalCost.Text = (wsregistration + (lcost * DAYS)).ToString("C");
}
writing a "return" anywhere within the function exits that function, maybe after you show the message box to enter location, you type
return;
and this should do the job.
Just Add return statement in your code after showing the message box like below
public partial class frmWorkshopSelector : Form
{
public frmWorkshopSelector()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close(); //When clicking the exit button, the program will close
}
private void btncalc_Click(object sender, EventArgs e)
{
int wsregistration = 0;
int lcost = 0;
const decimal DAYS = 3;
//For the following if statements, depending on what workshop and location is selected,
//their correstponding registration and lodging fees will be displayed
{
if (rbtHandlingStress.Checked == true)
{
wsregistration = 1000;
}
else if (rbtSupervisionSkills.Checked == true)
{
wsregistration = 1500;
}
else if (rbtTimeManagement.Checked == true)
{
wsregistration = 800;
}
else
MessageBox.Show("Please Select a Workshop");
lblTotalCost.Text = "";
lblLodgingCost.Text = "";
lblRegistrationCost.Text = "";
return;
}
{
if (rbtAustin.Checked == true)
{
lcost = 150;
}
else if (rbtChicago.Checked == true)
{
lcost = 225;
}
else if (rbtDallas.Checked == true)
{
lcost = 175;
}
else
{
MessageBox.Show("Please Select a Location");
lblRegistrationCost.Text = " ";
lblTotalCost.Text = " ";
lblLodgingCost.Text = " ";
return;
}
}
lblRegistrationCost.Text = wsregistration.ToString("C");
lblLodgingCost.Text = lcost.ToString("C");
lblTotalCost.Text = (wsregistration + (lcost * DAYS)).ToString("C");
}
private void btnReset_Click(object sender, EventArgs e)
{ //uncheks all radio buttons as well as clears out the previous calculations
lblRegistrationCost.Text = "";
lblLodgingCost.Text = "";
lblTotalCost.Text = "";
rbtHandlingStress.Checked = false;
rbtSupervisionSkills.Checked = false;
rbtTimeManagement.Checked = false;
rbtAustin.Checked = false;
rbtChicago.Checked = false;
rbtDallas.Checked = false;
}
}
}

Categories

Resources