Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var           diretorioArquivos = System.Configuration.ConfigurationManager.AppSettings["diretorioArquivos"];
            DirectoryInfo Dir = new DirectoryInfo(diretorioArquivos);

            FileInfo[] Files = Dir.GetFiles("*.txt", SearchOption.TopDirectoryOnly);

            Parallel.ForEach(Files, FileArquivo => {
                var novoArquivo = $" {FileArquivo.FullName.Replace(FileArquivo.Extension,"")}_{Guid.NewGuid()}{FileArquivo.Extension}";
                var linhas      = File.ReadAllLines(FileArquivo.FullName).ToList();
                linhas.RemoveAt(0);
                linhas.RemoveAt(linhas.Count - 1);

                using (StreamWriter sr = new StreamWriter(novoArquivo)) {
                    foreach (var lin in linhas)
                    {
                        sr.WriteLine(lin);
                    }
                }
                var engine       = new FixedFileEngine <Arquivo>();
                Arquivo[] result = engine.ReadFile(novoArquivo);
                foreach (var arq in result)
                {
                    Arquivos.AddOrUpdate(Guid.NewGuid(), arq, (key, value) => arq);
                }
                File.Delete(novoArquivo);
            });
            var arquivos = Arquivos.Select(x => x.Value).OrderBy(x => x.DataPregao).ToList();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void SimpleTest2()
        {
            var engine = new FixedFileEngine(typeof(CustomersFixed));
            Assert.AreEqual(91, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            engine.Options.RecordCondition.Condition = RecordCondition.IncludeIfBegins;
            engine.Options.RecordCondition.Selector = "F";
            Assert.AreEqual(8, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);
        }
Exemplo n.º 3
0
        public void ErrorWithTooLongValue(string value)
        {
            var engine   = new FixedFileEngine <ErrorCustomer>();
            var customer = new ErrorCustomer {
                mCustomerID = value
            };

            Assert.Throws <ConvertException>(() => engine.WriteString(new[] { customer }));
        }
Exemplo n.º 4
0
            public void Обработать()
            {
                FixedFileEngine   engine      = new FixedFileEngine(typeof(InvoiceImport));
                InvoiceImport     data        = (InvoiceImport)engine.ReadString(Буфер)[0];
                IObjectSpace      os          = CommonMethods.FindObjectSpaceByObject(this);
                fmCAVTInvoiceType sf_sfz_type = os.GetObjects <fmCAVTInvoiceType>().First(x => x.Prefix == "Z");

                СтрокаОснов.ProcessLine(os, this, data, sf_sfz_type);
            }
Exemplo n.º 5
0
        public void SimpleTest2()
        {
            FixedFileEngine engine = new FixedFileEngine(typeof(CustomersFixed));

            Assert.AreEqual(91, Common.ReadTest(engine, @"Good\CustomersFixed.txt").Length);

            engine.Options.RecordCondition.Condition = RecordCondition.IncludeIfBegins;
            engine.Options.RecordCondition.Selector  = "F";
            Assert.AreEqual(8, Common.ReadTest(engine, @"Good\CustomersFixed.txt").Length);
        }
Exemplo n.º 6
0
        public void ErrorWithShortEnoughValue(string originalValue, string expectedValue)
        {
            var engine   = new FixedFileEngine <ErrorCustomer>();
            var customer = new ErrorCustomer {
                mCustomerID = originalValue
            };
            var res = engine.WriteString(new[] { customer });

            Check.That(res).IsEqualTo($"{expectedValue}{Environment.NewLine}");
        }
Exemplo n.º 7
0
        public void Discard(string originalValue, string expectedValue)
        {
            var engine   = new FixedFileEngine <DiscardCustomer>();
            var customer = new DiscardCustomer {
                mCustomerID = originalValue
            };
            var res = engine.WriteString(new[] { customer });

            Check.That(res).IsEqualTo($"{expectedValue}{Environment.NewLine}");
        }
Exemplo n.º 8
0
        public void SimpleTest2()
        {
            var engine = new FixedFileEngine(typeof(CustomersFixed));

            Assert.AreEqual(91, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            engine.Options.RecordCondition.Condition = RecordCondition.IncludeIfBegins;
            engine.Options.RecordCondition.Selector  = "F";
            Assert.AreEqual(8, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);
        }
Exemplo n.º 9
0
        //-> {Example.File:Example.cs}

        /// <summary>
        /// Execute the engine and get some results
        /// </summary>
        public override void Run()
        {
            var engine = new FixedFileEngine <Customer>();

            Customer[] result = engine.ReadFile("input.txt");

            foreach (var detail in result)
            {
                this.Console.WriteLine(" Client: {0},  Name: {1}", detail.CustId, detail.Name);
            }
        }
Exemplo n.º 10
0
        public void SimpleTest()
        {
            var engine = new FixedFileEngine<CustomersFixed>();
            Assert.AreEqual(91, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            engine.Options.IgnoreFirstLines = 10;
            Assert.AreEqual(81, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            engine.Options.IgnoreLastLines = 6;
            Assert.AreEqual(75, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            Assert.AreEqual(183, engine.Options.RecordLength);
        }
Exemplo n.º 11
0
        //-> /File


        public override void Run()
        {
            //-> File:Example.cs

            var engine = new FixedFileEngine <Customer>();
            var result = engine.ReadFile("input.txt");

            foreach (var detail in result)
            {
                Console.WriteLine(" Client: {0},  Name: '{1}'", detail.CustId, detail.Name);
            }
            //-> /File
        }
Exemplo n.º 12
0
        public void SimpleTest()
        {
            var engine = new FixedFileEngine <CustomersFixed>();

            Assert.AreEqual(91, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            engine.Options.IgnoreFirstLines = 10;
            Assert.AreEqual(81, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            engine.Options.IgnoreLastLines = 6;
            Assert.AreEqual(75, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);

            Assert.AreEqual(183, engine.Options.RecordLength);
        }
Exemplo n.º 13
0
        public void SimpleTest()
        {
            FixedFileEngine engine = new FixedFileEngine(typeof(CustomersFixed));

            Assert.AreEqual(91, Common.ReadTest(engine, @"Good\CustomersFixed.txt").Length);

            engine.Options.IgnoreFirstLines = 10;
            Assert.AreEqual(81, Common.ReadTest(engine, @"Good\CustomersFixed.txt").Length);

            engine.Options.IgnoreLastLines = 6;
            Assert.AreEqual(75, Common.ReadTest(engine, @"Good\CustomersFixed.txt").Length);

            Assert.AreEqual(183, engine.Options.RecordLength);
        }
Exemplo n.º 14
0
        public override void Run()
        {
            //-> File:Example.cs
            var engine = new FixedFileEngine <Customer>();

            Customer[] result = engine.ReadFile("input.txt");

            foreach (var detail in result)
            {
                this.Console.WriteLine(" Client: {0},  Date: {1}", detail.CustId, detail.AddedDate.ToString("dd-MM-yyyy"));
            }

            //-> /File
        }
Exemplo n.º 15
0
        public static void Run(
            [BlobTrigger("stations/import/{name}", Connection = "StationStorage")] Stream importBlob,
            string name,
            [Queue("station-imports", Connection = "StationStorage")] CloudQueue outputQueue,
            TraceWriter log)
        {
            log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {importBlob.Length} Bytes");

            //read file
            var file = new StreamReader(importBlob);

            StringBuilder sb = new StringBuilder();
            string        fileLine;

            while ((fileLine = file.ReadLine()) != null)
            {
                if (!fileLine.ToLower().StartsWith("a") || fileLine.ToLower().Contains("file-spec"))
                {
                    continue;
                }

                sb.AppendLine(fileLine);
            }

            file.Close();

            // parse lines
            var engine = new FixedFileEngine <StationImportModel>();

            StationImportModel[] stationImportModels = engine.ReadString(sb.ToString());
            log.Info($"Parsed {stationImportModels.Length} stations.");

            // add to queue
            foreach (var stationImportModel in stationImportModels)
            {
                outputQueue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(stationImportModel)), TimeSpan.FromMinutes(10));
                log.Info($"Station {stationImportModel.StationName} added to queue.");
            }
        }
Exemplo n.º 16
0
        static public void ImportInvoices(IObjectSpace os, ДокИмпортОснований док, TextReader reader)
        {
            FixedFileEngine engine = new FixedFileEngine(typeof(InvoiceImport));
            String          line;

            os.Delete(док.Основания);
            fmCAVTInvoiceType sf_sfz_type = os.GetObjects <fmCAVTInvoiceType>().First(x => x.Prefix == "Z");

            while ((line = reader.ReadLine()) != null)
            {
                InvoiceImport data = (InvoiceImport)engine.ReadString(line)[0];
                if (data.SF_IO_TYPE.Trim() == String.Empty)
                {
                    continue;
                }
                СтрокаОснов строка = os.CreateObject <СтрокаОснов>();
                док.Основания.Add(строка);
                строка.БуферУст(line);
                СтрокаОснов.ImportLine(os, строка, data);
                СтрокаОснов.ProcessLine(os, строка, data, sf_sfz_type);
            }
            reader.Close();
        }
Exemplo n.º 17
0
        static public void ImportInvoices(IObjectSpace os, fmCAVTInvoiceRegister register, String file_name)
        {
//            OpenFileDialog dialog = new OpenFileDialog();
//            if (dialog.ShowDialog() == DialogResult.OK) {
            FixedFileEngine engine = new FixedFileEngine(typeof(fmCAVTInvoiceImport));

            fmCAVTInvoiceImport[]              imp_res            = (fmCAVTInvoiceImport[])engine.ReadFile(file_name);
            IList <fmCAVTInvoiceType>          inv_types          = os.GetObjects <fmCAVTInvoiceType>();
            IList <fmCAVTInvoiceTransferType>  inv_transfer_types = os.GetObjects <fmCAVTInvoiceTransferType>();
            IList <fmCAVTInvoiceOperationType> inv_oper_types     = os.GetObjects <fmCAVTInvoiceOperationType>();
            Int32  count   = 0;
            UInt32 seq_num = 0;

            foreach (fmCAVTInvoiceImport imp_rec in imp_res)
            {
                imp_rec.SF_VO_CODE    = imp_rec.SF_VO_CODE.Trim();
                imp_rec.SF_INT_NUMBER = imp_rec.SF_INT_NUMBER.Trim();
                imp_rec.SF_NUMBER     = imp_rec.SF_NUMBER.Trim();
                Decimal  summ_cost     = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
                Decimal  summ_nds      = Decimal.Parse(imp_rec.SUMM_NDS.Trim().Replace('.', ','));
                Decimal  summ_sub_cost = Decimal.Parse(imp_rec.SUMM_SUB_COST.Trim().Replace('.', ','));
                Decimal  summ_sub_nds  = Decimal.Parse(imp_rec.SUMM_SUB_NDS.Trim().Replace('.', ','));
                DateTime sf_date       = default(DateTime);
                DateTime.TryParseExact(imp_rec.SF_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out sf_date);
                fmCAVTInvoiceBase invoice = os.FindObject <fmCAVTInvoiceBase>(
                    XPQuery <fmCAVTInvoiceBase> .TransformExpression(
                        ((ObjectSpace)os).Session,
                        rec => rec.Supplier.Code == imp_rec.SF_VO_CODE &&
                        rec.RegNumber == imp_rec.SF_INT_NUMBER &&
                        rec.Date >= sf_date &&
                        rec.Date < sf_date.AddDays(1)
                        ));
                //if (invoice == null) {
                //    count++;
                //    System.Console.WriteLine(imp_rec.SF_INT_NUMBER + " " + imp_rec.SF_NUMBER + " " + imp_rec.SF_DATE + " " + summ_cost + " " + summ_nds);
                //}
                if (invoice == null)
                {
                    crmCParty party = os.GetObjects <crmCParty>(new BinaryOperator("Code", imp_rec.SF_VO_CODE)).FirstOrDefault();
                    invoice           = os.CreateObject <fmCAVTInvoiceBase>();
                    invoice.RegNumber = imp_rec.SF_INT_NUMBER;
                    invoice.Number    = imp_rec.SF_NUMBER;
                    invoice.Date      = sf_date;
                    invoice.Supplier  = party;
                    invoice.Customer  = register.Party;
                    invoice.SummAVT   = Decimal.Parse(imp_rec.SUMM_NDS.Trim().Replace('.', ','));
                    invoice.SummCost  = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
                }
                else
                {
                    invoice.SummAVT  = Decimal.Parse(imp_rec.SUMM_NDS.Trim().Replace('.', ','));
                    invoice.SummCost = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
                    fmCAVTInvoiceRegisterLine line_check = os.FindObject <fmCAVTInvoiceRegisterLine>(
                        CriteriaOperator.And(new BinaryOperator("InvoiceVersion", invoice.Current)), true);
                    if (line_check != null)
                    {
                        continue;
                    }
                }
                fmCAVTInvoiceRegisterLine line = register.InLines.Where(rec => rec.Invoice == invoice).FirstOrDefault();
                if (line == null)
                {
                    line = os.CreateObject <fmCAVTInvoiceRegisterLine>();
                    register.InLines.Add(line);
                }
                line.SequenceNumber = seq_num++;
                //                line_doc.DateTransfer = invoice.Date;
                line.Invoice      = invoice;
                line.TransferType = inv_transfer_types.Where(rec => rec.Code == "1").FirstOrDefault();
                if (String.IsNullOrEmpty(imp_rec.SF_TRANS_DATE.Trim()))
                {
                    DateTime trans_date = default(DateTime);
                    DateTime.TryParseExact(imp_rec.SF_TRANS_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out trans_date);
                    line.DateTransfer = trans_date;
                }
                if (line.DateTransfer < sf_date)
                {
                    line.DateTransfer = sf_date;
                }
                line.OperationType = inv_oper_types.Where(rec => rec.Code == imp_rec.SF_OPER_TYPE.Trim() ||
                                                          rec.Code == '0' + imp_rec.SF_OPER_TYPE.Trim()).FirstOrDefault();
            }
            System.Console.WriteLine("All " + count);
        }
Exemplo n.º 18
0
        static public void ImportSummAll_Correct(IObjectSpace os, fmCAVTBookVAT book, String file_name)
        {
//            OpenFileDialog dialog = new OpenFileDialog();
//            if (dialog.ShowDialog() == DialogResult.OK) {
            FixedFileEngine engine = new FixedFileEngine(typeof(InvoiceInfo));

            InvoiceInfo[] imp_res = (InvoiceInfo[])engine.ReadFile(file_name);
            foreach (var line in book.BookVATRecords)
            {
                if (line.BookBuhStruct != null)
                {
                    continue;
                }
                InvoiceInfo info = imp_res.FirstOrDefault(
                    x => x.sf_intnum.Trim() == line.VATInvoiceRegNumber &&
                    x.sf_number.Trim() == line.VATInvoiceNumber &&
                    x.sf_date == line.VATInvoiceDate.ToString("yyyyMMdd") &&
                    x.vo_code.Trim() == line.Party.Code
                    );
                if (info == null)
                {
                    info = imp_res.FirstOrDefault(
                        x => x.sf_intnum.Trim() == line.VATInvoiceRegNumber &&
                        x.sf_number.Trim() == line.VATInvoiceNumber &&
                        x.reg_sf_date == line.VATInvoiceDate.ToString("yyyyMMdd") &&
                        x.vo_code.Trim() == line.Party.Code
                        );
                }
                if (info == null)
                {
                    info = imp_res.FirstOrDefault(
                        x => x.sf_intnum.Trim() == line.VATInvoiceRegNumber &&
                        x.sf_intnum.Trim() == line.VATInvoiceNumber &&
                        x.sf_date == line.VATInvoiceDate.ToString("yyyyMMdd") &&
                        x.vo_code.Trim() == line.Party.Code
                        );
                    if (info != null)
                    {
                        line.VATInvoiceNumber = info.sf_number.Trim();
                    }
                }
                if (info == null)
                {
                    info = imp_res.FirstOrDefault(
                        x => x.sf_intnum.Trim() == line.VATInvoiceNumber &&
                        String.IsNullOrEmpty(line.VATInvoiceRegNumber) &&
                        x.sf_date == line.VATInvoiceDate.ToString("yyyyMMdd") &&
                        x.vo_code.Trim() == line.Party.Code
                        );
                    if (info != null)
                    {
                        line.VATInvoiceRegNumber = info.sf_intnum.Trim();
                        line.VATInvoiceNumber    = info.sf_number.Trim();
                    }
                }
                if (info != null)
                {
                    Decimal vat = Decimal.Parse(info.vat_19_deb.Trim().Replace('.', ',')) +
                                  Decimal.Parse(info.vat_19_deb_71.Trim().Replace('.', ',')) +
                                  Decimal.Parse(info.vat_19_deb_98.Trim().Replace('.', ',')) +
                                  Decimal.Parse(info.vat_virtual.Trim().Replace('.', ','));
                    Decimal cost_full  = Decimal.Parse(info.cost_full.Trim().Replace('.', ','));
                    Decimal cost_crd   = Decimal.Parse(info.cost_crd.Trim().Replace('.', ','));
                    Decimal cost_nocrd = Decimal.Parse(info.cost_nocrd.Trim().Replace('.', ','));
                    Decimal cost_calc  = Decimal.Parse(info.cost_calc.Trim().Replace('.', ','));
                    if (cost_full != 0)
                    {
                        line.SummAll_Correct = cost_full;
                    }
                    else if (cost_crd >= cost_nocrd + cost_calc)
                    {
                        line.SummAll_Correct = cost_crd + vat;
                    }
                    else
                    {
                        line.SummAll_Correct = cost_nocrd + cost_calc + vat;
                    }
                }
                else
                {
                }
            }
        }
        private void Import(IObjectSpace os, ОперацияКонтРучные конт, String file_name)
        {
            FixedFileEngine engine = new FixedFileEngine(typeof(OperationImport));

            OperationImport[] imp_res = (OperationImport[])engine.ReadFile(file_name);
            os.Delete(конт.Операции);
            DateTime date = default(DateTime);

            foreach (OperationImport oper_imp in imp_res)
            {
                ОснованиеДокумент doc = null;
                if (oper_imp.SF_TYPE.Trim() != "СФЗ")
                {
                    doc = os.FindObject <ОснованиеДокумент>(new BinaryOperator("РегНомер", oper_imp.SF_REGNUM.Trim()), true);
                }
                else
                {
                    DateTime.TryParseExact(oper_imp.SF_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date);
                    Основание осн = os.FindObject <Основание>(
                        new BinaryOperator("ИннПродавца", "5012039795") &
                        new BinaryOperator("Номер", oper_imp.SF_NUMBER.Trim()) &
                        new BinaryOperator("Дата", date, BinaryOperatorType.GreaterOrEqual) &
                        new BinaryOperator("Дата", date.AddDays(1), BinaryOperatorType.Less), true);
                    doc = осн != null ? осн.ДействующийДокумент : null;
                }
                Операция oper = os.CreateObject <Операция>();
                конт.Операции.Add(oper);
//                Decimal summ_cost = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
//                DateTime.TryParseExact(imp_rec.SF_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out sfdoc_date);
                oper.ТипКниги        = (Операция.ТипКнигиТип)Int32.Parse(oper_imp.BOOK.Trim());
                oper.ТипДеятельности = (Операция.ТипДеятельностиТип)Int32.Parse(oper_imp.WORK_TYPE.Trim());
                oper.ТипНапрОпер     = (Операция.ТипНапрОперТип)Int32.Parse(oper_imp.DIR.Trim());
                oper.ТипОперВнутр    = (Операция.ТипОперВнутрТип)Int32.Parse(oper_imp.OPERATION.Trim());
                String stavka = oper_imp.VAT_RATE.Trim();
                if (String.IsNullOrEmpty(stavka) || stavka == "0")
                {
                    stavka = "2";
                }
                oper.Ставка = (СтавкаНДС)Int32.Parse(stavka);
                //                oper_imp.VAT_MODE;
                oper.Проводка   = oper_imp.BUH_PROV.Trim();
                oper.СубсчетНДС = oper_imp.VAT_ACC.Trim();
                DateTime.TryParseExact(oper_imp.BUH_DT.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date);
                oper.ДатаБУ = date;
                DateTime.TryParseExact(oper_imp.VAT_DT.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date);
                oper.ДатаНДС           = date;
                oper.ОснованиеДокумент = doc;
                oper.КодПартнера       = oper_imp.VO_CODE.Trim();
                if (oper_imp.SF_TYPE.Trim() != "СФЗ")
                {
                    oper.ОснованиеРегНомер = oper_imp.SF_REGNUM.Trim();
                }
                else
                {
                    oper.ОснованиеРегНомер = doc != null ? doc.егНомер : null;
                }
                oper.СФТип     = oper_imp.SF_TYPE.Trim();
                oper.СФТипОриг = oper_imp.SF_TYPE_ORIG.Trim();
                oper.СФНомер   = oper_imp.SF_NUMBER.Trim();
                DateTime.TryParseExact(oper_imp.SF_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date);
                oper.СФДата  = date;
                oper.ПДТип   = oper_imp.PD_TYPE.Trim();
                oper.ПДНомер = oper_imp.PD_NUMBER.Trim();
                DateTime.TryParseExact(oper_imp.PD_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out date);
                oper.ПДДата             = date;
                oper.СуммаВсего         = Decimal.Parse(oper_imp.SUMM_ALL.Trim().Replace('.', ','));
                oper.СуммаСтоимость     = Decimal.Parse(oper_imp.SUMM_COST.Trim().Replace('.', ','));
                oper.СуммаНДСБаза       = Decimal.Parse(oper_imp.SUMM_VAT_PAY.Trim().Replace('.', ','));
                oper.СуммаНДСВычет      = Decimal.Parse(oper_imp.SUMM_VAT_BAY.Trim().Replace('.', ','));
                oper.СуммаНДССтоимость  = Decimal.Parse(oper_imp.SUMM_VAT_COST.Trim().Replace('.', ','));
                oper.СуммаНДС19Входящий = Decimal.Parse(oper_imp.SUMM_VAT_IN.Trim().Replace('.', ','));
                oper.СуммаНДС19Списано  = Decimal.Parse(oper_imp.SUMM_VAT_IN_USE.Trim().Replace('.', ','));
                if (oper.ТипКниги == Операция.ТипКнигиТип.ПРОДАЖ)
                {
                    if (oper.СФТип != "СФВ")
                    {
                        oper.СуммаСтоимость  = oper.СуммаВсего;
                        oper.СуммаСтоимость += -oper.СуммаНДСБаза;
                    }
                    else
                    {
                        oper.СуммаСтоимость = Decimal.Round(oper.СуммаНДСБаза * 100 / 18, 2);
                        oper.СуммаВсего     = oper.СуммаСтоимость + oper.СуммаНДСБаза;
                    }
                }
                //oper_imp.SUMM_ALL;
                //oper_imp.SUMM_COST;
                //oper_imp.SUMM_VAT_PAY;
                //oper_imp.SUMM_VAT_IN;
                //oper_imp.SUMM_VAT_IN_USE;
                //oper_imp.SUMM_VAT_COST;
                //oper_imp.SUMM_VAT_BAY;
                //System.Console.WriteLine(oper_import.SUMM_ALL + "_" + oper_import.SUMM_VAT_PAY + "_" + oper_import.SUMM_VAT_BAY);
            }
        }
Exemplo n.º 20
0
        private static void Main(string[] args)
        {
            {//读写分割文件
                var path    = AppDomain.CurrentDomain.BaseDirectory + "Delimited.txt";
                var engine  = new FileHelperEngine <Orders>();
                var records = engine.ReadFile(path);//读

                foreach (var record in records)
                {
                    Console.WriteLine($"{record.OrderID} {record.CustomerID} {record.OrderDate} {record.Freight}");
                }


                var orders = new List <Orders>();

                orders.Add(new Orders()
                {
                    OrderID    = 1,
                    CustomerID = "AIRG",
                    Freight    = 82.43M,
                    OrderDate  = new DateTime(2009, 05, 01)
                });

                orders.Add(new Orders()
                {
                    OrderID    = 2,
                    CustomerID = "JSYV",
                    Freight    = 12.22M,
                    OrderDate  = new DateTime(2009, 05, 02)
                });

                engine.WriteFile("Delimited.Txt", orders);//写
            }


            {//读定长文件
                var        engine = new FixedFileEngine <Customer>();
                Customer[] result = engine.ReadFile("Fixed.txt");

                foreach (var detail in result)
                {
                    Console.WriteLine(" Client: {0},  Name: {1}", detail.CustId, detail.Name);
                }
            }


            {// 按行读文件
                var    list = new List <string>();
                string line;
                System.IO.StreamReader file = new System.IO.StreamReader(@"E:\Personal\代码库\CodeBase\FIleHelpers\bin\Debug\测试药品id.txt");
                while ((line = file.ReadLine()) != null)
                {
                    list.Add(line);
                }
                var joinstring = string.Join(",", list.ToArray());
                Console.WriteLine(joinstring);
            }



            Console.ReadKey();
        }
Exemplo n.º 21
0
        public void SimpleTest3()
        {
            FixedFileEngine engine = new FixedFileEngine(typeof(CustomersFixed2));

            Assert.AreEqual(8, Common.ReadTest(engine, @"Good\CustomersFixed.txt").Length);
        }
Exemplo n.º 22
0
        private void ImportAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            fmCAVTBookBuhImport book_buh = e.CurrentObject as fmCAVTBookBuhImport;

            if (book_buh == null)
            {
                return;
            }
            ObjectSpace.CommitChanges();
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                FixedFileEngine engine = new FixedFileEngine(typeof(fmCAVTBookBuhImportImport));
                //         engine.Options.IgnoreFirstLines = 10;
                fmCAVTBookBuhImportImport[] imp_res = (fmCAVTBookBuhImportImport[])engine.ReadFile(dialog.FileName);
//                try {
                using (IObjectSpace os = this.ObjectSpace.CreateNestedObjectSpace()) {
                    book_buh = os.GetObject <fmCAVTBookBuhImport>(book_buh);
                    os.Delete(new List <fmCAVTBookBuhRecord>(book_buh.BookBuhRecords));
//                    book_buh = ObjectSpace.GetObject<fmCAVTBookBuhImport>(book_buh);
//                    ObjectSpace.Delete(new List<fmCAVTBookBuhRecord>(book_buh.BookBuhRecords));
                    foreach (fmCAVTBookBuhImportImport imp_rec in imp_res)
                    {
                        fmCAVTBookBuhRecord rec = os.CreateObject <fmCAVTBookBuhRecord>();
                        //fmCAVTBookBuhRecord rec = ObjectSpace.CreateObject<fmCAVTBookBuhRecord>();
                        book_buh.BookBuhRecords.Add(rec);

                        rec.BookType = imp_rec.BOOK_TYPE.Trim();

                        rec.RecordType     = imp_rec.REC_TYPE.Trim();
                        rec.RecordSummType = imp_rec.SUMM_TYPE.Trim();
                        rec.FiscalLetLine  = imp_rec.FISCAL_LINE.Trim();

                        rec.NDSRate         = imp_rec.NDS_RATE.Trim();
                        rec.BuhProvCode     = imp_rec.BUH_PROV.Trim();
                        rec.BuhProvOrigCode = imp_rec.BUH_PROV_ORIG.Trim();
                        rec.BuhPckCode      = imp_rec.BUH_PCK.Trim();
                        rec.BuhDocNumber    = imp_rec.BUH_DOC_NUM.Trim();
                        if (!String.IsNullOrEmpty(imp_rec.BUH_DOC_DATE.Trim()))
                        {
                            //rec.BuhDocDate = DateTime.TryParseExact((imp_rec.BUH_DOC_DATE);
                            DateTime.TryParseExact(imp_rec.BUH_DOC_DATE, "yyyyMMdd", null, DateTimeStyles.None, out rec.BuhDocDate);
                        }
                        //rec.BuhDocDate = imp_rec.BUH_DOC_DATE;
                        rec.AccSubDebetCode  = imp_rec.DEBET.Trim();
                        rec.AccSubCreditCode = imp_rec.CREDIT.Trim();
                        //                        if (!String.IsNullOrEmpty(imp_rec.SUMM.Trim())) {
                        //                            Decimal summ = 0;
                        //                            Decimal.TryParse(imp_rec.SUMM.Trim(), out summ );
                        //                            rec.RecordSumm = summ;
                        //                        }
                        rec.RecordSumm = imp_rec.SUMM;
                        if (rec.RecordSummType == "COS")
                        {
                            rec.SummCost = rec.RecordSumm;
                            if (rec.NDSRate == "2")
                            {
                                rec.SummVATControl = Decimal.Round(rec.RecordSumm * 18 / 100, 2);
                            }
                            else if (rec.NDSRate == "3")
                            {
                                rec.SummVATControl = Decimal.Round(rec.RecordSumm * 10 / 100, 2);
                            }
                        }
                        else if (rec.RecordSummType == "NDS")
                        {
                            rec.SummVAT        = rec.RecordSumm;
                            rec.SummVATControl = -rec.RecordSumm;
                        }
                        else if (rec.RecordSummType == "IN")
                        {
                            rec.SummVATIn      = rec.RecordSumm;
                            rec.SummVATControl = rec.RecordSumm;
                        }
                        else if (rec.RecordSummType == "SEB")
                        {
                            rec.SummVATCost    = rec.RecordSumm;
                            rec.SummVATControl = -rec.RecordSumm;
                        }
                        else if (rec.RecordSummType == "EXP")
                        {
                            rec.SummVATExp     = rec.RecordSumm;
                            rec.SummVATControl = -rec.RecordSumm;
                        }
                        else if (rec.RecordSummType == "NSF")
                        {
                            rec.SummVATNoInvoice = rec.RecordSumm;
                            rec.SummVATControl   = -rec.RecordSumm;
                        }
                        else if (rec.RecordSummType == "CRD")
                        {
                            rec.SummVATCrdOther = rec.RecordSumm;
                            rec.SummVATControl  = -rec.RecordSumm;
                        }
                        else if (rec.RecordSummType == "ALL")
                        {
                            rec.SummAll = rec.RecordSumm;
                            if (rec.NDSRate == "2")
                            {
                                rec.SummVATControl = Decimal.Round(rec.RecordSumm * 18 / 118, 2);
                            }
                            else if (rec.NDSRate == "3")
                            {
                                rec.SummVATControl = Decimal.Round(rec.RecordSumm * 10 / 110, 2);
                            }
                        }
                        rec.AVTInvoiceType      = imp_rec.SF_TYPE.Trim();
                        rec.AVTInvoiceRegNumber = imp_rec.SF_REGNUM.Trim();
                        rec.AVTInvoiceNumber    = imp_rec.SF_NUMBER.Trim();
                        if (!String.IsNullOrEmpty(imp_rec.SF_DATE.Trim()))
                        {
                            //    rec.AVTInvoiceDate = DateTime.Parse(imp_rec.BUH_DOC_DATE);
                            DateTime.TryParseExact(imp_rec.SF_DATE, "yyyyMMdd", null, DateTimeStyles.None, out rec.AVTInvoiceDate);
                        }
                        //rec.AVTInvoiceDate = (DateTime) imp_rec.SF_DATE;
                        rec.AVTInvoicePartyCode = imp_rec.COD_VO.Trim();
                        rec.PeriodOtchet        = imp_rec.PERIOD_OTCH.Trim();
                        rec.PeriodBuhgal        = imp_rec.PERIOD_BUH.Trim();
                        //
                        rec.PayDocType   = imp_rec.PP_TYPE.Trim();
                        rec.PayDocNumber = imp_rec.PP_NUMBER.Trim();
                        if (!String.IsNullOrEmpty(imp_rec.PP_DATE.Trim()))
                        {
                            //    rec.AVTInvoiceDate = DateTime.Parse(imp_rec.BUH_DOC_DATE);
                            DateTime.TryParseExact(imp_rec.PP_DATE, "yyyyMMdd", null, DateTimeStyles.None, out rec.PayDocDate);
                        }
                    }
                    os.CommitChanges();
                    //ObjectSpace.CommitChanges();
                }
                //catch {
                //    ObjectSpace.Rollback();
                //}
            }
            ObjectSpace.CommitChanges();
        }
Exemplo n.º 23
0
 public void SimpleTest3()
 {
     var engine = new FixedFileEngine(typeof(CustomersFixed2));
     Assert.AreEqual(8, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);
 }
Exemplo n.º 24
0
        static public void ImportInvoices(IObjectSpace os, String file_name)
        {
            //            OpenFileDialog dialog = new OpenFileDialog();
            //            if (dialog.ShowDialog() == DialogResult.OK) {
            FixedFileEngine engine = new FixedFileEngine(typeof(InvoiceImport));

            InvoiceImport[]                    imp_res            = (InvoiceImport[])engine.ReadFile(file_name);
            IList <fmCAVTInvoiceType>          inv_types          = os.GetObjects <fmCAVTInvoiceType>();
            IList <fmCAVTInvoiceTransferType>  inv_transfer_types = os.GetObjects <fmCAVTInvoiceTransferType>();
            IList <fmCAVTInvoiceOperationType> inv_oper_types     = os.GetObjects <fmCAVTInvoiceOperationType>();
            Int32             count       = 0;
            fmCAVTInvoiceType sf_sfz_type = os.GetObjects <fmCAVTInvoiceType>().First(x => x.Prefix == "Z");

            foreach (InvoiceImport imp_rec in imp_res)
            {
                imp_rec.SF_VO_CODE    = imp_rec.SF_VO_CODE.Trim();
                imp_rec.SF_INT_NUMBER = imp_rec.SF_INT_NUMBER.Trim();
                imp_rec.SF_NUMBER     = imp_rec.SF_NUMBER.Trim();
                Decimal  summ_cost     = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
                Decimal  summ_nds      = Decimal.Parse(imp_rec.SUMM_NDS.Trim().Replace('.', ','));
                Decimal  summ_sub_cost = Decimal.Parse(imp_rec.SUMM_SUB_COST.Trim().Replace('.', ','));
                Decimal  summ_sub_nds  = Decimal.Parse(imp_rec.SUMM_SUB_NDS.Trim().Replace('.', ','));
                DateTime sf_date       = default(DateTime);
                DateTime.TryParseExact(imp_rec.SF_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out sf_date);
                crmCParty party = os.GetObjects <crmCParty>(new BinaryOperator("Code", imp_rec.SF_VO_CODE)).FirstOrDefault();
                if (party == null)
                {
                    System.Console.WriteLine("SF " + imp_rec.SF_NUMBER + " party not found (" + imp_rec.SF_VO_CODE + ")");
                    continue;
                }
                Основание.ТипИсточника ts;
                if (imp_rec.SF_IO_TYPE == "I")
                {
                    ts = Основание.ТипИсточника.ВХОДЯЩИЙ;
                }
                else if (imp_rec.SF_IO_TYPE == "O")
                {
                    ts = Основание.ТипИсточника.ИСХОДЯЩИЙ;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("SF " + imp_rec.SF_NUMBER + " неопределен тип входящий/исходящий");
                }
                Основание.ТипОснования tsf;
                switch (imp_rec.SF_TYPE)
                {
                case "СЧФ":
                    tsf = Основание.ТипОснования.СЧФ;
                    break;

                case "УПД":
                    tsf = Основание.ТипОснования.УПД;
                    break;

                case "СФА":
                    tsf = Основание.ТипОснования.СФА;
                    break;

                case "СФЗ":
                    tsf = Основание.ТипОснования.СФЗ;
                    break;

                case "СЧГ":
                    tsf = Основание.ТипОснования.СЧГ;
                    break;

                case "БЖД":
                    tsf = Основание.ТипОснования.БЖД;
                    break;

                case "СФВ":
                    tsf = Основание.ТипОснования.СФВ;
                    break;

                case "БСО":
                    tsf = Основание.ТипОснования.БСО;
                    break;

                case "ЧЕК":
                    tsf = Основание.ТипОснования.ЧЕК;
                    break;

                default:
                    System.Console.WriteLine("SF: " + imp_rec.SF_NUMBER + " странный тип (" + imp_rec.SF_TYPE + ")");
                    continue;
                }
                String  inn        = "";
                String  kpp        = "";
                ЛицоТип party_type = ЛицоТип.НЕЗАДАН;
                if (party.Person != null)
                {
                    if (party.Person.Address.Country.CodeAlfa2 == "RU")
                    {
//                        Type party.ComponentTypeComponentObject.GetType();
                        if (party.ComponentType == typeof(crmCLegalPerson) ||
                            party.ComponentType == typeof(crmCLegalPersonUnit))
                        {
                            party_type = ЛицоТип.ЮР_ЛИЦО;
                            inn        = party.INN;
                            if (inn.Length == 9)
                            {
                                inn = "0" + inn;
                            }
                            kpp = party.KPP;
                            if (inn.Length == 8)
                            {
                                kpp = "0" + kpp;
                            }
                            if (inn.Length != 10)
                            {
                                System.Console.WriteLine("Party: " + party.Code + " fail INN (" + inn + ")");
                                continue;
                            }
                            if (kpp.Length != 9)
                            {
                                System.Console.WriteLine("Party: " + party.Code + " fail KPP (" + kpp + ")");
                                continue;
                            }
                        }
                        else
                        {
                            if (party.ComponentType == typeof(crmCBusinessman))
                            {
                                party_type = ЛицоТип.ПРЕДПРИНИМАТЕЛЬ;
                                inn        = party.INN;
                                if (inn.Length == 11)
                                {
                                    inn = "0" + inn;
                                }
                                if (inn.Length != 12)
                                {
                                    System.Console.WriteLine("Party: " + party.Code + " fail INN (" + inn + ")");
                                    continue;
                                }
                            }
                            else
                            if (party.ComponentType == typeof(crmCPhysicalParty))
                            {
                                party_type = ЛицоТип.ФИЗ_ЛИЦО;
                            }
                        }
                    }
                    else
                    {
                        party_type = ЛицоТип.ИНО_ПАРТНЕР;
                        System.Console.WriteLine("Party: " + party.Code + " инопартнер ");
                    }
                }
                if (party.Code == "2706")
                {
                    party_type = ЛицоТип.ОЗНИЦА;
                }
                //
                String sale_inn = "5012039795";
                if (ts == Основание.ТипИсточника.ВХОДЯЩИЙ)
                {
                    sale_inn = inn;
                }
                // !!!!!!!!!!!!!!!!!!!!!!!!!!
                // Выбраковываем СФ
                if (String.IsNullOrEmpty(sale_inn) || String.IsNullOrEmpty(imp_rec.SF_REGNUM.Trim()) && tsf != Основание.ТипОснования.СФЗ)
                {
                    continue;
                }
                // !!!!!!!!!!!!!!!!!!!!!!!!!!
                Основание sf = os.FindObject <Основание>(
                    XPQuery <Основание> .TransformExpression(
                        ((ObjectSpace)os).Session,
                        rec =>
                        rec.ИннПродавца == sale_inn &&
                        rec.Номер == imp_rec.SF_NUMBER &&
                        rec.Дата >= sf_date &&
                        rec.Дата < sf_date.AddDays(1)
                        ));
                if (sf == null)
                {
                    sf          = os.CreateObject <Основание>();
                    sf.Источник = ts;
                    sf.ИНН      = inn;
                    sf.Номер    = imp_rec.SF_NUMBER;
                    sf.Дата     = sf_date;
                    sf.КПП      = kpp;
                }
                sf.Корректировка = Основание.ТипПодчиненности.ОСНОВНОЙ;
                sf.Источник      = ts;
                sf.Тип           = tsf;
                sf.ЛицоТип       = party_type;
                ОснованиеДокумент sfdoc      = null;
                String            sfdoc_sver = imp_rec.SF_PRAV_NUMBER.Trim();
                if (String.IsNullOrEmpty(sfdoc_sver))
                {
                    sfdoc_sver = "0";
                }
                UInt16 sfdoc_ver = 0;
                UInt16.TryParse(sfdoc_sver, out sfdoc_ver);
                DateTime sfdoc_date = default(DateTime);
                DateTime.TryParseExact(imp_rec.SF_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out sfdoc_date);
                foreach (ОснованиеДокумент doc in sf.Документы)
                {
                    if (doc.НомерИсправления == sfdoc_ver)
                    {
                        sfdoc = doc;
                        break;
                    }
                }
                if (sfdoc == null)
                {
                    sfdoc = os.CreateObject <ОснованиеДокумент>();
                    sf.Документы.Add(sfdoc);
                    sfdoc.НомерИсправления = sfdoc_ver;
                    if (sf.ДействующийДокумент.НомерИсправления < sfdoc.НомерИсправления)
                    {
                        sf.ДействующийДокумент = sfdoc;
                    }
                }
                sfdoc.ДатаИсправления = sfdoc_date;
                sfdoc.егНомер         = imp_rec.SF_REGNUM.Trim();
                if (sf.Тип == Основание.ТипОснования.СФЗ && String.IsNullOrEmpty(sfdoc.егНомер))
                {
                    Int32 IntNumber = fmCAVTInvoiceNumberGenerator.GenerateNumber(((ObjectSpace)os).Session, sf.ДействующийДокумент.CID, sf_sfz_type, sf.Дата, 0);
                    sfdoc.егНомер = sf_sfz_type.Prefix + sf.Дата.ToString("yyyyMM").Substring(2, 4) + IntNumber.ToString("00000");
                }
                sfdoc.КодПартнера       = party.Code;
                sfdoc.НаименКонтрагента = party.Name;
                sfdoc.СуммаВсего        = summ_cost + summ_nds;
                sfdoc.СуммаНДС          = summ_nds;
                sfdoc.СуммаВсегоУвел    = sfdoc.СуммаВсего + summ_sub_cost;
                sfdoc.СуммаНДСУвел      = sfdoc.СуммаНДС + summ_sub_nds;
                //fmCAVTInvoiceBase invoice = os.FindObject<fmCAVTInvoiceBase>(
                //    XPQuery<fmCAVTInvoiceBase>.TransformExpression(
                //    ((ObjectSpace)os).Session,
                //    rec => rec.Supplier.Code == imp_rec.SF_VO_CODE &&
                //           rec.RegNumber == imp_rec.SF_INT_NUMBER &&
                //           rec.Date >= sf_date &&
                //           rec.Date < sf_date.AddDays(1)
                //    ));
                ////if (invoice == null) {
                ////    count++;
                ////    System.Console.WriteLine(imp_rec.SF_INT_NUMBER + " " + imp_rec.SF_NUMBER + " " + imp_rec.SF_DATE + " " + summ_cost + " " + summ_nds);
                ////}
                //if (invoice == null) {
                //    crmCParty party = os.GetObjects<crmCParty>(new BinaryOperator("Code", imp_rec.SF_VO_CODE)).FirstOrDefault();
                //    invoice = os.CreateObject<fmCAVTInvoiceBase>();
                //    invoice.RegNumber = imp_rec.SF_INT_NUMBER;
                //    invoice.Number = imp_rec.SF_NUMBER;
                //    invoice.Date = sf_date;
                //    invoice.Supplier = party;
                //    invoice.Customer = register.Party;
                //    invoice.SummAVT = Decimal.Parse(imp_rec.SUMM_NDS.Trim().Replace('.', ','));
                //    invoice.SummCost = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
                //}
                //else {
                //    invoice.SummAVT = Decimal.Parse(imp_rec.SUMM_NDS.Trim().Replace('.', ','));
                //    invoice.SummCost = Decimal.Parse(imp_rec.SUMM_COST.Trim().Replace('.', ','));
                //    fmCAVTInvoiceRegisterLine line_check = os.FindObject<fmCAVTInvoiceRegisterLine>(
                //            CriteriaOperator.And(new BinaryOperator("InvoiceVersion", invoice.Current)), true);
                //    if (line_check != null) continue;
                //}
                //fmCAVTInvoiceRegisterLine line = register.InLines.Where(rec => rec.Invoice == invoice).FirstOrDefault();
                //if (line == null) {
                //    line = os.CreateObject<fmCAVTInvoiceRegisterLine>();
                //    register.InLines.Add(line);
                //}
                //line.SequenceNumber = seq_num++;
                ////                line_doc.DateTransfer = invoice.Date;
                //line.Invoice = invoice;
                //line.TransferType = inv_transfer_types.Where(rec => rec.Code == "1").FirstOrDefault();
                //if (String.IsNullOrEmpty(imp_rec.SF_TRANS_DATE.Trim())) {
                //    DateTime trans_date = default(DateTime);
                //    DateTime.TryParseExact(imp_rec.SF_TRANS_DATE.Trim(), "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out trans_date);
                //    line.DateTransfer = trans_date;
                //}
                //if (line.DateTransfer < sf_date)
                //    line.DateTransfer = sf_date;
                //line.OperationType = inv_oper_types.Where(rec => rec.Code == imp_rec.SF_OPER_TYPE.Trim() ||
                //                                               rec.Code == '0' + imp_rec.SF_OPER_TYPE.Trim()).FirstOrDefault();
            }
            System.Console.WriteLine("All " + count);
        }
Exemplo n.º 25
0
        public void SimpleTest3()
        {
            var engine = new FixedFileEngine(typeof(CustomersFixed2));

            Assert.AreEqual(8, FileTest.Good.CustomersFixed.ReadWithEngine(engine).Length);
        }
Exemplo n.º 26
0
        public T[] ReadFile <T>(string path) where T : class
        {
            var engine = new FixedFileEngine <T>();

            return(engine.ReadFile(path));
        }