Beispiel #1
0
        /// <summary>
        /// 添加外围设备按钮添加事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addNewDevButton_Click(object sender, EventArgs e)
        {
            DevInfInitDialog devInfInitDialog = new DevInfInitDialog();

            devInfInitDialog.ShowDialog();  //获得这个新增设备的名字和基地址(后期可以添加多个同类设备)
            if (devInfInitDialog.baseAddrNameResult == "有内鬼")
            {
                return;
            }                                                             //有内鬼就是前面的设置有错误,所以不能添加
            DevInf newDevInf = new DevInf(devInfInitDialog.baseAddrNameResult, devInfInitDialog.baseAddrResult);

            MakeNewDevInfForm(newDevInf, "new" + devInfNum.ToString()); //尤其发现这个new其实没什么用了
            ALLDevInfFormHide();                                        //所有设备信息隐藏
            devInfSet.Add(newDevInf);                                   //添加这个新的设备信息

            if (showDevInfIndex != -1)
            {
                devInfSet[showDevInfIndex].Hide(); //这个if没必要存在,貌似
            }
            newDevInf.Show();                      //显示这个新的

            //关于设备信息集合的消息的更新
            selectedDevCheckedListBox.Items.Add(devInfInitDialog.baseAddrNameResult);
            MakeNewRadioButton(devInfInitDialog.baseAddrNameResult);
            devInfNum++;
            showDevInfIndex = showRadioButtonSet.Count - 1;
        }
Beispiel #2
0
        /// <summary>
        /// 读取文件按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void readFileButton_Click(object sender, EventArgs e)
        {
            if (readFileDir == "" || !File.Exists(readFileDir))  //文件路径 和 文件不存在的话
            {
                if (!ReadFileDirSelect())
                {
                    return;
                }
            }

            string fileContent = "";
            //文件流操作
            FileStream mouldCode;

            mouldCode = new FileStream(readFileDir, FileMode.Open, FileAccess.Read);
            StreamReader readFile = new StreamReader(mouldCode);

            //读取文件路径和保存文件路径和生成代码目录的存储
            fileContent = readFile.ReadLine();
            fileContent = GetValueInFileString(fileContent);
            readFileDir = fileContent == "%" ? "" : fileContent;

            fileContent = readFile.ReadLine();
            fileContent = GetValueInFileString(fileContent);
            saveFileDir = fileContent == "%" ? "" : fileContent;

            fileContent     = readFile.ReadLine();
            fileContent     = GetValueInFileString(fileContent);
            generateCodeDir = fileContent == "%" ? "" : fileContent;

            fileContent = readFile.ReadToEnd();

            readFile.Close();
            mouldCode.Close();
            if (fileContent == "")
            {
                MessageBox.Show("错误,空文件!");
                return;
            }

            //清空原来的panel和checkListBox和devInfSet的信息
            selectedDevCheckedListBox.Items.Clear();
            for (int i = 0; i < showRadioButtonSet.Count; i++)
            {
                showRadioButtonSet[i].Hide();
                showRadioButtonSet[i].Dispose();
            }
            showRadioButtonSet.Clear();
            for (int i = 0; i < devInfSet.Count; i++)
            {
                devInfSet[i].Hide();
                devInfSet[i].Dispose();
            }
            devInfSet.Clear();
            //开始分析标签化内容
            string showTextGet           = "";
            int    devInfLabelStartIndex = 0;
            int    devInfLabelEndIndex   = fileContent.IndexOf("[#devInf]");

            while (true)
            {
                DevInf newDevInf = new DevInf();
                MakeNewDevInfForm(newDevInf, "newDevInf" + devInfSet.Count);  //创建新的设备信息控件

                //拿到[devInf]和[#devInf]之间第一个baseAddr和baseAddrName,用来做显示
                //9是baseAddr=这九个字符
                //2是指代\n\t
                showTextGet = fileContent.Substring(fileContent.IndexOf("baseAddr", devInfLabelStartIndex) + 9, fileContent.IndexOf("baseAddrName", devInfLabelStartIndex) - 2 - fileContent.IndexOf("baseAddr", devInfLabelStartIndex) - 9);
                MakeNewRadioButton(showTextGet);
                selectedDevCheckedListBox.Items.Add(showTextGet);

                //获取设备信息设置要的也就是[devInf]和[#devInf]之间的内容 注意是之间
                //10是跳过这10个字符[devInf]\n\t
                //1是\t[#devInf]这里的\t
                newDevInf.ReadFile_DevInf(fileContent.Substring(devInfLabelStartIndex + 10, devInfLabelEndIndex - devInfLabelStartIndex - 1 - 10));

                //找下一个[devInf][#defInf]
                devInfLabelStartIndex = fileContent.IndexOf("[devInf]", devInfLabelEndIndex + 2);
                devInfSet.Add(newDevInf);

                if (devInfLabelStartIndex == -1)
                {
                    break;
                }
                devInfLabelEndIndex = fileContent.IndexOf("[#devInf]", devInfLabelStartIndex);
            }
            if (devInfSet.Count != 0)
            {
                //显示第一个设备信息
                ALLDevInfFormHide();
                devInfSet[0].Show();
                showRadioButtonSet[0].Checked = true;
                devInfNum       = devInfSet.Count;
                showDevInfIndex = 0;
            }
        }
Beispiel #3
0
 /// <summary>
 /// 新的设备信息显示控件创建,并且固定他的位置是12,106
 /// </summary>
 /// <param name="newDevInf"></param>
 /// <param name="devInfName"></param>
 private void MakeNewDevInfForm(DevInf newDevInf, string devInfName)
 {
     newDevInf.Location = new System.Drawing.Point(12, 106);
     newDevInf.Name     = devInfName;
     this.Controls.Add(newDevInf);
 }