Пример #1
0
        private void btm_Preprocess_Click(object sender, EventArgs e)
        {
            //((DataRowView)(fVSelectBindingSource.Current)).Row.SetField<int>("UserID", User.ID);
            SaveOfProcessedText();
            if (ofs_Ocr.FileName != "openFileDialog1")
            {
                PrepareControls(false);
                this.fVSelectBindingSource.AddNew();

                PreprocessDataModel preprocessDataModel = _ocrController.PreprocessData(File.ReadLines(ofs_Ocr.FileName),
                                                                                        "aaaaaaaaaa");
                tb_DataWystawienia.Text = preprocessDataModel.DateOfIssueOfDocument.ToString();
                tb_TerminPlatnosci.Text = preprocessDataModel.PaymentDate.ToString();
                tb_Vat.Text             = preprocessDataModel.Tax;
                tb_Kwota.Text           = preprocessDataModel.Cost.ToString();
            }
            else
            {
                MessageBox.Show("Musisz wskazać plik do przetworzenia.", "Uwaga!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #2
0
        public PreprocessDataModel PreprocessData(IEnumerable <string> file, string inputText)//string input = "aaaaaaaaaa";
        {
            PreprocessDataModel preprocessDataModel = new PreprocessDataModel();

            try
            {
                //auxiliary variables
                char comma   = ',';
                char percent = '%';

                string tax         = string.Empty;
                string grossAmount = string.Empty;
                string paymentDate = string.Empty;
                int    length      = inputText.Length;
                string data        = string.Empty;

                foreach (string line in file)
                {
                    if (line.Contains("USD") & line.Contains("Total"))
                    {
                        grossAmount = line;
                    }

                    if (line.Contains(percent))
                    {
                        tax = line;
                    }

                    if (line.Contains("-") & line.Length == length)
                    {
                        data = line;
                    }

                    if (line.Contains("Due date"))
                    {
                        paymentDate = line;
                    }
                }

                string secondAuxiliaryValueOfTax = string.Empty;
                string auxiliaryValueOfTax       = string.Empty;

                //separating the tax value from the string
                foreach (char str in tax)
                {
                    if (char.IsDigit(str) || str.Equals(percent))
                    {
                        if (str.Equals(percent))
                        {
                            break;
                        }
                        else
                        {
                            auxiliaryValueOfTax += str.ToString();
                        }
                    }
                    else
                    {
                        secondAuxiliaryValueOfTax += str.ToString();
                    }
                }
                string amountOfTax    = "23";
                string destinationTax = auxiliaryValueOfTax.Remove(0, auxiliaryValueOfTax.Length - 2);
                if (destinationTax != amountOfTax)
                {
                    destinationTax = auxiliaryValueOfTax.Remove(0, auxiliaryValueOfTax.Length - 1);
                }
                //auxiliary variables
                string alpha          = string.Empty;
                string cost           = string.Empty;
                string rawPaymentDate = string.Empty;
                //reading gross value from string
                foreach (char str in grossAmount)
                {
                    if (char.IsDigit(str) || str.Equals(comma))
                    {
                        cost += str.ToString();
                    }
                    else
                    {
                        alpha += str.ToString();
                    }
                }
                //conversion of gross amount into decimal
                decimal decimalOfCost = Convert.ToDecimal(cost.Replace(".", ","));
                //loop searching payment date in string
                foreach (char str in paymentDate)
                {
                    if (char.IsDigit(str))
                    {
                        rawPaymentDate += str.ToString();
                    }
                }
                //value assignment from analize
                DateTime rawDate = Convert.ToDateTime(data);
                preprocessDataModel.DateOfIssueOfDocument = rawDate;
                preprocessDataModel.PaymentDate           = rawDate.AddDays(Convert.ToInt32(rawPaymentDate));
                preprocessDataModel.Tax  = destinationTax;
                preprocessDataModel.Cost = decimalOfCost;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(preprocessDataModel);
        }