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


C# CsvReader.ToList方法代码示例

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


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

示例1: BeginImport

        public static DeviceImportContext BeginImport(DiscoDataContext Database, string Filename, bool HasHeader, Stream FileContent)
        {
            if (FileContent == null)
                throw new ArgumentNullException("FileContent");

            if (string.IsNullOrWhiteSpace(Filename))
                Filename = "<None Specified>";

            DeviceImportContext context;
            List<Tuple<string, DeviceImportFieldTypes>> header;
            List<string[]> rawData;

            using (TextReader csvTextReader = new StreamReader(FileContent))
            {
                using (CsvReader csvReader = new CsvReader(csvTextReader, HasHeader))
                {
                    csvReader.DefaultParseErrorAction = ParseErrorAction.ThrowException;
                    csvReader.MissingFieldAction = MissingFieldAction.ReplaceByNull;

                    rawData = csvReader.ToList();
                    header = csvReader.GetFieldHeaders().Select(h => Tuple.Create(h, DeviceImportFieldTypes.IgnoreColumn)).ToList();
                }
            }

            context = new DeviceImportContext(Filename, header, rawData);

            context.GuessHeaderTypes(Database);

            return context;
        }
开发者ID:garysharp,项目名称:Disco,代码行数:30,代码来源:DeviceImport.cs

示例2: UploadScores

        public ActionResult UploadScores(string data, int orgID)
        {
            var csv = new CsvReader(new StringReader(data), false, '\t');
            var list = csv.ToList();

            foreach (var score in list)
            {
                var peopleID = score[0].ToInt();

                var player = (from e in DbUtil.Db.OrganizationMembers
                              where e.OrganizationId == orgID
                              where e.PeopleId == peopleID
                              select e).SingleOrDefault();

                if (player != null) 
                    player.Score = score[1].ToInt();
                DbUtil.Db.SubmitChanges();
            }

            return Content("OK");
        }
开发者ID:GSBCfamily,项目名称:bvcms,代码行数:21,代码来源:OrgGroupsController.cs

示例3: DoUpload

        public bool DoUpload(string text, bool testing = false)
        {
            var rt = Db2.UploadPeopleRuns.OrderByDescending(mm => mm.Id).First();
            var csv = new CsvReader(new StringReader(text), false, '\t');
            var list = csv.ToList();

            var list0 = list.First().Select(kk => kk).ToList();
            names = list0.ToDictionary(i => i.TrimEnd(),
                i => list0.FindIndex(s => s == i), StringComparer.OrdinalIgnoreCase);

            if (names.ContainsKey("campus"))
            {
                var campuslist = (from li in list.Skip(1)
                                  where li.Length == names.Count
                                  group li by li[names["campus"]]
                                  into campus
                                  where campus.Key.HasValue()
                                  select campus.Key).ToList();
                var dbc = from c in campuslist
                          join cp in Db.Campus on c equals cp.Description into j
                          from cp in j.DefaultIfEmpty()
                          select new {cp, c};
                var clist = dbc.ToList();
                if (clist.Count > 0)
                {
                    var maxcampusid = 0;
                    if (Db.Campus.Any())
                        maxcampusid = Db.Campus.Max(c => c.Id);
                    foreach (var i in clist)
                        if (i.cp == null)
                        {
                            var cp = new Campu {Description = i.c, Id = ++maxcampusid};
                            if (!testing)
                                Db.Campus.InsertOnSubmit(cp);
                        }
                }
            }
            var now = DateTime.Now;
            if (!testing)
                Db.SubmitChanges();
            Campuses = Db.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);

            var q = (from li in list.Skip(1)
                     where li.Length == names.Count
                     group li by li[names["familyid"]]
                     into fam
                     select fam).ToList();
            rt.Count = q.Sum(ff => ff.Count());
            Db2.SubmitChanges();

            var standardnames = new List<string>
            {
                "familyid", "title", "first", "last", "goesby", "altname", "gender", "marital", "maidenName",
                "address", "address2", "city", "state", "zip", "position", "birthday", "cellphone", "homephone",
                "workphone", "email", "email2", "suffix", "middle", "joindate", "dropdate", "baptismdate", "weddingdate",
                "memberstatus", "employer", "occupation"
            };
            var orgs = new Dictionary<string, int>();
            var membertypes = new Dictionary<string, int>();

            foreach (var fam in q)
            {
                Family f = null;

                FindPerson3 pid;
                Person p = null;
                foreach (var a in fam)
                {
                    var potentialdup = false;
                    var first = a[names["first"]];
                    var last = a[names["last"]];
                    DateTime dt;
                    DateTime? dob = null;
                    if (names.ContainsKey("birthday"))
                        if (DateTime.TryParse(a[names["birthday"]], out dt))
                        {
                            dob = dt;
                            if (dob.Value < SqlDateTime.MinValue)
                                dob = null;
                        }
                    string email = null;
                    string cell = null;
                    string homephone = null;
                    if (names.ContainsKey("email"))
                        email = a[names["email"]].Trim();
                    if (names.ContainsKey("cellphone"))
                        cell = a[names["cellphone"]].GetDigits();
                    if (names.ContainsKey("homephone"))
                        homephone = a[names["homephone"]].GetDigits();
                    pid = Db.FindPerson3(first, last, dob, email, cell, homephone, null).FirstOrDefault();

                    if (noupdate && pid != null)
                    {
                        if (!testing)
                        {
                            var pd = Db.LoadPersonById(pid.PeopleId.Value);
                            pd.AddEditExtraBool("FoundDup", true);
                        }
                        potentialdup = true;
                        pid = null;
//.........这里部分代码省略.........
开发者ID:GSBCfamily,项目名称:bvcms,代码行数:101,代码来源:UploadPeopleModel.cs

示例4: DoUpload

        public bool DoUpload(string text)
        {
            var rt = Db2.UploadPeopleRuns.OrderByDescending(mm => mm.Id).First();
            var sep = text.First(vv => new char[] {'\t', ','}.Contains(vv));
            var csv = new CsvReader(new StringReader(text), false, sep);
            csv.SupportsMultiline = true;
            var list = csv.ToList();

            var list0 = list.First().Select(kk => kk).ToList();
            names = list0.ToDictionary(i => i.TrimEnd(),
                i => list0.FindIndex(s => s == i), StringComparer.OrdinalIgnoreCase);

            extravaluenames = (from name in names.Keys
                               where !standardnames.Contains(name, StringComparer.OrdinalIgnoreCase)
                               where !standardrecregnames.Contains(name)
                               select name).ToList();
            recregnames = (from name in names.Keys
                           where standardrecregnames.Contains(name)
                           select name).ToList();

            var db = DbUtil.Create(host);
            if (names.ContainsKey("campus"))
            {
                var campuslist = (from li in list.Skip(1)
                                  where li.Length == names.Count
                                  group li by li[names["campus"]]
                                  into campus
                                  where campus.Key.HasValue()
                                  select campus.Key).ToList();
                var dbc = from c in campuslist
                          join cp in db.Campus on c equals cp.Description into j
                          from cp in j.DefaultIfEmpty()
                          select new {cp, c};
                var clist = dbc.ToList();
                if (clist.Count > 0)
                {
                    var maxcampusid = 0;
                    if (db.Campus.Any())
                        maxcampusid = db.Campus.Max(c => c.Id);
                    foreach (var i in clist)
                        if (i.cp == null)
                        {
                            var cp = new Campu {Description = i.c, Id = ++maxcampusid};
                            if (!testing)
                                db.Campus.InsertOnSubmit(cp);
                        }
                }
            }
            var now = DateTime.Now;
            if (!testing)
                db.SubmitChanges();
            Campuses = db.Campus.ToDictionary(cp => cp.Description, cp => cp.Id);

            var q = (from li in list.Skip(1)
                     where li.Length == names.Count
                     group li by li[names["familyid"]]
                     into fam
                     select fam).ToList();
            rt.Count = q.Sum(ff => ff.Count());
            Db2.SubmitChanges();

            foreach (var fam in q)
            {
                Family f = null;
                var prevpid = 0;

                FindPerson3 pid;
                Person p = null;
                foreach (var a in fam)
                {
                    if (!testing)
                    {
                        db.SubmitChanges();
                        db.Dispose();
                        db = DbUtil.Create(host);
                    }

                    var potentialdup = false;
                    var first = a[names["first"]];
                    var last = a[names["last"]];
                    DateTime dt;
                    DateTime? dob = null;
                    if (names.ContainsKey("birthday"))
                        if (DateTime.TryParse(a[names["birthday"]], out dt))
                        {
                            dob = dt;
                            if (dob.Value < SqlDateTime.MinValue)
                                dob = null;
                        }
                    string email = null;
                    string cell = null;
                    string homephone = null;
                    if (names.ContainsKey("email"))
                        email = a[names["email"]].Trim();
                    if (names.ContainsKey("cellphone"))
                        cell = a[names["cellphone"]].GetDigits();
                    if (names.ContainsKey("homephone"))
                        homephone = a[names["homephone"]].GetDigits();
                    pid = db.FindPerson3(first, last, dob, email, cell, homephone, null).FirstOrDefault();

//.........这里部分代码省略.........
开发者ID:clearfunction,项目名称:bvcms,代码行数:101,代码来源:UploadPeopleModel.cs


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