182 lines
6.6 KiB
C#
182 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
|
|
namespace RFIDServicePlate
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
System.Collections.ObjectModel.ObservableCollection<CommodityModel> CommodityList = new System.Collections.ObjectModel.ObservableCollection<CommodityModel>();
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btn_Conn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// var result = RFID.InitRFIDConn(2, "", "", "com1", "38400", "8E1");
|
|
new Thread(() =>
|
|
{
|
|
MySQLInstallHelper _MySQLInstallHelper = new MySQLInstallHelper();
|
|
_MySQLInstallHelper.DataReceivedEventClick += _MySQLInstallHelper_DataReceivedEventClick;
|
|
_MySQLInstallHelper.StartMySQLInstall();
|
|
})
|
|
{ IsBackground = true }.Start();
|
|
// text_Read.Text = result.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
text_Read.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
private void _MySQLInstallHelper_DataReceivedEventClick(string resultString, MySQLInstallHelper.RunState hasExited)
|
|
{
|
|
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
|
|
{
|
|
CommodityModel _CommodityModel = new CommodityModel
|
|
{
|
|
CommodityName = resultString
|
|
};
|
|
CommodityList.Add(_CommodityModel);
|
|
((this.FindName("DataGrid_RFID")) as DataGrid).ItemsSource = CommodityList;
|
|
text_Read.Text = resultString;
|
|
if (hasExited == MySQLInstallHelper.RunState.Finish)
|
|
{
|
|
btn_Read_Click(null, null);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void btn_Read_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
CommodityList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.ObjectModel.ObservableCollection<CommodityModel>>(
|
|
Newtonsoft.Json.JsonConvert.SerializeObject(ESSupport.Lib.SyBaseHelper.QueryOdbc(
|
|
@"SELECT A.COMMODITY_NAME AS CommodityName,
|
|
A.COMMODITY_RETAILPRICE AS CommodityPrice,
|
|
A.COMMODITY_CODE AS CommodityCode
|
|
FROM T_COMMODITYEX A
|
|
WHERE A.SERVERPARTCODE = '888888' AND A.ISVALID = 1").Tables[0]));
|
|
((this.FindName("DataGrid_RFID")) as DataGrid).ItemsSource = CommodityList;
|
|
var result = RFID.TryReadRFTag();
|
|
text_Read.Text = result;
|
|
if (!string.IsNullOrWhiteSpace(result))
|
|
{
|
|
var RFIDCommodityList = result.Split('@').ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
text_Read.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
private void btn_Write_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string str_Code = CommodityList[DataGrid_RFID.SelectedIndex].CommodityCode;
|
|
var result = RFID.TryWriteRFTag(str_Code);
|
|
text_Read.Text = result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
text_Read.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
private void btn_Close_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var result = RFID.Dis_pose();
|
|
text_Read.Text = result.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
text_Read.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打开控制台执行拼接完成的批处理命令字符串
|
|
/// </summary>
|
|
/// <param name="inputAction">需要执行的命令委托方法:每次调用 <paramref name="inputAction"/> 中的参数都会执行一次</param>
|
|
private void ExecBatCommand(Action<Action<string>> inputAction)
|
|
{
|
|
System.Diagnostics.Process pro = null;
|
|
System.IO.StreamWriter sIn = null;
|
|
System.IO.StreamReader sOut = null;
|
|
|
|
try
|
|
{
|
|
pro = new System.Diagnostics.Process();
|
|
pro.StartInfo.FileName = "cmd.exe";
|
|
pro.StartInfo.UseShellExecute = false;
|
|
pro.StartInfo.CreateNoWindow = true;
|
|
pro.StartInfo.RedirectStandardInput = true;
|
|
pro.StartInfo.RedirectStandardOutput = true;
|
|
pro.StartInfo.RedirectStandardError = true;
|
|
|
|
pro.OutputDataReceived += Pro_OutputDataReceived;
|
|
//pro.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
|
pro.ErrorDataReceived += Pro_OutputDataReceived;
|
|
//pro.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
|
pro.Start();
|
|
sIn = pro.StandardInput;
|
|
sIn.AutoFlush = true;
|
|
|
|
pro.BeginOutputReadLine();
|
|
inputAction(value => sIn.WriteLine(value));
|
|
|
|
pro.WaitForExit();
|
|
}
|
|
finally
|
|
{
|
|
if (pro != null && !pro.HasExited)
|
|
pro.Kill();
|
|
|
|
if (sIn != null)
|
|
sIn.Close();
|
|
if (sOut != null)
|
|
sOut.Close();
|
|
if (pro != null)
|
|
pro.Close();
|
|
}
|
|
}
|
|
|
|
private void Pro_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
|
|
{
|
|
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate
|
|
{
|
|
CommodityModel _CommodityModel = new CommodityModel
|
|
{
|
|
CommodityName = e.Data
|
|
};
|
|
CommodityList.Add(_CommodityModel);
|
|
((this.FindName("DataGrid_RFID")) as DataGrid).ItemsSource = CommodityList;
|
|
text_Read.Text = e.Data;
|
|
});
|
|
}
|
|
}
|
|
}
|