Numpad User Control and Login Changes

This commit is contained in:
unknown
2011-01-06 12:47:00 +05:30
parent 232a62f8ca
commit e32e9f9e74
47 changed files with 1536 additions and 714 deletions

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tanshu.Accounts.PointOfSale
{
interface ILogin
{
bool LoginUser();
bool LogoutUser();
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.BI;
using System.Threading;
namespace Tanshu.Accounts.PointOfSale
{
class KeyboardLogin : ILogin
{
private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public bool LoginUser()
{
return LoginUser(true);
}
bool LoginUser(bool setThreadPrincipal)
{
using (LoginForm login = new LoginForm())
{
string userName;
login.ShowDialog();
bool authenticated = login.UserName(out userName);
if (authenticated && setThreadPrincipal)
SetThreadPrincipal(userName);
return authenticated;
}
}
public bool LogoutUser()
{
Session.User = null;
return true;
}
static void SetThreadPrincipal(string userName)
{
log.Warn(string.Format("User Login: '{0}'", userName));
if (userName.Contains(":"))
userName = userName.Substring(userName.IndexOf(":") + 1);
Session.User = new MembershipBI().GetUserFromName(userName);
}
}
}

View File

@ -0,0 +1,134 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class LoginForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnExit = new System.Windows.Forms.Button();
this.btnLogin = new System.Windows.Forms.Button();
this.txtPassword = new System.Windows.Forms.TextBox();
this.Label2 = new System.Windows.Forms.Label();
this.txtUserName = new System.Windows.Forms.TextBox();
this.Label1 = new System.Windows.Forms.Label();
this.numpadControl1 = new Tanshu.Common.KeyboardControl.NumpadControl();
this.SuspendLayout();
//
// btnExit
//
this.btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnExit.Location = new System.Drawing.Point(203, 64);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 3;
this.btnExit.Text = "E&xit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(78, 64);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(75, 23);
this.btnLogin.TabIndex = 2;
this.btnLogin.Text = "&Login";
this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(78, 38);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(200, 20);
this.txtPassword.TabIndex = 1;
this.txtPassword.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPassword_KeyDown);
//
// Label2
//
this.Label2.Location = new System.Drawing.Point(12, 41);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(60, 20);
this.Label2.TabIndex = 5;
this.Label2.Text = "Password";
//
// txtUserName
//
this.txtUserName.Location = new System.Drawing.Point(78, 12);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(200, 20);
this.txtUserName.TabIndex = 0;
this.txtUserName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtUserName_KeyDown);
//
// Label1
//
this.Label1.Location = new System.Drawing.Point(12, 15);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(60, 20);
this.Label1.TabIndex = 4;
this.Label1.Text = "Username";
//
// numpadControl1
//
this.numpadControl1.Location = new System.Drawing.Point(35, 93);
this.numpadControl1.Name = "numpadControl1";
this.numpadControl1.Size = new System.Drawing.Size(224, 224);
this.numpadControl1.TabIndex = 6;
this.numpadControl1.TabStop = false;
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnExit;
this.ClientSize = new System.Drawing.Size(290, 329);
this.Controls.Add(this.numpadControl1);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.Label2);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.Label1);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.btnExit);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Login";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnLogin;
internal System.Windows.Forms.TextBox txtPassword;
internal System.Windows.Forms.Label Label2;
internal System.Windows.Forms.TextBox txtUserName;
internal System.Windows.Forms.Label Label1;
private Tanshu.Common.KeyboardControl.NumpadControl numpadControl1;
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Threading;
using System.Windows.Forms;
using Tanshu.Accounts.BI;
using Tanshu.Accounts.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
public partial class LoginForm : Form
{
//size: 296, 123
private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private bool isAuthenticated;
private string userName;
private bool cancelled;
public LoginForm()
{
InitializeComponent();
isAuthenticated = false;
userName = null;
cancelled = true;
}
private void txtUserName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
txtPassword.Focus();
}
private void txtPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
btnLogin_Click(sender, e);
}
private void btnLogin_Click(object sender, EventArgs e)
{
userName = txtUserName.Text.Trim();
isAuthenticated = new MembershipBI().ValidateUser(userName, Tanshu.Common.Md5.Hash(txtPassword.Text, "Salt"));
if (isAuthenticated)
{
this.Close();
}
else
MessageBox.Show("Username or password is not valid");
}
public bool UserName(out string userName)
{
userName = this.userName;
return isAuthenticated;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.PointOfSale
{
static class Session
{
private static UserBO currentUser;
public static bool IsAuthenticated { get; private set; }
public static UserBO User
{
get
{
return currentUser;
}
set
{
if (value != null)
{
currentUser = value;
IsAuthenticated = true;
}
else
{
currentUser = null;
IsAuthenticated = false;
}
}
}
static public string printer()
{
return "";
}
}
}