CNAS取数仪器端升级
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. namespace CNAS_DBSync
  7. {
  8. public class InstrumentCodeOperation
  9. {
  10. //仪器编码合法性检测
  11. public int CheckInstrumentCode(string strCode, List<SyncInstrumentItemInfo> lstSyncInstrument)
  12. {
  13. //为空检测
  14. if (strCode == null || strCode.Trim() == "") return 0;
  15. //命名不允许有特殊字符
  16. //if (!isSpecialChar(strCode)) return -1;
  17. //是否在库中已存在
  18. if (!CheckCodeRepeat(strCode, lstSyncInstrument)) return -2;
  19. return 1;
  20. }
  21. /// <summary>
  22. /// 检查是否重复
  23. /// </summary>
  24. /// <param name="strCode"></param>
  25. /// <param name="lstSyncInstrument"></param>
  26. /// <returns></returns>
  27. private bool CheckCodeRepeat(string strCode,List<SyncInstrumentItemInfo> lstSyncInstrument)
  28. {
  29. bool bSuccess = true;
  30. var item = lstSyncInstrument.Where(s => s.Code == strCode).ToList<SyncInstrumentItemInfo>();
  31. if (item != null && item.Count > 0)
  32. {
  33. bSuccess = false;
  34. }
  35. return bSuccess;
  36. }
  37. /// <summary>
  38. /// 是否含有特殊字符
  39. /// </summary>
  40. /// <param name="strCheckString"></param>
  41. /// <returns></returns>
  42. public bool isSpecialChar(String strCheckString)
  43. {
  44. Regex regex = new Regex(@"[_.`~!@#$%^&*()+=|{}':;',\\[\\]<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t");
  45. return regex.IsMatch(strCheckString); ;
  46. }
  47. }
  48. }