diff --git a/MainWindow.xaml b/MainWindow.xaml
index df32b4e..a37dc0a 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -223,8 +223,8 @@
-
-
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index b970d36..0595c8a 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -31,6 +31,9 @@ using static System.Net.Mime.MediaTypeNames;
using formula_manage.UserClass;
using System.Drawing;
using System.Diagnostics;
+using System.Printing;
+using System.Drawing.Printing;
+using static System.Drawing.Printing.PrinterSettings;
namespace formula_manage
{
@@ -341,6 +344,21 @@ namespace formula_manage
private void print(object sender, RoutedEventArgs e)
{
+ Print.IsEnabled = false;
+ // var printServer = new PrintServer();
+ // PrinterList = printServer.GetPrintQueues();
+ // StringCollection strList = PrinterSettings.InstalledPrinters;
+
+ System.Windows.Controls.PrintDialog dialog = new System.Windows.Controls.PrintDialog();
+ //显示打印框,选择份数和打印机
+ if (dialog.ShowDialog() == true)
+ {
+ // dialog.PrintVisual(printArea, "Print Test");
+ // dialog.PrintVisual(richText, "测试");
+ }
+
+
+ Print.IsEnabled = true;
}
private void fabric(object sender, RoutedEventArgs e)
@@ -360,6 +378,7 @@ namespace formula_manage
}
private void confirm(object sender, RoutedEventArgs e)
{
+ Confirm.IsEnabled = false;
}
private void delete(object sender, RoutedEventArgs e)
@@ -686,6 +705,7 @@ namespace formula_manage
}
}
Save.IsEnabled = false;
+ Confirm.IsEnabled = false;
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
}
private void CP_CONC_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)//目标饱和度输入事件
@@ -738,6 +758,7 @@ namespace formula_manage
rowadd["UNIT"] = "g";
RRODUCTdataTable.Rows.Add(rowadd);
Save.IsEnabled = true;
+ Confirm.IsEnabled = true;
}
}
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
@@ -834,6 +855,7 @@ namespace formula_manage
row.EndEdit();
DataGridHelper.SetRealTimeCommit(Grid_RRODUCT, true); //实时更新datagrid
Save.IsEnabled = false;
+ Confirm.IsEnabled = false;
}
private void CP_PRODUCT_NAME_DropDownClosed(object sender, EventArgs e)//原料名选择事件
{
@@ -899,6 +921,7 @@ namespace formula_manage
row.EndEdit();
}
Save.IsEnabled = false;
+ Confirm.IsEnabled = false;
}
diff --git a/UserClass/UserPrint.cs b/UserClass/UserPrint.cs
new file mode 100644
index 0000000..fd40258
--- /dev/null
+++ b/UserClass/UserPrint.cs
@@ -0,0 +1,203 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing.Printing;
+using System.Linq;
+using System.Management;
+using System.Printing;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace formula_manage.UserClass
+{
+ internal class UserPrint
+ {
+ ///
+ /// 判断是否连接打印机
+ ///
+ public bool CheckPrinter()
+ {
+ //取得默认打印机名
+ PrintDocument pdoc = new PrintDocument();
+ string printerName1 = pdoc.PrinterSettings.PrinterName;
+
+ //ManagementScope scope = new ManagementScope(@"\root\cimv2");
+ //scope.Connect();
+
+ // Select Printers from WMI Object Collections
+ ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
+
+ string printerName = "";
+ foreach (ManagementObject printer in searcher.Get())
+ {
+ printerName = printer["Name"].ToString().ToLower();
+ if (printerName.IndexOf(printerName1.ToLower()) > -1)
+ {
+
+ if (printer["WorkOffline"].ToString().ToLower().Equals("true"))
+ {
+ switch (MessageBox.Show("默认打印机未连接或出错", "警告", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
+ {
+ case DialogResult.Retry:
+ CheckPrinter();
+ break;
+ }
+ return false;
+ // printer is offline by user
+
+ }
+ else
+ {
+ // printer is not offline
+
+ return true;
+ }
+ }
+ }
+ switch (MessageBox.Show("默认打印机未连接或出错", "警告", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error))
+ {
+ case DialogResult.Retry:
+ CheckPrinter();
+ break;
+ }
+ return false;
+ }
+
+ ///
+ /// 判断打印机状态,传Exception
+ ///
+ /// Exception
+ public void ErrerPrint(Exception ex)
+ {
+ PrintQueue pq = LocalPrintServer.GetDefaultPrintQueue();
+ string PrintStaticText = "";
+ bool isPrintErrer = false;
+
+
+ switch (pq.QueueStatus)
+ {
+ case PrintQueueStatus.Busy:
+ PrintStaticText = "打印机正忙";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.DoorOpen:
+ PrintStaticText = "打印机上的门已打开";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Error:
+ PrintStaticText = "由于错误情况,打印机无法打印。";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.IOActive:
+ PrintStaticText = "打印机正在与打印服务器交换数据";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Initializing:
+ PrintStaticText = "打印机正在初始化";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.ManualFeed:
+ PrintStaticText = "打印机正在等待用户将打印介质放入手动送纸盒";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.NoToner:
+ PrintStaticText = "打印机墨粉用完";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.None:
+ PrintStaticText = "未指定状态。";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.NotAvailable:
+ PrintStaticText = "状态信息不可用";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Offline:
+ PrintStaticText = "打印机处于脱机状态。";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.OutOfMemory:
+ PrintStaticText = "打印机无可用内存";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.OutputBinFull:
+ PrintStaticText = "打印机的输出纸盒已满";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.PagePunt:
+ PrintStaticText = "打印机不能打印当前页";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.PaperJam:
+ PrintStaticText = "打印机卡纸";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.PaperOut:
+ PrintStaticText = "打印机中没有或已用完当前打印作业所需的纸张类型";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.PaperProblem:
+ PrintStaticText = "打印机中的纸张导致未指定的错误情况";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Paused:
+ PrintStaticText = "打印队列已暂停";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.PendingDeletion:
+ PrintStaticText = "打印队列正在删除打印作业";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.PowerSave:
+ PrintStaticText = "打印机处于节能模式";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Printing:
+ PrintStaticText = "设备正在打印";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Processing:
+ PrintStaticText = "设备正在执行某种工作,如果此设备是集打印机、传真机和扫描仪于一体的多功能设备,则不需要打印";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.ServerUnknown:
+ PrintStaticText = "打印机处于错误状态";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.TonerLow:
+ PrintStaticText = "打印机中只剩下少量墨粉";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.UserIntervention:
+ PrintStaticText = "打印机要求通过用户操作来更正错误情况";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.Waiting:
+ PrintStaticText = "打印机正在等待打印作业";
+ isPrintErrer = true;
+ break;
+ case PrintQueueStatus.WarmingUp:
+ PrintStaticText = "打印机正在预热";
+ isPrintErrer = true;
+ break;
+ }
+
+ if (isPrintErrer)
+ {
+ //WriteLog.SetString(PrintStaticText);
+ MessageBox.Show(PrintStaticText, "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ if (ex.Message == "The net printer is unavailable.")
+ {
+
+
+ MessageBox.Show("网络打印机不可用", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ // WriteLog.SetString(ex.Message);
+ }
+ else
+ {
+ // WriteLog.SetException(ex);
+ }
+ }
+ }
+}
diff --git a/formula_manage.csproj b/formula_manage.csproj
index 1337f39..72420ed 100644
--- a/formula_manage.csproj
+++ b/formula_manage.csproj
@@ -124,6 +124,8 @@
+
+
packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll
@@ -180,6 +182,7 @@
+