Exemplo n.º 1
0
 public ContractNote(MainWindow mainWindow)
 {
     this.mainWindow             = mainWindow;
     pdfParser                   = new PdfParser(this);
     contractNoteTemplateManager = new ContractNoteTemplateManager(this);
     contractNoteItemManager     = new ContractNoteItemManager(this);
     ruleManager                 = new RuleManager();
     CharacterSimilarityHelper.loadDictionary();
 }
Exemplo n.º 2
0
        public ContractNoteItemManager getContractNoteItemManagerCopy()
        {
            ContractNoteItemManager contractNoteItemManagerCopy = new ContractNoteItemManager(contractNote);

            for (int i = 0; i < FIELD_COUNT; i++)
            {
                contractNoteItemManagerCopy.contractNoteItems[i].Value = contractNoteItems[i].Value;
                contractNoteItemManagerCopy.contractNoteItems[i].Valid = contractNoteItems[i].Valid;
            }
            contractNoteItemManagerCopy.pdfFilePath     = pdfFilePath;
            contractNoteItemManagerCopy.templateIsFound = templateIsFound;
            contractNoteItemManagerCopy.success         = success;
            contractNoteItemManagerCopy.isExported      = isExported;
            return(contractNoteItemManagerCopy);
        }
Exemplo n.º 3
0
        private void exportButton_Click(object sender, RoutedEventArgs e)
        {
            if (listBox.Items.Count == 0)
            {
                return;
            }
            Dictionary <string, List <ContractNoteItemManager> > dictionary = new Dictionary <string, List <ContractNoteItemManager> >();

            for (int i = listBox.Items.Count - 1; i >= 0; i--)
            {
                if (!contractNoteList[i].success)
                {
                    continue;
                }
                Rule   rule            = contractNote.ruleManager.getRuleWithSource(Path.GetDirectoryName(pdfFilePathList[i]));
                string destinationPath = rule.Destination;
                if (!Directory.Exists(destinationPath))
                {
                    try
                    {
                        Directory.CreateDirectory(destinationPath);
                    }
                    catch
                    {
                        MessageBox.Show(string.Format("Can't create directory:\n{0}", destinationPath));
                        return;
                    }
                }
                string fileNameWithoutExtension = contractNoteList[i].contractNoteItems[23].Value;
                string pdfFilePath = string.Format(@"{0}\{1}.pdf", destinationPath, fileNameWithoutExtension);
                try
                {
                    File.Copy(pdfFilePathList[i], pdfFilePath, true);
                }
                catch { }
                try
                {
                    File.Delete(pdfFilePathList[i]);
                }
                catch { }
                string contractNoteInstance = contractNoteList[i].contractNoteItems[0].Value;
                if (!dictionary.ContainsKey(contractNoteInstance))
                {
                    dictionary.Add(contractNoteInstance, new List <ContractNoteItemManager>());
                }
                dictionary[contractNoteInstance].Add(contractNoteList[i]);
                pdfFilePathList.RemoveAt(i);
                contractNoteList.RemoveAt(i);
                bitmapSourceList.RemoveAt(i);
                listBox.Items.RemoveAt(i);
            }
            DateTime now = DateTime.Now;

            foreach (KeyValuePair <string, List <ContractNoteItemManager> > pair in dictionary)
            {
                try
                {
                    Rule         rule        = contractNote.ruleManager.getRuleWithInstance(pair.Key);
                    string       csvFilePath = string.Format(@"{0}\{1}-{2}{3}{4}{5}{6}.csv", rule.Destination, pair.Key, now.Year, now.Month.ToString("00"), now.Day.ToString("00"), now.Hour.ToString("00"), now.Minute.ToString("00"));
                    StreamWriter sw          = new StreamWriter(csvFilePath);
                    for (int i = 0; i < ContractNoteItemManager.FIELD_COUNT; i++)
                    {
                        sw.Write(string.Format("{0}{1}", ContractNoteItemManager.fields[i], i == ContractNoteItemManager.FIELD_COUNT - 1 ? "\r\n" : ","));
                    }
                    for (int i = 0; i < pair.Value.Count; i++)
                    {
                        ContractNoteItemManager cnim = pair.Value[i];
                        for (int j = 0; j < ContractNoteItemManager.FIELD_COUNT; j++)
                        {
                            sw.Write(string.Format(@"{0}{1}", cnim.contractNoteItems[j].Value.Replace(",", ""), j == ContractNoteItemManager.FIELD_COUNT - 1 ? "\r\n" : ","));
                        }
                    }
                    sw.Close();
                }
                catch { }
            }
            listBox.SelectedIndex = previousSelectedIndexOfListBox = -1;
            if (listBox.Items.Count > 0)
            {
                listBox.SelectedIndex = 0;
            }
            else
            {
                displayContractNote(-1);
                showImage(true);
            }
            scanButton.IsEnabled   = allIsExported();
            exportButton.IsEnabled = false;

            if (scanButton.IsEnabled)
            {
                Process.Start(Application.ResourceAssembly.Location);
                Application.Current.Shutdown();
            }
            MessageBox.Show("Exporting Finished");
        }
Exemplo n.º 4
0
 public static bool isValidCandidate(string candidate)
 {
     return(ContractNoteItemManager.isValidCandidateForField(currentFieldName, candidate));
 }