Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Common
  6. {
  7. class Client
  8. {
  9. private int _id;
  10. public int Id { get; set; }
  11.  
  12. private string _name;
  13. public string Name { get; set; }
  14.  
  15. private Common.ClientType _type;
  16. public Common.ClientType Type { get; set; }
  17.  
  18. private string _identificationNumber;
  19. public string IdentificationNumber { get; set; }
  20.  
  21. private string _address;
  22. public string Address { get; set; }
  23.  
  24. private string _tel;
  25. public string Tel { get; set; }
  26.  
  27. private string _mob;
  28. public string Mob { get; set; }
  29.  
  30. private string _email;
  31. public string Email { get; set; }
  32.  
  33. private string _web;
  34. public string Web { get; set; }
  35.  
  36. Client() { }
  37. Client(string name, string identNum,Common.ClientType type,string address,string tel,string mob,string email,string web)
  38. {
  39. Name = name;
  40. IdentificationNumber = identNum;
  41. Type = type;
  42.  
  43. Address = address;
  44. Tel = tel;
  45. Email = email;
  46. Web = web;
  47. }
  48. }
  49. }
  50. }
  51.  
  52. ============================
  53. common
  54. using System;
  55. using System.Collections.Generic;
  56. using System.Text;
  57.  
  58. namespace Common
  59. {
  60. class Common
  61. {
  62.  
  63. public static long? currentUserId;
  64. public const string connectionString = @"Data Source=10.200.86.25;Initial Catalog=LT-3;Persist Security Info=True;User ID=LT-3;Password=***********";
  65. public enum ClientType
  66. {
  67. Individual=0,
  68. Organization=1
  69. }
  70. }
  71. }
  72.  
  73. =============================
  74. foorm 1
  75. using System;
  76. using System.Collections.Generic;
  77. using System.ComponentModel;
  78. using System.Data;
  79. using System.Drawing;
  80. using System.Linq;
  81. using System.Text;
  82. using System.Threading.Tasks;
  83. using System.Windows.Forms;
  84.  
  85. namespace Banking
  86. {
  87. public partial class Form1 : Form
  88. {
  89. public Form1()
  90. {
  91. InitializeComponent();
  92. }
  93.  
  94. private void loginButton_Click(object sender, EventArgs e)
  95. {
  96. string mess;
  97. bool res = Common.User.CheckLogin(textBox1.Text, textBox2.Text, out mess);
  98. if (!String.IsNullOrEmpty(mess))
  99. {
  100. MessageBox.Show(mess);
  101. if (res)
  102. {
  103. this.Hide();
  104. HomePage fm = new HomePage();
  105. fm.Closed += (s, args) => this.Close();
  106. fm.Show();
  107. }
  108. }
  109. }
  110. }
  111. }
  112.  
  113. ==================
  114. user
  115. using System;
  116.  
  117. namespace Common
  118. {
  119. public class User
  120. {
  121. private long _id;
  122. public long Id { get; set; } //get i set; se kratenki isto kako cel metod da se napise
  123. //get{return _id;} set{_id=value;}}
  124.  
  125. private string _name;
  126. public string Name { get; set; }
  127.  
  128. private string _username;
  129. public string Username { get; set; }
  130.  
  131. private string _password;
  132. public string Password { get; set; }
  133.  
  134. private long? _cashAccountId;
  135. public long? CashAccountId { get; set; } //zatoa sto se nadvoresni klucevi se defiiniraat vaka
  136.  
  137. private long? _clientId;
  138. public long? ClientId { get { return _clientId; } set { _clientId = value; Client = new Client(); } }
  139.  
  140. public User() { } // eden prazen konstruktor
  141.  
  142. public User(string name, string username, string password, long? cashaccId, long? clientid)
  143. { //eden parametriziran
  144. Name = name;
  145. Username = username;
  146. Password = password;
  147. CashAccountId = cashaccId;
  148. ClientId = clientid;
  149. }
  150. public static bool CheckLogin(string username,string password,out string message)
  151. {
  152. message = String.Empty;
  153. if(String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
  154. {
  155. message = "Invalid username or password!";
  156. return false;
  157. }
  158. try
  159. {
  160. using (SqlConnection con = new SqlConnection(Common.connectionString))
  161. {
  162. cmd.CommandType = CommandType.StoredProcedures;
  163. cmd.Parameters.AddWithValue("@username", username);
  164. cmd.Parameters.AddWithValue("@password", password);
  165.  
  166. SqlParameter param = new SqlParameter("@res", SqlDbType.Bit);
  167. param.Direction = ParameterDirection.ReturnValue;
  168. cmd.Parameters.Add(param);
  169.  
  170. cmd.Parameters.Add("@userId", SqlDbType.BigInt).Direction = ParameterDirection.Output;
  171. con.Open();
  172. cmd.ExecuteNonQuery();
  173.  
  174. object res = param.Value;
  175.  
  176. if ((int)res == 1)
  177. {
  178. long userId = Convert.ToInt64(cmd.Parameters["@userId"].Value);
  179. Common.currentUserId = userId;
  180. message = "Login successful";
  181. return true;
  182. }
  183. else
  184. {
  185. message = "Login failed";
  186. return false;
  187. }
  188. }
  189. }
  190. catch(Exception e)
  191. {
  192. message = e.Message;
  193. return false;
  194. }
  195. }
  196. }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement