コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: OH1TR/eLaskuViewer
        void ReloadLaskut()
        {
            ELasku lasku  = lvLaskut.SelectedItem as ELasku;
            ELasku select = null;

            Laskut.Clear();
            List <ELasku> laskut = ELasku.ReadFolder(Folder + "*.xml");

            foreach (var i in laskut)
            {
                Laskut.Add(i);
                if (lasku != null && i.SellerOrganisationName == lasku.SellerOrganisationName && i.InvoiceNumber == lasku.InvoiceNumber)
                {
                    select = i;
                }
            }

            if (select != null)
            {
                lvLaskut.SelectedItem = select;
            }


            var xx = laskut.GroupBy(l => l.EpiReference + l.EpiReference.ToString()).Where(g => g.Count() > 1).Select(i => new { EpiReference = i.Key, File = i.First().FileName }).ToArray();

            var files = Directory.GetFiles(Folder, "tiliote*.csv");

            if (files.Length > 0)
            {
                List <Tilirivi> rivit = Tilirivi.ReadFile(files[0]);

                rivit = rivit.Where(i => i.MaksupalveluID != null).ToList();

                foreach (var l in laskut)
                {
                    if (l.InvoiceDueDate == DateTime.Parse("9.12.2015"))
                    {
                        System.Threading.Thread.Sleep(1);
                    }

                    bool found = false;
                    for (int i = 0; i < rivit.Count; i++)
                    {
                        if (l.Tiliotteella == false &&
                            (l.EpiNameAddressDetails.Truncate(30) == rivit[i].Saaja.Replace("Ö", "O").Truncate(30) || rivit[i].Saaja.ToUpper().Contains(l.EpiNameAddressDetails.ToUpper())) &&
                            Math.Abs(l.InvoiceDueDate.Subtract(rivit[i].SuoritePaiva).TotalDays) < 2)
                        {
                            rivit.RemoveAt(i);
                            l.Tiliotteella = true;
                            found          = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        System.Threading.Thread.Sleep(1);
                    }
                }

                string notFound = "";

                rivit.ForEach(i => notFound += i.SuoritePaiva + " " + i.Saaja + " " + i.Summa.ToString() + Environment.NewLine);

                if (notFound.Length > 0)
                {
                    MessageBox.Show(notFound);
                }
            }
            else
            {
                foreach (var l in laskut)
                {
                    l.Tiliotteella = true;
                }
            }
        }