public void DeleteLoopInfoExecute(object o) { if (o != null && o.GetType().Name == "LoopModel") { LoopModel loop = (LoopModel)o; SCA.Interface.ILoopService loopService = new SCA.BusinessLib.BusinessLogic.LoopService(loop.Controller); loopService.DeleteLoopBySpecifiedLoopCode(loop.Code); } }
private void AddButton_Click(object sender, RoutedEventArgs e) { LoopModel loop = new LoopModel(); string strMachineNumber = this.MachineNumberInputLabel.Content.ToString(); string strLoopCode = this.LoopCodeComboBox.SelectedItem.ToString(); string strDeviceAmount = this.DeviceAmountInputTextBox.Text; int loopAmount = Convert.ToInt32(this.LoopAmountInputTextBox.Text); string strLoopName = this.LoopNameInputTextBox.Text; loop.Code = strLoopCode; loop.DeviceAmount = Convert.ToInt32(strDeviceAmount); loop.Name = strLoopName; loop.Controller = ((SCA.WPF.CreateLoop.CreateLoopsViewModel) this.DataContext).TheController; loop.ControllerID = loop.Controller.ID; SCA.Interface.ILoopService loopService = new SCA.BusinessLib.BusinessLogic.LoopService(loop.Controller); loopService.AddLoops(loop, strMachineNumber, loopAmount); RaiseEvent(new RoutedEventArgs(AddButtonClickEvent)); }
/// <summary> /// 创建回路 /// </summary> /// <param name="loopsAmount">回路数量</param> /// <param name="deviceAmount">器件数量</param> /// <param name="controller">所属控制器</param> /// <returns></returns> public List <Model.LoopModel> CreateLoops(int loopsAmount, int deviceAmount, ControllerModel controller) { ILoopService loopService = new LoopService(controller); //内存操作,返回数据集 return(loopService.CreateLoops <DeviceInfo8036>(loopsAmount, deviceAmount, controller, _deviceService)); #region refactor at 2017-02-27 //string strMachineNumber = controller.MachineNumber; //string strLoopLengthFormat = "#"; //for (int i = 0; i < controller.LoopAddressLength; i++) //{ // strLoopLengthFormat += "0"; //} //List<Model.LoopModel> lstLoopModel = new List<LoopModel>(); //for (int i = 0; i < loopsAmount; i++) //创建回路 //{ // LoopModel loop = new LoopModel(); // loop.Controller = controller; // loop.Code = strMachineNumber + i.ToString(strLoopLengthFormat); // loop.Name = strMachineNumber + i.ToString(strLoopLengthFormat); // loop.DeviceAmount = deviceAmount; // List<DeviceInfo8036> lstDevInfo = new List<DeviceInfo8036>(); // for (int j = 0; j < deviceAmount; j++) //创建器件 // { // DeviceInfo8036 devInfo = new DeviceInfo8036(); // devInfo.Code = j.ToString("#000"); // devInfo.TypeCode = 9; //此处默认值可为各个控制器进行配置。 // devInfo.Disable = 0; // lstDevInfo.Add(devInfo); // } // loop.SetDevices<DeviceInfo8036>(lstDevInfo); // lstLoopModel.Add(loop); //} //return lstLoopModel; #endregion refactor at 2017-02-27 }
public void ConfirmExecute() { ClearAllErrorMessage(); RuleAndErrorMessage rule; Regex exminator; IControllerConfig config = ControllerConfigManager.GetConfigObject(TheController.Type); bool verifyFlag = true; if (LoopCode == null) { ErrorMessageLoopCode = "请指定回路号"; verifyFlag = false; } if (DeviceAmount != null) { rule = new RuleAndErrorMessage("^[0-9]{1,3}$", "请填写数字"); exminator = new Regex(rule.Rule); if (!exminator.IsMatch(DeviceAmount)) { ErrorMessageDeviceAmount = rule.ErrorMessage; verifyFlag = false; } else { int maxValue = config.GetMaxDeviceAmountValue(); if (Convert.ToInt32(DeviceAmount) > maxValue) { ErrorMessageDeviceAmount = "控制器最大节点数为:" + maxValue.ToString(); verifyFlag = false; } } } if (LoopsAmount != null) { rule = new RuleAndErrorMessage("^[0-9]{1,3}$", "请填写数字"); exminator = new Regex(rule.Rule); if (!exminator.IsMatch(LoopsAmount)) { ErrorMessageLoopAmount = rule.ErrorMessage; verifyFlag = false; } else { int maxValue = config.GetMaxLoopAmountValue(); if (Convert.ToInt32(LoopsAmount) > maxValue) { ErrorMessageLoopAmount = "控制器最大回路数为:" + maxValue.ToString(); verifyFlag = false; } } } rule = new RuleAndErrorMessage("^[A-Za-z0-9\u4E00-\u9FFF()()]{0,8}$", "允许填写”中英文字符、阿拉伯数字、圆括号”,最大长度8个字符"); exminator = new Regex(rule.Rule); if (!exminator.IsMatch(LoopName)) { ErrorMessageLoopName = rule.ErrorMessage; verifyFlag = false; } if (verifyFlag) { LoopModel loop = new LoopModel(); loop.Code = LoopCode; loop.DeviceAmount = Convert.ToInt32(DeviceAmount); loop.Name = LoopName; loop.Controller = TheController; loop.ControllerID = TheController.ID; SCA.Interface.ILoopService loopService = new SCA.BusinessLib.BusinessLogic.LoopService(loop.Controller); bool result = loopService.AddLoops(loop, ControllerMachineNumber, Convert.ToInt32(LoopsAmount)); SCA.WPF.Infrastructure.EventMediator.NotifyColleagues("RefreshNavigator", result); } }