Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Diagnostics;
  8. using System.Windows.Forms;
  9. using System.Linq;
  10. using System.Xml.Linq;
  11. using System.Data.SqlClient;
  12.  
  13. namespace POSMainForm
  14. {
  15.     public partial class frmLogin : Form
  16.     {
  17.         public frmLogin()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void frmLogin_Load(object sender, EventArgs e)
  23.         {
  24.             SQLConn.getData();
  25.            
  26.         }
  27.  
  28.         private void Login()
  29.         {
  30.             try
  31.             {
  32.                 SQLConn.sqL = "SELECT * FROM Staff WHERE Username = '" + txtusername.Text + "' AND UPassword = '" + txtPassword.Text + "'";
  33.                 SQLConn.ConnDB();
  34.                 SQLConn.cmd = new SqlCommand(SQLConn.sqL, SQLConn.conn);
  35.                 SQLConn.dr = SQLConn.cmd.ExecuteReader();
  36.  
  37.                 if (SQLConn.dr.Read() == true)
  38.                 {
  39.  
  40.                     if (SQLConn.dr["Role"].ToString().ToUpper() == "Admin")
  41.                     {
  42.                         frmMain m = new frmMain(SQLConn.dr["Username"].ToString(),Convert.ToInt32(SQLConn.dr["StaffID"]));
  43.                         m.Show();
  44.                         this.Hide();
  45.                     }
  46.                     else
  47.                     {
  48.                        // frmPOS m = new frmPOS(Convert.ToInt32(SQLConn.dr["StaffID"]));
  49.                       //  m.Show();
  50.                         this.Hide();
  51.                     }
  52.                 }
  53.                 else
  54.                 {
  55.                     Interaction.MsgBox("Invalid Password. Please try again.",MsgBoxStyle.Exclamation, "Login");
  56.                 }
  57.  
  58.             }
  59.             catch (Exception ex)
  60.             {
  61.                 Interaction.MsgBox(ex.Message);
  62.             }
  63.             finally
  64.             {
  65.                 SQLConn.cmd.Dispose();
  66.                 SQLConn.conn.Close();
  67.             }
  68.         }
  69.  
  70.         private void txtPassword_KeyDown(object sender, KeyEventArgs e)
  71.         {
  72.             if (e.KeyCode == Keys.Enter)
  73.             {
  74.                 Login();
  75.             }
  76.         }
  77.  
  78.         private void txtusername_KeyDown(object sender, KeyEventArgs e)
  79.         {
  80.             if (e.KeyCode == Keys.Enter)
  81.             {
  82.                 Login();
  83.             }
  84.         }
  85.  
  86.         private void btnCancel_Click(object sender, EventArgs e)
  87.         {
  88.             Application.Exit();
  89.         }
  90.  
  91.         private void frmLogin_KeyDown(object sender, KeyEventArgs e)
  92.         {
  93.             if (e.KeyCode == Keys.F12)
  94.             {
  95.                 frmDatabaseConfig dc = new frmDatabaseConfig();
  96.                 dc.ShowDialog();
  97.             }
  98.         }
  99.        
  100.         private void btnOkay_Click_1(object sender, EventArgs e)
  101.         {
  102.            
  103.                
  104.                    
  105.  
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement