Exemple #1
0
        ///<summary>
        /// 修改节点
        ///</summary>
        private void UpdateXmlNode(hyProcess process)
        {
            //xmlDoc = new XmlDocument();
            //xmlDoc.Load("hyProcess.xml"); // 加载xml文件
            // 获取processgroup节点的所有子节点
            XmlNodeList xnl2 = xmlDoc.SelectSingleNode("processgroup").ChildNodes;

            // 遍历所有子节点
            foreach (XmlNode xn2 in xnl2)
            {
                XmlElement xe2 = (XmlElement)xn2;                                          // 将子节点类型转换为XmlElement类型

                if (Convert.ToInt32(xe2.GetAttribute("process_id")) == process.process_id) // 工艺ID 是否能够匹配上,工艺ID自动生成。
                {
                    xe2.SetAttribute("process_name", process.process_name.ToString());     // 工艺名称

                    // 循环修改station
                    XmlNodeList xnl3  = xe2.ChildNodes;
                    int         index = 0;
                    foreach (XmlNode xn3 in xnl3)
                    {//staion
                        XmlElement xe3 = (XmlElement)xn3;
                        index = Convert.ToInt32(xe3.GetAttribute("station_id"));
                        xe3.ChildNodes.Item(0).InnerText = Encript.Encode(process.stationParaList[index].workingTemp.ToString()); // 工作时间// 加密
                        xe3.ChildNodes.Item(1).InnerText = Encript.Encode(process.stationParaList[index].workingTime.ToString()); // 工作温度// 加密
                        xe3.ChildNodes.Item(2).InnerText = Encript.Encode(process.stationParaList[index].formula);                // 配方// 加密
                    }
                    break;
                }
            }

            xmlDoc.Save("hyProcess.xml");//保存。
        }
Exemple #2
0
        /*
         *
         * 从 xml 数据中  读取一个已经存在的工作组(N个工作流的组合)
         *
         * */

        private void LoadXml()
        {
            processList = new List <hyProcess>();// 创建工作流列表

            xmlDoc = new XmlDocument();
            xmlDoc.Load("hyProcess.xml"); //加载xml文件
            xroot = xmlDoc.SelectSingleNode("processgroup");

            XmlNodeList xnl1 = xroot.ChildNodes;

            foreach (XmlNode xn1 in xnl1)
            {// process
                // 每一个工作流,都包含关联一个工艺
                // 每个工艺中,都包含了13个station(炉子,水槽)的参数.station para
                hyProcess process = new hyProcess();

                XmlElement xe1 = (XmlElement)xn1;
                process.process_id      = Convert.ToInt32(xe1.GetAttribute("process_id"));       // 工艺ID
                process.process_name    = xe1.GetAttribute("process_name");                      // 工艺名称
                process_id_max_assigned = Math.Max(process_id_max_assigned, process.process_id); // 已经分配的最大process_id

                XmlNodeList xnl2  = xe1.ChildNodes;
                int         index = 0;
                foreach (XmlNode xn2 in xnl2)
                {//staion
                    XmlElement xe2 = (XmlElement)xn2;
                    index = Convert.ToInt32(xe2.GetAttribute("station_id"));
                    process.stationParaList[index].workingTemp = Convert.ToInt32(Encript.Decode(xe2.ChildNodes.Item(0).InnerText)); // 工作温度// 加密
                    process.stationParaList[index].workingTime = Convert.ToInt32(Encript.Decode(xe2.ChildNodes.Item(1).InnerText)); // 工作时间// 加密
                    process.stationParaList[index].formula     = Encript.Decode(xe2.ChildNodes.Item(2).InnerText);                  // 配方// 加密
                }
                processList.Add(process);
            }
        }
        private void buttonNewProcess_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定新增工艺吗?", "提示", MessageBoxButtons.OKCancel);

            if (dr == DialogResult.Cancel)
            {
                return;
            }
            try
            {
                // 新增工艺
                // 将新增的 process 添加到 XML 文件中
                hyProcess process = new hyProcess();

                PullDataFromTextBox(process);     // 从 TextBox 中抽取数据

                processGroup.NewProcess(process); // XML 文件会保存,同时 processGroup的列表会增加

                // 更新 dataGridView
                // 只需要更新数据源 DataSource 就可以了。也就是 dt.
                string[] strArr = new string[27]; // 1 + 13*2 = 27
                strArr[0] = process.process_name; // process.process_id.ToString();
                for (int i = 0; i < hyProcess.stationNum; i++)
                {
                    strArr[i * 2 + 1] = process.stationParaList[i].workingTemp.ToString(); // 工作温度
                    strArr[i * 2 + 2] = process.stationParaList[i].workingTime.ToString(); // 工作时间
                }
                dt.Rows.Add(strArr);

                // 跳转选择新增的那一行
                // dataGridView 排序后会引起索引变化,那么如何找到该索引呢,使用下面的方法。
                for (int i = 0; i < rowMergeView1.Rows.Count; i++)
                {
                    if (rowMergeView1.Rows[i].Cells[0].Value.ToString() == strArr[0])
                    {
                        rowMergeView1.CurrentCell = rowMergeView1.Rows[i].Cells[0]; // 设置当前行(焦点)
                    }
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("工作时间和工作温度必须是整数,不能为其他字符");
            }
            finally
            {
            }
        }
        private void PullDataFromTextBox(hyProcess process)
        {
            if (labelList.Count <= 0)
            {
                return;
            }
            for (int i = 0; i < hyProcess.stationNum; i++)
            {
                process.stationParaList[i].workingTemp = Convert.ToInt32(labelList[i].workTemperatureLabel.Text);
                process.stationParaList[i].workingTime = Convert.ToInt32(labelList[i].workTimeLabel.Text);
                process.stationParaList[i].formula     = labelList[i].formulaLabel.Text;
            }

            process.process_name = textBoxProcessName.Text;

            return;
        }
Exemple #5
0
        /*
         *
         * 在 xml 数据中  追加(插入)数据。
         *
         * */

        private void InsertXmlNode(hyProcess process)
        {
            /**
             * 插入一个工作流
             * <workflow>
             * */
            XmlElement xe1 = xmlDoc.CreateElement("process");                  //创建一个﹤workflow﹥节点

            process_id_max_assigned++;                                         // 工艺ID
            process.process_id = process_id_max_assigned;                      // 工艺ID
            xe1.SetAttribute("process_id", process.process_id.ToString());     // 工艺ID
            xe1.SetAttribute("process_name", process.process_name.ToString()); // 工艺名称

            /**
             * 循环插入station
             * <station>
             * */
            foreach (hyStationPara stationPara in process.stationParaList)
            {
                XmlElement xe2 = xmlDoc.CreateElement("station");
                xe2.SetAttribute("station_id", stationPara.station_id.ToString());// 工位ID

                /**
                 * <working_time>,<working_temp>,<starting_time>,<ending_time>
                 * */
                XmlElement xe3_1 = xmlDoc.CreateElement("working_temp");              // 工作温度
                xe3_1.InnerText = Encript.Encode(stationPara.workingTemp.ToString()); // 加密
                xe2.AppendChild(xe3_1);
                XmlElement xe3_2 = xmlDoc.CreateElement("working_time");              // 工作时间
                xe3_2.InnerText = Encript.Encode(stationPara.workingTime.ToString()); // 加密
                xe2.AppendChild(xe3_2);
                XmlElement xe3_3 = xmlDoc.CreateElement("formula");                   // 配方
                xe3_3.InnerText = Encript.Encode(stationPara.formula.ToString());     // 加密
                xe2.AppendChild(xe3_3);                                               //添加到﹤staion﹥节点中

                xe1.AppendChild(xe2);                                                 //添加到﹤process﹥节点中
            }

            xroot.AppendChild(xe1);       //添加到﹤processgroup﹥节点中
            xmlDoc.Save("hyProcess.xml"); //保存其更改
        }
        private void buttonUpdateProcess_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确定更新当前工艺数据吗?", "提示", MessageBoxButtons.OKCancel);

            if (dr == DialogResult.Cancel)
            {
                return;
            }
            // 修改 dataGridView 中的数据
            try
            {
                // dataGridView 排序后会引起索引变化,那么如何找到该索引呢,使用下面的方法。
                DataRowView drv   = rowMergeView1.SelectedRows[0].DataBoundItem as DataRowView;
                int         index = dt.Rows.IndexOf(drv.Row);

                // 新增工艺
                // 将新增的 process 添加到 XML 文件中
                hyProcess process = new hyProcess();

                PullDataFromTextBox(process);// 从 TextBox 中抽取数据
                process.process_id = processGroup.processList[index].process_id;

                processGroup.UpdateProcess(index, process);// XML 文件会保存,同时 processGroup 的列表会增加

                // 更新 dataGridView
                // 只需要更新数据源 DataSource 就可以了。也就是 dt.
                for (int i = 0; i < hyProcess.stationNum; i++)                                     // 1 + 13*2 = 27
                {
                    dt.Rows[index][i * 2 + 1] = process.stationParaList[i].workingTemp.ToString(); // 工作温度
                    dt.Rows[index][i * 2 + 2] = process.stationParaList[i].workingTime.ToString(); // 工作时间
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("工作时间和工作温度必须是整数,不能为其他字符");
            }
            finally
            {
            }
        }
Exemple #7
0
        /**
         * 新增一个工作流
         * */

        public void NewWorkFlow(int process_id, int carrier_name, int person_id, int loading_station_id)
        {
            lastWorkFlow = currWorkFlow;
            currWorkFlow = new hyWorkFlow(this);
            max_workflow_id_assigned++;
            currWorkFlow.process_id   = process_id;                     // 工艺ID
            currWorkFlow.carrier.name = carrier_name;                   // 夹具名称
            currWorkFlow.person_id    = person_id;                      // 创建人员ID

            currWorkFlow.workflow_id        = max_workflow_id_assigned; // 工作流ID,自动生成
            currWorkFlow.carrier_id         = max_workflow_id_assigned; // 夹具ID,自动生成
            currWorkFlow.loading_station_id = loading_station_id;       // 取料工位ID,备用

            hyProcess rawProcess = null;

            foreach (hyProcess process in MainForm.processGroup.processList)
            {
                rawProcess = process;
                if (process.process_id == process_id)
                {
                    currWorkFlow.process.process_name = process.process_name;
                    int ii = 0;
                    foreach (hyStationPara stationPara in process.stationParaList)
                    {
                        currWorkFlow.process.stationParaList[ii].station_id  = stationPara.station_id;
                        currWorkFlow.process.stationParaList[ii].workingTemp = stationPara.workingTemp; // 工作温度
                        currWorkFlow.process.stationParaList[ii].workingTime = stationPara.workingTime; // 工作时间
                        if (currWorkFlow.process.stationParaList[ii].workingTime > 0)
                        {
                            switch (ii)
                            {
                            case 0:
                                GenericOp.temperature1_1 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 2:
                                GenericOp.temperature2_1 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 3:
                                GenericOp.temperature4 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 4:
                                GenericOp.temperature5 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 5:
                                GenericOp.temperature6 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 6:
                                GenericOp.temperature7 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 9:
                                GenericOp.temperature3_1 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 10:
                                GenericOp.temperature11 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            case 11:
                                GenericOp.temperature12 = (currWorkFlow.process.stationParaList[ii].workingTemp);
                                break;

                            default:
                                break;
                            }
                        }

                        ii++;
                    }
                    SerialTemp.commState = SerialTemp.COMM_STATE.IDLE;
                    Thread.Sleep(100);
                    SerialTemp.commState = SerialTemp.COMM_STATE.IDLE;
                    Thread.Sleep(100);
                    SerialTemp.commState = SerialTemp.COMM_STATE.IDLE;
                    Thread.Sleep(100);
                    SerialTemp.commState = SerialTemp.COMM_STATE.IDLE;
                    break;
                }
            }
            if (rawProcess == null)
            {
                MessageBox.Show("新增工艺出错,没有找到匹配的工艺号!");
                return;
            }
            // 根据 工艺ID (process id),读取工艺参数文件
            int stationIndex = 0;

            //bool isHead = true;
            //int iii = 0;
            currWorkFlow.max_workflow_endingtime = 0;
            // -------------------------------------------------------------------------
            // 生成一个工作流序列,原始工作序列。
            foreach (hyStationPara stationPara in currWorkFlow.process.stationParaList)
            {
                stationPara.station_id = stationIndex;
                // -------------------------------------------------------------------------
                // 生成一个工作流序列,原始工作序列。
                if (stationPara.enabled)
                {
                    currWorkFlow.max_workflow_endingtime = Math.Max(currWorkFlow.max_workflow_endingtime, MainForm.SystemMinutes); // 这里每一行的最大允许时间永远是在最新时间之后的。
                    stationPara.startingTimeWithHead     = currWorkFlow.max_workflow_endingtime;                                   // 开始时间 hyProcess.interval 5 分钟间隔时间
                    stationPara.endingTime = stationPara.startingTimeWithHead + stationPara.workingTimeWithHead;                   // 结束时间
                    currWorkFlow.max_workflow_endingtime = stationPara.endingTime;                                                 // 更新总结束时间
                }
                stationIndex++;
            }

            // -------------------------------------------------------------------------
            // 将序列添加到 workGroup 中去。但是要做以下检查:1)紧跟上一个工作流后边,2)避免和以前任何工作流的切换时间发生冲突
            // 也就是寻找当前工作流的位置
            if (lastWorkFlow != null)
            {
                int max = 0;
                for (int i = 0; i < hyProcess.stationNum; i++)
                {
                    hyStationPara curr = currWorkFlow.process.stationParaList[i];
                    hyStationPara last = lastWorkFlow.process.stationParaList[i];
                    if (curr.enabled)
                    {
                        this.max_station_endingTime[i] = Math.Max(this.max_station_endingTime[i], MainForm.SystemMinutes);// 这里每一行的最大允许时间永远是在最新时间之后的。
                        int a = (this.max_station_endingTime[i] - curr.startingTimeWithHead);
                        max = Math.Max(max, a);
                    }
                }
                for (int i = 0; i < hyProcess.stationNum; i++)
                {
                    hyStationPara stationPara = currWorkFlow.process.stationParaList[i];
                    if (stationPara.enabled)
                    {
                        stationPara.startingTimeWithHead    += max;
                        stationPara.endingTime               = stationPara.startingTimeWithHead + stationPara.workingTimeWithHead; // 结束时间
                        currWorkFlow.max_workflow_endingtime = stationPara.endingTime;                                             // 更新总结束时间
                    }
                }
            }

            // -------------------------------------------------------------------------
            // 开始时间是否与切换时间冲突,检查
            bool checkPass = false;

            while (!checkPass)
            {
                for (stationIndex = 0; stationIndex < hyProcess.stationNum; stationIndex++)
                {
                    hyStationPara stationPara = currWorkFlow.process.stationParaList[stationIndex];
                    if (stationPara.enabled)
                    {
                        foreach (int changTime in changeTimeList)
                        {
                            int interval = stationPara.startingTimeWithHead - changTime;
                            if (Math.Abs(interval) < hyProcess.interval_m)
                            {
                                int delay = hyProcess.interval_m - interval;
                                for (int i = 0; i < hyProcess.stationNum; i++)
                                {
                                    stationPara = currWorkFlow.process.stationParaList[i];
                                    stationPara.startingTimeWithHead    += delay;                                              // 加一个大的量。加小了有问题。
                                    stationPara.endingTime               = stationPara.startingTime + stationPara.workingTime; // 结束时间
                                    currWorkFlow.max_workflow_endingtime = stationPara.endingTime;                             // 更新总结束时间
                                }
                                stationIndex = -1;                                                                             // 有冲突,重新来过
                                break;                                                                                         // 有冲突,重新来过
                            }
                        }
                    }
                }
                checkPass = true;
            }

            int j = 0;

            foreach (hyStationPara stationPara in currWorkFlow.process.stationParaList)
            {
                if (stationPara.enabled)
                {
                    this.max_station_endingTime[j] = Math.Max(this.max_station_endingTime[j], stationPara.endingTime);// 更新每一行的总结束时间
                }
                j++;
            }
            currWorkFlow.carrier.UpdateCarrierInfo(hyWorkFlow.POS_LOAD); // 更新夹具信息
            workFlowList.Add(currWorkFlow);                              // 添加工作流

            UpdateChangeOverTime();                                      // 更新 换型过度时间
            // 插入 数据 XML
            InsertXmlNode();
        }
Exemple #8
0
        /**
         * 修改数据文件
         * */

        public void UpdateProcess(int index, hyProcess process)
        {
            UpdateXmlNode(process);// XML文件
            processList[index] = process;
        }
Exemple #9
0
        /**
         * 新增一个工艺
         * */

        public void NewProcess(hyProcess process)
        {
            processList.Add(process); // 添加工艺
            InsertXmlNode(process);   // 追加数据文件
        }