using CnasSynchrousModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace CnasSynchronusClient { public class InstrumentCodeOperation { //仪器编码合法性检测 public int CheckInstrumentCode(string strCode, List lstSyncInstrument) { //为空检测 if (strCode == null || strCode.Trim() == "") return 0; //命名不允许有特殊字符 //if (!isSpecialChar(strCode)) return -1; //是否在库中已存在 if (!CheckCodeRepeat(strCode, lstSyncInstrument)) return -2; return 1; } /// /// 检查是否重复 /// /// /// /// private bool CheckCodeRepeat(string strCode,List lstSyncInstrument) { bool bSuccess = true; var item = lstSyncInstrument.Where(s => s.Code == strCode).ToList(); if (item != null && item.Count > 0) { bSuccess = false; } return bSuccess; } /// /// 是否含有特殊字符 /// /// /// public bool isSpecialChar(String strCheckString) { Regex regex = new Regex(@"[_.`~!@#$%^&*()+=|{}':;',\\[\\]<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t"); return regex.IsMatch(strCheckString); ; } } }