private void btnReset_Click(object sender, RoutedEventArgs e) { bool isSuccess = true; AsyncWorker worker = new AsyncWorker(Application.Current.MainWindow); if (worker.InvokeDoWorkMethod(ResetPortIP) == 1) { isSuccess = true; } else { isSuccess = false; } if (isSuccess) { ((MainWindow)App.Current.MainWindow).statusPanelPage.ShowMessage((string)this.FindResource("ResStr_Setting_Successfully_"), Brushes.Black); } else { ((MainWindow)App.Current.MainWindow).statusPanelPage.ShowMessage((string)this.FindResource("ResStr_Setting_Fail"), Brushes.Red); } }
private void ApplyButtonClick(object sender, RoutedEventArgs e) { string strDrvName = ""; string strPrinterName = m_MainWin.statusPanelPage.m_selectedPrinter; PrintError printRes = PrintError.Print_OK; AsyncWorker worker = new AsyncWorker(Application.Current.MainWindow); CRM_PrintInfo crmPrintInfo = new CRM_PrintInfo(); if (true == common.IsError(m_currentStatus)) { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); VOP.Controls.MessageBoxEx.Show(VOP.Controls.MessageBoxExStyle.Simple, m_MainWin, (string)this.FindResource("ResStr_Operation_can_not_be_carried_out_due_to_machine_malfunction_"), (string)this.FindResource("ResStr_Error")); return; } if (false == common.GetPrinterDrvName(strPrinterName, ref strDrvName)) { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); MessageBoxEx_Simple messageBox = new MessageBoxEx_Simple((string)this.TryFindResource("ResStr_can_not_be_carried_out_due_to_software_has_error__please_try__again_after_reinstall_the_Driver_and_Virtual_Operation_Panel_"), (string)this.FindResource("ResStr_Error")); messageBox.Owner = App.Current.MainWindow; messageBox.ShowDialog(); return; } //Collect user info crmPrintInfo.SetPrintDocType(CurrentPrintType); crmPrintInfo.m_strPrinterName = strPrinterName; crmPrintInfo.m_strPrintCopys = String.Format("{0}", (sbyte)spinnerControl1.Value); //bool isSFP = common.IsSFPPrinter(strDrvName); //bool isWiFiModel = common.IsSupportWifi(strDrvName); //if (isSFP) //{ // if (isWiFiModel) // crmPrintInfo.m_strPrinterModel = "Lenovo LJ2208W"; // else // crmPrintInfo.m_strPrinterModel = "Lenovo LJ2208"; //} //else //{ // if (isWiFiModel) // crmPrintInfo.m_strPrinterModel = "Lenovo M7208W"; // else // crmPrintInfo.m_strPrinterModel = "Lenovo M7208"; //} crmPrintInfo.m_strPrinterModel = strDrvName; if (CurrentPrintType == PrintType.PrintFile_Txt) { dll.SetCopies(m_MainWin.statusPanelPage.m_selectedPrinter, 1); } else { dll.SetCopies(m_MainWin.statusPanelPage.m_selectedPrinter, (sbyte)spinnerControl1.Value); } switch (CurrentPrintType) { case PrintType.PrintFile: case PrintType.PrintFile_Image: case PrintType.PrintFile_Txt: case PrintType.PrintFile_Pdf: case PrintType.PrintFile_PPT: try { if (FilePaths.Count == 1) { string fileExt = System.IO.Path.GetExtension(FilePaths[0]).ToLower(); if (fileExt == ".xls" || fileExt == ".xlsx") { ExcelHelper helper = new ExcelHelper(FilePaths[0]); if (helper.Open()) { helper.Print(m_MainWin.statusPanelPage.m_selectedPrinter, (int)spinnerControl1.Value); helper.Close(); } else { printRes = PrintError.Print_File_Not_Support; } } else if (fileExt == ".pub") { PubHelper helper = new PubHelper(FilePaths[0]); dll.VopSetDefaultPrinter(m_MainWin.statusPanelPage.m_selectedPrinter); if (helper.Open()) { helper.Print(m_MainWin.statusPanelPage.m_selectedPrinter, (int)spinnerControl1.Value); helper.Close(); } else { printRes = PrintError.Print_File_Not_Support; } } //else if (fileExt == ".ppt" // || fileExt == ".pptx") //{ // PPTHelper helper = new PPTHelper(FilePaths[0]); // if (helper.Open()) // { // helper.PrintAll(m_MainWin.statusPanelPage.m_selectedPrinter, // (int)spinnerControl1.Value); // helper.Close(); // } // else // { // printRes = PrintError.Print_File_Not_Support; // } //} else if (fileExt == ".pdf") { dll.VopSetDefaultPrinter(m_MainWin.statusPanelPage.m_selectedPrinter); // printRes = (PrintError)worker.InvokeDoWorkMethod(DoPdfPrint); print.Print(FilePaths[0]); } else { printRes = worker.InvokePrintFileMethod(dll.PrintFile, m_MainWin.statusPanelPage.m_selectedPrinter, FilePaths[0], needFitToPage, (int)CurrentDuplexType, IsPortrait, (int)spinnerControl1.Value, scalingValue); } } } catch (COMException ex) { if ((uint)ex.ErrorCode == 0x80ff000d) //Open file is locked by other process { MessageBoxEx_Simple messageBox = new MessageBoxEx_Simple(ex.Message, (string)this.FindResource("ResStr_Warning")); messageBox.Owner = App.Current.MainWindow; messageBox.ShowDialog(); } else if ((uint)ex.ErrorCode == 0x800a03ec) //Insufficient disk space { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); VOP.Controls.MessageBoxEx.Show( VOP.Controls.MessageBoxExStyle.Simple, m_MainWin, (string)this.FindResource("ResStr_Operation_cannot_be_carried_out_due_to_insufficient_memory_or_hard_disk_space_Please_try_again_after_freeing_memory_or_hard_disk_space_"), (string)this.FindResource("ResStr_Error") ); } else { printRes = PrintError.Print_File_Not_Support; } } catch (Exception) { printRes = PrintError.Print_File_Not_Support; } break; case PrintType.PrintImages: if (FilePaths.Count == 1) { printRes = worker.InvokePrintFileMethod(dll.PrintFile, m_MainWin.statusPanelPage.m_selectedPrinter, FilePaths[0], needFitToPage, (int)CurrentDuplexType, IsPortrait, (int)spinnerControl1.Value, scalingValue); } else { if (dll.PrintInit(m_MainWin.statusPanelPage.m_selectedPrinter, "Neo_Multi_Pictures", (int)enumIdCardType.NonIdCard, new IdCardSize(), needFitToPage, (int)CurrentDuplexType, IsPortrait, scalingValue)) { foreach (string path in FilePaths) { dll.AddImagePath(path); } printRes = (PrintError)worker.InvokeDoWorkMethod(dll.DoPrintImage); } else { printRes = PrintError.Print_Operation_Fail; } } break; case PrintType.PrintIdCard: IdCardSize idCardSize = new IdCardSize(); idCardSize.Width = SelectedTypeItem.Width; idCardSize.Height = SelectedTypeItem.Height; if (dll.PrintInit(m_MainWin.statusPanelPage.m_selectedPrinter, SelectedTypeItem.Name, (int)SelectedTypeItem.TypeId, idCardSize, needFitToPage, (int)DuplexPrintType.NonDuplex, IsPortrait, scalingValue)) { using (IdCardPrintHelper helper = new IdCardPrintHelper()) { int i = 0; foreach (BitmapSource src in IdCardEditWindow.croppedImageList) { helper.AddImage(src); dll.AddImageRotation(IdCardEditWindow.imageRotationList[i]); i++; } printRes = (PrintError)worker.InvokeDoWorkMethod(dll.DoPrintIdCard); } } else { printRes = PrintError.Print_Operation_Fail; } break; } if (printRes == PrintError.Print_File_Not_Support) { MessageBoxEx_Simple messageBox = new MessageBoxEx_Simple((string)this.TryFindResource("ResStr_This_file_is_not_supported__please_select_another_one_"), (string)this.FindResource("ResStr_Warning")); messageBox.Owner = App.Current.MainWindow; messageBox.ShowDialog(); this.m_MainWin.subPageView.Child = this.m_MainWin.winFileSelectionPage; crmPrintInfo.m_strPrintSuccess = "false"; } else if (printRes == PrintError.Print_Memory_Fail) { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); MessageBoxEx_Simple messageBox = new MessageBoxEx_Simple((string)this.TryFindResource("ResStr_Memory_Alloc_Fail"), (string)this.FindResource("ResStr_Error")); messageBox.Owner = App.Current.MainWindow; messageBox.ShowDialog(); crmPrintInfo.m_strPrintSuccess = "false"; } else if (printRes == PrintError.Print_Insufficient_Memory_Or_Disk_Space) { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); VOP.Controls.MessageBoxEx.Show( VOP.Controls.MessageBoxExStyle.Simple, m_MainWin, (string)this.FindResource("ResStr_Operation_cannot_be_carried_out_due_to_insufficient_memory_or_hard_disk_space_Please_try_again_after_freeing_memory_or_hard_disk_space_"), (string)this.FindResource("ResStr_Error") ); crmPrintInfo.m_strPrintSuccess = "false"; } else if (printRes == PrintError.Print_Operation_Fail) { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); MessageBoxEx_Simple messageBox = new MessageBoxEx_Simple((string)this.TryFindResource("ResStr_can_not_be_carried_out_due_to_software_has_error__please_try__again_after_reinstall_the_Driver_and_Virtual_Operation_Panel_"), (string)this.FindResource("ResStr_Error")); messageBox.Owner = App.Current.MainWindow; messageBox.ShowDialog(); crmPrintInfo.m_strPrintSuccess = "false"; } else if (printRes == PrintError.Print_Get_Default_Printer_Fail) { m_MainWin.statusPanelPage.ShowMessage((string)this.TryFindResource("ResStr_Print_Fail"), Brushes.Red); MessageBoxEx_Simple messageBox = new MessageBoxEx_Simple((string)this.TryFindResource("ResStr_can_not_be_carried_out_due_to_software_has_error__please_try__again_after_reinstall_the_Driver_and_Virtual_Operation_Panel_"), (string)this.FindResource("ResStr_Error")); messageBox.Owner = App.Current.MainWindow; messageBox.ShowDialog(); crmPrintInfo.m_strPrintSuccess = "false"; } else { crmPrintInfo.m_strPrintSuccess = "true"; } m_MainWin.UploadPrintInfo(crmPrintInfo); }