I tried to put a label1.text = progressbar1.value.ToString(); and it would not read out how much it has progressed. This is what I have so far with some help.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
label1.Text = progressBar1.Value.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private const Int32 TOTAL_CHECKBOXES = 4;
private static Int32 s_Checks = 0;
private void OnCheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked || checkBox2.Checked || checkBox3.Checked || checkBox4.Checked == true)
{
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
}
}
private void clearCheckBoxToolStripMenuItem_Click(object sender, EventArgs e)
{
if (checkBox1.Checked || checkBox2.Checked || checkBox3.Checked || checkBox4.Checked == true)
{
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = progressBar1.Value.ToString();
}
}
}
public Form1()
{
InitializeComponent();
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
label1.Text = progressBar1.Value.ToString();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Start();
}
Related
I am having a little problem with validation on my calculator, I would like when I press enter or all other characters except numbers ,it would notify me of an error.
Basically, I would like that when I type a letter or special character with the keyboard I get an error returned
I am using windows form, I attach below my code:
double num1;
double num2;
double result;
String oper = "+";
private void button_minus_Click(object sender, EventArgs e)
{
// label1.Text += minus_click.Text;
num1 = double.Parse(label1.Text);
oper = "-";
label1.Text += oper;
label1.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text += button15.Text;
}
private void button16_Click(object sender, EventArgs e)
{
label1.Text += button16.Text;
}
private void button5_Click(object sender, EventArgs e)
{
label1.Text += button5.Text;
}
private void button4_Click(object sender, EventArgs e)
{
label1.Text += button4.Text;
}
private void button6_Click(object sender, EventArgs e)
{
label1.Text += division_click.Text;
}
private void button4_Click_1(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
}
private void button6_Click_1(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
label1.Text += button7.Text;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button_AC_Click(object sender, EventArgs e)
{
label1.Text = String.Empty;
label3.Text = String.Empty;
}
private void button2_Click_1(object sender, EventArgs e)
{
label1.Text += button16.Text;
}
private void button3_Click_1(object sender, EventArgs e)
{
label1.Text += button17.Text;
}
private void button7_Click_1(object sender, EventArgs e)
{
label1.Text += button7.Text;
}
private void button8_Click(object sender, EventArgs e)
{
label1.Text += button8.Text;
}
private void button9_Click(object sender, EventArgs e)
{
label1.Text += button9.Text;
}
private void button11_Click_1(object sender, EventArgs e)
{
label1.Text += button11.Text;
}
private void button12_Click(object sender, EventArgs e)
{
label1.Text += button12.Text;
}
private void button13_Click(object sender, EventArgs e)
{
label1.Text += button6.Text;
}
private void buttonPoint_Click(object sender, EventArgs e)
{
label1.Text += buttonPoint.Text;
num1 = (double)Convert.ToDecimal(label1.Text);
num2 = (double)Convert.ToDecimal(label1.Text);
}
private void button10_Click_1(object sender, EventArgs e)
{
label1.Text += moltiplication_click.Text;
}
private void button18_Click(object sender, EventArgs e)
{
label1.Text += addiction_click.Text;
}
private void button3_Click(object sender, EventArgs e)
{
label1.Text += button3.Text;
}
private void button5_Click_1(object sender, EventArgs e)
{
label1.Text += button5.Text;
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
private void panel1_Paint_1(object sender, PaintEventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void addiction_click_Click(object sender, EventArgs e)
{
//label1.Text += addiction_click.Text;
num1 = double.Parse(label1.Text);
oper = "+";
label1.Text = string.Empty;
label3.Text = String.Empty;
}
private void moltiplication_click_Click(object sender, EventArgs e)
{
//label1.Text += moltiplication_click.Text;
num1 = double.Parse(label1.Text);
oper = "*";
label1.Text += oper;
label1.Text = "";
label3.Text = String.Empty;
}
private void division_click_Click(object sender, EventArgs e)
{
num1 = double.Parse(label1.Text);
oper = "/";
label1.Text += oper;
label1.Text = "";
label3.Text = String.Empty;
}
private void buttonPIĆ¹OMENO_Click_2(object sender, EventArgs e)
{
num1 = double.Parse(label1.Text);
}
private void buttonPERCENTUAL_Click_2(object sender, EventArgs e)
{
//num1 = (double)Convert.ToDecimal(label1.Text);
oper = "%";
label1.Text += oper;
label3.Text = String.Empty;
}
private void button3_Click_0(object sender, EventArgs e)
{
label1.Text += button3.Text;
}
private void equals_click_Click(object sender, EventArgs e)
{
num2 = Convert.ToInt32(label1.Text);
label1.Text = label1.Text;
switch (oper)
{
case "+":
result = num1 + num2;
label3.Text = Convert.ToString(result);
break;
case "-":
result = num1 - num2;
label3.Text = Convert.ToString(result);
break;
case "*":
result = num1 * num2;
label3.Text = Convert.ToString(result);
break;
case "/":
result = num1 / num2;
label3.Text = Convert.ToString(result);
break;
case "%":
num2 = (double)Convert.ToDecimal(label3.Text);
result = num1 % num2;
label3.Text = result.ToString();
break;
}
label3.Text = result.ToString();
}
private void label1_Click_1(object sender, EventArgs e)
{
}
public bool ValidationEmptyNumber(String s)
{
bool isNumber = true;
while (isNumber)
{
label1.Text = num1.ToString();
label1.Text = num2.ToString();
return isNumber = true;
if (label1.Text == String.Empty)
{
MessageBox.Show("please enter a number");
return isNumber = false;
}
}
}
public bool ValidationOnlyNumbers(String s) {
bool isNumber;
Regex regex = new Regex("[a-zA-Z]+");
Match match = regex.Match("impossible to insert letters or special characters");
while (isNumber = true)
{
label1.Text = num1.ToString();
label1.Text = num2.ToString();
return isNumber;
if (match.Success)
{
label1.Text = match.Value;
MessageBox.Show(match.Value);
}
{
}
}
{
}
}
}
}
I have problem, which consists in aesthetic sense, correctly - There is textBox to which i apply true condition of UseSystemPasswordChar.. It's work! But i get bold points. Try to change font size - decreases textbox's field. Below is the code (although why is it here?). Can anyone help, thank you in advance)
public partial class frmRegistr : Form
{
public frmRegistr()
{
InitializeComponent();
}
int counter = 0;
int a = 0;
string b;
private void frmRegistr_Load(object sender, EventArgs e)
{
b = label1.Text;
a = b.Length;
label1.Text = "";
timer1.Start();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (counter < a)
{
counter++;
label1.Text = b.Substring(0, counter);
}
else
{
timer1.Stop();
}
}
private void label4_Click(object sender, EventArgs e)
{
timer3.Start();
}
private void label4_MouseHover(object sender, EventArgs e)
{
//if this.MouseLeave
label4.BackColor = Color.FromArgb(((int)(((byte)(154)))), ((int)(((byte)(181)))), ((int)(((byte)(101)))));
}
private void timer2_Tick(object sender, EventArgs e)
{
if (Opacity == 1)
{
timer2.Stop();
}
Opacity += .2;
}
private void timer3_Tick(object sender, EventArgs e)
{
if (Opacity <= 0)
{
this.Close();
}
Opacity -= .2;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox2.UseSystemPasswordChar = true;
}
}
}
If you want to define your own password character, use property TextBox.PasswordChar. If you want this in a certain font, use Control.Font
As you only have to do this once, do this in the constructor:
public MyForm : Form
{
InitializeComponents(),
this.textBox1.PasswordChar = '_';
this.textBox11.Font = new Font(...)
};
You can also decide to do this using the visual studio designer.
You can setup this in VisualStudio designer, but this is code:
textBox1.PasswordChar = '*';
//* = password character
So I've just started coding and i'm probably using a very rudimentary method to do this but i wanted to make a click counter so i can make a 'Drop Log' for Runescape. Everything's going smooth however I've noticed that after X amount of Clicker counters programmed the buttons start to lag? Debug isn't popping up with any issues, its kind of just getting stuck?
Here's my code:
namespace DropLog_v2
{
public partial class Form1 : Form
{
//Pernix Counts
int CountP = 0;
int CountP2 = 0;
int CountP3 = 0;
int CountP4 = 0;
int CountP5 = 0;
int CountP6 = 0;
//Virtus Counts
int CountV = 0;
int CountV2 = 0;
int CountV3 = 0;
int CountV4 = 0;
int CountV5 = 0;
int CountV6 = 0;
int CountV7 = 0;
//Torva Counts
int CountM = 0;
public Form1()
{
InitializeComponent();
}
//Move Window
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - lastPoint.X;
this.Top += e.Y - lastPoint.Y;
}
}
Point lastPoint;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
lastPoint = new Point(e.X, e.Y);
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - lastPoint.X;
this.Top += e.Y - lastPoint.Y;
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
lastPoint = new Point(e.X, e.Y);
}
//Close Window
private void button1_Click(object sender, EventArgs e)
{
Close();
}
//Pernix Buttons
private void Pernix1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
CountP++;
PernixL1.Text = CountP.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountP > 0)
CountP--;
PernixL1.Text = CountP.ToString();
}
}
private void Pernix2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
CountP2++;
PernixL2.Text = CountP2.ToString();
}
else if (e.Button == MouseButtons.Right)
{
if (CountP2 > 0)
CountP2--;
PernixL2.Text = CountP2.ToString();
}
}
private void Pernix3_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountP3++;
PernixL3.Text = CountP3.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountP3 > 0)
CountP3--;
PernixL3.Text = CountP3.ToString();
}
}
private void Pernix4_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountP4++;
PernixL4.Text = CountP4.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountP4 > 0)
CountP4--;
PernixL4.Text = CountP4.ToString();
}
}
private void Pernix5_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountP5++;
PernixL5.Text = CountP5.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountP5 > 0)
CountP5--;
PernixL5.Text = CountP5.ToString();
}
}
private void Pernix6_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountP6++;
PernixL6.Text = CountP6.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountP6 > 0)
CountP6--;
PernixL6.Text = CountP6.ToString();
}
}
//Virtus Buttons
private void Virtus1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV++;
VirtusL1.Text = CountV.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV > 0)
CountV--;
VirtusL1.Text = CountV.ToString();
}
}
private void Virtus2_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV2++;
VirtusL2.Text = CountV2.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV2 > 0)
CountV2--;
VirtusL2.Text = CountV2.ToString();
}
}
private void Virtus3_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV3++;
VirtusL3.Text = CountV3.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV3 > 0)
CountV3--;
VirtusL3.Text = CountV3.ToString();
}
}
private void Virtus4_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV4++;
VirtusL4.Text = CountV4.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV4 > 0)
CountV4--;
VirtusL4.Text = CountV4.ToString();
}
}
private void Virtus5_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV5++;
VirtusL5.Text = CountV5.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV5 > 0)
CountV5--;
VirtusL5.Text = CountV5.ToString();
}
}
private void Virtus6_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV6++;
VirtusL6.Text = CountV6.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV6 > 0)
CountV6--;
VirtusL6.Text = CountV6.ToString();
}
}
private void Virtus7_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountV7++;
VirtusL7.Text = CountV7.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountV7 > 0)
CountV7--;
VirtusL7.Text = CountV7.ToString();
}
}
//Torva Buttons
private void Torva1_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button==MouseButtons.Left)
{
CountM++;
TorvaL1.Text = CountM.ToString();
}
else if(e.Button==MouseButtons.Right)
{
if (CountM > 0)
CountM--;
TorvaL1.Text = CountM.ToString();
}
}
}
}
All was working Great until i tried doing the next line of code for the first 'torva' clicker and now its become laggy..
All help is appreciated (Novice, so please go easy)
You have MouseMove instead of MouseDown
I have code that takes data from serial com port from a weighing machine. It works okay, but receives data in several lines. I'm trying to make it receive data in one line.
In the code below I need to take weight from weigh bridge machine automatically by timer using Visual Studio 2005. It works, but I receive weight values on several lines.
I need to receive weight in one line and automatically update and convert it to an integer.
using System;
using System.IO.Ports;
using System.Windows.Forms;
namespace CommSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void Application_Idle(object sender, EventArgs e)
{
label3.Text = serialPort1.IsOpen ? "[Open]" : "[Closed]";
}
private void button1_Click(object sender, EventArgs e)
{
if (pollingCheckbox.Checked)
{
timer1.Enabled = true;
}
else
{
timer1.Enabled = false;
TransmitCommand();
}
}
private void TransmitCommand()
{
if (textBox1.Text.Length > 0)
{
if (serialPort1.IsOpen)
{
serialPort1.Write(textBox1.Text + "\r");
}
}
}
private void ClosePort()
{
if (serialPort1.IsOpen)
{
serialPort1.DataReceived -= new SerialDataReceivedEventHandler(serialPort1_DataReceived);
serialPort1.Close();
}
}
private void closePortToolStripMenuItem_Click(object sender, EventArgs e)
{
ClosePort();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.PortName = Properties.Settings.Default.Port;
serialPort1.BaudRate = Properties.Settings.Default.Baud;
serialPort1.DataBits = Properties.Settings.Default.DataBits;
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), Properties.Settings.Default.Parity);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), Properties.Settings.Default.StopBits);
Application.Idle += new EventHandler(Application_Idle);
}
private void OpenPort()
{
serialPort1.Open();
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
private void openPortToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenPort();
}
private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
{
ClosePort();
using (Form2 form = new Form2())
{
if (form.ShowDialog(this) == DialogResult.OK)
{
serialPort1.PortName = Properties.Settings.Default.Port;
serialPort1.BaudRate = Properties.Settings.Default.Baud;
serialPort1.DataBits = Properties.Settings.Default.DataBits;
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), Properties.Settings.Default.Parity);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), Properties.Settings.Default.StopBits);
}
}
}
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (!InvokeRequired)
{
if (e.EventType == SerialData.Chars)
{
string portData = serialPort1.ReadExisting();
textBox2.AppendText(portData);
}
}
else
{
SerialDataReceivedEventHandler invoker = new SerialDataReceivedEventHandler(serialPort1_DataReceived);
BeginInvoke(invoker, new object[] { sender, e });
}
}
private void pollingCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (timer1.Enabled && !pollingCheckbox.Checked)
{
timer1.Enabled = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pollingCheckbox.Checked)
{
TransmitCommand();
}
}
}
}
I have a withdrawal screen in my code that i when i withdraw money i want it to update the access database but my code only removes the amount of money off the database from within the program. Once the program is closed the database resets to its previous state.
My code for this screen
int moneyselected = 0;
Decimal balance = frmaccount.Balance;
public FrmTransaction()
{
InitializeComponent();
}
private void btnWithdraw_Click(object sender, EventArgs e)
{
if (moneyselected == 0)
{
MessageBox.Show("Select Amount");
}
else
{
if (moneyselected > balance)
{
MessageBox.Show("Not enough funds");
}
else
{
balance = balance - moneyselected;
OleDbCommandBuilder cb = new OleDbCommandBuilder(FrmLogin.da);
FrmLogin.da.Update(FrmLogin.ds1, "tblCustomers");
MessageBox.Show("Amount Withdrawn = " + moneyselected.ToString() + "\r\nBalance = " + balance.ToString());
}
}
}
private void btnWithdrawreceipt_Click(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
Form FrmLogin = new FrmLogin();
this.Hide();
FrmLogin.Show();
}
private void FrmTransaction_Load(object sender, EventArgs e)
{
}
private void rb10_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 10;
}
private void rb20_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 20;
}
private void rb30_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 30;
}
private void rb40_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 40;
}
private void rb50_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 50;
}
private void rb60_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 60;
}
private void rb70_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 70;
}
private void rb80_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 80;
}
private void rb90_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 90;
}
private void Cashamountbox_Enter(object sender, EventArgs e)
{
}
private void rb100_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 100;
}
private void rb150_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 150;
}
private void rb250_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 250;
}
}>>LOGIN PAGE<<
}
namespace BANK_ATM_PROJECT
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}
int failedAttempts = 0;
public static OleDbConnection con = new OleDbConnection();
string dbProvider;
string dbSource;
public static OleDbDataAdapter da;
public static DataSet ds1 = new DataSet();
string sql;
string pin;
int rownum = 0;
bool valid = false;
public static decimal balance = 0;
private void FrmLogin_Load(object sender, EventArgs e)
{
{
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;";
dbSource = "Data Source = 'D:\\bank11.accdb'";
con.ConnectionString = dbProvider + dbSource;
ds1 = new DataSet();
con.Open();
sql = " SELECT tblCustomers.* FROM tblCustomers";
da = new OleDbDataAdapter(sql, con);
rownum = da.Fill(ds1, "tblCustomers");
con.Close();
{
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
System.Environment.Exit(0);
this.Close();
}
private bool validate()
{
ds1 = new DataSet();
con.Open();
sql = "SELECT tblCustomers.* FROM tblCustomers WHERE ((tblCustomers.AccountNo) = '" + txtAccount.Text + "')";
da = new OleDbDataAdapter(sql, con);
rownum = da.Fill(ds1, "tblCustomers");
con.Close();
if (rownum != 1)
{
return false;
}
else
{
pin = ds1.Tables["tblCustomers"].Rows[0][4].ToString();
if (pin == txtPin.Text)
{
return true;
}
else
{
MessageBox.Show("INVALID PIN");
return false;
}
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
valid = validate();
if (!valid)
{
//Increment the number of failed attempts
failedAttempts += 1;
if (failedAttempts == 1)
MessageBox.Show("You Have 2 Attempts Left");
if (failedAttempts == 2)
MessageBox.Show("You Have 1 Attempt Left");
//If equal to 3
if (failedAttempts == 3)
MessageBox.Show("Card Retained");
{
}
}
else
{
valid = validate();
if (valid == true)
{
if (txtAccount.Text == "11111111" && txtPin.Text == "9999")
{
Frmmanager Manager = new Frmmanager();
this.Close();
Manager.Show();
}
else
{
frmaccount account = new frmaccount();
this.Close();
account.Show();
{
txtAccount.Clear();
txtPin.Clear();
valid = validate();
if (valid == true)
{
if (txtAccount.Text == "11111111" && txtPin.Text == "9999")
{
Frmmanager Manager = new Frmmanager();
this.Close();
Manager.Show();
}
else
{
frmaccount Account = new frmaccount();
this.Close();
account.Show();
{
txtAccount.Clear();
txtPin.Clear();
}
}
}
}
}
}
}
}
}
}
I though the
ds.update would have updated it but this only seems to work within the program
Any help or advice would be appreciated
I think the problerm is in the following code,Here you cretate a new instance of FrmLogin instead of refering to the current instance:
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
Form FrmLogin = new FrmLogin();
this.Hide();
FrmLogin.Show();
}
try the following:
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
FrmLogin obj = (FrmLogin)Application.OpenForms["FrmLogin"];
this.Hide();
obj.Show();
}
And generraly when you referring to FrmLogin is better to use obj as ref in order to be sure you referenning to current instance. So add this to the start of your code:
obj = (FrmLogin)Application.OpenForms["FrmLogin"];
And every ref to FrmLogin make it via obj
are you checking the database in debug folder or in your project solution ?
try checking in debug folder.