using System;
using System.Data;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using TouchCashier.Parameter;
using System.IO;
using System.Windows.Media.Animation;
using System.Collections.Generic;
using System.Windows.Documents;
using DirectShowLib;
namespace TouchCashier
{
///
/// MainWindow.xaml 的交互逻辑
///
/// 登录界面进行的操作:
/// 1、启动数据库,进行数据库连接检测
/// 2、加载系统参数信息
/// 3.1、检测是否异常重启,异常重启的情况下进行自动登录
/// 3.2、用户输入账号及登录密码进行登录
/// 4、检测当前账期结算情况,记录账期开始信息、工班登录信息
/// 5、打开收银主操作界面,并启动自然日数据生成线程,对自然日数据进行检测上传
///
public partial class MainWindow : Window
{
#region 参数属性
private Thread LoginThread { get; set; }
bool IsLogin = false;
#endregion
#region 构造函数 -> 登陆界面
public MainWindow()
{
InitializeComponent();
}
#endregion
#region 事件 -> 系统加载
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//初始化界面
imgload.Image = Properties.Resources.登录状态;
imga.Image = Properties.Resources.load;
PictureFigr.Image = Properties.Resources.扫描指纹;
PictureFace.Image = Properties.Resources.人脸识别;
WorkUtils.PublicStore.LoggerHelper.WriteLogger(
$"///【------------------------【{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}】收银系统开始启动...------------------------】///\r\n");
//检测系统盘剩余空间,当剩余空间小于500MB时,提醒用户清理磁盘,否则系统无法运行(本地数据库运行需要C盘剩余空间大于500M,做为数据库缓冲区)
long long_Space = WorkUtils.Peripheral.PCDeviceHelper.GetHardDiskFreeSpace("C");
long long_MinSpace = (long)500 * 1024 * 1024;
//判断C盘剩余空间大小,当剩余可用空间小于500MB时,提示用户先清理系统盘空间
if (long_Space < long_MinSpace)
{
//记录磁盘空间不足,启动失败日志
WorkUtils.PublicStore.LoggerHelper.WriteLogger(
$"///【------------------------【{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}】收银系统启动失败,C盘空间不足------------------------】///\r\n");
//弹窗提醒用户由于C盘空间不足,软件启动失败,需要清理后再启动
List list_Message = new List
{
new Run("系统[C]盘"),
new Run("剩余空间不足,") { Foreground = Brushes.Red, FontWeight = FontWeights.Bold },
new Run("收银软件启动失败\n"),
new Run("请清理后重新启动收银软件!")
};
MessageWarningMain mwm_FailWindow = new MessageWarningMain(list_Message, false)
{
Owner = this
};
mwm_FailWindow.ShowDialog();
//打开我的电脑窗口,方便用户清理磁盘空间
try { System.Diagnostics.Process.Start("explorer.exe"); } catch { }
System.Environment.Exit(0);
return;
}
WorkUtils.PublicStore.LoggerHelper.WriteLogger(
$"///{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")} C盘剩余空间:{WorkUtils.PublicStore.FileHelper.ConvertSize(long_Space)}///\r\n");
//本地数据库未启动,开始执行数据库启动程序
if (!WorkUtils.PublicStore.SyBaseHelper.TestConnect())
{
try
{
//数据库服务程序
string str_AppPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dbsrv12.exe");
//数据库DB文件路径
string str_DataBaseFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "datebase", "hydb.db");
//数据库启动参数
string str_Arguments = $" -os 10240k -m -c 8m -q -n {Dns.GetHostName()}";
//启动本地数据库
System.Diagnostics.Process.Start(str_AppPath, str_DataBaseFilePath + str_Arguments);
}
catch { }
ConnDetection _ConnDetection = new ConnDetection();
_ConnDetection.ShowDialog();
}
//打开本地时间计时器
WorkUtils.LocalConfig.Timer_LocalDateTime.Start();
TxtVersion.Text = "YSv" + System.Windows.Forms.Application.ProductVersion;
TxtVersion.Foreground = Brushes.Black;
//启动后台线程加载程序
new Thread(Loading)
{
IsBackground = true
}.Start();
Grid_Load.Visibility = Visibility.Visible;
}
#endregion
#region 方法 -> 系统加载
///
/// 系统加载
///
private void Loading()
{
string str_MessageLog = "";
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate ()
{
TxtLoad.Text = "正在加载系统设置,请稍候...";
});
//校验升级本地数据库表结构
WorkUtils.Other.DataBaseUpdate.PosDataBaseUpdate(ref str_MessageLog);
//加载本地数据库初始化门店参数信息,首次安装直接进入配置页面,配置完成后重启加载
if (!WorkUtils.LocalConfig.LocalConfiguration())
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate ()
{
TxtLoad.Text = "首次启动,请配置系统门店参数...";
//打开参数配置页面
new ChildWindow.Parameter.ScanConfigCheck() { Owner = this }.ShowDialog();
try
{
//配置完成,重启系统加载信息
System.Diagnostics.Process.Start("AutoUpdateEx.exe");
System.Environment.Exit(0);
}
catch (Exception) { System.Environment.Exit(0); }
});
return;
}
//开机时获取本地初始化信息,云端获取更新信息并上报、自然日数据生成上报、与服务器校准收银机本地时间
str_MessageLog += WorkUtils.Loading.GetConfig() + "\r\n";
str_MessageLog += $"///------------收银系统启动加载完成【{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}】,等待用户登录------------///" + "\r\n";
//写入启动加载过程产生的日志信息到本地日志文件
WorkUtils.PublicStore.LoggerHelper.WriteLogger(str_MessageLog);
//开机前对日结数据进行检测
try
{
if (!string.IsNullOrWhiteSpace(WorkUtils.LocalConfig.Code_ServerPart) && //检查服务区编码
!string.IsNullOrWhiteSpace(WorkUtils.LocalConfig.Code_Shop) && //检查门店编码
!string.IsNullOrWhiteSpace(WorkUtils.LocalConfig.Code_Machine)) //检查收银机编码
{
//已经配置了服务区、门店、收银机号的情况下,开机前对日结数据、自然日数据等进行检测
WorkUtils.Check.CheckTimeAuto.HalfHourTick();
}
}
catch { }
#region 系统启动加载结束,主线程界面显示控制处理
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
//开机执行数据清理
new System.Threading.Tasks.Task(() => WorkUtils.Loading.CalibrateMyData()).Start();
//启动收银心跳程序定时器线程,线程每5分钟上报一次心跳信息到云端
WorkUtils.LocalConfig.StateFeedback.Start();
//启动Socket客户端连接线程
WorkUtils.LocalConfig.CloudSuperSocketClient.Start();
//显示软件名称到界面
TxtSoftwareName.Text = WorkUtils.LocalConfig.Name_SoftWare;
////快捷键版、触屏版判断显示
cb_Touch.IsChecked = WorkUtils.LocalConfig.IsTouch;
cb_Key.IsChecked = !cb_Touch.IsChecked;
#region 设置界面Logo
//显示业主单位Logo
Enum.TryParse(WorkUtils.LocalConfig.OwnerUnit_ID, out WorkUtils.Other.Enumeration.OwnerUnitName oun_OwnerUnit);
if (oun_OwnerUnit == WorkUtils.Other.Enumeration.OwnerUnitName.stig)
{
//四川Logo未更新,不显示
img_logo.Visibility = Visibility.Collapsed;
}
else
{
img_logo.Source = new BitmapImage(new Uri(WorkUtils.Other.OwnerLogoHelper.LogoNoNameByLogin(oun_OwnerUnit), UriKind.Relative));
}
#endregion
//隐藏加载动画
Grid_Load.Visibility = Visibility.Collapsed;
//判断是否异常重启,异常重启的执行自动登录
if (WorkUtils.LocalConfig.IsAutoLogon)
{
#region 异常重启收银机自动登录
string str_SelectSQL = $@"Select A.SellWorkerCode,A.SellWorkerName,A.SellWorkerPassword
From T_SellWorker A,T_PersonSell_New B Where A.ServerPartCode = B.ServerPartCode And
Upper(A.SellWorkerCode) = Upper(B.SellWorker_Code) And
B.ServerPartCode = '{WorkUtils.LocalConfig.Code_ServerPart}' And
B.ShopCode = '{WorkUtils.LocalConfig.Code_Shop}' And
B.MachineCode = '{WorkUtils.LocalConfig.Code_Machine}' And B.EndDate Is Null";
//取出已登录的收银员工号,进行自动登录
DataTable _DataTable = WorkUtils.PublicStore.SyBaseHelper.QueryOdbc(str_SelectSQL).Tables[0];
if (_DataTable.Rows.Count > 0)
{
TxtUserName.Text = _DataTable.Rows[0]["SellWorkerCode"].ToString();
TxtPwd.Password = _DataTable.Rows[0]["SellWorkerPassword"].ToString();
Grid_User.Visibility = Visibility.Collapsed;
GridLoad.Visibility = Visibility.Visible;
Button_Click(btn_login, null);
}
#endregion
}
TxtUserName.Focus();
});
#endregion
}
#endregion
#region 事件 -> 全局键盘按键
private void Window_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Escape:
Button_Click(btn_close, null);
break;
case Key.F1:
Button_Click(btnarport, null);
break;
case Key.F2:
//cb_SelfTouch.IsChecked = true;//自助版本默认只有自助选项
//cb_Key.IsChecked = !cb_Key.IsChecked;
if (cb_Key.IsChecked.Value)
{
cb_Key.IsChecked = false;
cb_Touch.IsChecked = true;
cb_SelfTouch.IsChecked = false;
CheckBox_Click(cb_Touch, null);
}
else if (cb_Touch.IsChecked.Value)
{
cb_Key.IsChecked = false;
cb_Touch.IsChecked = false;
cb_SelfTouch.IsChecked = true;
CheckBox_Click(cb_SelfTouch, null);
}
else
{
cb_Key.IsChecked = true;
cb_Touch.IsChecked = false;
cb_SelfTouch.IsChecked = false;
CheckBox_Click(cb_Key, null);
}
break;
case Key.F3:
Button_Click(btnScaveng, null);
break;
case Key.F4:
Button_Click(btnParameter, null);
break;
case Key.F5:
Button_Click(btn_report, null);
break;
case Key.F6:
Button_Click(btn_Test, null);
break;
case Key.Down:
TxtUserName.Focus();
if (Grid_keyboard.Margin == new Thickness(240, 453, 240, 0))
{
GetKeyboard();
}
break;
}
//禁用系统自带的关闭功能,使用自定义的关闭按钮
if (e.SystemKey == Key.F4)
{
e.Handled = true;
}
}
#endregion
#region 事件 -> 收银工号输入框按键事件
///
/// 收银工号输入框按键事件
///
///
///
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//工号验证
TxtUserName.Text = TxtUserName.Text.PadLeft(4, '0');
//跳到密码输入框
TxtPwd.SelectAll();
TxtPwd.Focus();
}
else if (e.Key == Key.F16)
{
//清空账号输入框
TxtUserName.Text = "";
return;
}
}
#endregion
#region 事件 -> 密码输入框按键事件
///
/// 密码输入框按键事件
///
///
///
private void TxtPwd_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//登录
Button_Click(btn_login, null);
return;
}
else if (e.Key == Key.F16)
{
//清空密码
TxtPwd.Password = "";
return;
}
}
#endregion
#region 事件 -> 软件版本选择按钮
///
/// 软件版本选择按钮事件
///
///
///
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
var cheboxName = ((CheckBox)sender).Name;
if (cheboxName == "cb_Key")
{
cb_Touch.IsChecked = !((CheckBox)sender).IsChecked;
cb_SelfTouch.IsChecked = !((CheckBox)sender).IsChecked;
}
else if (cheboxName == "cb_SelfTouch")
{
cb_Touch.IsChecked = !((CheckBox)sender).IsChecked;
cb_Key.IsChecked = !((CheckBox)sender).IsChecked;
}
else
{
cb_Key.IsChecked = !((CheckBox)sender).IsChecked;
cb_SelfTouch.IsChecked = !((CheckBox)sender).IsChecked;
}
//cb_SelfTouch.IsChecked = true;//checkbox选项默认只选中自助版本
if (Grid_keyboard.Margin == new Thickness(240, 205, 243, 0))
{
LostKeyboard();
}
}
#endregion
#region 事件 -> 登录窗口功能按钮
///
/// 登录窗口功能按钮事件
///
///
///
private void Button_Click(object sender, RoutedEventArgs e)
{
Button keybtn = sender as Button;
if (!keybtn.IsEnabled)
{
return;
}
string str_Result;
string Log = "";
var list_Message = new List();
switch (keybtn.Name)
{
case "btn_login":
#region 登录按钮
keybtn.IsEnabled = false;
#region 登录的收银工号有效性验证
TxtMessage.Text = "";
//非空判断
if (TxtUserName.Text.Trim() == "")
{
DisplayMessageToMain(TxtMessage, "用户名不能为空!", "#FF0000");
keybtn.IsEnabled = true;
TxtUserName.Focus();
return;
}
if (TxtPwd.Password == "")
{
DisplayMessageToMain(TxtMessage, "密码不能为空!", "#FF0000");
keybtn.IsEnabled = true;
TxtPwd.Focus();
return;
}
str_Result = WorkUtils.Check.CheckLogin.CheckLocalTime();
if (!string.IsNullOrWhiteSpace(str_Result))
{
//收银机本地时间错误,提醒用户调整后再登录
string str_Message = "本地时间小于上一账期时间,请调整后再重新登录。";
DisplayMessageToMain(TxtMessage, str_Message, "#FF0000");
MessageWarningMain _CommodityPrompt = new MessageWarningMain(false, str_Message + "\r\n" + str_Result)
{
Owner = this
};
_CommodityPrompt.ShowDialog();
keybtn.IsEnabled = true;
TxtUserName.Focus();
TxtUserName.SelectAll();
return;
}
Log += "【收银机本地时间校验通过】\r\n";
//验证登录的收银工号是否有效
str_Result = WorkUtils.Login.PersonLogin(TxtUserName.Text, TxtPwd.Password);
if (!string.IsNullOrWhiteSpace(str_Result))
{
//输入的收银工号权限验证不通过,显示原因提示给用户
DisplayMessageToMain(TxtMessage, str_Result, "#FF0000");
keybtn.IsEnabled = true;
TxtUserName.Focus();
TxtUserName.SelectAll();
return;
}
Log += $"{TxtUserName.Text}, {TxtPwd.Password},【收银权限验证通过】\r\n";
#endregion
#region 24小时未结账验证,账期超过24小时要求立即进行结账操作
//24小时未结账验证,账期超过24小时要求立即进行结账操作
str_Result = WorkUtils.Check.CheckLogin.CkeckOutEndaccount();
if (!string.IsNullOrWhiteSpace(str_Result))
{
//账期超过24小时要求立即进行结账操作
CommodityShift _CommodityShift = new CommodityShift(true, false, true)
{
Owner = this
};
_CommodityShift.ShowDialog();
if (_CommodityShift.DialogResult != true)
{
DisplayMessageToMain(TxtMessage, str_Result, "#FF0000");
Grid_User.Visibility = Visibility.Visible;
GridLoad.Visibility = Visibility.Collapsed;
keybtn.IsEnabled = true;
TxtUserName.Focus();
TxtUserName.SelectAll();
return;
}
}
Log += $"【24小时未结账验证通过】\r\n";
#endregion
#region 已登录工班检查,存在未交班的记录要求先交班再更换工号登录
//交班检测
str_Result = WorkUtils.Check.CheckLogin.CheckPersonsell(TxtUserName.Text.Trim(), out string str_SellWorkerCode);
if (!string.IsNullOrWhiteSpace(str_Result))
{
var ccwm_CashWorker = WorkUtils.LocalConfig.QueryCashWorker(str_SellWorkerCode);
list_Message.Clear();
list_Message.Add(new Run("工号 "));
list_Message.Add(new Run($"[{str_SellWorkerCode}]{ccwm_CashWorker.SellWorkerName}") { Foreground = Brushes.Red });
list_Message.Add(new Run(" 已登录\n"));
list_Message.Add(new Run($"确认更换使用工号[{TxtUserName.Text.Trim()}]登录?"));
list_Message.Add(new Run($"\n\n确认后请输入工班交接金额。") { Foreground = Brushes.Gray, FontSize = 16 });
var mwm_Message = new MessageWarningMain(list_Message)
{
Owner = this
};
mwm_Message.ShowDialog();
if (mwm_Message.DialogResult != true)
{
DisplayMessageToMain(TxtMessage, str_Result, "#FF0000");
keybtn.IsEnabled = true;
TxtUserName.Text = str_SellWorkerCode;
TxtPwd.Password = "";
TxtPwd.Focus();
TxtPwd.SelectAll();
return;
}
CommodityShift _CommodityShift = new CommodityShift(false, false, false)
{
Owner = this
};
_CommodityShift.ShowDialog();
if (_CommodityShift.DialogResult != true)
{
DisplayMessageToMain(TxtMessage, str_Result, "#FF0000");
keybtn.IsEnabled = true;
TxtUserName.Text = str_SellWorkerCode;
TxtPwd.Password = "";
TxtPwd.Focus();
TxtPwd.SelectAll();
return;
}
}
Log += $"【已登录工班检查通过】\r\n";
#endregion
WorkUtils.PublicStore.LoggerHelper.WriteLogger(Log);
//登录时的操作
DisplayMessageToMain(TxtLogin, "", "#FF0000");
Grid_wf.Visibility = Visibility.Visible;
LostKeyboard();
stp_title.Visibility = Visibility.Collapsed;
stp_name.Visibility = Visibility.Collapsed;
stp_pwd.Visibility = Visibility.Collapsed;
stp_img.Visibility = Visibility.Visible;
btn_login.IsEnabled = false;
btn_close.IsEnabled = false;
btnParameter.IsEnabled = false;
string UserName = TxtUserName.Text.Trim().ToUpper();
TxtUserName.IsEnabled = false;
TxtPwd.IsEnabled = false;
decimal dec_PettyCash = 0;
//备用金填写功能暂不上线
//if (WorkUtils.Check.CheckLogin.IsExistsAccount())
//{
// var main_PettyCash = new ChildWindow.PosReport.PettyCashInput() { Owner = this };
// main_PettyCash.ShowDialog();
// if (main_PettyCash.DialogResult == true)
// {
// dec_PettyCash = main_PettyCash.PettyCashAmount;
// }
//}
if ((LoginThread == null || !LoginThread.IsAlive) && !IsLogin)
{
//标记正在执行登录,避免重复执行
IsLogin = true;
//启动登录系统线程
LoginThread = new Thread(() => Login_User(UserName, dec_PettyCash))
{
IsBackground = true
};
LoginThread.Start();
}
#endregion
break;
case "btnParameter":
#region 参数
ParameterPower _ParameterPower = new ParameterPower()
{
Owner = this
};
_ParameterPower.ShowDialog();
if (_ParameterPower.DialogResult == true)
{
ParConfigtion _ParConfigtion = new ParConfigtion()
{
Owner = this
};
_ParConfigtion.ShowDialog();
//重新加载最新的参数信息
WorkUtils.LocalConfig.LocalConfiguration();
}
#endregion
break;
case "btnScaveng":
#region 扫码配置参数
var _ScavengConfig = new ChildWindow.Parameter.ScanConfigCheck()
{
Owner = this
};
_ScavengConfig.ShowDialog();
#endregion
break;
case "btn_close":
#region 取消
UpLoadSwitch _UpLoadSwitch = new UpLoadSwitch()
{
Owner = this
};
if (_UpLoadSwitch.ShowDialog() == true)
{
DataUpload _DataUpload = new DataUpload()
{
Owner = this
};
_DataUpload.ShowDialog();
}
#endregion
break;
case "btnarport":
#region 查看状态
CashRegisterInf _CashRegisterInf = new CashRegisterInf()
{
Owner = this
};
_CashRegisterInf.ShowDialog();
#endregion
break;
case "btn_user":
#region 账号登录
Grid_LoginUser.Visibility = Visibility.Visible;
Grid_LoginFinger.Visibility = Visibility.Collapsed;
Grid_LoginFace.Visibility = Visibility.Collapsed;
gif_face.Visibility = Visibility.Collapsed;
gif_finger.Visibility = Visibility.Collapsed;
img_face.Visibility = Visibility.Visible;
img_finger.Visibility = Visibility.Visible;
TxtUserName.Focus();
TxtUserName.SelectAll();
if (Grid_keyboard.Margin == new Thickness(240, 453, 240, 0))
{
GetKeyboard();
}
#endregion
break;
case "btn_face":
#region 人脸识别登录
LostKeyboard();
Grid_LoginUser.Visibility = Visibility.Collapsed;
Grid_LoginFinger.Visibility = Visibility.Collapsed;
Grid_LoginFace.Visibility = Visibility.Visible;
gif_face.Visibility = Visibility.Collapsed;
gif_finger.Visibility = Visibility.Collapsed;
img_face.Visibility = Visibility.Visible;
img_finger.Visibility = Visibility.Visible;
TxtStateFace.Text = "正在连接识别器,请稍候..";
#endregion
break;
case "btn_finger":
#region 指纹识别登录
LostKeyboard();
Grid_LoginUser.Visibility = Visibility.Collapsed;
Grid_LoginFinger.Visibility = Visibility.Visible;
Grid_LoginFace.Visibility = Visibility.Collapsed;
gif_face.Visibility = Visibility.Collapsed;
gif_finger.Visibility = Visibility.Collapsed;
img_face.Visibility = Visibility.Visible;
img_finger.Visibility = Visibility.Visible;
TxtState.Text = "正在连接识别器,请稍候..";
#endregion
break;
case "btnDownDate":
#region 基础信息下载
CashierDataDownload();
#endregion
break;
case "btn_report":
//报表查询
new CommodityMenu(0, true) { Owner = this }.ShowDialog();
break;
case "btn_Test":
list_Message.Clear();
list_Message.Add(new Run("即将进入收银练习模式,"));
list_Message.Add(new Run("该模式仅供收银员练习使用\n"));
list_Message.Add(new Run("请勿在练习模式下进行真实交易!!!") { Foreground = Brushes.Red, FontWeight = FontWeights.Bold });
new MessageWarningMain(list_Message, false) { Owner = this }.ShowDialog();
WorkUtils.PublicStore.LoggerHelper.WriteLogger("收银员进入了练习模式。");
new ChildWindow.CommodityManage.CashierPracticeMode().Show();
Close();
break;
}
}
#endregion
#region 方法 -> 用户登录系统
///
/// 用户登录系统
///
/// 收银工号
/// 备用金
private void Login_User(string userName, decimal pettyCash)
{
string str_Result = WorkUtils.Login.SystemLogin(userName, pettyCash);
WorkUtils.PublicStore.LoggerHelper.WriteLogger("【系统登录验证】" + str_Result);
//登录验证不通过时,停止登录操作,显示验证失败原因给用户
if (!string.IsNullOrWhiteSpace(str_Result))
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate ()
{
DisplayMessageToMain(TxtMessage, str_Result, "#FF0000");
Grid_User.Visibility = Visibility.Visible;
GridLoad.Visibility = Visibility.Collapsed;
LoginFail();
GetKeyboard();
});
return;
}
WorkUtils.PublicStore.CloudLogger.SocketLoggerNotifyEvent(null, new Model.Other.NotifyEventArgs
{
NotifyLoggerType = WorkUtils.Other.Enumeration.LoggerType.登录通知,
NotifyLoggerTime = DateTime.Now,
NotifyLoggerMessage = $"【登录时间:{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}】" +
$"工号:[{WorkUtils.LocalConfig.Code_SellWorker}]{WorkUtils.LocalConfig.Name_SellWorker} 登录成功;" +
$"当前版本:YSv{System.Windows.Forms.Application.ProductVersion}",
NotifyUploadState = true
});
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate ()
{
#region 根据用户选择,打开键盘版或触屏版主操作界面
//根据用户选择,打开键盘版或触屏版主操作界面
//if (cb_Key.IsChecked == true)
//{
// //登录成功时,保存启动的软件版本(键盘版)
// WorkUtils.LocalConfig.IsTouch = false;
// WorkUtils.LocalConfig.UpdateLocalConfig("IsTouch", "0");
// //键盘版操作界面
// CommoditySaleCashier _CommoditySaleCashier = new CommoditySaleCashier();
// _CommoditySaleCashier.Show();
// Close();
//}
//else
if(cb_SelfTouch.IsChecked==true)
{
//登录成功时,保存启动的软件版本(自助结算版)
WorkUtils.LocalConfig.IsTouch = true;
WorkUtils.LocalConfig.UpdateLocalConfig("IsTouch", "2");
//自助触屏版操作界面
CommoditySelfCashier _CommoditySelf = new CommoditySelfCashier();
_CommoditySelf.Show();
Close();
}
else
{
//登录成功时,保存启动的软件版本(触屏版)
WorkUtils.LocalConfig.IsTouch = true;
WorkUtils.LocalConfig.UpdateLocalConfig("IsTouch", "1");
//触屏版操作界面
CommoditySaleOther _CommoditySaleOther = new CommoditySaleOther();
_CommoditySaleOther.Show();
Close();
}
#endregion
});
}
#endregion
#region 事件 -> 键盘动画效果
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
if (Grid_keyboard.Margin == new Thickness(240, 453, 240, 0))
{
GetKeyboard();
}
}
///
/// 界面打开虚拟键盘的动画
///
private void GetKeyboard()
{
//键盘弹出
Storyboard storyboard_action = new Storyboard();
storyboard_action.Stop();
storyboard_action.Children.Clear();
//添加动画
ThicknessAnimation stb_1 = new ThicknessAnimation(new Thickness(240, 453, 240, 0), new Thickness(240, 205, 240, 0), new Duration
(TimeSpan.FromSeconds(0.2)));
Storyboard.SetTarget(stb_1, Grid_keyboard);
Storyboard.SetTargetProperty(stb_1, new PropertyPath("Margin"));
storyboard_action.Children.Add(stb_1);
//添加动画2
ThicknessAnimation stb_2 = new ThicknessAnimation(new Thickness(100, 115, 100, 98), new Thickness(100, 0, 100, 98), new Duration(TimeSpan.FromSeconds(0.2)));
Storyboard.SetTarget(stb_2, Grid_User);
Storyboard.SetTargetProperty(stb_2, new PropertyPath("Margin"));
storyboard_action.Children.Add(stb_2);
storyboard_action.Begin();
}
///
/// 界面关闭虚拟键盘的动画
///
private void LostKeyboard()
{
if (Grid_keyboard.Margin == new Thickness(240, 205, 240, 0))
{
//键盘收起
Storyboard storyboard_action = new Storyboard();
storyboard_action.Stop();
storyboard_action.Children.Clear();
//添加动画
ThicknessAnimation stb_1 = new ThicknessAnimation(new Thickness(240, 205, 240, 0), new Thickness(240, 453, 240, 0), new Duration(TimeSpan.FromSeconds(0.2)));
Storyboard.SetTarget(stb_1, Grid_keyboard);
Storyboard.SetTargetProperty(stb_1, new PropertyPath("Margin"));
storyboard_action.Children.Add(stb_1);
//添加动画2
ThicknessAnimation stb_2 = new ThicknessAnimation(new Thickness(100, 0, 100, 98), new Thickness(100, 115, 100, 98), new Duration(TimeSpan.FromSeconds(0.2)));
Storyboard.SetTarget(stb_2, Grid_User);
Storyboard.SetTargetProperty(stb_2, new PropertyPath("Margin"));
storyboard_action.Children.Add(stb_2);
storyboard_action.Begin();
}
}
#endregion
#region 方法 -> 登录失败时的界面显示控制
private void LoginFail()
{
btn_login.IsEnabled = true;
btn_close.IsEnabled = true;
btnParameter.IsEnabled = true;
TxtUserName.IsEnabled = true;
stp_name.Visibility = Visibility.Visible;
stp_pwd.Visibility = Visibility.Visible;
stp_img.Visibility = Visibility.Collapsed;
stp_title.Visibility = Visibility.Visible;
TxtPwd.IsEnabled = true;
TxtUserName.Focus();
TxtUserName.SelectAll();
Grid_wf.Visibility = Visibility.Collapsed;
Grid_User.Visibility = Visibility.Visible;
GridLoad.Visibility = Visibility.Collapsed;
IsLogin = false;
}
#endregion
#region 方法 -> 更换门店或首次安装开机的机器需要下载基础信息
///
/// 更换门店或首次安装开机的机器需要下载基础信息
///
private void CashierDataDownload()
{
if (WorkUtils.LocalConfig.Thread_DataTrans == null || !WorkUtils.LocalConfig.Thread_DataTrans.IsAlive)
{
WorkUtils.LocalConfig.Thread_DataTrans = new Thread(() =>
{
string str_MessageLog = "";
#region 启动基础数据下载更新
#region 收银参数配置下载
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
Grid_Load.Visibility = Visibility.Visible;
this.IsEnabled = false;
TxtLoad.Text = "正在下载基础数据信息,请稍候......";
});
WorkUtils.Cloud.CloudTransfer.IssueConfigurationToMachine(ref str_MessageLog);
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
pbrDown.Value += 25;
});
#endregion
#region 门店信息数据下载
WorkUtils.Cloud.CloudTransfer.IssueShopInfoToMachine(ref str_MessageLog);
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
pbrDown.Value += 25;
});
#endregion
#region 收银工号数据下载
WorkUtils.Cloud.CloudTransfer.IssueSellWorkerInfoToMachine(DateTime.Now, ref str_MessageLog);
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
pbrDown.Value += 25;
});
#endregion
#region 移动支付参数配置下载
WorkUtils.Cloud.CloudTransfer.IssueMobileConfigToMachine(ref str_MessageLog);
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
pbrDown.Value += 25;
});
#endregion
#region 下载操作完成处理
str_MessageLog += "基础信息下载完成!";
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
Grid_Load.Visibility = Visibility.Collapsed;
pbrDown.Value = 0;
DisplayMessageToMain(TxtMessage, "基础信息下载完成!", "#FF0000");
this.IsEnabled = true;
TxtUserName.Focus();
TxtUserName.SelectAll();
});
#endregion
WorkUtils.PublicStore.LoggerHelper.WriteLogger(str_MessageLog);
#endregion
})
{
IsBackground = true
};
WorkUtils.LocalConfig.Thread_DataTrans.Start();
}
}
#endregion
#region 方法 -> 显示提示文本内容到窗口界面上
///
/// 显示提示文本内容到窗口界面上
///
///
///
///
private void DisplayMessageToMain(TextBlock textBlock, string message, string colorString)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
{
textBlock.Text = message;
textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorString));
//要执行的代码
});
}
#endregion
}
}