|
@@ -3,6 +3,7 @@ using NPOI.HSSF.UserModel;
|
|
using NPOI.SS.Formula.Functions;
|
|
using NPOI.SS.Formula.Functions;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
|
|
+using QRCoder;
|
|
using SCADA.Comm;
|
|
using SCADA.Comm;
|
|
using SCADA.CommonCtrl;
|
|
using SCADA.CommonCtrl;
|
|
using SCADA.CommonCtrl.AnimationHelper;
|
|
using SCADA.CommonCtrl.AnimationHelper;
|
|
@@ -21,6 +22,7 @@ using System.Data;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.IO.Ports;
|
|
using System.IO.Ports;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
+using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
@@ -48,12 +50,12 @@ namespace SCADA_DAQ.Customer
|
|
/// <summary>
|
|
/// <summary>
|
|
/// excel文件信息
|
|
/// excel文件信息
|
|
/// </summary>
|
|
/// </summary>
|
|
- private DataTable ExcelData = new DataTable();
|
|
|
|
|
|
+ private DataTable ExcelData;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 条码对应的长宽信息
|
|
/// 条码对应的长宽信息
|
|
/// </summary>
|
|
/// </summary>
|
|
- private Dictionary<string, BarcodeInformation> BarcodeInfo = new Dictionary<string, BarcodeInformation>();
|
|
|
|
|
|
+ private Dictionary<string, BarcodeInformation> BarcodeInfo;
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 条形码的索引
|
|
/// 条形码的索引
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -76,6 +78,9 @@ namespace SCADA_DAQ.Customer
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
ToolBar.Items.Add(myButton = new OpenFileButton() { Margin = new Thickness(15, 0, 0, 0) });
|
|
ToolBar.Items.Add(myButton = new OpenFileButton() { Margin = new Thickness(15, 0, 0, 0) });
|
|
|
|
+ //var comTest = new ToolBarButton() { ButtonKind = SCADA.CommonCtrl.ButtonKind.StartButton, Title = "清除" };
|
|
|
|
+ //ToolBar.Items.Add(comTest);
|
|
|
|
+ //comTest.Click += ComTest_Click; ;
|
|
myButton.Click += MyButton_Click;
|
|
myButton.Click += MyButton_Click;
|
|
if (BarcodeReader1 != null)
|
|
if (BarcodeReader1 != null)
|
|
{
|
|
{
|
|
@@ -84,6 +89,13 @@ namespace SCADA_DAQ.Customer
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //private void ComTest_Click(object sender, RoutedEventArgs e)
|
|
|
|
+ //{
|
|
|
|
+ // ExcelData = new DataTable();
|
|
|
|
+ // BarcodeInfo = new Dictionary<string, BarcodeInformation>();
|
|
|
|
+ // DataGridDt.DataContext = "";
|
|
|
|
+ //}
|
|
|
|
+
|
|
private void BarcodeReader1_BarCodeReceived(object sender, SCADA.BarcodeReader.BarcodeReceivedEventArgs e)
|
|
private void BarcodeReader1_BarCodeReceived(object sender, SCADA.BarcodeReader.BarcodeReceivedEventArgs e)
|
|
{
|
|
{
|
|
string barCode = null;
|
|
string barCode = null;
|
|
@@ -157,26 +169,35 @@ namespace SCADA_DAQ.Customer
|
|
|
|
|
|
private void MyButton_Click(object sender, OpenFileButton.OpenFileButtonMouseEventArgs e)
|
|
private void MyButton_Click(object sender, OpenFileButton.OpenFileButtonMouseEventArgs e)
|
|
{
|
|
{
|
|
|
|
+ ExcelData = new DataTable();
|
|
|
|
+ BarcodeInfo = new Dictionary<string, BarcodeInformation>();
|
|
string fileName = $@"{e.OpenFileName}";
|
|
string fileName = $@"{e.OpenFileName}";
|
|
string fileExt = Path.GetExtension($@"{e.OpenFileName}").ToLower();
|
|
string fileExt = Path.GetExtension($@"{e.OpenFileName}").ToLower();
|
|
- IWorkbook workbook;
|
|
|
|
- using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
|
|
|
|
|
|
+ IWorkbook workbook = null;
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- if (fileExt == ".xlsx")
|
|
|
|
- {
|
|
|
|
- workbook = new XSSFWorkbook(fs);
|
|
|
|
- }
|
|
|
|
- else if (fileExt == ".xls")
|
|
|
|
|
|
+ using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
|
|
{
|
|
{
|
|
- workbook = new HSSFWorkbook(fs);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- workbook = null;
|
|
|
|
- MessageBox.Show("未能选择正确的Excel表");
|
|
|
|
- return;
|
|
|
|
|
|
+ if (fileExt == ".xlsx")
|
|
|
|
+ {
|
|
|
|
+ workbook = new XSSFWorkbook(fs);
|
|
|
|
+ }
|
|
|
|
+ else if (fileExt == ".xls")
|
|
|
|
+ {
|
|
|
|
+ workbook = new HSSFWorkbook(fs);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("未能选择正确的Excel表");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ catch (Exception)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("Excel表已在另一进程打开,请关闭选择的Excel表");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
ISheet sheet = workbook.GetSheetAt(0);
|
|
ISheet sheet = workbook.GetSheetAt(0);
|
|
IRow header = sheet.GetRow(sheet.FirstRowNum);
|
|
IRow header = sheet.GetRow(sheet.FirstRowNum);
|
|
int startRow = sheet.FirstRowNum + 1;
|
|
int startRow = sheet.FirstRowNum + 1;
|