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