コード例 #1
0
ファイル: FormVariable.cs プロジェクト: hebskjcc/OpenR8-1
        private void FormVariable_Load(object sender, EventArgs e)
        {
            formMain = (FormMain)this.MdiParent;
            //comboBox1.DataSource = Enum.GetValues(typeof(Data.VariableType));
            //comboBox1.DataSource = R8.typeArray;
            int variableNum = R8.GetVariableNum();

            //MessageBox.Show("variableNum = " + variableNum);
            variableNum = R8.GetVariableNum();
            StringBuilder str = new StringBuilder(R7.STRING_SIZE);

            string[] typeArray;
            if (variableNum > 0)
            {
                typeArray = new string[variableNum];
                for (int i = 0; i < variableNum; i++)
                {
                    R8.GetVariableType(str, R7.STRING_SIZE, i);
                    typeArray[i] = str.ToString();
                    // MessageBox.Show("typeArray" + i + " = " + str);
                }
                comboBox1.DataSource = typeArray;
            }
            else
            {
                //如果沒讀到,用預設值
                comboBox1.DataSource = new string[] { "int", "bool", "float", "double", "string", "image", "json" };
            }

            //20170327 Variable 沒 SN ,不顯示視窗元件。
            if (variableSn == -1 || variableSn == 0)
            {
                comboBox1.Visible     = false;
                label1.Visible        = false;
                labelValue.Visible    = false;
                label3.Visible        = false;
                label4.Visible        = false;
                labelSn.Visible       = false;
                textBoxName.Visible   = false;
                label5.Visible        = false;
                textBoxRemark.Visible = false;
                buttonDelete.Visible  = false;
            }
            else
            {
                comboBox1.Visible     = true;
                label1.Visible        = true;
                labelValue.Visible    = true;
                label3.Visible        = true;
                label4.Visible        = true;
                labelSn.Visible       = true;
                textBoxName.Visible   = true;
                label5.Visible        = true;
                textBoxRemark.Visible = true;
                buttonDelete.Visible  = true;
            }

            str_Variable = R8.TranslationString(str_Variable);
            this.Text    = str_Variable;
        }
コード例 #2
0
ファイル: FormVariable.cs プロジェクト: hebskjcc/OpenR8-1
        //20170327 leo: 依今天信件增加 [選到 variable 時,自動 focus 到 Value] 功能。
        public void focusToValueBox()
        {
            //20170531 leo: 依信件指示改為[Edit 時,如果 variable name 是預設值,則 focus 到 Variable From Name ,如果 variable name 有改過,則 focus 到 Variable From Value ]
            if (variableSn != -1 && variableSn != 0)
            {
                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[variableSn].type);

                if ((str.ToString() + variableSn.ToString()).Equals(FormMain.r8.variables[variableSn].name))
                {
                    textBoxName.Focus();
                }
                else if (valueComboBox != null)
                {
                    valueComboBox.Focus();
                }
                else if (valueNumericUpDown != null)
                {
                    valueNumericUpDown.Focus();
                }
                else if (valueTextBox != null)
                {
                    valueTextBox.Focus();
                }


                preVariableType = str.ToString();

                str.Clear();
            }



            return;
        }
コード例 #3
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public static int getVariableTypeByString(string type)
        {
            int           res         = 0;
            int           variableNum = R8.GetVariableNum();
            StringBuilder str         = new StringBuilder(R7.STRING_SIZE);

            for (int i = 0; i < variableNum; i++)
            {
                R8.GetVariableType(str, R7.STRING_SIZE, i);
                if (str.ToString().Equals(type))
                {
                    res = i;
                    break;
                }
            }
            str.Clear();
            return(res);
        }
コード例 #4
0
ファイル: FormVariables.cs プロジェクト: hebskjcc/OpenR8-1
        //20170327 Functions Variables 方塊不顯示 SN
        // Variables 的名稱顯示分散太多地方,把它都整合到這邊
        private string getVariableShowText(Variable variable)
        {
            string returnStr = "";

            if (variable.sn != -1 && variable.sn != 0)
            {
                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, variable.type);
                switch (str.ToString())
                {
                case "image":
                case "Image":
                case "mat":
                case "Mat":
                case "json":
                case "Json":
                case "object":
                case "Object":
                    returnStr = variable.name;
                    break;

                default:
                    if (variable.value == null || variable.value.Length == 0 || variable.value.Equals(""))
                    {
                        returnStr = variable.name;
                    }
                    else
                    {
                        returnStr = variable.name + " (" + variable.value + ")";
                    }
                    break;
                }
                str.Clear();
            }
            if (variable.remark.Length > 0)
            {
                returnStr += " (" + variable.remark + ")";
            }
            return(returnStr);
        }
コード例 #5
0
        public override string ToString()
        {
            //20170209 leo: 討論後, Mat 類型的不印 value

            /*
             * if (sn != -1)
             * {
             *  StringBuilder str = new StringBuilder(R7.STRING_SIZE);
             *  R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[sn].type);
             *  switch (str.ToString())
             *  {
             *      case "image":
             *      case "Image":
             *      case "mat":
             *      case "Mat":
             *      case "json":
             *      case "Json":
             *          return "[" + sn + "][" + name + "]";
             *          //break;
             *      default:
             *          break;
             *  }
             *  str.Clear();
             * }
             *      return "[" + sn + "][" + name + "][" + value + "]";
             */
            //20170309 leo: 依早上討論,顯示格式修改 sample path #1 [a2_sample3.png][remark]
            string returnStr = "";

            if (sn != -1 && sn != 0 && FormMain.r8.variables[sn] != null)
            {
                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[sn].type);
                switch (str.ToString())
                {
                case "image":
                case "Image":
                case "mat":
                case "Mat":
                case "json":
                case "Json":
                case "object":
                case "Object":
                    //returnStr = name + " " + sn + " ";
                    returnStr = name;
                    break;

                default:
                    //returnStr = name + " " + sn + " " + "[" + value + "]";
                    if (value == null || value.Length == 0 || value.Equals(""))
                    {
                        returnStr = name;
                    }
                    else
                    {
                        returnStr = name + " (" + value + ")";
                    }
                    break;
                }
                str.Clear();
            }

            if (remark.Length > 0)
            {
                returnStr += " (" + remark + ")";
            }
            return(returnStr);
        }
コード例 #6
0
ファイル: FormVariable.cs プロジェクト: hebskjcc/OpenR8-1
        public void showVariable(int variableSn)
        {
            //20170315 leo: 發現介面 bug :若 showVariable 運行中時,又觸發一次 showVariable ,會導致 FormVariable 介面錯亂。
            //加個 bool 變數,若 showVariable 運行中,則不再觸發
            if (isShowVariableRunning)
            {
                return;
            }
            isShowVariableRunning = true;
            //System.Console.WriteLine("showVariable variableSn " + variableSn + ", " + this.variableSn);
            if (this.variableSn != variableSn)
            {
                //variableSn 更換, setVariable
                // setVariable();//20170214 leo: 改為 任何一個FormVariable 的零件 unfocus 時觸發
            }
            this.variableSn = variableSn;
            if (variableSn == -1 || variableSn == 0)
            {
                textBoxName.Text             = "";
                labelSn.Text                 = "";
                this.comboBox1.SelectedIndex = 0;
                textBoxRemark.Text           = "";
                if (valueComboBox != null)
                {
                    valueComboBox.Dispose();
                    valueComboBox = null;
                }
                if (valueNumericUpDown != null)
                {
                    valueNumericUpDown.Dispose();
                    valueNumericUpDown = null;
                }
                if (valueTextBox != null)
                {
                    valueTextBox.Dispose();
                    valueTextBox = null;
                }

                //20170327 Variable 沒 SN ,不顯示視窗元件。
                comboBox1.Visible     = false;
                label1.Visible        = false;
                labelValue.Visible    = false;
                label3.Visible        = false;
                label4.Visible        = false;
                labelSn.Visible       = false;
                textBoxName.Visible   = false;
                label5.Visible        = false;
                textBoxRemark.Visible = false;
                buttonDelete.Visible  = false;
            }
            else
            {
                //20170327 Variable 沒 SN ,不顯示視窗元件。
                comboBox1.Visible     = true;
                label1.Visible        = true;
                labelValue.Visible    = true;
                label3.Visible        = true;
                label4.Visible        = true;
                labelSn.Visible       = true;
                textBoxName.Visible   = true;
                label5.Visible        = true;
                textBoxRemark.Visible = true;
                buttonDelete.Visible  = true;

                textBoxName.Text = FormMain.r8.variables[variableSn].name;
                labelSn.Text     = FormMain.r8.variables[variableSn].sn.ToString();
                //20170117 leo: type 改為不鎖定
                //this.comboBox1.Enabled = true;
                this.comboBox1.SelectedIndex = FormMain.r8.variables[variableSn].type;
                //this.comboBox1.Enabled = false;
                value = FormMain.r8.variables[variableSn].value;
                this.textBoxRemark.Text = FormMain.r8.variables[variableSn].remark;

                //如果 type 為 image ,不顯示 value
                if (FormMain.r8.variables[variableSn].type == R8.getVariableTypeByString("image") ||
                    FormMain.r8.variables[variableSn].type == R8.getVariableTypeByString("json") ||
                    FormMain.r8.variables[variableSn].type == R8.getVariableTypeByString("object")
                    )
                {
                    FormMain.r8.variables[variableSn].value = "";
                    //this.textBoxValue.Visible = false;
                }
                else
                {
                    //this.textBoxValue.Visible = true;
                }
                //20170120 leo value 欄位依 type 切換元件。 textBox / comboBox / domainUpDown
                Point valueLocation = new Point(this.labelValue.Location.X + this.labelValue.Width + 10, this.labelValue.Location.Y);



                StringBuilder str = new StringBuilder(R7.STRING_SIZE);
                R8.GetVariableType(str, R7.STRING_SIZE, FormMain.r8.variables[variableSn].type);

                //20170330 leo: 切換元件時,若[type沒換]則不進行切換 (避免設置 value,按 enter 然後focus跳掉)
                bool needChangeValueBox = true;
                if (preVariableType.Equals(str.ToString()))
                {
                    needChangeValueBox = false;
                }

                preVariableType = str.ToString();

                if (needChangeValueBox)
                {
                    if (valueComboBox != null)
                    {
                        valueComboBox.Dispose();
                        valueComboBox = null;
                    }
                    if (valueNumericUpDown != null)
                    {
                        valueNumericUpDown.Dispose();
                        valueNumericUpDown = null;
                    }
                    if (valueTextBox != null)
                    {
                        valueTextBox.Dispose();
                        valueTextBox = null;
                    }
                }
                switch (str.ToString())
                {
                case "bool":
                case "Bool":
                case "boolean":
                case "Boolean":
                    //comboBox
                {
                    if (needChangeValueBox || valueComboBox == null)
                    {
                        valueComboBox = new ComboBox();

                        valueComboBox.Items.AddRange(new string[] { "False", "True" });
                        int res = 0;
                        if (!Int32.TryParse(value, out res))
                        {
                            res = 0;
                        }
                        if (res >= 1)
                        {
                            res = 1;
                        }
                        else
                        {
                            res = 0;
                        }
                        valueComboBox.SelectedIndex         = res;
                        valueComboBox.Location              = valueLocation;
                        valueComboBox.SelectedIndexChanged += valueComboBox_SelectedIndexChanged;
                        //valueComboBox.LostFocus += buttonSet_Click;
                        valueComboBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        valueComboBox.Leave   += new System.EventHandler(this.focus_Leave);
                        valueComboBox.TabIndex = 4;
                        this.Controls.Add(valueComboBox);
                    }
                    else
                    {
                        int res = 0;
                        if (!Int32.TryParse(value, out res))
                        {
                            res = 0;
                        }
                        if (res >= 1)
                        {
                            res = 1;
                        }
                        else
                        {
                            res = 0;
                        }
                        valueComboBox.SelectedIndex = res;
                    }
                }
                break;

                case "double":
                case "Double":
                    //numericUpDown
                {
                    if (needChangeValueBox || valueNumericUpDown == null)
                    {
                        valueNumericUpDown               = new NumericUpDown();
                        valueNumericUpDown.Maximum       = (decimal)int.MaxValue;
                        valueNumericUpDown.Minimum       = (decimal)int.MinValue;
                        valueNumericUpDown.Increment     = (decimal)0.5;
                        valueNumericUpDown.DecimalPlaces = 3;
                        valueNumericUpDown.Text          = value;
                        valueNumericUpDown.Location      = valueLocation;
                        valueNumericUpDown.TextChanged  += valueNumericUpDown_TextChanged;
                        valueNumericUpDown.Leave        += new System.EventHandler(this.focus_Leave);
                        valueNumericUpDown.TabIndex      = 4;
                        valueNumericUpDown.KeyDown      += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        //valueNumericUpDown.LostFocus += buttonSet_Click;
                        this.Controls.Add(valueNumericUpDown);
                    }
                    else
                    {
                        valueNumericUpDown.Text = value;
                    }
                }
                break;

                case "float":
                case "Float":
                    //numericUpDown
                {
                    if (needChangeValueBox || valueNumericUpDown == null)
                    {
                        valueNumericUpDown               = new NumericUpDown();
                        valueNumericUpDown.Maximum       = (decimal)int.MaxValue;
                        valueNumericUpDown.Minimum       = (decimal)int.MinValue;
                        valueNumericUpDown.Increment     = (decimal)0.5;
                        valueNumericUpDown.DecimalPlaces = 3;
                        valueNumericUpDown.Text          = value;
                        valueNumericUpDown.Location      = valueLocation;
                        valueNumericUpDown.TextChanged  += valueNumericUpDown_TextChanged;
                        valueNumericUpDown.Leave        += new System.EventHandler(this.focus_Leave);
                        valueNumericUpDown.TabIndex      = 4;
                        //valueNumericUpDown.LostFocus += buttonSet_Click;
                        valueNumericUpDown.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        this.Controls.Add(valueNumericUpDown);
                    }
                    else
                    {
                        valueNumericUpDown.Text = value;
                    }
                }
                break;

                case "image":
                case "Image":
                case "mat":
                case "Mat":
                case "json":
                case "Json":     //20170216 新增 type: json
                case "object":
                case "Object":   //20170612 新增 type: object
                    //none

                    break;

                case "int":
                case "Int":
                    //numericUpDown
                {
                    if (needChangeValueBox || valueNumericUpDown == null)
                    {
                        valueNumericUpDown              = new NumericUpDown();
                        valueNumericUpDown.Maximum      = (decimal)int.MaxValue;
                        valueNumericUpDown.Minimum      = (decimal)int.MinValue;
                        valueNumericUpDown.Increment    = (decimal)1;
                        valueNumericUpDown.Text         = value;
                        valueNumericUpDown.Location     = valueLocation;
                        valueNumericUpDown.TextChanged += valueNumericUpDown_TextChanged;
                        valueNumericUpDown.Leave       += new System.EventHandler(this.focus_Leave);
                        valueNumericUpDown.TabIndex     = 4;
                        // valueNumericUpDown.LostFocus += buttonSet_Click;
                        valueNumericUpDown.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        this.Controls.Add(valueNumericUpDown);
                    }
                    else
                    {
                        valueNumericUpDown.Text = value;
                    }
                }
                break;

                case "string":
                case "String":
                case "str":
                case "Str":
                    //textBox
                {
                    if (needChangeValueBox || valueTextBox == null)
                    {
                        valueTextBox              = new TextBox();
                        valueTextBox.Text         = value;
                        valueTextBox.Location     = valueLocation;
                        valueTextBox.Width        = textBoxName.Width;  // 20170316_ 2. Value 的文字框寬度拉到跟 Name 的文字框相同。
                        valueTextBox.TextChanged += valueTextBox_TextChanged;
                        valueTextBox.Leave       += new System.EventHandler(this.focus_Leave);
                        valueTextBox.TabIndex     = 4;
                        //valueTextBox.Multiline = true;
                        valueTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);
                        // valueTextBox.LostFocus += buttonSet_Click;
                        this.Controls.Add(valueTextBox);
                    }
                    else
                    {
                        valueTextBox.Text = value;
                    }
                }
                break;
                }
                str.Clear();
            }
            isShowVariableRunning = false;
            return;
        }
コード例 #7
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public static void writeProgramXml(string path)
        {
            XElement xml = new XElement("program");

            //根據 http://stackoverflow.com/questions/27548227/add-new-xelements-with-new-line-in-xdocument-with-preservewhitespace-loadoptions
            //換行需要自己加...
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("version", FormMain.r8.getVersion()));
            xml.Add(Environment.NewLine);
            //xml.Add(new XElement("workSpacePath", FormMain.workSpacePath));//20170120 leo: 寫檔時,應該也把 workSpacePath 寫進去
            //xml.Add(Environment.NewLine);//20170306 leo: 改為不寫入 workSpacePath
            xml.Add(new XElement("functionSnMax", FormMain.r8.getFunctionSnMax()));
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("variableSnMax", FormMain.r8.getVariableSnMax()));
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("functionSnCount", FormMain.r8.getFunctionsCount()));
            xml.Add(Environment.NewLine);
            xml.Add(new XElement("variableSnCount", FormMain.r8.getVariablesCount()));
            xml.Add(Environment.NewLine);

            XElement functionsXml = new XElement("functions");

            xml.Add(functionsXml);
            xml.Add(Environment.NewLine);
            functionsXml.Add(Environment.NewLine);

            int      i, j;
            Function function;
            XElement functionXml = null;

            for (i = 0; i < FormMain.r8.getFunctionSnLast(); i++)
            {
                function = FormMain.r8.functions[i];
                if (function == null)
                {
                    continue;
                }
                functionXml = new XElement("function");
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("sn", function.sn));
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("name", function.name));
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("posY", function.posY));
                functionXml.Add(Environment.NewLine);
                if (function.enable)
                {
                    functionXml.Add(new XElement("enable", "1"));
                }
                else
                {
                    functionXml.Add(new XElement("enable", "0"));
                }
                functionXml.Add(Environment.NewLine);
                functionXml.Add(new XElement("remark", function.remark));
                functionXml.Add(Environment.NewLine);
                if (R8.HAS_POS)
                {
                    functionXml.Add(new XElement("posX", function.getPosX()));
                    functionXml.Add(Environment.NewLine);
                    functionXml.Add(new XElement("posY", function.getPosY()));
                    functionXml.Add(Environment.NewLine);
                }
                for (j = 0; j < function.parameters.Count; j++)
                {
                    functionXml.Add(new XElement("variableSn", function.parameters.ElementAt(j).variableSn));
                    functionXml.Add(Environment.NewLine);
                }
                functionsXml.Add(functionXml);
                functionsXml.Add(Environment.NewLine);
            }


            XElement variablesXml = new XElement("variables");

            xml.Add(variablesXml);
            xml.Add(Environment.NewLine);
            variablesXml.Add(Environment.NewLine);
            StringBuilder str = new StringBuilder(R7.STRING_SIZE);
            Variable      variable;
            XElement      variableXml = null;

            for (i = 0; i < FormMain.r8.getVariableSnLast(); i++)
            {
                variable = FormMain.r8.variables[i];
                if (variable == null)
                {
                    continue;
                }
                variableXml = new XElement("variable");
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("sn", variable.sn));
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("name", variable.name));
                variableXml.Add(Environment.NewLine);
                //20170119 leo 今天討論後, type 要改為 string 小寫
                //variableXml.Add(new XElement("type", variable.type));
                //variableXml.Add(new XElement("type", Enum.GetName(typeof(Variable.VariableType), variable.type).ToLower()));
                //variableXml.Add(new XElement("type", R8.typeArray[variable.type].ToLower()));
                R8.GetVariableType(str, R7.STRING_SIZE, variable.type);
                variableXml.Add(new XElement("type", str));
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("value", variable.value));
                variableXml.Add(Environment.NewLine);
                variableXml.Add(new XElement("remark", variable.remark));
                variableXml.Add(Environment.NewLine);
                variablesXml.Add(variableXml);
                variablesXml.Add(Environment.NewLine);
            }
            str.Clear();
            //xml.Save(path);
            //20180212 現在這邊要求要加標頭:

            /*
             #R7
             # -*- coding: utf-8 -*-
             # R7 version 1.8.6
             */
            //改用 stream
            StreamWriter streamWriter = new StreamWriter(path);

            streamWriter.WriteLine("#!R7");
            streamWriter.WriteLine("# -*- coding: utf-8 -*-");
            StringBuilder sb = new StringBuilder(1024);

            R7.GetVersion(sb, 1024);
            streamWriter.WriteLine("# R7 version " + sb.ToString());
            sb.Clear();
            xml.Save(streamWriter);
            streamWriter.Close();
            return;
        }
コード例 #8
0
ファイル: R8.cs プロジェクト: hebskjcc/OpenR8-1
        public R8(XElement xml)
        {
            XElement element = xml.Element("functionSnCount");
            //20170626 leo:加入舊版支援
            bool isOldVerson = false;

            if (element == null)
            {
                //此時判定為舊版
                isOldVerson = true;
                element     = xml.Element("intentSnCount");
                if (!Int32.TryParse(element.Value, out functionSnCount))
                {
                    functionSnCount = 0;
                }

                element = xml.Element("dataSnCount");
                if (!Int32.TryParse(element.Value, out variableSnCount))
                {
                    variableSnCount = 0;
                }

                element = xml.Element("intentSnMax");
                if (!Int32.TryParse(element.Value, out functionSnMax))
                {
                    functionSnMax = 0;
                }

                element = xml.Element("dataSnMax");
                if (!Int32.TryParse(element.Value, out variableSnMax))
                {
                    variableSnMax = 0;
                }
            }
            else
            {
                if (!Int32.TryParse(element.Value, out functionSnCount))
                {
                    functionSnCount = 0;
                }

                element = xml.Element("variableSnCount");
                if (!Int32.TryParse(element.Value, out variableSnCount))
                {
                    variableSnCount = 0;
                }

                element = xml.Element("functionSnMax");
                if (!Int32.TryParse(element.Value, out functionSnMax))
                {
                    functionSnMax = 0;
                }

                element = xml.Element("variableSnMax");
                if (!Int32.TryParse(element.Value, out variableSnMax))
                {
                    variableSnMax = 0;
                }
            }

            element = xml.Element("version");
            version = element.Value.ToString();


            int res;
            IEnumerable <XElement> variableElements;// = xml.Element("variables").Elements("variable");

            if (isOldVerson)
            {
                variableElements = xml.Element("datas").Elements("data");
            }
            else
            {
                variableElements = xml.Element("variables").Elements("variable");
            }
            Variable      variable;
            string        tempTypeString;
            int           variableNum = R8.GetVariableNum();
            StringBuilder str         = new StringBuilder(R7.STRING_SIZE);
            int           tempInt     = -1;

            for (int i = 0; i < variableElements.Count(); i++)
            {
                variable = new Variable();
                element  = variableElements.ElementAt(i);
                if (!Int32.TryParse(element.Element("sn").Value, out res))
                {
                    res = -1;
                }
                variable.sn = res;

                /*
                 * if (!Int32.TryParse(element.Element("type").Value, out res))
                 * {
                 *  res = -1;
                 * }
                 */

                tempTypeString = element.Element("type").Value;
                tempInt        = -1;
                for (int j = 0; j < variableNum; j++)
                {
                    R8.GetVariableType(str, R7.STRING_SIZE, j);
                    //統一轉小寫再比
                    if (str.ToString().ToLower().Equals(tempTypeString.ToLower()))
                    {
                        tempInt = j;
                        break;
                    }
                }
                //System.Console.WriteLine("type: " + tempTypeString + "  value:" + tempInt);
                if (tempInt != -1)
                {
                    variable.type = tempInt;
                }
                //Variable.VariableType.String;
                variable.value         = element.Element("value").Value;
                variable.name          = element.Element("name").Value;
                variable.remark        = element.Element("remark").Value;
                variables[variable.sn] = variable;
            }
            str.Clear();

            IEnumerable <XElement> functionElements;// = xml.Element("functions").Elements("function");

            if (isOldVerson)
            {
                functionElements = xml.Element("intents").Elements("intent");
            }
            else
            {
                functionElements = xml.Element("functions").Elements("function");
            }
            IEnumerable <XElement> variableSnElements = null;
            XElement subElement;
            Function function;

            for (int i = 0; i < functionElements.Count(); i++)
            {
                function = new Function();
                element  = functionElements.ElementAt(i);
                if (!Int32.TryParse(element.Element("sn").Value, out res))
                {
                    res = -1;
                }
                function.sn         = res;
                function.name       = element.Element("name").Value;
                function.remark     = element.Element("remark").Value;
                function.parameters = Function.getFunctionParameters(function.name);

                if (element.Element("enable") != null)
                {
                    if (element.Element("enable").Value.Equals("0"))
                    {
                        function.enable = false;
                    }
                    else
                    {
                        function.enable = true;
                    }
                }
                else
                {
                    function.enable = true;
                }

                if (R8.HAS_POS)
                {
                    if (!Int32.TryParse(element.Element("posX").Value, out res))
                    {
                        res = -1;
                    }
                    function.rectangle.X = res;
                    if (!Int32.TryParse(element.Element("posY").Value, out res))
                    {
                        res = -1;
                    }
                    function.rectangle.Y = res;
                }
                else
                {
                    function.rectangle.X = 0;
                    function.rectangle.Y = function.sn * 60;
                    //20170118 leo 新的 posY
                    if (!Int32.TryParse(element.Element("posY").Value, out res))
                    {
                        res = 0;
                    }
                    function.posY = res;
                }
                functions[function.sn] = function;

                //variableSn 不分 input/ output 了,由 Function.Parameter 定義 (以後要從 json 撈)
                if (isOldVerson)
                {
                    variableSnElements = element.Elements("dataSn");
                }
                else
                {
                    variableSnElements = element.Elements("variableSn");
                }
                int j = 0;
                //20170407 leo add: 就算 supportList 沒找到目標 function name,也把 parameters variable 補齊,避免 user 開不同版本運行後, program 壞掉。
                if (variableSnElements.Count() != function.parameters.Count && function.parameters.Count == 0)
                {
                    //MessageBox.Show("Warning: function [" + function.name + "] may not in support list.");

                    for (j = 0; j < variableSnElements.Count(); j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }

                        int type = 0;
                        if (res != -1)
                        {
                            //parameter 名稱遺失了,但 variable 的 type 還是會有
                            //type = variables[res].type;
                            if (variables[res] != null)
                            {
                                type = variables[res].type;
                            }
                        }

                        Function.Parameter parameter = new Function.Parameter("unload", type);
                        parameter.option     = "IN";
                        parameter.variableSn = res;
                        function.parameters.Add(parameter);
                        // MessageBox.Show("Adding: " + parameter.name + " " + parameter.type);
                    }
                }
                //20170817 leo: 發現當版本不同時,如果同一個 function 名稱,新版的參數比舊版多,
                //然後用舊版 R8 開啟 .r6 檔案時,這邊會 error 。
                //修正:
                else if (variableSnElements.Count() != function.parameters.Count)
                {
                    for (j = 0; j < variableSnElements.Count() && j < function.parameters.Count; j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }
                        function.parameters.ElementAt(j).variableSn = res;
                    }

                    for (j = function.parameters.Count; j < variableSnElements.Count(); j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }

                        int type = 0;
                        if (res != -1)
                        {
                            //parameter 名稱遺失了,但 variable 的 type 還是會有
                            //type = variables[res].type;
                            if (variables[res] != null)
                            {
                                type = variables[res].type;
                            }
                        }

                        Function.Parameter parameter = new Function.Parameter("unload", type);
                        parameter.option     = "IN";
                        parameter.variableSn = res;
                        function.parameters.Add(parameter);
                        // MessageBox.Show("Adding: " + parameter.name + " " + parameter.type);
                    }
                }
                else
                {
                    //for (int j = 0; j < variableSnElements.Count() && j < function.parameters.Count; j++)
                    for (j = 0; j < variableSnElements.Count(); j++)
                    {
                        subElement = variableSnElements.ElementAt(j);
                        if (!Int32.TryParse(subElement.Value, out res))
                        {
                            res = -1;
                        }
                        function.parameters.ElementAt(j).variableSn = res;
                    }
                }

                //Console.WriteLine("sn = " + function.sn);
                //Console.WriteLine("name = " + function.name);
            }

            // Console.WriteLine("functionSnCount = " + functionSnCount);
        }