You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
9.8 KiB
C#
293 lines
9.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using POSV.Entity;
|
|
using POSV.HttpApi;
|
|
using POSV.Utils;
|
|
using System.IO;
|
|
using DevComponents.DotNetBar;
|
|
using POSV.ShoppingCart;
|
|
|
|
namespace POSV.Component
|
|
{
|
|
[ToolboxItem(true)]
|
|
public partial class LoginControl : BaseUserControl
|
|
{
|
|
public LoginControl()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.txtWorkerNo.GotFocus += OnInputGotFocus;
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
if (this.DesignMode) return;
|
|
|
|
var background = @"images/login.jpg";
|
|
if (File.Exists(background))
|
|
{
|
|
this.mainPanel.Style.BackgroundImagePosition = eBackgroundImagePosition.Tile;
|
|
this.mainPanel.Style.BackgroundImage = Image.FromFile(background);
|
|
this.mainPanel.Invalidate();
|
|
}
|
|
|
|
|
|
this.txtWorkerNo.Height = 38;
|
|
this.txtWorkerNo.Multiline = false;
|
|
this.txtWorkerNo.Text = string.Empty;
|
|
this.txtWorkerNo.IsEnterInputKey = true;
|
|
|
|
this.txtPasswd.Height = 38;
|
|
this.txtPasswd.Multiline = false;
|
|
this.txtPasswd.Text = string.Empty;
|
|
this.txtPasswd.IsEnterInputKey = true;
|
|
}
|
|
|
|
public override bool Focused
|
|
{
|
|
get
|
|
{
|
|
if (this.ActiveControl == null)
|
|
{
|
|
this.ActiveControl = this.txtWorkerNo;
|
|
}
|
|
|
|
return this.ActiveControl.Focused;
|
|
}
|
|
}
|
|
|
|
protected override void OnResize(EventArgs e)
|
|
{
|
|
this.Visible = false;
|
|
base.OnResize(e);
|
|
this.Visible = true;
|
|
}
|
|
|
|
private bool ValidateInputValue()
|
|
{
|
|
if (string.IsNullOrEmpty(txtWorkerNo.Text.Trim()))
|
|
{
|
|
this.ShowMessage(this.lblInfo , "工号不能为空,请输入..." , false);
|
|
this.txtWorkerNo.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(txtPasswd.Text.Trim()))
|
|
{
|
|
this.ShowMessage(this.lblInfo , "密码不能为空,请输入..." , false);
|
|
this.txtPasswd.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (!Global.Instance.AuthLogin) {
|
|
DialogForm.ShowAlert(this, "特别提示", "您的POS使用权限已过期,请联系代理商续费!");
|
|
return false;
|
|
}
|
|
|
|
this.ShowMessage(this.lblInfo , "提交认证中,请稍候..." , false);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
private void OnTouchBeforeClick(object sender , TouchEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnTouchClick(object sender , TouchEventArgs e)
|
|
{
|
|
switch (e.Value)
|
|
{
|
|
case "clear":
|
|
//如果当前焦点控件是输入框
|
|
if (this.ActiveControl is NumericTextBox)
|
|
{
|
|
var activeControl = this.ActiveControl as NumericTextBox;
|
|
activeControl.Text = string.Empty;
|
|
}
|
|
break;
|
|
case "accept":
|
|
//验证通过
|
|
{
|
|
var valid = ValidateInputValue();
|
|
if (valid)
|
|
{
|
|
Login();
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
InputSimulatorUtils.SendKey(KeyCodes.Map[e.Value]);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 注册成功事件触发
|
|
/// </summary>
|
|
public event SucceedEventHandler Succeed;
|
|
protected virtual void OnSucceed(SucceedEventArgs e)
|
|
{
|
|
Succeed?.Invoke(this , e);
|
|
}
|
|
|
|
private void Login()
|
|
{
|
|
try
|
|
{
|
|
var userName = this.txtWorkerNo.Text.Trim().PadLeft(5 , '0');
|
|
|
|
var passwd = this.txtPasswd.Text.Trim();
|
|
|
|
Tuple<bool , string , Worker> response = null;
|
|
|
|
//是否需要确认登录信息
|
|
bool isConfirm = false;
|
|
if (Global.Instance.Online)
|
|
{
|
|
//调用业务系统开放平台
|
|
Tuple<bool, string, PosAuth> responsePosAuth = LoginApi.PosAuth(Global.Instance.Authc.StoreId, Global.Instance.Authc.PosNo);
|
|
if (responsePosAuth.Item1)
|
|
{
|
|
PosAuth posAuth = responsePosAuth.Item3;
|
|
if (posAuth.CostMode == 0)
|
|
{
|
|
try
|
|
{
|
|
lock (Global.Instance.SyncLock)
|
|
{
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
{
|
|
using (var transaction = db.GetTransaction())
|
|
{
|
|
string sql = "update pos_store_info set dueDate ='{0}'";
|
|
sql = string.Format(sql, posAuth.DueDate);
|
|
db.Execute(sql, null);
|
|
transaction.Complete();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LOGGER.Error(ex);
|
|
}
|
|
//租赁模式剩余时间小于0天,禁止登陆系统
|
|
if (posAuth.AuthDays < 0)
|
|
{
|
|
Global.Instance.AuthLogin = false;
|
|
DialogForm.ShowAlert(this, "特别提示", "您的POS使用权限已过期,请联系代理商续费!");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
//调用业务系统开放平台
|
|
response = LoginApi.ValidateWorker(Global.Instance.Authc.StoreId , Global.Instance.Authc.PosNo , userName , passwd);
|
|
isConfirm = false;
|
|
}
|
|
else
|
|
{
|
|
response = LoginApi.DatabaseLogin(userName , passwd);
|
|
|
|
isConfirm = true;
|
|
}
|
|
|
|
//返回成功
|
|
if (response.Item1)
|
|
{
|
|
this.ShowMessage(this.lblInfo , response.Item2 , false);
|
|
|
|
Worker worker = response.Item3;
|
|
|
|
if (isConfirm)
|
|
{
|
|
|
|
List<string> dayList = OrderUtils.GetUnUpLoadDay();
|
|
StoreInfo storeInfo = null;
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
{
|
|
storeInfo = db.FirstOrDefault<StoreInfo>("where id = @0", Global.Instance.Authc.StoreId);
|
|
}
|
|
//如果门店设置最大登录天数大于0并且实际未上传数据的天数大于该天数,就不允许离线登录了
|
|
if (storeInfo!=null && storeInfo.MaxOffLine>0 && dayList.Count>= storeInfo.MaxOffLine) {
|
|
|
|
this.ShowMessage(this.lblInfo, string.Format("门店最多允许离线登录{0}天,请联网登录!", storeInfo.MaxOffLine), false);
|
|
|
|
return;
|
|
}
|
|
var confirm = new LoginConfirm(Global.Instance.Authc , worker);
|
|
//确认登录
|
|
if (DialogResult.OK == confirm.ShowDialog())
|
|
{
|
|
//登陆成功通知事件
|
|
this.OnSucceed(new SucceedEventArgs(worker));
|
|
}else
|
|
{
|
|
this.txtWorkerNo.Text = string.Empty;
|
|
this.txtPasswd.Text = string.Empty;
|
|
|
|
this.ShowMessage(this.lblInfo , "工号不能为空,请输入..." , false);
|
|
this.txtWorkerNo.Focus();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//登陆成功通知事件
|
|
this.OnSucceed(new SucceedEventArgs(worker));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.ShowMessage(this.lblInfo , response.Item2 , true);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LOGGER.Error(ex , "收银员登录验证异常");
|
|
this.ShowMessage(this.lblInfo , "收银员登录验证异常" , true);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnInputEnterClick(object sender , EnterEventArg e)
|
|
{
|
|
var valid = ValidateInputValue();
|
|
if (valid)
|
|
{
|
|
Login();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public delegate void SucceedEventHandler(object sender , SucceedEventArgs e);
|
|
|
|
public class SucceedEventArgs : EventArgs
|
|
{
|
|
public readonly Worker Worker;
|
|
public readonly bool Closed;
|
|
|
|
public SucceedEventArgs(Worker worker,bool closed = false)
|
|
{
|
|
this.Worker = worker;
|
|
|
|
this.Closed = closed;
|
|
}
|
|
}
|
|
}
|