首页 > 代码库 > 大数据List校验检查

大数据List校验检查

1.http://msdn.microsoft.com/zh-cn/library/dd997411(v=vs.110).aspx 
2.
  #region ZFCSTAEntity Compare 比对是否相等时,仅比较关键字段 ,提高过滤速度        /// <summary>        /// List<ZFCSTAEntity> 比较时,比较主要关键字段,其他字段忽略,忽略大小写,提高过滤速度 WERKS/PJCTID/YEAR        /// </summary>        public class ZFCSTAEntityListWERKSPJCTIDYEAREquality : IEqualityComparer<ZFCSTAEntity>        {            public bool Equals(ZFCSTAEntity x, ZFCSTAEntity y)            {                try                {                    return (x.WERKS.Equals(y.WERKS, StringComparison.CurrentCultureIgnoreCase))                        && (x.PJCTID.Equals(y.PJCTID, StringComparison.CurrentCultureIgnoreCase))                        && (x.YEAR.Equals(y.YEAR, StringComparison.CurrentCultureIgnoreCase));                }                catch                {                    return false;                }            }            public int GetHashCode(ZFCSTAEntity obj)            {                if (obj == null)                {                    return 0;                }                else                {                    return obj.ToString().GetHashCode();                }            }        }

 

  private void Set_Import_ErrorNewParral()        {            Leoni.Core.CompareHelper.ListContianCompare co = new CompareHelper.ListContianCompare();            Core_Func core_func = new Core_Func();            Get_Check_Data();            Stopwatch watch = new Stopwatch();            watch.Reset();            watch.Start();            #region Mandatory Check            //Plant check            //List<ZEINEEntity> listZEINE_WERKS_Empty = _listZEINE.Where((ZEINEEntity item) => item.WERKS == null || item.WERKS.Length == 0).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_WERKS_Empty)            //{            //    item.ErrorMsg += string.Format(" / Plant can not be empty . ");            //}            System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>            {                if (item.WERKS == null || item.WERKS.Length == 0)                {                                        item.ErrorMsg += string.Format(" / Plant can not be empty . ");                }            });            watch.Stop();            new WriteLog().WritelogDetail("WPlantCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //MATNR check            //List<ZEINEEntity> listZEINE_MATNR_Empty = _listZEINE.Where((ZEINEEntity item) => item.MATNR == null || item.MATNR.Length == 0).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_MATNR_Empty)            //{            //    item.ErrorMsg += string.Format(" / Leoni Part Number can not be empty . ");            //}            System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>            {                if (item.MATNR == null || item.MATNR.Length == 0)                {                                     item.ErrorMsg += string.Format(" / Leoni Part Number can not be empty . ");                }            });            watch.Stop();            new WriteLog().WritelogDetail("WLeoni Part NumberCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //Supplier ID check            //List<ZEINEEntity> listZEINE_LIFNR_Empty = _listZEINE.Where((ZEINEEntity item) => item.LIFNR == null || item.LIFNR.Length == 0).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_LIFNR_Empty)            //{            //    item.ErrorMsg += string.Format(" / Supplier ID can not be empty . ");            //}            System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>            {                if (item.LIFNR == null || item.LIFNR.Length == 0)                {                                       item.ErrorMsg += string.Format(" / Supplier ID can not be empty . ");                }            });            watch.Stop();            new WriteLog().WritelogDetail("WSupplier IDCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //Currency check            //List<ZEINEEntity> listZEINE_WAERS_Empty = _listZEINE.Where((ZEINEEntity item) => item.WAERS == null || item.WAERS.Length == 0).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_WAERS_Empty)            //{            //    item.ErrorMsg += string.Format(" / Currency can not be empty . ");            //}            System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>            {                if (item.WAERS == null || item.WAERS.Length == 0)                {                                        item.ErrorMsg += string.Format(" / Currency can not be empty . ");                }            });            watch.Stop();            new WriteLog().WritelogDetail("WCurrencyCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            #endregion            #region Valid Check            #region New mathod            //Check current plant or 00 plant & supplier ID exist in table ZLFA1 or not                          //Check current plant or 00 plant & supplier ID exist in table ZLFA1 or not              var listZT023_LIFNR_Except_00 = _listZLFA1_LIFNR.Where(c => c.WERKS == generalDictionary._global_werks)                                                            .Select(item => new { LIFNR = item.LIFNR.ToLower() })                                                            .ToList();            if (listZT023_LIFNR_Except_00 != null && listZT023_LIFNR_Except_00.Count() > 0)            {                var listZT023_LIFNR_Except = _listZEINE.Where((ZEINEEntity item) => item.WERKS != null && item.WERKS.Length > 0 && item.LIFNR != null && item.LIFNR.Length > 0)                                                       .Select(item => new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() })                                                       .Except(_listZLFA1_LIFNR.Select(item => new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() }))                                                       .Where(item => !listZT023_LIFNR_Except_00.Exists(c => c.LIFNR == item.LIFNR.ToLower() ? true : false))                                                       .ToList();                if (listZT023_LIFNR_Except != null && listZT023_LIFNR_Except.Count() > 0)                {                    System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>                    {                        if (listZT023_LIFNR_Except.Contains(new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() }))                        {                                                     item.ErrorMsg += string.Format(" / Supplier ID  :  " + item.LIFNR + " don‘t exist in Plant : " + generalDictionary._global_werks + " . ");                        }                    });                    //List<ZEINEEntity> listZEINE_LIFNR_Except = _listZEINE.FindAll(item => listZT023_LIFNR_Except.Contains(new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() }));                    //foreach (var item in listZEINE_LIFNR_Except)                    //{                    //    item.ErrorMsg += string.Format(" / Supplier ID  :  " + item.LIFNR + " don‘t exist in Plant : " + generalDictionary._global_werks + " . ");                    //}                }            }            watch.Stop();            new WriteLog().WritelogDetail("WSupplierPlantCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //Leoni Part Number valid check            List<string> listZMARA_MATNR_Except = _listZEINE.Where((ZEINEEntity item) => item.MATNR != null && item.MATNR.Length > 0)                                                                   .Select(item => item.MATNR.ToLower())                                                                   .Except(_listZMARA_MATNR.Select(item => item.MATNR.ToLower()))                                                                   .ToList<string>();            ////Leoni Part Number valid check                      if (listZMARA_MATNR_Except != null && listZMARA_MATNR_Except.Count() > 0)            {                System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>                {                    if (listZMARA_MATNR_Except.Contains(item.MATNR.ToLower()))                    {                                              item.ErrorMsg += string.Format(" / Leoni Part Number :  " + item.MATNR + " don‘t exist . ");                    }                });                //List<ZEINEEntity> listZEINE_MATNR_Except = _listZEINE.Where(item => listZMARA_MATNR_Except.Contains(item.MATNR.ToLower())).ToList<ZEINEEntity>();                //foreach (var item in listZEINE_MATNR_Except)                //{                //    item.ErrorMsg += string.Format(" / Leoni Part Number :  " + item.MATNR + " don‘t exist . ");                //}            }            watch.Stop();            new WriteLog().WritelogDetail("WLeoni Part Number2Check_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //Currency valid check            List<string> listZTCURC_WAERS_Except = _listZEINE.Where((ZEINEEntity item) => item.WAERS != null && item.WAERS.Length > 0)                                                             .Select(item => item.WAERS.ToLower())                                                             .Except(_listZTCURC_WAERS.Select(item => item.WAERS.ToLower())).ToList<string>();            if (listZTCURC_WAERS_Except != null && listZTCURC_WAERS_Except.Count() > 0)            {                System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>                {                    if (listZTCURC_WAERS_Except.Contains(item.WAERS.ToLower()))                    {                                              item.ErrorMsg += string.Format(" / Currency :  " + item.WAERS + " don‘t exist . ");                    }                });                //List<ZEINEEntity> listZEINE_WAERS_Except = _listZEINE.FindAll(item => listZTCURC_WAERS_Except.Contains(item.WAERS.ToLower()));                //foreach (var item in listZEINE_WAERS_Except)                //{                //    item.ErrorMsg += string.Format(" / Currency :  " + item.WAERS + " don‘t exist . ");                //}            }            watch.Stop();            new WriteLog().WritelogDetail("WCurrencyRuleCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //Country Key valid check            List<string> listZT005_LAND1_Except = _listZEINE.Where((ZEINEEntity item) => item.LAND1 != null && item.LAND1.Length > 0)                                                            .Select(item => item.LAND1.ToLower())                                                            .Except(_listLZT005_LAND1.Select(item => item.LAND1.ToLower())).ToList<string>();            if (listZT005_LAND1_Except != null && listZT005_LAND1_Except.Count() > 0)            {                System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>                {                    if (listZT005_LAND1_Except.Contains(item.LAND1.ToLower()))                    {                                              item.ErrorMsg += string.Format(" / Country Key :  " + item.LAND1 + " don‘t exist . ");                    }                });                //List<ZEINEEntity> listZEINE_LAND1_Except = _listZEINE.FindAll(item => listZT005_LAND1_Except.Contains(item.LAND1.ToLower()));                //foreach (var item in listZEINE_LAND1_Except)                //{                //    item.ErrorMsg += string.Format(" / Country Key :  " + item.LAND1 + " don‘t exist . ");                //}            }            watch.Stop();            new WriteLog().WritelogDetail("WCountry KeyCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            watch.Reset();            watch.Start();            //check valid of Condition pricing unit              System.Threading.Tasks.Parallel.ForEach(_listZEINE, (item) =>            {                if (!core_func.CheckPriceUnit(item.PEINH))                {                                      item.ErrorMsg += string.Format(" / Condition pricing unit :  " + item.PEINH + " not valid , just can be 1 or 2 or 3 or 4 or 5 . ");                }            });            //List<ZEINEEntity> listZEINE_PEINH_Except = _listZEINE.Where(item => !core_func.CheckPriceUnit(item.PEINH)).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_PEINH_Except)            //{            //    item.ErrorMsg += string.Format(" / Condition pricing unit :  " + item.PEINH + " not valid , just can be 1 or 2 or 3 or 4 or 5 . ");            //}            watch.Stop();            new WriteLog().WritelogDetail("TCondition pricing unitCheck_" + watch.ElapsedMilliseconds, watch.ElapsedMilliseconds.ToString());            #endregion            #region old Mathod            //////Plant valid check            ////List<string> listZT001W_WERKS_Except = _listZEINE.Where((ZEINEEntity item) => item.WERKS != null && item.WERKS.Length > 0)            ////                                                 .Select(item => item.WERKS.ToLower())            ////                                                 .Except(_listLZT001W_WERKS.Select(item => item.WERKS.ToLower())).ToList<string>();            ////List<ZEINEEntity> listZEINE_WERKS_Except = _listZEINE.FindAll(item => listZT001W_WERKS_Except.Contains(item.WERKS.ToLower()));            ////foreach (var item in listZEINE_WERKS_Except)            ////{            ////    item.ErrorMsg += string.Format(" / Plant :  " + item.WERKS + " don‘t exist . ");            ////}            ////Check current plant or 00 plant & supplier ID exist in table ZLFA1 or not              //var listZT023_LIFNR_Except_00 = _listZLFA1_LIFNR.Where(c => c.WERKS == generalDictionary._global_werks)            //                                                .Select(item => new { LIFNR = item.LIFNR.ToLower() })            //                                                .ToList();            //if (listZT023_LIFNR_Except_00 != null && listZT023_LIFNR_Except_00.Count() > 0)            //{            //    var listZT023_LIFNR_Except = _listZEINE.Where((ZEINEEntity item) => item.WERKS != null && item.WERKS.Length > 0 && item.LIFNR != null && item.LIFNR.Length > 0)            //                                           .Select(item => new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() })            //                                           .Except(_listZLFA1_LIFNR.Select(item => new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() }))            //                                           .Where(item => !listZT023_LIFNR_Except_00.Exists(c => c.LIFNR == item.LIFNR.ToLower() ? true : false))            //                                           .ToList();            //    if (listZT023_LIFNR_Except != null && listZT023_LIFNR_Except.Count() > 0)            //    {            //        List<ZEINEEntity> listZEINE_LIFNR_Except = _listZEINE.FindAll(item => listZT023_LIFNR_Except.Contains(new { WERKS = item.WERKS.ToLower(), LIFNR = item.LIFNR.ToLower() }));            //        //List<ZEINEEntity> listZEINE_LIFNR_Except = _listZEINE.FindAll(item => listZT023_LIFNR_Except.Exists(c => c.WERKS == item.WERKS.ToLower() && c.LIFNR == item.LIFNR.ToLower() ? true : false))            //        //                                                     .ToList<ZEINEEntity>();            //        foreach (var item in listZEINE_LIFNR_Except)            //        {            //            item.ErrorMsg += string.Format(" / Supplier ID  :  " + item.LIFNR + " don‘t exist in Plant : " + generalDictionary._global_werks + " . ");            //        }            //    }            //}            ////Leoni Part Number valid check            //List<string> listZMARA_MATNR_Except = _listZEINE.Where((ZEINEEntity item) => item.MATNR != null && item.MATNR.Length > 0)            //                                                .Select(item => item.MATNR.ToLower())            //                                                .Except(_listZMARA_MATNR.Select(item => item.MATNR.ToLower())).ToList<string>();            //if (listZMARA_MATNR_Except != null && listZMARA_MATNR_Except.Count() > 0)            //{            //    List<ZEINEEntity> listZEINE_MATNR_Except = _listZEINE.FindAll(item => listZMARA_MATNR_Except.Contains(item.MATNR.ToLower()));            //    //var listZMARA_MATNR_Except = _listZEINE.Where((ZEINEEntity item) => item.MATNR != null && item.MATNR.Length > 0)            //    //                                                 .Select(item => new { MATNR = item.MATNR.ToLower() })            //    //                                                 .Except(_listZMARA_MATNR.Select(item => new { MATNR = item.MATNR.ToLower() })).ToList();            //    //List<ZEINEEntity> listZEINE_MATNR_Except = _listZEINE.FindAll(item => listZMARA_MATNR_Except.Exists(c => c.MATNR == item.MATNR.ToLower() ? true : false))            //    //                                                     .ToList<ZEINEEntity>();            //    foreach (var item in listZEINE_MATNR_Except)            //    {            //        item.ErrorMsg += string.Format(" / Leoni Part Number :  " + item.MATNR + " don‘t exist . ");            //    }            //}            ////Currency valid check            //List<string> listZTCURC_WAERS_Except = _listZEINE.Where((ZEINEEntity item) => item.WAERS != null && item.WAERS.Length > 0)            //                                                 .Select(item => item.WAERS.ToLower())            //                                                 .Except(_listZTCURC_WAERS.Select(item => item.WAERS.ToLower())).ToList<string>();            //if (listZTCURC_WAERS_Except != null && listZTCURC_WAERS_Except.Count() > 0)            //{            //    List<ZEINEEntity> listZEINE_WAERS_Except = _listZEINE.FindAll(item => listZTCURC_WAERS_Except.Contains(item.WAERS.ToLower()));            //    foreach (var item in listZEINE_WAERS_Except)            //    {            //        item.ErrorMsg += string.Format(" / Currency :  " + item.WAERS + " don‘t exist . ");            //    }            //}            ////Country Key valid check            //List<string> listZT005_LAND1_Except = _listZEINE.Where((ZEINEEntity item) => item.LAND1 != null && item.LAND1.Length > 0)            //                                                .Select(item => item.LAND1.ToLower())            //                                                .Except(_listLZT005_LAND1.Select(item => item.LAND1.ToLower())).ToList<string>();            //if (listZT005_LAND1_Except != null && listZT005_LAND1_Except.Count() > 0)            //{            //    List<ZEINEEntity> listZEINE_LAND1_Except = _listZEINE.FindAll(item => listZT005_LAND1_Except.Contains(item.LAND1.ToLower()));            //    foreach (var item in listZEINE_LAND1_Except)            //    {            //        item.ErrorMsg += string.Format(" / Country Key :  " + item.LAND1 + " don‘t exist . ");            //    }            //}            //check valid of Condition pricing unit            //List<ZEINEEntity> listZEINE_PEINH_Except = _listZEINE.Where(item => !core_func.CheckPriceUnit(item.PEINH)).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_PEINH_Except)            //{            //    item.ErrorMsg += string.Format(" / Condition pricing unit :  " + item.PEINH + " not valid , just can be 1 or 2 or 3 or 4 or 5 . ");            //}            //#endregion            #endregion            //#region Length Check            ////Check General            //List<ZEINEEntity> listZEINE_MATNR_Length = _listZEINE.Where((ZEINEEntity item) => item.MATNR != null && item.MATNR.Length > 18).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_MATNR_Length)            //{            //    item.ErrorMsg += string.Format(" / Leoni Part Number  :  " + item.MATNR + " length can not larger than 18 ");            //}            //List<ZEINEEntity> listZEINE_LIFNR_Length = _listZEINE.Where((ZEINEEntity item) => item.LIFNR != null && item.LIFNR.Length > 10).ToList<ZEINEEntity>();            //foreach (var item in listZEINE_LIFNR_Length)            //{            //    item.ErrorMsg += string.Format(" / Supplier ID  :  " + item.LIFNR + " length can not larger than 18 ");            //}            #endregion        }

 

大数据List校验检查