Advertisement
Guest User

Untitled

a guest
May 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11.  
  12.  
  13.  
  14. namespace Retail_POS.Forms
  15. {
  16.  
  17.  
  18.  
  19.  
  20.  
  21. public partial class frmLogin : Form
  22. {
  23.  
  24. // declaration
  25. int Attempts = 0;
  26.  
  27. public static bool _Logged = false;
  28. public static string _USERID = "";
  29. public static string _PASSWORD = "";
  30. public static string _USERNAME = "";
  31.  
  32. public static bool _FILE = false ;
  33. public static bool _MANAGE = false ;
  34. public static bool _REPORTS = false ;
  35. public static bool _SALES = false ;
  36. public static bool _STOCK = false ;
  37. public static bool _ADMINISTRATOR = false ;
  38. public static bool _UNDO_SALE = false ;
  39.  
  40.  
  41.  
  42. public frmLogin()
  43. {
  44. InitializeComponent();
  45. }
  46.  
  47. private void frmLogin_Load(object sender, EventArgs e)
  48. {
  49.  
  50. SqlConnection sqlConnection = new SqlConnection(
  51. "Server=AUTUMN-PC\\SQLEXPRESS;" +
  52. "Integrated Security=True");
  53. // Create command
  54. //SqlCommand cmdLogin = new SqlCommand(
  55. // "SELECT userid, password FROM userprofile", sqlConnection);
  56.  
  57. //open connection
  58. sqlConnection.Open();
  59. // // Execute the command
  60. // SqlDataReader reader = comm.ExecuteReader();
  61. // while (reader.Read())
  62.  
  63. // {
  64.  
  65. // txtUserName += reader[""];
  66. // txtPassword += reader["PASSWORD"];
  67. // }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. //close
  76. //reader.Close();
  77. //conn.Close();
  78.  
  79. }
  80. //Functions and procedure
  81. private bool fnLogin(string prmUSER_NAME, string prmPASSWORD)
  82. {
  83.  
  84.  
  85. // Initialize connection
  86. // Define database connection
  87. //SqlConnection conn = new SqlConnection(
  88. // "Server=AUTUMN-PC\\SQLEXPRESS;" +
  89. // "Database=RetailPOS;User ID=sa;" +
  90. // "Password=m1nwoo");
  91.  
  92.  
  93.  
  94.  
  95.  
  96. bool Return = false;
  97. try
  98. {
  99. string varSQL = "SELECT USERPROFILE.USERID " +
  100. " FROM USERPROFILE " +
  101. " WHERE USERPROFILE.USERID='" + prmUSER_NAME + "' " +
  102. " AND USERPROFILE.PASSWORD ='" + prmPASSWORD + "'";
  103.  
  104.  
  105. SqlConnection sqlConnection = new SqlConnection(Class.clsMain.CnnStr);
  106. //sqlConnection.Open();
  107. SqlCommand cmdLogin = new SqlCommand(varSQL,sqlConnection);
  108. SqlDataReader drLogin = cmdLogin.ExecuteReader();
  109. while (drLogin.Read())
  110. {
  111. Return=true;
  112. _USERID =drLogin["USERID"].ToString();
  113. _PASSWORD = drLogin["PASSWORD"].ToString();
  114. _USERNAME = drLogin["USERNAME"].ToString();
  115. }
  116. drLogin.Close();
  117. sqlConnection.Close();
  118. cmdLogin.Dispose();
  119. return (Return);
  120. }
  121. catch (Exception ex) {
  122. MessageBox.Show("fnLogin\n" + ex.Message,
  123. "System Information");
  124. return (Return);
  125. }
  126. }
  127.  
  128. private void ButtonLogin_Click(object sender, EventArgs e)
  129. {
  130. _Logged = fnLogin(txtUserName.Text,txtPassword.Text);
  131. if (Attempts >= 3)
  132. {
  133. _Logged = false;
  134. MessageBox.Show("Sorry,Too many attempts. Please Contact Admin",
  135. "System Information");
  136. this.Close();
  137. }
  138. if (_Logged)
  139. this.Close();
  140. }
  141.  
  142.  
  143.  
  144. private void buttonCancel_Click(object sender, EventArgs e)
  145. {
  146. this.Close();
  147. }
  148.  
  149.  
  150.  
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement