コード例 #1
0
        //20170929 leo: undo redo 用
        public void readProgramR8(R8 r8)
        {
            //清空畫面
            foreach (Button b in buttons)
            {
                b.Dispose();
            }
            buttons.Clear();
            buttonsLocationY = buttonStartY;

            //標籤也要清空
            foreach (Label l in lineLabels)
            {
                l.Dispose();
            }
            lineLabels.Clear();


            //20170322 leo: 增加[New File] 模式,清空 variable 後就 return
            if (r8 == null)
            {
                formMain.formVariables.showVariables(null);
                formMain.formFunction.showFunction(null);
                R8.clearLogBox();
                this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
                return;
            }
            Function        function     = null;
            List <Function> functionList = new List <Function>();

            //改為 sort 完依 posY 排序再放 button
            for (int i = 0; i < r8.getFunctionSnLast(); i++)
            {
                function = r8.functions[i];
                if (function == null)
                {
                    continue;
                }
                functionList.Add(function);
            }

            functionList.Sort(delegate(Function i1, Function i2) { return(i1.posY.CompareTo(i2.posY)); });
            for (int i = 0; i < functionList.Count; i++)
            {
                function = functionList.ElementAt(i);
                addButton(getFunctionShowText(function), function.sn, function.enable);
                function.posY = buttons.Count;//讀出 button 後,應該要再依實際 button 位置進行 posY排序
            }
            this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
            formMain.formVariables.showVariables(null);
            formMain.formFunction.showFunction(null);
            this.Invalidate();
            return;
        }
コード例 #2
0
 private void buttonClear_Click(object sender, EventArgs e)
 {
     R8.clearLogBox();
 }
コード例 #3
0
        public void readProgramXml(string path)
        {
            //清空畫面
            foreach (Button b in buttons)
            {
                b.Dispose();
            }
            buttons.Clear();
            buttonsLocationY = buttonStartY;

            //標籤也要清空
            foreach (Label l in lineLabels)
            {
                l.Dispose();
            }
            lineLabels.Clear();


            //20170322 leo: 增加[New File] 模式,清空 variable 後就 return
            if (path == null)
            {
                FormMain.r8 = new R8();
                formMain.formVariables.showVariables(null);
                formMain.formFunction.showFunction(null);
                R8.clearLogBox();
                this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
                return;
            }
            //20170322 end

            //讀 xml
            //20180212 新的 r6 不是純 xml 了,前面會有額外的字串 # XXXXX
            //總之改用 Stream 先讀一遍,把是 # 開頭的砍了

            int    counter = 0;
            string line;

            System.IO.StreamReader file          = new System.IO.StreamReader(path);
            StringBuilder          stringBuilder = new StringBuilder();

            while ((line = file.ReadLine()) != null)
            {
                // MessageBox.Show("Line " + counter + " = " + line);
                if (line.Length > 1)
                {
                    if (line[0] != '#')
                    {
                        stringBuilder.Append(line);
                    }
                }
                counter++;
            }
            FormMain.r8 = new R8(XElement.Parse(stringBuilder.ToString()));
            file.Close();
            stringBuilder.Clear();

            //FormMain.r8 = new R8(XElement.Load(path));

            Function        function     = null;
            List <Function> functionList = new List <Function>();

            //改為 sort 完依 posY 排序再放 button
            for (int i = 0; i < FormMain.r8.getFunctionSnLast(); i++)
            {
                function = FormMain.r8.functions[i];
                if (function == null)
                {
                    continue;
                }
                functionList.Add(function);
                //addButton("[" + function.sn + "] [" + function.name + "]", function.sn);
            }

            functionList.Sort(delegate(Function i1, Function i2) { return(i1.posY.CompareTo(i2.posY)); });
            for (int i = 0; i < functionList.Count; i++)
            {
                function = functionList.ElementAt(i);
                //20170309 leo: 依早上討論,顯示格式修改 ImageOpen 1 [remark][disabled]
                //addButton("[" + function.sn + "] [" + function.name + "]", function.sn, function.enable);

                /*
                 * if (function.remark.Length > 0)
                 * {
                 *  addButton(function.name + " " + function.sn + " " + "[" + function.remark + "]" , function.sn, function.enable);
                 * }
                 * else {
                 *  addButton(function.name + " " + function.sn + " ", function.sn, function.enable);
                 * }*/
                addButton(getFunctionShowText(function), function.sn, function.enable);
                //20170309 leo end
                function.posY = buttons.Count;//讀出 button 後,應該要再依實際 button 位置進行 posY排序
            }
            this.Text = Program_Functions + "  " + buttons.Count + " of " + FormMain.r8.getFunctionsCount();
            //20170125 leo: 讀檔案後 show variable
            formMain.formVariables.showVariables(null);
            //20170208 leo: 讀檔案後 formFunction 清空
            formMain.formFunction.showFunction(null);
            this.Invalidate();
            Program.clearRecord();
            Program.recordProgram(FormMain.r8, formMain.toolStripMenuItemUndo, formMain.toolStripMenuItemRedo);
            //Program.recordProgram(FormMain.r8);
            return;
        }