CNAS取数仪器端升级
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InstrumentCodeOperation.cs 1.7KB

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