: : Hello I have a issue to discuss that recently I have a made a C# program for Rental Car Management, although its very easy cause all it contained was SQL statements manipulating the data form database. The issues starts when I gather all the elements or functions and display them to be accessed by one Main window where I can access all the different elements of the programs. I am showing you the code for this part, My teacher says its bit complicated and he would have done it simpler and differently.
: : I will appreciate any help comments to improve this.
: :
: : static void Main(string[ ] args)
: : {
: : CMS cms=new CMS();
: : cms.Go();
: : }
: :
: : public void ActionPerformed( string c )
: : {
: : switch (c)
: : {
: : case "ManageCustomer":
: : ManageCustomer m1= new ManageCustomer();
: : m1.Go();
: : break;
: : case "ManageContract":
: : ManageContract m2 = new ManageContract();
: : m2.Go();
: : break;
: : case "ManageEmployee":
: : ManageEmployee m3 = new ManageEmployee();
: : m3.Go();
: : break;
: : case "ManagePayment":
: : ManagePayment m4 = new ManagePayment();
: : m4.Go();
: : break;
: : case "ManageCar":
: : ManageCar m5 = new ManageCar();
: : m5.Go();
: : break;
: : case"ManageCarCatagories":
: : ManageCarCatagories m6 = new ManageCarCatagories();
: : m6.Go();
: : break;
: : case "Exit":
: : entry.CloseGUI();
: : break;
: : default:
: : return;
: : }
: : }
: : //every thing OK up til here, no problems, but all the problems start after this.
: :
: : public void Go()
: : {
: : entry = new Views.Form(formSpec);
: : for( ; ; ) // he thinks this is not right!!!
: : {
: : string c = entry.GetControl();
: : if (c==null) break;
: : ActionPerformed(c);
: : }
: : entry.CloseGUI();
: : }
: :
: :
:
: You didn't post all your code, so I can't see what kind of class Views.Form is, but the following fragment seems tricky:
:
: for( ; ; ) // he thinks this is not right!!!
: //he's wrong.
: {
: string c = entry.GetControl();
: if (c==null) break;
: ActionPerformed(c);
: }
:
:
: You enter an endless loop and it seems that you try to loop through all controls within 'entry'.
: But doesn't 'entry.GetControl()' returns the same control each iteration? That would mean you will never leave the loop. I expect you would need something like this:
:
: foreach (Control control in entry.Controls)
:
: If that's not the case, then pls post the code for the Views.Form.GetControl() method.
:
:
:
: Greets,
: Eric Goldstein
: www.gvh-maatwerk.nl
:
:
hello
thanks ever so much your attention,
I tried your method , but I get this error that the 'entry'is not found, I am posting you the "form" so you can have the whole picture.
using System;
using Views;
using System.IO;
using System.Drawing;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
namespace CMS1
{
public class ManageCar
{
static string source = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=DanCarRental.mdb";
OleDbConnection db; // connects to the DB.
OleDbCommand command;
OleDbDataReader reader;
string sql;
Views.Form form;
string formSpec = @"<Form Text=ManageCar BackColor = silver>
<vertical>
<horizontal>
</horizontal>
<vertical>
<horizontal>
<Label Name=VehicleID Width=100/>
<TextBox Name=VehicleID/>
</horizontal>
<horizontal>
<Label Name= LicensePlateNum Width=100/>
<TextBox Name=LicensePlateNum/>
</horizontal>
<horizontal>
<Label Name= Type Width=100/>
<TextBox Name=Type/>
</horizontal>
<horizontal>
<Label Name= Color Width=100/>
<TextBox Name=Color/>
</horizontal>
<horizontal>
<Label Name=Status Width=100/>
<TextBox Name=Status/>
</horizontal>
<horizontal>
<Label Name= MilesDriven Width=100/>
<TextBox Name=MilesDriven/>
</horizontal>
<horizontal>
<Label Name= ACPresent Width=100/>
<TextBox Name=ACPresent/>
</horizontal>
<horizontal>
<Label Name=CDPresent Width=100/>
<TextBox Name=CDPresent/>
</horizontal>
<horizontal>
<Label Name= ModelNum Width=100/>
<TextBox Name=ModelNum/>
</horizontal>
<horizontal>
<Label Name= CarYear Width=100/>
<TextBox Name=CarYear/>
</horizontal>
<horizontal>
<Button Name='Create'/>
<Button Name='Read'/>
<Button Name='Update'/>
</horizontal>
<horizontal>
<Button Name='Delete'/>
<Button Name='Clear'/>
<Button Name='Exit'/>
</horizontal>
</vertical>
</vertical>
</form>";
you the main idea is not to loose the Main window, while one(lets say user) chooses to manage a customer, and as he/she pushes the button to activate the window, the Main window should stay there, and lets say when the user is finished with manageing customer, he/she closes the window and still the Main is there, so user can again choose another function.
kind regards
dmu4014