zoukankan      html  css  js  c++  java
  • C# LINQ

    DataTable Detail = EditData.Tables[dt_MyUserRole._TableName].Copy();
               Detail.AcceptChanges();
               var enumTable = from d1 in dtRoleAuthority.AsEnumerable()
                               join d2 in Detail.AsEnumerable()
                               on d1.Field<string>(dt_MyRole.RoleID) equals
                                  d2.Field<string>(dt_MyUserRole.RoleID)
                               select new
                               {
                                   RoldID = d1.Field<string>(dt_MyRoleAuthority.RoleID),
                                   FullName = d1.Field<string>(dt_MyRoleAuthority.FullName),
                                   Authority = d1.Field<int>(dt_MyRoleAuthority.Authority),
                                   PKey = d1.Field<string>(dt_MyRoleAuthority.FullName) + "." + d1.Field<int>(dt_MyRoleAuthority.Authority)
                               };
               TreeListNode node;
               foreach (var v in enumTable)
               {
                   node = tree_Module.FindNodeByKeyID(v.PKey);
                   if (node != null)
                       _TreeListInitial.SetNodeCheckState(node, CheckState.Checked);
               }
    //需要新增的
                //需要删除的
                //需要替换的
    
                var DataEdit = from dtLocation in LocalDetailFiles.AsEnumerable()
                               join dtServer in ServerDetailFiles.AsEnumerable()
                               on dtLocation.Field<string>(DataSchema.DetailSchema.Path) + dtLocation.Field<string>(DataSchema.DetailSchema.Name) equals
                                  dtServer.Field<string>(DataSchema.DetailSchema.Path) + dtServer.Field<string>(DataSchema.DetailSchema.Name)
                               where dtLocation.Field<DateTime>(DataSchema.DetailSchema.EditDate) > dtServer.Field<DateTime>(DataSchema.DetailSchema.EditDate)
                               select new
                               {
                                   Name = dtLocation.Field<string>(DataSchema.DetailSchema.Name),
                                   Path = dtLocation.Field<string>(DataSchema.DetailSchema.Path)
                               };
                var DataAdd = from dtLocal in LocalDetailFiles.AsEnumerable()
                              where !ServerDetailFiles.AsEnumerable().Any(y => y.Field<string>(DataSchema.DetailSchema.Path) + y.Field<string>(DataSchema.DetailSchema.Name) == dtLocal.Field<string>(DataSchema.DetailSchema.Path) + dtLocal.Field<string>(DataSchema.DetailSchema.Name))
                              select new
                              {
                                  Name = dtLocal.Field<string>(DataSchema.DetailSchema.Name),
                                  Path = dtLocal.Field<string>(DataSchema.DetailSchema.Path)
                              };
                var DataDelete = from dtServer in ServerDetailFiles.AsEnumerable()
                                 where !LocalDetailFiles.AsEnumerable().Any(y => y.Field<string>(DataSchema.DetailSchema.Path) + y.Field<string>(DataSchema.DetailSchema.Name) == dtServer.Field<string>(DataSchema.DetailSchema.Path) + dtServer.Field<string>(DataSchema.DetailSchema.Name))
                                 select new
                                 {
                                     Name = dtServer.Field<string>(DataSchema.DetailSchema.Name),
                                     Path = dtServer.Field<string>(DataSchema.DetailSchema.Path)
                                 };
    
                dtUpdateFiles = new DataTable();
                dtUpdateFiles.Columns.Add("Name", typeof(System.String));
                dtUpdateFiles.Columns.Add("Path", typeof(System.String));
                dtUpdateFiles.Columns.Add("Type", typeof(System.String));
    
                foreach (var v in DataAdd)
                {
                    DataRow dr = dtUpdateFiles.Rows.Add();
                    dr["Type"] = "1";
                    dr["Name"] = v.Name;
                    dr["Path"] = v.Path;
    
                    //ListViewItem item = new ListViewItem("新增");
                    //item.SubItems.Add(v.Name);//文件名
                    //item.SubItems.Add(v.Path);//路径
                    //LVFile.Items.Add(item);
                }
                foreach (var v in DataEdit)
                {
                    DataRow dr = dtUpdateFiles.Rows.Add();
                    dr["Type"] = "2";
                    dr["Name"] = v.Name;
                    dr["Path"] = v.Path;
    
                    //ListViewItem item = new ListViewItem("替换");
                    //item.SubItems.Add(v.Name);//文件名
                    //item.SubItems.Add(v.Path);//路径
                    //LVFile.Items.Add(item);
                }
                foreach (var v in DataDelete)
                {
                    DataRow dr = dtUpdateFiles.Rows.Add();
                    dr["Type"] = "3";
                    dr["Name"] = v.Name;
                    dr["Path"] = v.Path;
    
                    //ListViewItem item = new ListViewItem("删除");
                    //item.SubItems.Add(v.Name);//文件名
                    //item.SubItems.Add(v.Path);//路径
                    //LVFile.Items.Add(item);
                }
    慎于行,敏于思!GGGGGG
  • 相关阅读:
    初学python 遇到的坑
    golang 裸写一个pool池控制协程的大小
    自制C#版3DS文件的解析器并用SharpGL显示3DS模型
    [译+改]最长回文子串(Longest Palindromic Substring) Part II
    [译]最长回文子串(Longest Palindromic Substring) Part I
    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之纹理Textures
    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之网格Meshes
    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之网格渲染器和过滤器Mesh renderers and filters
    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之材质了解Materials
    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/4309081.html
Copyright © 2011-2022 走看看