protected override List <DeviceType> GetConfiguredDeviceTypeWithController(ControllerModel controller) { List <DeviceType> lstDeviceType = new List <DeviceType>(); List <short> lstDeviceCode = new List <short>(); foreach (var l in controller.Loops) { foreach (var dev in l.GetDevices <DeviceInfo8036>()) { if (!lstDeviceCode.Contains(dev.TypeCode)) { lstDeviceCode.Add(dev.TypeCode); } } } ControllerConfig8036 config = new ControllerConfig8036(); List <DeviceType> lstAllTypeInfo = config.GetALLDeviceTypeInfo(null); //var result =from c in lstAllTypeInfo where c.Code= foreach (var v in lstDeviceCode) { var result = lstAllTypeInfo.Where((s) => s.Code == v); if (result.Count() > 0) { lstDeviceType.Add(result.FirstOrDefault()); } } return(lstDeviceType); }
/// <summary> /// 取得器件信息 /// </summary> /// <returns></returns> //public List<DeviceInfo8036> GetDevicesInfo(int loopID) //{ // List<DeviceInfoBase> devicesInfo=_controllerOperation.GetDevicesInfo(loopID); // return devicesInfo; //} public bool CreateController(ControllerModel controller, IDeviceTypeDBService deviceTypeDBService, IControllerDBService controllerDBService) { try { #region 控制器配置 ControllerConfig8036 config = new ControllerConfig8036(); string strMatchingDevTypeID = config.GetDeviceTypeCodeInfo(); #region comment //StringBuilder sbDeviceTypeSQL = new StringBuilder("Select Code,Name,IsValid,ProjectID, MatchingController from DeviceType where Code in ("+strMatchingDevTypeID+");" ); //List<Model.DeviceType> lstDeviceType=(List<Model.DeviceType>)_databaseService.GetDataListBySQL<DeviceType>(sbDeviceTypeSQL); //foreach (DeviceType devType in lstDeviceType) //{ // devType.MatchingController = devType.MatchingController == null ? "" : devType.MatchingController; // //如果MatchingController中不包含当前的控制器,则更新字段 // if (!devType.MatchingController.Contains(ControllerType.NT8036.ToString())) // { // devType.MatchingController = devType.MatchingController == "" ? devType.MatchingController : devType.MatchingController + ","; // devType.MatchingController = devType.MatchingController + ControllerType.NT8036; // sbDeviceTypeSQL = new StringBuilder("Update DeviceType set MatchingController='" + devType.MatchingController + "' where Code=" + devType.Code + ";"); // // _databaseService.ExecuteBySql(sbDeviceTypeSQL); // } //} #endregion deviceTypeDBService.UpdateMatchingController(ControllerType.NT8036, strMatchingDevTypeID); //refactor 2017-02-23 #endregion #region 增加控制器信息 refactor commented //版本号怎么计,是按原版本号累加,还是初始化一个新的版本号 //当前为初始化一个新的版本号 //StringBuilder sbControllerSQL = new StringBuilder("Insert into Controller(ID,PrimaryFlag,TypeID,DeviceAddressLength,Name,PortName,BaudRate,MachineNumber,Version,ProjectID) values("); //sbControllerSQL.Append(controller.ID + ",'"); //sbControllerSQL.Append(controller.PrimaryFlag + "',");//+ "',0);"); //sbControllerSQL.Append((int)controller.TypeCode + ","); //sbControllerSQL.Append(controller.DeviceAddressLength + ",'"); //sbControllerSQL.Append(controller.Name + "','"); //sbControllerSQL.Append(controller.PortName + "',"); //sbControllerSQL.Append(controller.BaudRate + ",'"); //sbControllerSQL.Append(controller.MachineNumber + "',"); //sbControllerSQL.Append(controller.Version + ","); //sbControllerSQL.Append(controller.Project.ID + ")"); //_databaseService.ExecuteBySql(sbControllerSQL); #endregion controllerDBService.AddController(controller); //refactor at 2017-02-23 return(true); } catch (Exception ex) { return(false); } }