Example #1
0
		static void RunTimeRecordsFixed()
		{

			Console.WriteLine("Run Time Records now =) ...");
			Console.WriteLine();

			FixedLengthClassBuilder cb = new FixedLengthClassBuilder("Customer", FixedMode.ExactLength);
			cb.AddField("CustId", 5, typeof(Int32));
			cb.AddField("Name", 20, typeof(string));
			cb.AddField("Balance", 8, typeof(Decimal));
			cb.AddField("AddedDate", 8, typeof(DateTime));
			cb.LastField.Converter.Kind = ConverterKind.Date;
			cb.LastField.Converter.Arg1 = "ddMMyyyy";
			
			
			// Estas dos lineas son el uso de la librería
			FileHelperEngine engine = new FileHelperEngine(cb.CreateRecordClass());

			DataTable dt = engine.ReadFileAsDT(@"..\Data\CustomersFixedLength.txt");

			// Aqui es donde ustedes agregan su código
			foreach (DataRow dr in dt.Rows)
			{
				Console.WriteLine("Customer: " + dr[0].ToString() + " - " + dr[1].ToString());
			}

		}
Example #2
0
		public void FullClassBuildingFixed()
		{
			FixedLengthClassBuilder cb = new FixedLengthClassBuilder("Customers");

			cb.AddField("Field1", 8, typeof(DateTime));
			cb.LastField.Converter.Kind = ConverterKind.Date;
			cb.LastField.Converter.Arg1 = "ddMMyyyy";
			cb.LastField.FieldNullValue = DateTime.Now;
			
			
			cb.AddField("Field2", 3, typeof(string));
			cb.LastField.AlignMode = AlignMode.Right;
			cb.LastField.AlignChar = ' ';
			
			cb.AddField("Field3", 3, typeof(int));
			 
			cb.LastField.AlignMode = AlignMode.Right;
			cb.LastField.AlignChar = '0';
			cb.LastField.TrimMode = TrimMode.Both;
			
			engine = new FileHelperEngine(cb.CreateRecordClass());

			DataTable dt = engine.ReadFileAsDT(Common.TestPath(@"Good\test1.txt"));

			Assert.AreEqual(4, dt.Rows.Count);
			Assert.AreEqual(4, engine.TotalRecords);
			Assert.AreEqual(0, engine.ErrorManager.ErrorCount);
		}