Пример #1
0
        private void OnMenuFile_Open(object sender, EventArgs e)
        {
            OpenFileDialog sFD = new OpenFileDialog();

            sFD.Title            = "保存文件";
            sFD.ShowHelp         = true;
            sFD.Filter           = "工程文件(*.cfg)|*.cfg"; //过滤格式
            sFD.FilterIndex      = 1;                   //格式索引
            sFD.RestoreDirectory = false;
            sFD.InitialDirectory = "c:\\";              //默认路径
            if (sFD.ShowDialog() == DialogResult.OK)
            {
                string filePath          = sFD.FileName;
                List <DeviceForXml> list = ReadXml(filePath);
                foreach (DeviceForXml item in list)
                {
                    DeviceMessage devMsg = item.devMsg;
                    Device429     device = new Device429();
                    device.BoardNo      = devMsg.BoardNo;
                    device.BoardType    = devMsg.BoardType;
                    device.ChannelCount = devMsg.ChannelCount;
                    device.ChannelType  = devMsg.ChannelType;
                    device.DevID        = devMsg.DevID;
                    device.filterStr    = devMsg.filter;
                    TopMenuVM topMenuVM = new TopMenuVM(device);
                    topMenuVM.OpenSetting();//将xml初始化设备及软件
                }
            }
        }
Пример #2
0
        private void SaveObject(object sender, EventArgs e)
        {
            if (treeViewContainer.flag == false)
            {
                MessageBox.Show("当前没有设备,无需保存工程!");
                return;
            }
            SaveFileDialog sFD = new SaveFileDialog();

            sFD.Title            = "保存文件";
            sFD.ShowHelp         = true;
            sFD.Filter           = "工程文件(*.cfg)|*.cfg"; //过滤格式
            sFD.FilterIndex      = 1;                   //格式索引
            sFD.RestoreDirectory = false;
            sFD.InitialDirectory = "c:\\";              //默认路径
            if (sFD.ShowDialog() == DialogResult.OK)
            {
                //获得保存文件的路径
                string              filePath     = sFD.FileName;
                string              xmlResult    = string.Empty;
                DeviceForXml        deviceForXml = new DeviceForXml();
                List <DeviceForXml> list         = new List <DeviceForXml>();
                //遍历整个tree获取device
                foreach (var item in treeViewContainer.treeView.Nodes)
                {
                    TreeNode treeNode = (TreeNode)item;
                    foreach (var A429Dev in treeNode.Nodes)
                    {
                        TreeNode treeNodeA429Dev = (TreeNode)A429Dev;
                        foreach (var treeNodes in treeNodeA429Dev.Nodes)
                        {
                            TreeNode treeNodes429 = (TreeNode)treeNodes;
                            //string[] pathParts = treeNodes429.Name.Split('_');
                            Device429 _device429 = App.Instance.FlightBusManager.Bus429.GetSpecificItem(treeNodes429.Name);
                            TopMenuVM topMenuVM  = new TopMenuVM(_device429);
                            topMenuVM.SaveSetting();
                            deviceForXml = topMenuVM._deviceInfo;
                            list.Add(deviceForXml);
                        }
                    }
                }
                xmlResult = SimpleSerializer.Serialize <List <DeviceForXml> >(list);
                //保存
                using (FileStream fsWrite = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    byte[] buffer = Encoding.Default.GetBytes(xmlResult);
                    fsWrite.Write(buffer, 0, buffer.Length);
                }
            }
        }