当前位置: 首页>>代码示例>>C#>>正文


C# FileHelperEngine.ReadFileAsDT方法代码示例

本文整理汇总了C#中FileHelperEngine.ReadFileAsDT方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine.ReadFileAsDT方法的具体用法?C# FileHelperEngine.ReadFileAsDT怎么用?C# FileHelperEngine.ReadFileAsDT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileHelperEngine的用法示例。


在下文中一共展示了FileHelperEngine.ReadFileAsDT方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestingNameAndTypes

		public void TestingNameAndTypes()
        {
            var cb = new DelimitedClassBuilder("Customers", ",");
            cb.IgnoreFirstLines = 1;
            cb.IgnoreEmptyLines = true;

            cb.AddField("Field1", typeof (DateTime));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.QuoteMode = QuoteMode.AlwaysQuoted;
            cb.LastField.FieldNullValue = DateTime.Today;

            cb.AddField("Field2", typeof (string));
            cb.LastField.FieldQuoted = true;
            cb.LastField.QuoteChar = '"';

            cb.AddField("Field3", typeof (int));

            mEngine = new FileHelperEngine(cb.CreateRecordClass());

            DataTable dt = mEngine.ReadFileAsDT(TestCommon.GetPath("Good", "Test2.txt"));

            Assert.AreEqual("Field1", dt.Columns[0].ColumnName);
            Assert.AreEqual(typeof (DateTime), dt.Columns[0].DataType);

            Assert.AreEqual("Field2", dt.Columns[1].ColumnName);
            Assert.AreEqual(typeof (string), dt.Columns[1].DataType);

            Assert.AreEqual("Field3", dt.Columns[2].ColumnName);
            Assert.AreEqual(typeof (int), dt.Columns[2].DataType);
        }
开发者ID:calebillman,项目名称:FileHelpers,代码行数:30,代码来源:DelimitedClassBuilderTests.cs

示例2: FullClassBuildingFixed

        public void FullClassBuildingFixed()
        {
            var 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;

            mEngine = new FileHelperEngine(cb.CreateRecordClass());

            DataTable dt = mEngine.ReadFileAsDT(FileTest.Good.Test1.Path);

            Assert.AreEqual(4, dt.Rows.Count);
            Assert.AreEqual(4, mEngine.TotalRecords);
            Assert.AreEqual(0, mEngine.ErrorManager.ErrorCount);
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:28,代码来源:FixedLengthClassBuilderTests.cs

示例3: FullClassBuilding

        public void FullClassBuilding()
        {
            var cb = new DelimitedClassBuilder("Customers", ",");
            cb.IgnoreFirstLines = 1;
            cb.IgnoreEmptyLines = true;

            cb.AddField("Field1", typeof(DateTime));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.QuoteMode = QuoteMode.AlwaysQuoted;
            cb.LastField.FieldNullValue = DateTime.Today;

            cb.AddField("Field2", typeof(string));
            cb.LastField.FieldQuoted = true;
            cb.LastField.QuoteChar = '"';

            cb.AddField("Field3", typeof(int));

            mEngine = new FileHelperEngine(cb.CreateRecordClass());

            DataTable dt = mEngine.ReadFileAsDT(TestCommon.GetPath("Good", "Test2.txt"));

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

            Assert.AreEqual("Field1", dt.Columns[0].ColumnName);
            Assert.AreEqual("Field2", dt.Columns[1].ColumnName);
            Assert.AreEqual("Field3", dt.Columns[2].ColumnName);

            Assert.AreEqual("Hola", dt.Rows[0][1]);
            Assert.AreEqual(DateTime.Today, dt.Rows[2][0]);
        }
开发者ID:calebillman,项目名称:FileHelpers,代码行数:32,代码来源:DelimitedClassBuilderTests.cs

示例4: ReadFile

        public void ReadFile()
        {
            var engine = new FileHelperEngine<SampleType>();
            var dt = engine.ReadFileAsDT(FileTest.Good.Test1.Path);

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

            Assert.AreEqual(new DateTime(1314, 12, 11), (DateTime) dt.Rows[0]["Field1"]);
            Assert.AreEqual("901", (string) dt.Rows[0]["Field2"]);
            Assert.AreEqual(234, (int) dt.Rows[0]["Field3"]);

            Assert.AreEqual(new DateTime(1314, 11, 10), (DateTime) dt.Rows[1]["Field1"]);
            Assert.AreEqual("012", (string) dt.Rows[1]["Field2"]);
            Assert.AreEqual(345, (int) dt.Rows[1]["Field3"]);
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:17,代码来源:ReadersAsDataTable.cs

示例5: ReadNullableTypes

        public void ReadNullableTypes()
        {
            var engine = new FileHelperEngine<NullableType>();
            var res = engine.ReadFileAsDT(FileTest.Good.NullableTypes1.Path);

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

            Assert.AreEqual(new DateTime(1314, 12, 11), (DateTime) res.Rows[0]["Field1"]);
            Assert.AreEqual("901", (string) res.Rows[0]["Field2"]);
            Assert.AreEqual(234, (int) res.Rows[0]["Field3"]);

            Assert.AreEqual(DBNull.Value, res.Rows[1]["Field1"]);
            Assert.AreEqual("012", (string) res.Rows[1]["Field2"]);
            Assert.AreEqual(345, (int) res.Rows[1]["Field3"]);

            Assert.AreNotEqual(DBNull.Value, res.Rows[2]["Field1"]);
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:19,代码来源:ReadersAsDataTable.cs

示例6: ReadFile

        public void ReadFile()
        {
            Type t = ClassBuilder.ClassFromString(Class);

            mEngine = new FileHelperEngine(t);

            DataTable dt = mEngine.ReadFileAsDT(FileTest.Good.Test1.Path);

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

            Assert.AreEqual(new DateTime(1314, 12, 11), dt.Rows[0][0]);
            Assert.AreEqual("901", dt.Rows[0][1]);
            Assert.AreEqual(234, dt.Rows[0][2]);

            Assert.AreEqual(new DateTime(1314, 11, 10), dt.Rows[1][0]);
            Assert.AreEqual("012", dt.Rows[1][1]);
            Assert.AreEqual(345, dt.Rows[1][2]);
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:20,代码来源:ClassBuilderTests.cs

示例7: ReadFile

		public void ReadFile()
		{
			Type t = ClassBuilder.ClassFromString(mClass);

			engine = new FileHelperEngine(t);

			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);

			Assert.AreEqual(new DateTime(1314, 12, 11), dt.Rows[0][0]);
			Assert.AreEqual("901", dt.Rows[0][1]);
			Assert.AreEqual(234, dt.Rows[0][2]);

			Assert.AreEqual(new DateTime(1314, 11, 10), dt.Rows[1][0]);
			Assert.AreEqual("012", dt.Rows[1][1]);
			Assert.AreEqual(345, dt.Rows[1][2]);

		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:21,代码来源:RunTimeClass.cs

示例8: UploadButton_Click

        protected void UploadButton_Click(object sender, EventArgs e)
        {
            // csv

            bool isLive = true;

            if (FileUpload.HasFiles)
            {
                foreach (HttpPostedFile uploadedFile in FileUpload.PostedFiles)
                {

                    string Filename = "";
                    string Extension = "";

                    Filename = uploadedFile.FileName;
                    Extension = Path.GetExtension(Filename).ToLower();

                    string thisID = Guid.NewGuid().ToString();

                    if (Extension == ".csv")
                    {

                        uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Temp/"), thisID + Extension));

                        //MySqlConnection DBConnection;
                        //MySqlCommand DBCommand;

                        //MySqlDataReader DBResult;

                        FileHelperEngine engine = new FileHelperEngine(typeof(ContactsVerticalBar));

                        DataTable objTable = engine.ReadFileAsDT(System.IO.Path.Combine(Server.MapPath("~/Temp/"), thisID + Extension));

                        ResultsLiteral.Text += "<table><tr><th>Name</th><th>Company</th><th>Tel</th><th>Mobile</th><th>Email</th></tr>";

                        ResultsStatsLiteral.Text = "Importing " + objTable.Rows.Count + " rows...";

                        foreach (DataRow row in objTable.Rows)
                        {
                            string thisName = row["Name"].ToString();
                            string thisCompany = row["Company"].ToString();
                            string thisTel = row["Tel"].ToString();
                            string thisMobile = row["Mobile"].ToString();
                            string thisEmail = row["Email"].ToString();

                            string thisPosition = row["Position"].ToString();
                            string thisAddress = row["Address"].ToString();
                            string thisStreet = row["Street"].ToString();
                            string thisTown = row["Town"].ToString();
                            string thisCounty = row["County"].ToString();
                            string thisPostcode = row["Postcode"].ToString();
                            string thisLocationID = row["LocationID"].ToString();
                            string thisContactType = row["ContactType"].ToString();

                            string thisContactTypeText = "";

                            if (!string.IsNullOrEmpty(thisName))
                            {

                                switch (thisContactType)
                                {
                                    case "1":
                                        thisContactTypeText = "Location Owner";
                                        break;
                                    case "2":
                                        thisContactTypeText = "Project Company";
                                        break;
                                    default:
                                        thisContactTypeText = "";
                                        thisContactTypeText = "Location Owner";
                                        thisContactType = "1";
                                        break;
                                }

                                ResultsLiteral.Text += "<tr><td valign=\"top\">" + thisContactTypeText + "</td><td>" + thisName + "</td><td>" + thisCompany + "</td><td>" + thisTel + "</td><td>" + thisMobile + "</td><td>" + thisEmail + "</td></tr>";

                                ResultsLiteral.Text += "<tr><td></td><td colspan=\"5\">";

                                ResultsLiteral.Text += "<b>Notes:</b>";

                                UK_Film_Location_Class.ContactDetails objContact = new UK_Film_Location_Class.ContactDetails();

                                bool foundContact = false;

                                if (!string.IsNullOrEmpty(thisEmail))
                                {
                                    objContact.getContactFromEmail(thisEmail);

                                    if (!string.IsNullOrEmpty(objContact.ContactID))
                                    {
                                        ResultsLiteral.Text += "<p>Contact found by Email!</p>";
                                        foundContact = true;
                                    }

                                }

                                if (!foundContact && !string.IsNullOrEmpty(thisTel))
                                {
                                    objContact.getContactFromTel(thisTel);
                                    if (!string.IsNullOrEmpty(objContact.ContactID))
//.........这里部分代码省略.........
开发者ID:AdamDShort,项目名称:UK-Film-Location-Admin,代码行数:101,代码来源:ImportContacts.aspx.cs

示例9: readWholeTable

        protected override DataTable readWholeTable(UnitType source)
        {
            //initialize the engine
            FileHelperEngine engine = new FileHelperEngine(getRecordType(source));

            //ignore the average annual outputs
            engine.Options.IgnoreLastLines = getNumberOfLinesForAverageAnnualOutput(source);

            //Console.WriteLine("Reading whole table for " + source.ToString());
            return engine.ReadFileAsDT(getOutputFileFromType(source));
        }
开发者ID:ajarbancina,项目名称:swat-eclipse,代码行数:11,代码来源:ExtractSWAT_Text_FileHelperEngine.cs

示例10: ReadFileAsDataTable

        public void ReadFileAsDataTable()
        {
            FileHelperEngine<SampleType> engine = new FileHelperEngine<SampleType>();

            DataTable res;
            res = engine.ReadFileAsDT(FileTest.Good.Test1.Path);

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

            Assert.AreEqual(new DateTime(1314, 12, 11), res.Rows[0]["Field1"]);
            Assert.AreEqual("901", res.Rows[0]["Field2"]);
            Assert.AreEqual(234, res.Rows[0]["Field3"]);

            Assert.AreEqual(new DateTime(1314, 11, 10), res.Rows[1]["Field1"]);
            Assert.AreEqual("012", res.Rows[1]["Field2"]);
            Assert.AreEqual(345, res.Rows[1]["Field3"]);
        }
开发者ID:TheJeremyGray,项目名称:FileWatcherService,代码行数:19,代码来源:ReadersGeneric.cs

示例11: ReadFileEncDec

        public void ReadFileEncDec()
        {
            var tempFile = "temp.fhc";
            ClassBuilder.ClassToBinaryFile(tempFile, Class);

            Type t = ClassBuilder.ClassFromBinaryFile(tempFile);
            File.Delete(tempFile);

            mEngine = new FileHelperEngine(t);

            DataTable dt = mEngine.ReadFileAsDT(FileTest.Good.Test1.Path);

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

            Assert.AreEqual(new DateTime(1314, 12, 11), dt.Rows[0][0]);
            Assert.AreEqual("901", dt.Rows[0][1]);
            Assert.AreEqual(234, dt.Rows[0][2]);

            Assert.AreEqual(new DateTime(1314, 11, 10), dt.Rows[1][0]);
            Assert.AreEqual("012", dt.Rows[1][1]);
            Assert.AreEqual(345, dt.Rows[1][2]);
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:24,代码来源:ClassBuilderTests.cs

示例12: ReadFileDiffDir

        public void ReadFileDiffDir()
        {
            string oldDir = Environment.CurrentDirectory;
            Environment.CurrentDirectory = Path.GetTempPath();

            Type t = ClassBuilder.ClassFromString(Class);
            Environment.CurrentDirectory = oldDir;

            mEngine = new FileHelperEngine(t);

            DataTable dt = mEngine.ReadFileAsDT(FileTest.Good.Test1.Path);

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

            Assert.AreEqual(new DateTime(1314, 12, 11), dt.Rows[0][0]);
            Assert.AreEqual("901", dt.Rows[0][1]);
            Assert.AreEqual(234, dt.Rows[0][2]);

            Assert.AreEqual(new DateTime(1314, 11, 10), dt.Rows[1][0]);
            Assert.AreEqual("012", dt.Rows[1][1]);
            Assert.AreEqual(345, dt.Rows[1][2]);
        }
开发者ID:abombss,项目名称:FileHelpers,代码行数:24,代码来源:ClassBuilderTests.cs

示例13: ReadFileAsDataTable

		public void ReadFileAsDataTable()
		{
			engine = new FileHelperEngine(typeof (SampleType));

			DataTable res;

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

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

			Assert.AreEqual(new DateTime(1314, 12, 11), res.Rows[0]["Field1"]);
			Assert.AreEqual("901", res.Rows[0]["Field2"]);
			Assert.AreEqual(234, res.Rows[0]["Field3"]);

			Assert.AreEqual(new DateTime(1314, 11, 10), res.Rows[1]["Field1"]);
			Assert.AreEqual("012", res.Rows[1]["Field2"]);
			Assert.AreEqual(345, res.Rows[1]["Field3"]);

		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:21,代码来源:Readers.cs

示例14: ReadAsDataTable2

		public void ReadAsDataTable2()
        {
            var cb = new DelimitedClassBuilder("ImportContact", ",");
            cb.IgnoreEmptyLines = true;
            cb.GenerateProperties = true;

            cb.AddField("FirstName", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("LastName", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("StreetNumber", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("StreetAddress", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("Unit", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("City", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("State", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            cb.AddField("Zip", typeof (string));
            cb.LastField.TrimMode = TrimMode.Both;
            cb.LastField.FieldQuoted = false;

            var engine = new FileHelperEngine(cb.CreateRecordClass());

            DataTable contactData = engine.ReadFileAsDT(TestCommon.GetPath("Good", "ReadAsDataTable.txt"));

            Assert.AreEqual(3, contactData.Rows.Count);
            Assert.AreEqual(8, contactData.Columns.Count);

            Assert.AreEqual("Alex & Jen", contactData.Rows[0][0].ToString());
            Assert.AreEqual("Mark & Lisa K", contactData.Rows[1][0].ToString());

            // new DelimitedClassBuilder("", ",");
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:50,代码来源:DynamicClassExtra.cs

示例15: TestExtractFromText_FileHelperAsyncEngine

 /// <summary>
 /// Read data from SWAT output file using FileHelperAsyncEngine
 /// </summary>
 /// <remarks>
 /// 1. Need to define classes correponding to each data table
 /// 2. Get the data table directly
 /// </remarks>
 static void TestExtractFromText_FileHelperAsyncEngine(string filePah)
 {
     Console.WriteLine("FileHelperAsyncEngine");
     DateTime before = DateTime.Now;
     FileHelperEngine engine = new FileHelperEngine(typeof(SWATSub));
     using (DataTable dt = engine.ReadFileAsDT(filePah))
     {
         DataRow[] rows = dt.Select("SUB=1");
         //foreach (DataRow r in rows)
         //{
         //    Console.WriteLine(string.Format("{0},{1},{2}", r["SUB"], r["MON"], r["PETmm"]));
         //}
     }
     DateTime after = DateTime.Now;
     Console.WriteLine(string.Format("******\nTime Used: {0} seconds\n******", after.Subtract(before).TotalSeconds));
 }
开发者ID:ajarbancina,项目名称:swat-eclipse,代码行数:23,代码来源:Program.cs


注:本文中的FileHelperEngine.ReadFileAsDT方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。