コード例 #1
0
        public void UseRealArch()
        {
            //controller.
            //1.从控制器接收数据
            //2.判断控制器当前设置的状态:上传或下载
            //3.得到控制器类型
            //4.加载“具体的控制器处理类”,执行数据处理,及回复66确认
            DeviceInfo8036 deviceInfo = new DeviceInfo8036();

            //1.取得当前操作的控制器数据
            SCA.BusinessLib.ModelOperation.ControllerModelOperation cModelOperation = new SCA.BusinessLib.ModelOperation.ControllerModelOperation();
            ControllerModel controllerModel = cModelOperation.GetControllersBySpecificID(1);

            //2.判断当前控制器的连接状态
            //ICom  com=Substitute.For<ICom>();
            IControllerCommunication controller = Substitute.For <IControllerCommunication>();

            controller.PortName.Returns <string>("Com1");
            controller.BaudRate.Returns <int>(38400);

            controller.OpenPort().Returns <bool>(true);             //打开端口

            controller.TestControllerStatus().Returns <bool>(true); //获取控制器状态<收到巡检命令 CA>

            //controller.
            //3.执行下传数据指令

            //controller.Received
            IControllerOperation operation = Substitute.For <IControllerOperation>();
            // operation.GetControllerType().Returns<ControllerType>(ControllerType.NT8036);
            // SCA.BusinessLib.BusinessLogic.ControllerManager controllerManager = new SCA.BusinessLib.BusinessLogic.ControllerManager();

            //  controllerManager.AddController(controllerModel.ID,operation);//一个Controller对应一个Operation
        }
コード例 #2
0
        /// <summary>
        /// 取得当前控制器有效的设备类型
        /// </summary>
        /// <returns></returns>
        private List <DeviceType> GetValidDeviceTypes()
        {
            List <DeviceType> lstDeviceType = new List <DeviceType>();
            ControllerManager manager       = new ControllerManager();

            manager.InitializeAllControllerOperation(null);
            IControllerOperation controllerOperator = manager.GetController(TheController.Type);

            return(controllerOperator.GetAllDeviceTypeOfController(TheController));
        }
コード例 #3
0
ファイル: SummaryViewModel.cs プロジェクト: A1X71/twilight
 /// <summary>
 /// 生成控制器摘要信息
 /// </summary>
 private void GenerateSummaryInfo()
 {
     SummaryNodes.Clear();
     if (TheController != null)
     {
         ControllerManager controllerManager = new ControllerManager();
         controllerManager.InitializeAllControllerOperation(null);
         IControllerOperation controllerOperation = controllerManager.GetController(TheController.Type);
         //controllerOperation
         SummaryInfo controllerSummary = controllerOperation.GetSummaryNodes(TheController, 1);
         SummaryNodes.Add(controllerSummary);
     }
 }
コード例 #4
0
        /// <summary>
        /// 取得查询结果
        /// </summary>
        private void QueryDevicesInfo()
        {
            ControllerModel controller = TheController;
            //返回所有的器件类型
            ControllerManager _cManager;

            _cManager = new ControllerManager();
            _cManager.InitializeAllControllerOperation(null);
            IControllerOperation          cOperation          = _cManager.GetController(controller.Type);
            List <DeviceInfoForSimulator> lstSimulatorDevices = cOperation.GetSimulatorDevices(controller);

            lstSimulatorDevices = ProcessQueryCondition(lstSimulatorDevices);
            DeviceInfoObservableCollection.Clear();
            foreach (var d in lstSimulatorDevices)
            {
                DeviceInfoObservableCollection.Add(d);
            }
        }
コード例 #5
0
        public void TestControllerDownloadData()
        {
            
            //controller.
            //1.从控制器接收数据
            //2.判断控制器当前设置的状态:上传或下载
            //3.得到控制器类型
            //4.加载“具体的控制器处理类”,执行数据处理,及回复66确认
            IControllerCommunication controller = Substitute.For<IControllerCommunication>();
            controller.PortName.Returns<string>("Com1");
            controller.BaudRate.Returns<int>(38400);
            controller.OpenPort().Returns<bool>(true);
            //controller.Received
            IControllerOperation operation = Substitute.For<IControllerOperation>();
            operation.GetControllerType().Returns<ControllerType>(ControllerType.NT8036);
            SCA.BusinessLib.BusinessLogic.ControllerManager controllerManager = new BusinessLib.BusinessLogic.ControllerManager();

            controllerManager.AddController(1, operation);
        }
コード例 #6
0
        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            SCA.Model.ProjectModel project = new Model.ProjectModel();
            project.Name     = this.ProjectNameInputTextBox.Text;
            project.SavePath = SaveFilePathInputTextBox.Text;
            string strImportedFilePath = ImportFilePathInputTextBox.Text;
            //string strProjectFileSavePath = SaveFilePathInputTextBox.Text;
            //string strProjectName = ProjectNameInputTextBox.Text;
            // project.SavePath = this.FilePathInputTextBox.Text;


            //~~~~~~~~
            IFileService     _fileService = new FileService();
            IDatabaseService _databaseService;
            ILogRecorder     _logRecorder;

            _databaseService = new MSAccessDatabaseAccess(strImportedFilePath, null, _fileService);
            IOldVersionSoftwareDBService oldVersionService = new OldVersionSoftware8036DBService(_databaseService);

            IControllerOperation controllerOperation = null;

            string[]        strFileInfo    = oldVersionService.GetFileVersionAndControllerType();
            ControllerModel controllerInfo = null;

            if (strFileInfo.Length > 0)
            {
                switch (strFileInfo[0])
                {
                case "8036":
                    controllerOperation = new ControllerOperation8036(_databaseService);
                    break;
                }
                if (controllerOperation != null)
                {
                    controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService);
                }
                //strFileInfo[1];
            }
            //~~~~~~~~~
            project.Controllers.Add(controllerInfo);
            SCA.BusinessLib.ProjectManager.GetInstance.CreateProject(project);
            RaiseEvent(new RoutedEventArgs(ConfirmButtonClickEvent));
        }
コード例 #7
0
        public void ImportDataFromExcelExecute()
        {
            if (ExcelFilePath != "")
            {
                FileService fileService = new FileService();
                //ControllerOperation8001 operation = new ControllerOperation8001();
                ControllerManager controllerManager = new ControllerManager();
                controllerManager.InitializeAllControllerOperation(null);
                //IControllerOperation controllerOperation = controllerManager.GetController(SelectedControllerType);
                _operation = controllerManager.GetController(TheController.Type);
                //ControllerOperationCommon.ProgressBarCancelFlag = false;
                _operation.SetStaticProgressBarCancelFlag(false);
                //_operation
                //_operation = new ControllerOperation8001();
                _operation.UpdateProgressBarEvent       += UpdateProgressBarUI;
                _operation.ReadingExcelCompletedEvent   += ReadingExcelComplete;
                _operation.ReadingExcelCancelationEvent += CanceledExcelImportHandler;
                _operation.ReadingExcelErrorEvent       += ReadingExcelErrorHandler;
                string strErrorMessage;
                ReadExcelLoopArgumentForIn param = new ReadExcelLoopArgumentForIn();
                param.FilePath    = ExcelFilePath;
                param.FileService = fileService;
                param.Controller  = TheController;


                //  System.Threading.Thread thread = new System.Threading.Thread(Read);
                //  thread.Start(param);
                Read(param);
                //SCA.BusinessLib.ProjectManager.GetInstance.TheControllerViaImporting = _operation.ReadEXCELTemplate(ExcelFilePath, fileService,TheController,out strErrorMessage);

                //#region 显示数据选择页面
                //ConfigSection = Visibility.Collapsed;
                //ImportContentSelectorViewModel importContentSelectorVM = new ImportContentSelectorViewModel();
                //importContentSelectorVM.TheController = TheController;
                //importContentSelectorVM.SelfVisibility = Visibility.Visible;
                //importContentSelectorVM.ImportDataSelectorVisibility = Visibility.Visible;
                //importContentSelectorVM.InitilizeData(strErrorMessage);
                //ImportContentSelectorDataContext = importContentSelectorVM;
                ////importContentSelectorVM=
                //#endregion
                ToggleButtonStateForReadingExcel(true);
            }
        }
コード例 #8
0
ファイル: MainWindowViewModel.cs プロジェクト: wpmyj/twilight
 /// <summary>
 /// 删除控制器信息
 /// </summary>
 /// <param name="controller"></param>
 /// <returns></returns>
 public bool DeleteControllerBySpecifiedControllerID(ControllerModel controller)
 {
     try
     {
         if (MessageBox.Show("确认删除吗?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             ControllerManager controllerManager = new ControllerManager();
             controllerManager.InitializeAllControllerOperation(null);
             IControllerOperation controllerOperation = controllerManager.GetController(controller.Type);
             controllerOperation.DeleteControllerBySpecifiedControllerID(controller.ID);
         }
     }
     catch
     {
         return(false);
     }
     return(true);
     //controllerOperation.AddControllerToProject(controller);
 }
コード例 #9
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            ControllerModel controller = new ControllerModel();

            controller.Name = ControllerNameInputTextBox.Text;
            controller.Type = (ControllerType)ControllerTypeComboBox.SelectedItem;
            controller.DeviceAddressLength = Convert.ToInt32(DeviceCodeLengthComboBox.SelectedItem);

            controller.MachineNumber = ControllerMachineNumInputTextBox.Text;

            controller.PortName          = SerialPortNumberComboBox.SelectedItem.ToString();
            controller.LoopAddressLength = 2;//回路地址长度默认为2


            ControllerManager controllerManager = new ControllerManager();

            controllerManager.InitializeAllControllerOperation(null);

            IControllerOperation controllerOperation = controllerManager.GetController(controller.Type);

            controllerOperation.AddControllerToProject(controller);
            RaiseEvent(new RoutedEventArgs(AddButtonClickEvent));
        }
コード例 #10
0
        public void ConvertOldVersionSoftwareDataFileToCurrentModel8036()
        {
            _databaseService = new MSAccessDatabaseAccess(@"C:\Users\Administrator\Desktop\foo\8036.mdb", _logRecorder, _fileService);
            IOldVersionSoftwareDBService oldVersionService = new OldVersionSoftware8036DBService(_databaseService);

            IControllerOperation controllerOperation = null;

            string[]        strFileInfo    = oldVersionService.GetFileVersionAndControllerType();
            ControllerModel controllerInfo = null;

            if (strFileInfo.Length > 0)
            {
                switch (strFileInfo[0])
                {
                case "8036":
                    controllerOperation = new ControllerOperation8036(_databaseService);
                    break;
                }
                if (controllerOperation != null)
                {
                    controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService);
                }
                //strFileInfo[1];
            }
            Assert.That(controllerInfo.Type, Is.EqualTo(ControllerType.NT8036), "控制器类型不正确");
            Assert.That(controllerInfo.Loops.Count, Is.EqualTo(2), "回路数量不正确");
            Assert.That(controllerInfo.Loops[0].Code, Is.EqualTo("00101"), "回路名称不正确");
            Assert.That(controllerInfo.Loops[0].DeviceAmount, Is.EqualTo(46), "01回路数量不正确");
            Assert.That(controllerInfo.Loops[0].GetDevices <Model.DeviceInfo8036>()[0].Code, Is.EqualTo("00101001"), "器件编码不正确");

            Assert.That(controllerInfo.Loops[1].Code, Is.EqualTo("00102"), "回路名称不正确");

            Assert.That(controllerInfo.StandardConfig.Count, Is.EqualTo(1), "标准组态数量为1");
            Assert.That(controllerInfo.StandardConfig[0].Code, Is.EqualTo("0001"), "标准组态编号为0001");
            Assert.That(controllerInfo.StandardConfig[0].DeviceNo4, Is.EqualTo("00001009"), "编号4的编号为00001009");
            Assert.That(controllerInfo.StandardConfig[0].LinkageNo3, Is.EqualTo("0003"), "联动组3的编号为0003");
        }
コード例 #11
0
        public void ConvertOldVersionSoftwareDataFileToCurrentModel8001()
        {
            _databaseService = new MSAccessDatabaseAccess(@"E:\2016\6 软件优化升级\4 实际工程数据\工程数据111\连城心怡都城_文件版本5.mdb", _logRecorder, _fileService);
            IOldVersionSoftwareDBService oldVersionService   = new OldVersionSoftware8001DBService(_databaseService);
            IControllerOperation         controllerOperation = null;

            string[]        strFileInfo    = oldVersionService.GetFileVersionAndControllerType();
            ControllerModel controllerInfo = null;

            if (strFileInfo.Length > 0)
            {
                switch (strFileInfo[0])
                {
                case "8001":
                    controllerOperation = new ControllerOperation8001();
                    break;
                }
                if (controllerOperation != null)
                {
                    controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService);
                }
                //strFileInfo[1];
            }
            Assert.That(controllerInfo.Type, Is.EqualTo(ControllerType.NT8001), "控制器类型不正确");
            Assert.That(controllerInfo.DeviceAddressLength, Is.EqualTo(7), "器件长度为7");
            Assert.That(controllerInfo.Loops.Count, Is.EqualTo(10), "回路数量不正确");
            Assert.That(controllerInfo.Loops[0].Code, Is.EqualTo("0001"), "回路名称不正确");
            Assert.That(controllerInfo.Loops[0].DeviceAmount, Is.EqualTo(46), "01回路器件数量不正确");
            Assert.That(controllerInfo.Loops[0].GetDevices <Model.DeviceInfo8001>()[0].Code, Is.EqualTo("0001001"), "器件编码不正确");

            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].Code, Is.EqualTo("0003001"), "器件编码不正确");
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].TypeCode, Is.EqualTo(4), "器件类型不正确");
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].Disable, Is.EqualTo(0), "隔离不正确");
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].SensitiveLevel, Is.EqualTo(2), "灵敏度不正确");
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].Location, Is.EqualTo("A2三层306店"), "地点不正确");
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].BuildingNo, Is.EqualTo(1), "楼号不正确");
            //区号可以为0
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].ZoneNo, Is.EqualTo(2), "区号不正确");
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].FloorNo, Is.EqualTo(3), "层号不正确");
            //房间可以为0
            Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].RoomNo, Is.EqualTo(null), "房间号不正确");

            Assert.That(controllerInfo.Loops[1].Code, Is.EqualTo("0002"), "回路名称不正确");

            Assert.That(controllerInfo.StandardConfig.Count, Is.EqualTo(20), "标准组态数量为20");
            Assert.That(controllerInfo.StandardConfig[13].Code, Is.EqualTo("0014"), "标准组态编号为0014");
            Assert.That(controllerInfo.StandardConfig[13].DeviceNo4, Is.EqualTo("0007102"), "编号4的编号为0007102");
            Assert.That(controllerInfo.StandardConfig[13].LinkageNo2, Is.EqualTo("0020"), "联动组2的编号为0020");


            Assert.That(controllerInfo.MixedConfig.Count, Is.EqualTo(53), "混合组态数量为53");
            Assert.That(controllerInfo.MixedConfig[13].Code, Is.EqualTo("0014"), "混合组态编号为0014");
            Assert.That(controllerInfo.MixedConfig[13].ActionCoefficient, Is.EqualTo("1"), "编号14的动作常数为1");
            Assert.That(controllerInfo.MixedConfig[13].ActionType, Is.EqualTo(LinkageActionType.AND), "编号14的动作类型为与");
            Assert.That(controllerInfo.MixedConfig[13].DeviceTypeCodeA, Is.EqualTo(13), "编号14的类型A为13");
            Assert.That(controllerInfo.MixedConfig[29].TypeC, Is.EqualTo(LinkageType.ZoneLayer), "编号30的类型c为区层");
            Assert.That(controllerInfo.MixedConfig[29].BuildingNoC, Is.EqualTo(6), "编号30的楼号为6");
            Assert.That(controllerInfo.MixedConfig[29].ZoneNoC, Is.EqualTo(5), "编号30的区号为5");
            Assert.That(controllerInfo.MixedConfig[29].LayerNoC, Is.EqualTo(-1), "编号30的层号为-1");
            Assert.That(controllerInfo.MixedConfig[30].TypeC, Is.EqualTo(LinkageType.Address), "编号31的类型c为地址");
            Assert.That(controllerInfo.MixedConfig[30].MachineNoC, Is.EqualTo("00"), "编号31的机号为00");
            Assert.That(controllerInfo.MixedConfig[30].LoopNoC, Is.EqualTo("07"), "编号31的路号为07");
            Assert.That(controllerInfo.MixedConfig[30].DeviceCodeC, Is.EqualTo("075"), "编号31的地编号为075");

            Assert.That(controllerInfo.GeneralConfig.Count, Is.EqualTo(37), "通用组态数量为37");
            Assert.That(controllerInfo.GeneralConfig[13].Code, Is.EqualTo("0014"), "通用组态编号为0014");
            Assert.That(controllerInfo.GeneralConfig[13].ActionCoefficient, Is.EqualTo("1"), "编号14的动作常数为1");
            Assert.That(controllerInfo.GeneralConfig[13].BuildingNoA, Is.EqualTo(6), "编号14的楼号为6");
            Assert.That(controllerInfo.GeneralConfig[13].ZoneNoA, Is.EqualTo(5), "编号14的区号为5");
            Assert.That(controllerInfo.GeneralConfig[13].LayerNoA1, Is.EqualTo(0), "编号14的层号A1为0");
            Assert.That(controllerInfo.GeneralConfig[13].LayerNoA2, Is.EqualTo(0), "编号14的层号A2为0");
            Assert.That(controllerInfo.GeneralConfig[13].DeviceTypeCodeA, Is.EqualTo(13), "编号14的类型A为13");

            Assert.That(controllerInfo.GeneralConfig[13].TypeC, Is.EqualTo(LinkageType.ZoneLayer), "编号14的分类C为区层");
            Assert.That(controllerInfo.GeneralConfig[13].BuildingNoC, Is.EqualTo(6), "编号14的楼号为6");
            Assert.That(controllerInfo.GeneralConfig[13].ZoneNoC, Is.EqualTo(5), "编号14的区号C为5");
            Assert.That(controllerInfo.GeneralConfig[13].LayerNoC, Is.EqualTo(-1), "编号14的层号C为-1");
            Assert.That(controllerInfo.GeneralConfig[13].DeviceTypeCodeC, Is.EqualTo(36), "编号14的层号C为36");

            Assert.That(controllerInfo.GeneralConfig[14].TypeC, Is.EqualTo(LinkageType.Address), "编号15的分类C为地址");
            Assert.That(controllerInfo.GeneralConfig[14].MachineNoC, Is.EqualTo("00"), "编号15的机号为0");
            Assert.That(controllerInfo.GeneralConfig[14].LoopNoC, Is.EqualTo("01"), "编号15的路号为1");
            Assert.That(controllerInfo.GeneralConfig[14].DeviceCodeC, Is.EqualTo("001"), "编号15的层号C为001");
            Assert.That(controllerInfo.GeneralConfig[14].DeviceTypeCodeC, Is.EqualTo(null), "编号14的层号C为null");
        }
コード例 #12
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            ClearAllErrorMessage();
            ControllerModel controller = new ControllerModel();

            bool verifyFlag = true;

            if (ControllerTypeComboBox.SelectedItem != null)
            {
                controller.Type = (ControllerType)ControllerTypeComboBox.SelectedItem;
            }
            else
            {
                this.ErrorMessageControllerType.Text = "请选择控制器类型";
                verifyFlag = false;
            }
            if (DeviceCodeLengthComboBox.SelectedItem != null)
            {
                controller.DeviceAddressLength = Convert.ToInt32(DeviceCodeLengthComboBox.SelectedItem);
            }
            else
            {
                this.ErrorMessageControllerDeviceAddressLength.Text = "请选择器件长度";
                verifyFlag = false;
            }
            if (SerialPortNumberComboBox.SelectedItem != null)
            {
                controller.PortName = SerialPortNumberComboBox.SelectedItem.ToString();
            }
            else
            {
                this.ErrorMessageControllerPortName.Text = "请选择端口";
                verifyFlag = false;
            }
            if (this.ControllerMachineNumInputTextBox.Text == "")
            {
                this.ErrorMessageControllerDeviceAddressLength.Text = "请填写器件长度";
                verifyFlag = false;
            }
            if (verifyFlag)
            {
                controller.Name              = ControllerNameInputTextBox.Text;
                controller.MachineNumber     = ControllerMachineNumInputTextBox.Text;
                controller.LoopAddressLength = 2;//回路地址长度默认为2
                IControllerConfig config = ControllerConfigManager.GetConfigObject(controller.Type);
                int maxMachineNumber     = config.GetMaxMachineAmountValue(controller.DeviceAddressLength);
                Dictionary <string, RuleAndErrorMessage> dictRule = config.GetControllerInfoRegularExpression(controller.DeviceAddressLength);

                RuleAndErrorMessage rule = dictRule["Name"];

                Regex exminator = new Regex(rule.Rule);
                if (!string.IsNullOrEmpty(controller.Name))
                {
                    if (!exminator.IsMatch(controller.Name))
                    {
                        this.ErrorMessageControllerName.Text = rule.ErrorMessage;
                        verifyFlag = false;
                    }
                }
                else
                {
                    this.ErrorMessageControllerName.Text = "请填写控制器名称";
                    verifyFlag = false;
                }
                rule      = dictRule["MachineNumber"];
                exminator = new Regex(rule.Rule);
                if (!exminator.IsMatch(ControllerMachineNumInputTextBox.Text))
                {
                    this.ErrorMessageControllerMachineNumber.Text = rule.ErrorMessage;
                    verifyFlag = false;
                }
                else
                {
                    controller.MachineNumber = this.ControllerMachineNumInputTextBox.Text;
                }
                if (verifyFlag)
                {
                    if (Convert.ToInt16(controller.MachineNumber) > maxMachineNumber)
                    {
                        this.ErrorMessageControllerMachineNumber.Text = "机号超出范围,最大机号为" + maxMachineNumber.ToString();

                        verifyFlag = false;
                    }
                }
            }
            if (verifyFlag)
            {
                ControllerManager controllerManager = new ControllerManager();
                controllerManager.InitializeAllControllerOperation(null);
                IControllerOperation controllerOperation = controllerManager.GetController(controller.Type);
                controllerOperation.AddControllerToProject(controller);
                RaiseEvent(new RoutedEventArgs(AddButtonClickEvent));
            }
        }
コード例 #13
0
        public void ComfirmExecute()
        {
            this.ErrorMessagePromptImportFilePath = "";
            this.ErrorMessagePromptName           = "";
            this.ErrorMessagePromptSaveFilePath   = "";
            bool          verifyFlag    = true;
            ProjectConfig projectConfig = new ProjectConfig();
            Dictionary <string, RuleAndErrorMessage> dictRule = projectConfig.GetProjectInfoRegularExpression();
            RuleAndErrorMessage rule = dictRule["Name"];
            Regex exminator          = new Regex(rule.Rule);

            if (!string.IsNullOrEmpty(ProjectName))
            {
                if (!exminator.IsMatch(ProjectName))
                {
                    ErrorMessagePromptName = rule.ErrorMessage;
                    verifyFlag             = false;
                }
            }
            else
            {
                ErrorMessagePromptName = "请输入工程名称";
                verifyFlag             = false;
            }
            if (string.IsNullOrEmpty(ImportedFilePath))
            {
                ErrorMessagePromptImportFilePath = "请选择有效导入文件路径";
                verifyFlag = false;
            }
            if (string.IsNullOrEmpty(SavedFilePath))
            {
                ErrorMessagePromptSaveFilePath = "请选择有效文件存储路径";
                verifyFlag = false;
            }
            if (verifyFlag)
            {
                IFileService         _fileService         = new FileService();
                ILogRecorder         _logRecorder         = null;
                string               strImportedFilePath  = this.ImportedFilePath;
                string               strExtentionName     = strImportedFilePath.Substring(strImportedFilePath.LastIndexOf(".") + 1);
                DBFileVersionManager dbFileVersionManager = new DBFileVersionManager(this.ImportedFilePath, _logRecorder, _fileService);
                //取得某一系列的数据文件操作服务(4,5,6 系列没有项目,7开始有项目信息,以文件扩展名作为划分依据)
                IDBFileVersionService dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByExtentionName(strExtentionName);
                //取得文件版本
                int fileVersion = dbFileVersionService.GetFileVersion();
                dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByVersionID(fileVersion);
                //取得项目信息
                ProjectModel project = dbFileVersionService.GetProject(1);
                project.Name     = this.ProjectName;                                 //以当前设置的名称作为项目名
                project.SavePath = this.SavedFilePath + "\\" + project.Name + ".nt"; //以当前设置的路径作为项目的存储路径
                IControllerOperation controllerOperation = null;
                //取得项目下所有控制器信息
                List <ControllerModel> lstController = dbFileVersionService.GetControllersByProject(project);
                int             dataFileVersion      = 0;     //数据文件版本
                ControllerModel controller           = null;
                foreach (var controllerInfo in lstController) //取得控制器操作服务
                {
                    if (project.FileVersion == -1)            //4,5,6版本文件无项目信息
                    {
                        project.FileVersion = controllerInfo.FileVersion;
                    }
                    switch (controllerInfo.Type)
                    {
                    case ControllerType.FT8000:
                        controllerOperation = new ControllerOperation8000();
                        break;

                    case ControllerType.FT8003:
                        controllerOperation = new ControllerOperation8003();
                        break;

                    case ControllerType.NT8001:
                        controllerOperation = new ControllerOperation8001();
                        break;

                    case ControllerType.NT8007:
                        controllerOperation = new ControllerOperation8007();
                        break;

                    case ControllerType.NT8021:
                        controllerOperation = new ControllerOperation8021();
                        break;

                    case ControllerType.NT8036:
                        controllerOperation = new ControllerOperation8036();
                        break;
                    }
                    if (controllerOperation != null)                                                                                             //合法控制器类型
                    {
                        dataFileVersion      = Convert.ToInt32(project.FileVersion);                                                             //取得当前项目文件版本号
                        dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByVersionID(dataFileVersion);                         //取得当前文件的数据文件服务
                        //controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService);
                        controller = controllerOperation.OrganizeControllerInfoFromSpecifiedDBFileVersion(dbFileVersionService, controllerInfo); //取得组织完成的控制器信息
                    }
                    if (controller != null)                                                                                                      //将组织完成的信息增加至项目中
                    {
                        project.Controllers.Add(controllerInfo);
                    }
                }
                if (dataFileVersion != 0)//将所有数据转换为当前软件应用的数据版本
                {
                    project = dbFileVersionManager.VersionConverter(dataFileVersion, DBFileVersionManager.CurrentDBFileVersion, project);
                }
                SCA.BusinessLib.ProjectManager.GetInstance.CreateProject(project);
                EventMediator.NotifyColleagues("DisplayTheOpenedProject", null);
            }
        }
コード例 #14
0
 public bool AddController(ControllerType key, IControllerOperation val)
 {
     return(_controllers.TryAdd(key, val));
 }
コード例 #15
0
        public void DownloadExcelTemplateExecute()
        {
            VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();

            dialog.Description            = "选择存储的文件夹";
            dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog.
            bool?blnResult = dialog.ShowDialog();

            if (blnResult != null)
            {
                if ((bool)blnResult)
                {
                    string      strFilePath  = dialog.SelectedPath;
                    FileService fileService  = new FileService();
                    string      suffixString = "";
                    if (ExcelVersionForTemplate == EXCELVersion.EXCEL2003)
                    {
                        suffixString = ")模板文件.xls";
                    }
                    else
                    {
                        suffixString = ")模板文件.xlsx";
                    }
                    ControllerManager controllerManager = new ControllerManager();
                    controllerManager.InitializeAllControllerOperation(null);
                    IControllerOperation operation = controllerManager.GetController(SelectedControllerType);

                    if (DefaultTemplateState)
                    {
                        //ControllerOperation8001 operation = new ControllerOperation8001();
                        // operation.DownloadDefaultEXCELTemplate(strFilePath + "//" + "默认(" + SelectedControllerType.ToString() + suffixString, fileService, null);
                        operation.DownloadDefaultEXCELTemplate(strFilePath + "//" + "默认(" + SelectedControllerType.ToString() + suffixString, fileService, null, SelectedControllerType);
                    }
                    else if (CustomizedTemplateState)
                    {
                        ExcelTemplateCustomizedInfo customizedInfo = new ExcelTemplateCustomizedInfo();
                        customizedInfo.ControllerType           = SelectedControllerType;
                        customizedInfo.ControllerName           = ControllerName;//应该限制此控制器名称的长度
                        customizedInfo.MachineNumber            = MachineNumber;
                        customizedInfo.SelectedDeviceCodeLength = SelectedDeviceCodeLength;
                        customizedInfo.SerialPortNumber         = SerialPortNumber;
                        customizedInfo.LoopAmount             = LoopAmount;
                        customizedInfo.LoopGroupAmount        = LoopGroupAmount;
                        customizedInfo.StandardLinkageFlag    = StandardLinkageFlag;
                        customizedInfo.MixedLinkageFlag       = MixedLinkageFlag;
                        customizedInfo.GeneralLinkageFlag     = GeneralLinkageFlag;
                        customizedInfo.ManualControlBoardFlag = ManualControlBoardFlag;
                        customizedInfo.DefaultDeviceTypeCode  = SelectedDeviceTypeCode;
                        // ControllerOperation8001 operation = new ControllerOperation8001(); //暂时写为8001,后续需要改为各控制器通用代码
                        string fileName = "";
                        if (ControllerName.Length > 10)
                        {
                            fileName = fileName + ControllerName.Substring(0, 10) + "控制器(" + SelectedControllerType.ToString() + suffixString;
                        }
                        else
                        {
                            fileName = fileName + ControllerName + "控制器(" + SelectedControllerType.ToString() + suffixString;
                        }

                        //    operation.DownloadDefaultEXCELTemplate(strFilePath + "//" +fileName , fileService, customizedInfo);
                        operation.DownloadDefaultEXCELTemplate(strFilePath + "//" + fileName, fileService, customizedInfo, SelectedControllerType);
                    }
                }
            }
        }
コード例 #16
0
ファイル: HierarchyViewModel.cs プロジェクト: wpmyj/twilight
        public HierarchyViewModel()
        {
            IProjectManager              projManager         = ProjectManager.GetInstance;
            IFileService                 _fileService        = new FileService();
            IDatabaseService             _databaseService    = new MSAccessDatabaseAccess(@"C:\Users\Administrator\Desktop\foo\8036.mdb", null, _fileService);
            IOldVersionSoftwareDBService oldVersionService   = new OldVersionSoftware8036DBService(_databaseService);
            IControllerOperation         controllerOperation = null;

            string[]        strFileInfo    = oldVersionService.GetFileVersionAndControllerType();
            ControllerModel controllerInfo = null;

            if (strFileInfo.Length > 0)
            {
                switch (strFileInfo[0])
                {
                case "8036":
                    controllerOperation = new ControllerOperation8036(_databaseService);
                    break;
                }
                if (controllerOperation != null)
                {
                    controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService);
                }
                //strFileInfo[1];
            }


            ProjectModel proj = new ProjectModel()
            {
                ID = 1, Name = "尼特智能"
            };

            proj.Controllers.Add(controllerInfo);



            _databaseService  = new MSAccessDatabaseAccess(@"E:\2016\6 软件优化升级\4 实际工程数据\工程数据111\连城心怡都城_文件版本5.mdb", null, _fileService);
            oldVersionService = new OldVersionSoftware8001DBService(_databaseService);

            strFileInfo    = oldVersionService.GetFileVersionAndControllerType();
            controllerInfo = null;
            if (strFileInfo.Length > 0)
            {
                switch (strFileInfo[0])
                {
                case "8001":
                    controllerOperation = new ControllerOperation8001(null);
                    break;
                }
                if (controllerOperation != null)
                {
                    controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService);
                }
                //strFileInfo[1];
            }

            proj.Controllers.Add(controllerInfo);

            projManager.CreateProject(proj);

            List <ProjectModel> lstProjects = new List <ProjectModel>();

            lstProjects.Add(proj);
            Initialize(lstProjects, null);
        }
コード例 #17
0
        /// <summary>
        /// 生成EXCEL文件摘要信息页
        /// </summary>
        /// <param name="excelService"></param>
        /// <param name="sheetNames"></param>
        /// <returns></returns>
        protected bool GenerateExcelSummarySheet(ProjectModel project, ref IExcelService excelService, out List <string> sheetNames)
        {
            List <string> lstSheetNames = new List <string>();

            try
            {
                List <MergeCellRange> lstMergeCellRange = new List <MergeCellRange>();
                MergeCellRange        mergeCellRange    = new MergeCellRange();
                mergeCellRange.FirstRowIndex    = 0;
                mergeCellRange.LastRowIndex     = 0;
                mergeCellRange.FirstColumnIndex = 0;
                mergeCellRange.LastColumnIndex  = 2;
                lstMergeCellRange.Add(mergeCellRange);

                const int         Loop_Amount_Per_Sheet = 8;
                ControllerManager controllerManager     = new ControllerManager();
                controllerManager.InitializeAllControllerOperation(null);
                List <SummaryInfo> lstSummaryInfo = new List <SummaryInfo>();
                lstSheetNames.Add("项目摘要");
                foreach (var controller in project.Controllers)
                {
                    IControllerOperation controllerOperation = controllerManager.GetController(controller.Type);
                    //取控制器摘要信息逻辑
                    SummaryInfo controllerSummary = controllerOperation.GetSummaryNodes(controller, 2);
                    controllerSummary.Name += "-机号:" + controller.MachineNumber;
                    lstSummaryInfo.Add(controllerSummary);
                    int loopSheetAmount = Convert.ToInt32(Math.Ceiling((float)controller.Loops.Count / Loop_Amount_Per_Sheet));
                    for (int i = 0; i < loopSheetAmount; i++)
                    {
                        lstSheetNames.Add(controller.Name + "-回路分组" + (i + 1).ToString());
                    }
                    if (controller.StandardConfig.Count > 0)
                    {
                        lstSheetNames.Add(controller.Name + "-标准组态");
                    }
                    if (controller.MixedConfig.Count > 0)
                    {
                        lstSheetNames.Add(controller.Name + "-混合组态");
                    }
                    if (controller.GeneralConfig.Count > 0)
                    {
                        lstSheetNames.Add(controller.Name + "-通用组态");
                    }
                    if (controller.ControlBoard.Count > 0)
                    {
                        lstSheetNames.Add(controller.Name + "-网络手动盘");
                    }
                }
                excelService.CreateExcelSheets(lstSheetNames);

                ControllerOperationCommon controllerOperator = new ControllerOperationCommon();
                controllerOperator.SetDefaultExcelStyle(ref excelService); //取得默认EXCEL样式

                excelService.RowHeight = (short)20;                        //到下一个高度设置前,使用该高度
                excelService.SetCellValue(lstSheetNames[0], 0, 0, project.Name, CellStyleType.Caption);
                excelService.RowHeight = (short)15;
                int startRowIndex = 1; //开始行
                int endRowIndex   = 0; //结束行
                foreach (var info in lstSummaryInfo)
                {
                    endRowIndex++;
                    //info.name格式:summary.Name = "控制器:控制器名(控制器类型,器件长度)-机号:001";
                    startRowIndex = endRowIndex;
                    string strControllerName = "";
                    string strControllerType = "";
                    string strControllerDeviceAddressLength = "";
                    string strControllerMachineNumber       = "";
                    int    startIndex = info.Name.IndexOf(':') + 1;
                    int    endIndex   = info.Name.IndexOf('[');
                    if (startIndex < endIndex)
                    {
                        strControllerName = info.Name.Substring(startIndex, endIndex - startIndex);
                    }
                    startIndex = info.Name.IndexOf('[') + 1;
                    endIndex   = info.Name.IndexOf(',');
                    if (startIndex < endIndex)
                    {
                        strControllerType = info.Name.Substring(startIndex, endIndex - startIndex);
                    }

                    startIndex = info.Name.IndexOf(',') + 1;
                    endIndex   = info.Name.IndexOf(']');
                    if (startIndex < endIndex)
                    {
                        strControllerDeviceAddressLength = info.Name.Substring(startIndex, endIndex - startIndex);
                    }
                    startIndex = info.Name.LastIndexOf(':') + 1;
                    if (startIndex != -1)
                    {
                        strControllerMachineNumber = info.Name.Substring(startIndex);
                    }

                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 0, strControllerName, CellStyleType.Data);
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 1, "类型", CellStyleType.Data);
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 2, strControllerType, CellStyleType.Data);
                    endRowIndex++;
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 0, null, CellStyleType.Data);
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 1, "机号", CellStyleType.Data);
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 2, strControllerMachineNumber, CellStyleType.Data);
                    endRowIndex++;
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 0, null, CellStyleType.Data);
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 1, "器件长度", CellStyleType.Data);
                    excelService.SetCellValue(lstSheetNames[0], endRowIndex, 2, strControllerDeviceAddressLength + "位", CellStyleType.Data);
                    for (int i = 0; i < info.ChildNodes.Count; i++)
                    {
                        if (info.ChildNodes[i].Name != "设备类型")
                        {
                            endRowIndex++;
                            excelService.SetCellValue(lstSheetNames[0], endRowIndex, 0, null, CellStyleType.Data);
                            excelService.SetCellValue(lstSheetNames[0], endRowIndex, 1, info.ChildNodes[i].Name + "数量", CellStyleType.Data);
                            excelService.SetCellValue(lstSheetNames[0], endRowIndex, 2, info.ChildNodes[i].Number.ToString(), CellStyleType.Data);
                        }
                    }
                    mergeCellRange = new MergeCellRange();
                    mergeCellRange.FirstRowIndex    = startRowIndex;
                    mergeCellRange.LastRowIndex     = endRowIndex;
                    mergeCellRange.FirstColumnIndex = 0;
                    mergeCellRange.LastColumnIndex  = 0;
                    lstMergeCellRange.Add(mergeCellRange);
                }
                excelService.SetColumnWidth(lstSheetNames[0], 1, 15f);
                excelService.SetMergeCells(lstSheetNames[0], lstMergeCellRange);//设置"摘要信息"合并单元格
                sheetNames = lstSheetNames;
            }
            catch (Exception ex)
            {
                sheetNames = lstSheetNames;
                return(false);
            }
            return(true);
        }
コード例 #18
0
        /// <summary>
        /// 将项目文件发布为EXCEL文档
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public bool ExportProjectToExcel(ProjectModel project, string strFilePath, IFileService fileService)
        {
            if (project == null)
            {
                return(false);
            }
            try
            {
                EXCELVersion version = EXCELVersion.EXCEL2003;
                strFilePath += "\\" + project.Name + ".xls";
                IExcelService excelService          = ExcelServiceManager.GetExcelService(version, strFilePath, fileService);
                List <string> sheetNames            = new List <string>();
                const int     Loop_Amount_Per_Sheet = 8;
                GenerateExcelSummarySheet(project, ref excelService, out sheetNames);
                ControllerManager controllerManager = new ControllerManager();
                controllerManager.InitializeAllControllerOperation(null);

                //生成“项目摘要”信息


                foreach (var controller in project.Controllers)
                {
                    IControllerOperation controllerOperation = controllerManager.GetController(controller.Type);

                    int loopSheetAmount = Convert.ToInt32(Math.Ceiling((float)controller.Loops.Count / Loop_Amount_Per_Sheet));
                    int loopStartIndex  = 0;//记录每个Sheet页内初始索引号
                    for (int i = 0; i < loopSheetAmount; i++)
                    {
                        string           loopName     = controller.Name + "-回路分组" + (i + 1).ToString();
                        int              loopEndIndex = (i + 1) * Loop_Amount_Per_Sheet;
                        List <LoopModel> lstLoops     = new List <LoopModel>();
                        for (int j = loopStartIndex; j < loopEndIndex; j++)
                        {
                            //loopStartIndex++;
                            if (j >= controller.Loops.Count) //超过最大回路数
                            {
                                break;
                            }
                            lstLoops.Add(controller.Loops[j]);
                        }
                        controllerOperation.ExportLoopDataToExcel(ref excelService, lstLoops, loopName);
                        lstLoops.Clear();
                    }
                    if (controller.StandardConfig.Count > 0)
                    {
                        string strSheetName = controller.Name + "-标准组态";
                        controllerOperation.ExportStandardLinkageDataToExcel(ref excelService, controller.StandardConfig, strSheetName);
                    }
                    if (controller.MixedConfig.Count > 0)
                    {
                        string strSheetName = controller.Name + "-混合组态";
                        controllerOperation.ExportMixedLinkageDataToExcel(ref excelService, controller.MixedConfig, strSheetName);
                    }
                    if (controller.GeneralConfig.Count > 0)
                    {
                        string strSheetName = controller.Name + "-通用组态";
                        controllerOperation.ExportGeneralLinkageDataToExcel(ref excelService, controller.GeneralConfig, strSheetName);
                    }
                    if (controller.ControlBoard.Count > 0)
                    {
                        string strSheetName = controller.Name + "-网络手动盘";
                        controllerOperation.ExportManualControlBoardDataToExcel(ref excelService, controller.ControlBoard, strSheetName);
                    }
                }
                excelService.SaveToFile();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }