/// <summary>
        /// 将条件动作块的结构体转换成列表
        /// </summary>
        /// <param name="tempStuct">传入的结构体</param>
        /// <returns>返回转换后的列表</returns>
        public List <string> StructToList(ProcessStruct tempStuct)
        {
            List <string> tempList = new List <string>();

            //条件数和动作数
            tempList.Add(tempStuct.NumOfConditions.ToString());
            tempList.Add(tempStuct.NumOfActions.ToString());
            //是否只在开始计算
            if (tempStuct.IsOnlyStart == true)
            {
                tempList.Add("1");
            }
            else
            {
                tempList.Add("0");
            }
            //条件列表
            tempList.Add(String.Join(";", tempStuct.Conditions.ToArray()));
            //动作列表
            List <string> tempAction = new List <string>();

            foreach (List <string> action in tempStuct.Actions)
            {
                tempAction.Add(String.Join("|", action.ToArray()));
            }
            tempList.Add(String.Join(";", tempAction.ToArray()));
            //顺序表
            List <string> tempBox = new List <string>();

            for (int i = 0; i < tempStuct.NumOfConditions; i++)
            {
                List <string> tempRow = new List <string>();
                for (int j = 0; j < tempStuct.NumOfActions; j++)
                {
                    tempRow.Add(tempStuct.OrderBox[i, j]);
                }
                tempBox.Add(String.Join(",", tempRow.ToArray()));
            }
            tempList.Add(String.Join(";", tempBox.ToArray()));
            //子策略
            tempList.Add(String.Join(",", tempStuct.Tactic.ToArray()));
            //控件属性
            if (tempStuct.ControlAttribute.Count != 0)
            {
                foreach (List <string> element in tempStuct.ControlAttribute)
                {//每个element为一个控件属性,第一位存放控件名
                    tempList.Add(String.Join(";", element.ToArray()));
                }
            }
            else
            {
                tempList.Add(null);
            }

            return(tempList);
        }
Example #2
0
        private bool IsAselect         = false;                             //当前的动作名是否被选择


        /// <summary>
        /// 根据传入的结构体初始化窗口的值
        /// </summary>
        /// <param name="PStruct">传入的存放条件动作块各值的结构体</param>
        public ProcessForm1(ProcessStruct PStruct)
        {
            InitializeComponent();
            //结构体副本
            newStruct = PStruct;
            //条件数和动作数
            NumCondition      = PStruct.NumOfConditions;
            NumAction         = PStruct.NumOfActions;
            ConditionNum.Text = NumCondition.ToString();
            ActionNum.Text    = NumAction.ToString();
            //根据条件数和动作数生成对应的列表
            CreateConditionList(NumCondition);
            CreateActionList(NumAction);
            //选择是否只在开始计算一次
            if (PStruct.IsOnlyStart == true)
            {
                OnlyStartType.Select();
            }
            else if (PStruct.IsOnlyStart == false)
            {
                EveryTimeType.Select();
            }
            //条件表达式和动作表达式的副本
            Action    = PStruct.Actions;
            Condition = PStruct.Conditions;
            //顺序表
            if (PStruct.OrderBox.Length != 0)
            {
                OrderBox = PStruct.OrderBox;
            }
            else
            {
                OrderBox = new string[NumCondition, NumAction];
            }
            CreateBox(NumCondition, NumAction);
            for (int i = 0; i < NumCondition; i++)
            {
                for (int j = 0; j < NumAction; j++)
                {
                    OrderDefineBox.Rows[i].Cells[j + 1].Value = OrderBox[i, j];
                }
            }
            //当前条件动作模块所在的页面的子策略
            if (PStruct.Tactic.Count != 0)
            {
                TacticBox.Items.AddRange(PStruct.Tactic.ToArray());
            }
            //所在页面的所有控件属性
            ControlAtrribute = PStruct.ControlAttribute;
        }
        private string[,] OrderBox; //条件为列动作为行的顺序表

        #endregion Fields

        #region Constructors

        /// <summary>
        /// 根据传入的结构体初始化窗口的值
        /// </summary>
        /// <param name="PStruct">传入的存放条件动作块各值的结构体</param>
        public ProcessForm1(ProcessStruct PStruct)
        {
            InitializeComponent();
            //结构体副本
            newStruct = PStruct;
            //条件数和动作数
            NumCondition = PStruct.NumOfConditions;
            NumAction = PStruct.NumOfActions;
            ConditionNum.Text = NumCondition.ToString();
            ActionNum.Text = NumAction.ToString();
            //根据条件数和动作数生成对应的列表
            CreateConditionList(NumCondition);
            CreateActionList(NumAction);
            //选择是否只在开始计算一次
            if (PStruct.IsOnlyStart == true)
            { OnlyStartType.Select(); }
            else if (PStruct.IsOnlyStart == false)
            { EveryTimeType.Select(); }
            //条件表达式和动作表达式的副本
            Action = PStruct.Actions;
            Condition = PStruct.Conditions;
            //顺序表
            if (PStruct.OrderBox.Length != 0)
            {
                OrderBox = PStruct.OrderBox;
            }
            else
            { OrderBox = new string[NumCondition, NumAction]; }
            CreateBox(NumCondition, NumAction);
            for (int i = 0; i < NumCondition; i++)
            {
                for (int j = 0; j < NumAction; j++)
                { OrderDefineBox.Rows[i].Cells[j + 1].Value = OrderBox[i, j]; }
            }
            //当前条件动作模块所在的页面的子策略
            if (PStruct.Tactic.Count != 0)
            { TacticBox.Items.AddRange(PStruct.Tactic.ToArray()); }
            //所在页面的所有控件属性
            ControlAtrribute = PStruct.ControlAttribute;
        }
        /// <summary>
        /// 将条件控制块的数据列表转换成结构体
        /// </summary>
        /// <param name="tempList">传入的列表</param>
        /// <returns>返回转换后的结构体</returns>
        public ProcessStruct ListToStruct(List<string> tempList)
        {
            ProcessStruct tempStruct = new ProcessStruct();
            //条件数和动作数
            tempStruct.NumOfConditions = Convert.ToInt32(tempList[0]);
            tempStruct.NumOfActions = Convert.ToInt32(tempList[1]);
            //是否只在开始计算
            if (tempList[2] == "1")
                tempStruct.IsOnlyStart = true;
            else
                tempStruct.IsOnlyStart = false;
            //条件列表
            List<string> tempConditions = new List<string>();
            foreach (string condition in tempList[3].Split(new char[] { ';' }))
            { tempConditions.Add(condition); }
            tempStruct.Conditions = tempConditions;
            //动作列表
            List<List<string>> tempActions = new List<List<string>>();
            foreach (string action in tempList[4].Split(new char[] { ';' }))
            {
                List<string> tempAction = new List<string>();
                foreach (string element in action.Split(new char[] { '|' }))
                { tempAction.Add(element); }
                tempActions.Add(tempAction);
            }
            tempStruct.Actions = tempActions;
            //顺序表
            string[,] tempBox = new string[tempStruct.NumOfConditions, tempStruct.NumOfActions];
            if (tempList[5] != null)
            {
                string[] tempRow = tempList[5].Split(new char[] { ';' });
                for (int i = 0; i < tempStruct.NumOfConditions; i++)
                {
                    string[] temp = tempRow[i].Split(new char[] { ',' });
                    for (int j = 0; j < tempStruct.NumOfActions; j++)
                    { tempBox[i, j] = temp[j]; }
                }
            }
            tempStruct.OrderBox = tempBox;
            //子策略
            List<string> tempTactic = new List<string>();
            if (tempList[6] != null)
            {
                foreach (string tactic in tempList[6].Split(new char[] { ',' }))
                { tempTactic.Add(tactic); }
            }
            tempStruct.Tactic = tempTactic;
            //控件属性
            List<List<string>> tempCAtrribute = new List<List<string>>();
            if (tempList[7] != null)
            {
                for (int i = 7; i < tempList.Count; i++)
                {
                    string[] element = tempList[i].Split(new char[] { ';' });
                    List<string> CElement = new List<string>();
                    foreach (string attribute in element)
                    { CElement.Add(attribute); }
                    tempCAtrribute.Add(CElement);
                }
            }
            tempStruct.ControlAttribute = tempCAtrribute;

            return tempStruct;
        }
        /// <summary>
        /// 将条件动作块的结构体转换成列表
        /// </summary>
        /// <param name="tempStuct">传入的结构体</param>
        /// <returns>返回转换后的列表</returns>
        public List<string> StructToList(ProcessStruct tempStuct)
        {
            List<string> tempList = new List<string>();
            //条件数和动作数
            tempList.Add(tempStuct.NumOfConditions.ToString());
            tempList.Add(tempStuct.NumOfActions.ToString());
            //是否只在开始计算
            if (tempStuct.IsOnlyStart == true)
                tempList.Add("1");
            else
                tempList.Add("0");
            //条件列表
            tempList.Add(String.Join(";", tempStuct.Conditions.ToArray()));
            //动作列表
            List<string> tempAction = new List<string>();
            foreach (List<string> action in tempStuct.Actions)
            {
                tempAction.Add(String.Join("|", action.ToArray()));
            }
            tempList.Add(String.Join(";", tempAction.ToArray()));
            //顺序表
            List<string> tempBox = new List<string>();
            for (int i = 0; i < tempStuct.NumOfConditions; i++)
            {
                List<string> tempRow = new List<string>();
                for (int j = 0; j < tempStuct.NumOfActions; j++)
                {
                    tempRow.Add(tempStuct.OrderBox[i, j]);
                }
                tempBox.Add(String.Join(",", tempRow.ToArray()));
            }
            tempList.Add(String.Join(";", tempBox.ToArray()));
            //子策略
            tempList.Add(String.Join(",", tempStuct.Tactic.ToArray()));
            //控件属性
            if (tempStuct.ControlAttribute.Count != 0)
            {
                foreach (List<string> element in tempStuct.ControlAttribute)
                {//每个element为一个控件属性,第一位存放控件名
                    tempList.Add(String.Join(";", element.ToArray()));
                }
            }
            else
            { tempList.Add(null); }

            return tempList;
        }
        /// <summary>
        /// 将条件控制块的数据列表转换成结构体
        /// </summary>
        /// <param name="tempList">传入的列表</param>
        /// <returns>返回转换后的结构体</returns>
        public ProcessStruct ListToStruct(List <string> tempList)
        {
            ProcessStruct tempStruct = new ProcessStruct();

            //条件数和动作数
            tempStruct.NumOfConditions = Convert.ToInt32(tempList[0]);
            tempStruct.NumOfActions    = Convert.ToInt32(tempList[1]);
            //是否只在开始计算
            if (tempList[2] == "1")
            {
                tempStruct.IsOnlyStart = true;
            }
            else
            {
                tempStruct.IsOnlyStart = false;
            }
            //条件列表
            List <string> tempConditions = new List <string>();

            foreach (string condition in tempList[3].Split(new char[] { ';' }))
            {
                tempConditions.Add(condition);
            }
            tempStruct.Conditions = tempConditions;
            //动作列表
            List <List <string> > tempActions = new List <List <string> >();

            foreach (string action in tempList[4].Split(new char[] { ';' }))
            {
                List <string> tempAction = new List <string>();
                foreach (string element in action.Split(new char[] { '|' }))
                {
                    tempAction.Add(element);
                }
                tempActions.Add(tempAction);
            }
            tempStruct.Actions = tempActions;
            //顺序表
            string[,] tempBox = new string[tempStruct.NumOfConditions, tempStruct.NumOfActions];
            if (tempList[5] != null)
            {
                string[] tempRow = tempList[5].Split(new char[] { ';' });
                for (int i = 0; i < tempStruct.NumOfConditions; i++)
                {
                    string[] temp = tempRow[i].Split(new char[] { ',' });
                    for (int j = 0; j < tempStruct.NumOfActions; j++)
                    {
                        tempBox[i, j] = temp[j];
                    }
                }
            }
            tempStruct.OrderBox = tempBox;
            //子策略
            List <string> tempTactic = new List <string>();

            if (tempList[6] != null)
            {
                foreach (string tactic in tempList[6].Split(new char[] { ',' }))
                {
                    tempTactic.Add(tactic);
                }
            }
            tempStruct.Tactic = tempTactic;
            //控件属性
            List <List <string> > tempCAtrribute = new List <List <string> >();

            if (tempList[7] != null)
            {
                for (int i = 7; i < tempList.Count; i++)
                {
                    string[]      element  = tempList[i].Split(new char[] { ';' });
                    List <string> CElement = new List <string>();
                    foreach (string attribute in element)
                    {
                        CElement.Add(attribute);
                    }
                    tempCAtrribute.Add(CElement);
                }
            }
            tempStruct.ControlAttribute = tempCAtrribute;

            return(tempStruct);
        }