Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Common
- {
- class Client
- {
- private int _id;
- public int Id { get; set; }
- private string _name;
- public string Name { get; set; }
- private Common.ClientType _type;
- public Common.ClientType Type { get; set; }
- private string _identificationNumber;
- public string IdentificationNumber { get; set; }
- private string _address;
- public string Address { get; set; }
- private string _tel;
- public string Tel { get; set; }
- private string _mob;
- public string Mob { get; set; }
- private string _email;
- public string Email { get; set; }
- private string _web;
- public string Web { get; set; }
- Client() { }
- Client(string name, string identNum,Common.ClientType type,string address,string tel,string mob,string email,string web)
- {
- Name = name;
- IdentificationNumber = identNum;
- Type = type;
- Address = address;
- Tel = tel;
- Email = email;
- Web = web;
- }
- }
- }
- }
- ============================
- common
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Common
- {
- class Common
- {
- public static long? currentUserId;
- public const string connectionString = @"Data Source=10.200.86.25;Initial Catalog=LT-3;Persist Security Info=True;User ID=LT-3;Password=***********";
- public enum ClientType
- {
- Individual=0,
- Organization=1
- }
- }
- }
- =============================
- foorm 1
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Banking
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void loginButton_Click(object sender, EventArgs e)
- {
- string mess;
- bool res = Common.User.CheckLogin(textBox1.Text, textBox2.Text, out mess);
- if (!String.IsNullOrEmpty(mess))
- {
- MessageBox.Show(mess);
- if (res)
- {
- this.Hide();
- HomePage fm = new HomePage();
- fm.Closed += (s, args) => this.Close();
- fm.Show();
- }
- }
- }
- }
- }
- ==================
- user
- using System;
- namespace Common
- {
- public class User
- {
- private long _id;
- public long Id { get; set; } //get i set; se kratenki isto kako cel metod da se napise
- //get{return _id;} set{_id=value;}}
- private string _name;
- public string Name { get; set; }
- private string _username;
- public string Username { get; set; }
- private string _password;
- public string Password { get; set; }
- private long? _cashAccountId;
- public long? CashAccountId { get; set; } //zatoa sto se nadvoresni klucevi se defiiniraat vaka
- private long? _clientId;
- public long? ClientId { get { return _clientId; } set { _clientId = value; Client = new Client(); } }
- public User() { } // eden prazen konstruktor
- public User(string name, string username, string password, long? cashaccId, long? clientid)
- { //eden parametriziran
- Name = name;
- Username = username;
- Password = password;
- CashAccountId = cashaccId;
- ClientId = clientid;
- }
- public static bool CheckLogin(string username,string password,out string message)
- {
- message = String.Empty;
- if(String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
- {
- message = "Invalid username or password!";
- return false;
- }
- try
- {
- using (SqlConnection con = new SqlConnection(Common.connectionString))
- {
- cmd.CommandType = CommandType.StoredProcedures;
- cmd.Parameters.AddWithValue("@username", username);
- cmd.Parameters.AddWithValue("@password", password);
- SqlParameter param = new SqlParameter("@res", SqlDbType.Bit);
- param.Direction = ParameterDirection.ReturnValue;
- cmd.Parameters.Add(param);
- cmd.Parameters.Add("@userId", SqlDbType.BigInt).Direction = ParameterDirection.Output;
- con.Open();
- cmd.ExecuteNonQuery();
- object res = param.Value;
- if ((int)res == 1)
- {
- long userId = Convert.ToInt64(cmd.Parameters["@userId"].Value);
- Common.currentUserId = userId;
- message = "Login successful";
- return true;
- }
- else
- {
- message = "Login failed";
- return false;
- }
- }
- }
- catch(Exception e)
- {
- message = e.Message;
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement