示例#1
0
        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
文件: 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);
        }
示例#3
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);
        }