|
Hi Guys,
I have added a basic logon form that gets a users logon name and password and matches that to a given list to my project. Once it has been validated it calls the main form. Now, the problem I have is that when it calls the main form I can't connect to the db. The user validation is done in the logon form class as you can see below.
private void button1_Click(object sender, EventArgs e)
{
frmNef frm1 = new frmNef();
if (textBox1.Text == "maphanga" && textBox2.Text == "marsha" || textBox1.Text == "nkosi" && textBox2.Text == "mdu" || textBox1.Text == "carrim" && textBox2.Text == "allerece" || textBox1.Text == "raphela" && textBox2.Text == "rachel" || textBox1.Text == "mazibuko" && textBox2.Text == "zoliswa")
{
this.DialogResult = DialogResult.OK;
}
else MessageBox.Show("Invalid Username and or Password supplied");
}
This is then validated in the main form's load event.
private void frmNef_Load(object sender, EventArgs e)
{
Login login = new Login();
if (login.ShowDialog(this) == DialogResult.OK)
{
return;
}
else this.Close();
login.Close();
login.Dispose();
Can somebody please tell me how I can do this better so as to get the connection to the DB working properly with the logon form? I had to remove the logon form before the app would work again.
Thanking you in advance.
|
|
|
|
|
Kwagga wrote: I can't connect to the db.
Yeah it requires some code or something to do that. Your posted code contains nothing that connects to a database. There are a large number of articles here on CodeProject about Database development using C#. Perhaps you might look at them.
|
|
|
|
|
Sorry mate. The db connection works fine when I remove the logon form code. When I add the logon form code in I can't see anything in the DB, nor can I save anything back in. It is almost as if the logon form is not releasing focus to the main form. However it opens the main form OK but I guess it might be that it loops somewhere or doing something silly like that which I just can't seem to figure out.
Anyway, here is more code from the main form.
Login login = new Login();
if (login.ShowDialog() == DialogResult.OK)
{
return;
}
else this.Close();
login.Close();
login.Dispose();
try
{
DateTime dtCurrentTime = DateTime.Now;
tlstrlblTime.Text = dtCurrentTime.ToShortTimeString();
DateTime dtCurrentDate = DateTime.Today;
tlstrlblDate.Text = dtCurrentDate.ToShortDateString();
m_cnADONetConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\CallCentre.mdb";
m_cnADONetConnection.Open();
m_daDataAdapter =
new OleDbDataAdapter("Select * From [CallCentre]", m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandbuilder =
new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtCallCentre);
this.ShowCurrentRecord();
If you can point me to some of the posts I would greatly appreciate it. I have been searching here and on Google but none of the topics i find actauly refers to what I'm doing. Most of them are for web development.
|
|
|
|
|
Kwagga wrote: if (login.ShowDialog() == DialogResult.OK)
{
return;
}
|
|
|
|
|
Thanks mate but what about the "return"? I don't understand what you trying to say.
|
|
|
|
|
He is saying that the return statement you have is dropping you out of the procedure. Because of it, you aren't ever getting to the try block...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Thanks Paul. I will try and change this. However, strange thing is that it works fine in another project of mines where I use a .MDF as database. I will and modify this one and see what happens.
|
|
|
|
|
Guys, just so you know, I sorted this out. Instead of using "return" i used " this.Show();. Not sure if this is the correct thing to do but it seems to be working fine.
Thanks so much of the assistance from both of you.
Cheers
B
|
|
|
|
|
Cool deal, glad it seems to be working
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Hi, I have a simple blackjack game I am toying with and I need to count the amount of times the player has pressed the "Deal" button. Any suggestions ?
Thanks
|
|
|
|
|
|
More specifically, it is an aspx application and I need a way to capture the callback in a variable or by using IsCallBack to keep track of postbacks. Any help ????
|
|
|
|
|
Okay, final thing (for now) on graphics. How do you move what you draw? Does it involve the right or top , etc? I tried
rectangle1.Location = new System.Drawing.Point(x, y);
, but it didn't work. (x/y being someplace not important)
And, this is in a swich event for the arrow keys, just to let anyone who's curious to know.
Thanks in advance
|
|
|
|
|
Hi, I have a standard answer to painting questions, here it is:
there are several steps to draw something so it becomes visible on the screen:
1.
decide on what object you want to draw; it normally is a Control (e.g. a Panel) or a
Form itself. I prefer to add a Panel to a Form, then draw on the Panel.
2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of
your drawing. For a rectangle that could be top and left coordinate, and width+height,
or just a Rectangle object. etc.
3.
create a Paint handler for that Panel, and do all your drawing in there, using the
Graphics class and your variables.
4.
when you want to move things, modify the variables and call Panel.Invalidate() or
one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler
of a Windows.Forms.Timer
BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Please give me an example of Panel.Invalidate(). Thanks though, I honestly see what you are getting at.
|
|
|
|
|
MasterSharp wrote: Please give me an example of Panel.Invalidate().
They hide those in the documentation[^]
|
|
|
|
|
MasterSharp wrote: Please give me an example of Panel.Invalidate().
if you have a Panel myPanel on which you draw some shape myShape and
want to move the shape, then do something along these lines:
myShape.X=myShape.X+100;
myPanel.Invalidate();
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Can you do that with the form? I tried and 'it didn't work'.
|
|
|
|
|
MasterSharp wrote: Can you do that with the form?
Whatever "that" is, the answer is yes.
MasterSharp wrote: I tried and 'it didn't work'
Can you be more specific; "didn't work" doesn't tell me anything.
If it does not compile, show the exact code and the first (couple of) error message(s).
If it does not run properly, show the relevant code, and describe the outcome;
if an Exception occurs, show its entire ToString() value.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
MasterSharp wrote: How do you move what you draw?
You can't. Once you have drawn something somewhere, it's drawn. It's like a brush stroke on a canvas, you can't move that around once it's done.
MasterSharp wrote: I tried
rectangle1.Location = new System.Drawing.Point(x, y);
That would work if it was a windows control. They repaint themselves when needed. Graphics that has been drawn are just pixels on the screen, they doesn't exist as an entity that you can manipulate in any way.
MasterSharp wrote: but it didn't work.
I am amazed about how often people describe a result with "doesn't work". It doesn't say anything about what the problem is, and it can be anything from a slight difference from what was expected to a total failure.
What do you mean exctly when you say that "it didn't work"?
---
single minded; short sighted; long gone;
|
|
|
|
|
It did not make the graphics move, but you just told me the reason. SO to make it move, you'd have to (for animating), draw the graphic, then dispose, draw, dispose...?
|
|
|
|
|
Something like that, yes. Think of it like a cartoon: draw 1 frame on one piece of paper, drawn the next frame on another piece of paper, etc.
The drawing should be done in the OnPaint override of your window/control. When you want to draw a new frame, call this.Invalidate() in your window/control code.
|
|
|
|
|
I keep hearing Invalidate(). What's that mean??? I get most else.
|
|
|
|
|
The Invalidate method is used to tell a control that it needs to redraw itself.
It will create a windows message that is put in the message queue. When the message is processed, it will raise the Paint event for the control that is used to redraw the control.
---
single minded; short sighted; long gone;
|
|
|
|
|
MasterSharp wrote: to make it move, you'd have to (for animating), draw the graphic, then dispose, draw, dispose...?
Disposing anything that you used to draw graphics doesn't remove what you have drawn. You can't remove anything that you have drawn, you have to draw something else to replace it.
If you have for example drawn an image on the screen, you would have to remove it by drawing with the background color, the draw the image at the new location.
---
single minded; short sighted; long gone;
|
|
|
|