public void StartScan(string filename, string dcode) { //ScanHelperXP scan = new ScanHelperXP(); CC_File file; PDFHelper pdf = new PDFHelper(); bool flag = true; var list = new List<Image>(); try { if (comboStat.SelectedValue != null && comboStat.SelectedValue.ToString() == "Duplex") { list = scan.StartScan(1); } else { list = scan.StartScan(); } //Image img = Image.FromFile("D:\\test.png"); //list.Add(img); //Image img2 = Image.FromFile("D:\\2.bmp"); //list.Add(img2); //Image img3 = Image.FromFile("D:\\2.bmp"); //list.Add(img3); //Image img4 = Image.FromFile("D:\\2.bmp"); //list.Add(img4); //Image img5 = Image.FromFile("D:\\2.bmp"); //list.Add(img5); } catch (Exception ex) { //如果发生异常则之后则后面则不再提示信息 flag = false; Alert.Show(ex.Message); } if (list != null && list.Count != 0) { var templist = list.ToList(); string path = LocalPath + "\\" + filename + ".pdf"; MethodInvoker mi = delegate { try { pdf.MakePDF(path, templist); } catch (Exception ex) { //Alert.Show("生成文档失败"); } //Alert.Show("文档生成成功!"); file = new CC_File(); file.CCF_DCode = dcode; file.CCF_Name = filename; file.CCF_Directory = path; list = null; CCFileList.Add(file); SaveDictionary(); SavePath(); Alert.Show("文档生成成功!"); }; mi.BeginInvoke(null, null); } else { if (flag) { Alert.Show("未找到可扫描文件请确认扫描仪是否可用!"); } } }
//public CC_File StartScan(string filename, string dcode) //{ // ScanHelper scan = new ScanHelper(); // CC_File file; // PDFHelper pdf = new PDFHelper(); // var list = scan.StartScan(); // if (list != null && list.Count != 0) // { // pdf.MakePDF(LocalPath + filename + ".pdf", list); // file = new CC_File(); // file.CCF_DCode = dcode; // file.CCF_Name = filename; // file.CCF_iType = "Prod"; // file.CCF_Directory = LocalPath + filename + ".pdf"; // return file; // } // else // { // Alert.Show("请确认是否已把扫描文档放到Feeder"); // return null; // } //} public void StartScan(string filename, string dcode) { bool flag = true; CC_File file; PDFHelper pdf = new PDFHelper(); List<Image> list = new List<Image>(); try { list = scan.StartScan(); } catch (Exception ex) { flag = false; Alert.Show(ex.Message); } if (list != null && list.Count != 0) { var templist = list.ToList(); string path = LocalPath + "\\" + filename + ".pdf"; MethodInvoker mi = delegate { try { pdf.MakePDF(path, templist); } catch { } //AutoClosedMessageBox.Show(" 文档生成成功!", " 提示", 15, 2000); file = new CC_File(); file.CCF_DCode = dcode; file.CCF_Name = filename; file.CCF_iType = "ProdRepair"; file.CCF_Directory = path; list = null; CCFileList.Add(file); SavePath(); Alert.Show("文档生成成功!"); }; mi.BeginInvoke(null, null); //GC.Collect(); //return file; } else { if (flag) { Alert.Show("请确认是否已把扫描文档放到Feeder"); } //return null; } }