Пример #1
0
        private void scanButton_Click(object sender, RoutedEventArgs e)
        {
            int maxFileCount = 20;

            pdfFilePathList.Clear();
            listBox.Items.Clear();
            Dictionary <string, bool> dictionary = new Dictionary <string, bool>();

            for (int i = 0; i < contractNote.ruleManager.ruleList.Count; i++)
            {
                string sourceFolderPath = contractNote.ruleManager.ruleList[i].Source;
                if (!Directory.Exists(sourceFolderPath) || dictionary.ContainsKey(sourceFolderPath))
                {
                    continue;
                }
                dictionary.Add(sourceFolderPath, true);
                foreach (string f in Directory.GetFiles(contractNote.ruleManager.ruleList[i].Source))
                {
                    if (!System.IO.Path.GetExtension(f).ToLower().Equals(".pdf"))
                    {
                        continue;
                    }
                    pdfFilePathList.Add(f);
                    listBox.Items.Add(f);
                    if (pdfFilePathList.Count >= maxFileCount)
                    {
                        break;
                    }
                }
                if (pdfFilePathList.Count >= maxFileCount)
                {
                    break;
                }
            }
            if (pdfFilePathList.Count == 0)
            {
                MessageBox.Show("There is not Contract Note to process");
                return;
            }
            TemporaryDataManager.createNewTemporaryDirectory();
            contractNote.contractNoteItemManager.masterListManager.initializeMasterList();
            setEnable(false);
            contractNoteList.Clear();
            bitmapSourceList.Clear();
            currentParsingPdfNo = 0;
            parseContractNote();
        }
        public void parsePdf(string filePath)
        {
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath).Replace(' ', '_');

            tempPngFilePath          = TemporaryDataManager.getFilePath(fileNameWithoutExtension, "png");
            tempJpgFilePath          = TemporaryDataManager.getFilePath(fileNameWithoutExtension, "jpg");
            tempPdfFilePath          = TemporaryDataManager.getFilePath(fileNameWithoutExtension, "pdf");
            tempRawFilePath          = TemporaryDataManager.getFilePath(fileNameWithoutExtension, "txt");
            tempNonMergedOcrFilePath = TemporaryDataManager.getFilePath(fileNameWithoutExtension, "nocr");
            tempMergedOcrFilePath    = TemporaryDataManager.getFilePath(fileNameWithoutExtension, "ocr");
            try
            {
                File.Copy(filePath, tempPdfFilePath, true);
            }
            catch { }
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                string  command   = AppDomain.CurrentDomain.BaseDirectory + "ConvertPdfToPng.exe";
                string  parameter = tempPdfFilePath + " " + tempPngFilePath;
                Process process   = new Process();
                process.StartInfo.FileName        = command;
                process.StartInfo.Arguments       = parameter;
                process.StartInfo.CreateNoWindow  = true;
                process.StartInfo.UseShellExecute = false;
                process.Start();
                process.WaitForExit();
            };
            backgroundWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                System.Threading.Thread.Sleep(100);
                FluentGrayConverter fgc = new FluentGrayConverter();
                fgc.convert(tempPngFilePath, tempJpgFilePath);
                GC.Collect();
                doOcrCallback();
            };
            backgroundWorker.RunWorkerAsync();
        }
Пример #3
0
        public MainWindow()
        {
            InitializeComponent();
            createFieldTextBoxes();

            string applicationName = AppDomain.CurrentDomain.FriendlyName;
            string processName     = applicationName.Substring(0, applicationName.Length - 4);

            if (Process.GetProcessesByName(processName).Length > 1)
            {
                MessageBox.Show(string.Format("{0} is already running", processName));
                Application.Current.Shutdown();
            }

            DateTime expireDate = new DateTime(2017, 3, 29, 12, 0, 0);
            DateTime today      = DateTime.Now;

            if (today > expireDate)
            {
                //MessageBox.Show(@"Please Contact '*****@*****.**'", "Demo Expired");
                //Application.Current.Shutdown();
            }

            SplashWindow splashWindow = new SplashWindow();

            splashWindow.Show();

            TemporaryDataManager.cleanTemporaryDirectory();
            contractNote = new ContractNote(this);
            setEnable(false);
            scanButton.IsEnabled    = true;
            settingButton.IsEnabled = true;
            quitButton.IsEnabled    = true;

            splashWindow.Close();
        }