private void IDTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Tab) { PWTextBox.Focus(); } if (e.KeyCode == Keys.Enter) { LogInbtn_Click(sender, e); } }
private void OkButton_Click(object sender, EventArgs e) { SqlConnection newConnection = new SqlConnection(); newConnection.ConnectionString = "Data Source=MAKS-PC;Initial Catalog=PressWiz;Integrated Security=True"; SqlCommand myCommand = new SqlCommand("SELECT * FROM [UserAccounts] WHERE First_Name = '" + First_Name + "' AND Password ='******';", newConnection); SqlDataReader myReader; try { newConnection.Open(); myReader = myCommand.ExecuteReader(); int count = 0; while (myReader.Read()) { count++; } myReader.Close(); newConnection.Close(); if (count == 1) { ChangePW newChangePW = new ChangePW(First_Name); this.Hide(); newChangePW.ShowDialog(); this.Close(); } else { MessageBox.Show("Invalid Password !", First_Name, MessageBoxButtons.OK, MessageBoxIcon.Error); PWTextBox.Focus(); } } catch (InvalidOperationException ioe) { MessageBox.Show(ioe.ToString(), "Connection Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); OkButton.Focus(); } catch (SqlException se) { MessageBox.Show(se.ToString(), "Connection Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); OkButton.Focus(); } }
private void LogInbtn_Click(object sender, EventArgs e) { string loginid = IDTextBox.Text; string loginpw = PWTextBox.Text; string strconn = "Server=localhost;Database=test;User Id=root;Password=1234;Charset=utf8"; if (String.IsNullOrEmpty(IDTextBox.Text)) { MetroMessageBox.Show(this, "ID를 입력하여 주세요.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); IDTextBox.Focus(); return; } else if (String.IsNullOrEmpty(PWTextBox.Text)) { MetroMessageBox.Show(this, "Password를 입력하여 주세요.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); PWTextBox.Focus(); return; } MySqlConnection conn = new MySqlConnection(strconn); MySqlCommand cmd = new MySqlCommand(); try { conn.Open(); string strlogincheckQ = "select * from shop where sid = '" + IDTextBox.Text + "'"; cmd.Connection = conn; cmd.CommandText = strlogincheckQ; MySqlDataReader rdr = cmd.ExecuteReader(); if (!rdr.HasRows) { var Msgresult = MetroMessageBox.Show(this, "등록되지 않은 가맹점입니다.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); if (Msgresult == DialogResult.OK) { IDTextBox.Focus(); } } if (rdr.Read()) { if (rdr["spw"].ToString() == PWTextBox.Text) { var Msgresult = MetroMessageBox.Show(this, "성공", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); if (Msgresult == DialogResult.OK) { shopForm shopfrm = new shopForm(); //shopfrm.Text = rdr["sname"].ToString(); shopfrm.Show(); Program.ac.MainForm = shopfrm; subposForm subposfrm = new subposForm(); subposfrm.Show(); this.Close(); } } else { var Msgresult = MetroMessageBox.Show(this, "아이디와 패스워드가 일치하지 않습니다.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); if (Msgresult == DialogResult.OK) { IDTextBox.Focus(); } } } rdr.Dispose(); rdr.Close(); } catch (Exception E) { MetroMessageBox.Show(this, "데이터 베이스 오류 :\n" + E.Message + "\n" + E.StackTrace); } finally { cmd.Dispose(); conn.Dispose(); conn.Close(); } return; }
private void ChangePW_Load(object sender, EventArgs e) { PWTextBox.Focus(); }
private void SaveButton_Click(object sender, EventArgs e) { if (PWTextBox.Text == "" || PWTextBox.Text.Length < 6) { MessageBox.Show("Password cannot be null and must be longer than five Charactors", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); PWTextBox.Text = ""; ReTextbox.Text = ""; PWTextBox.Focus(); } else { if (ReTextbox.Text == "") { MessageBox.Show("Re Enter Password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); PWTextBox.Focus(); } else { if (PWTextBox.Text != ReTextbox.Text) { MessageBox.Show("Passwords are mismatch", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); PWTextBox.Text = ""; ReTextbox.Text = ""; PWTextBox.Focus(); } else { SqlConnection myConnection = new SqlConnection("Data Source=MAKS-PC;Initial Catalog=PressWiz;Integrated Security=True"); SqlCommand myCommand = new SqlCommand(); myCommand.Connection = myConnection; myCommand.CommandText = "UPDATE UserAccounts SET Password = '******' WHERE First_Name ='" + First_Name + "';"; try { myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); } catch (InvalidCastException ice) { MessageBox.Show(ice.ToString()); } catch (ObjectDisposedException ode) { MessageBox.Show(ode.ToString()); } catch (SqlException se) { MessageBox.Show(se.ToString()); } catch (InvalidOperationException ioe) { MessageBox.Show(ioe.ToString()); } this.Close(); } } } }
private void ReEnterPassword_Load(object sender, EventArgs e) { PWTextBox.Focus(); }