Exemple #1
0
        /// <summary>初始化层控制项
        /// 初始化层控制项
        /// </summary>

        public void InitFromXml(string filePath)
        {
            try
            {
                ListCell.Clear();
                ListIndex.Clear();
                XmlDocument myxmldoc  = new XmlDocument();
                string      filePath1 = filePath + @"\Project\Layer.xml";

                myxmldoc.Load(filePath1);

                string     xpath     = "root/ListCell";
                XmlElement childNode = (XmlElement)myxmldoc.SelectSingleNode(xpath);
                RunDefault1 = childNode.GetAttribute("RunDefault1");

                xpath = "root/ListCell/row";
                XmlNodeList mynodes = myxmldoc.SelectNodes(xpath);
                foreach (XmlElement node in mynodes)
                {
                    int        sAtt  = Convert.ToInt32(node.GetAttribute("ID"));
                    string     sType = node.GetAttribute("RecipeType");
                    string     sName = node.GetAttribute("Name");
                    CLayerCell nCell = new CLayerCell(sType, sName, sAtt);
                    nCell.Linker     = node.GetAttribute("Linker");
                    nCell.StrValue   = node.GetAttribute("InitialValue");
                    nCell.ValueType  = node.GetAttribute("ValueType");
                    nCell.RatioValue = node.GetAttribute("RatioValue");
                    nCell.sRange     = node.GetAttribute("sRange");

                    ListCell.Add(nCell);
                    if (nCell.CellType == ECellType.GC_head)
                    {
                        ListIndex.Add(ListCell.IndexOf(nCell));
                    }

                    //if (nCell.CellType == ECellType.GC_AO || nCell.CellType == ECellType.GC_AO2 || nCell.CellType == ECellType.GC_AO3)
                    //{
                    //    nCell.StrValue = "";
                    //}
                }
                ListIndex.Add(ListCell.Count);
                for (int i = 0; i < ListIndex.Count - 1; i++)
                {
                    ListCell[ListIndex[i]].iHeadFirst = ListIndex[i] + 1;
                    ListCell[ListIndex[i]].iHeadLast  = ListIndex[i + 1] - 1;
                }

                //读取PortInf_Table,获取对应的地址和容量
                filePath1 = filePath + @"\Project\IO\PortInf_Table.xml";
                myxmldoc.Load(filePath1);
                xpath     = "IO/VariableInf_Table";
                childNode = (XmlElement)myxmldoc.SelectSingleNode(xpath);

                foreach (CLayerCell nCell in ListCell)
                {
                    nCell.iLinker.Clear();
                    nCell.iCapacity.Clear();
                    switch (nCell.CellType)
                    {
                    case ECellType.GC_AO:
                    case ECellType.GC_AO2:
                    case ECellType.GC_AO3:
                        string[] sAB1 = nCell.Linker.Split(',');
                        for (int i = 0; i < sAB1.Length; i++)
                        {
                            int k = 0;
                            foreach (XmlElement item in childNode.ChildNodes)
                            {
                                string sVarName = item.GetAttribute("Name");
                                if (sAB1[i] == item.GetAttribute("Name") && item.GetAttribute("Driver") == "NJ301")
                                {
                                    nCell.iLinker.Add(Convert.ToInt32(item.GetAttribute("ByteAddr")) + 5000);
                                    nCell.iCapacity.Add(Convert.ToInt32(item.GetAttribute("IntTag9")));
                                    k++;
                                    break;
                                }
                            }
                            if (k == 0)
                            {
                                nCell.iLinker.Add(0);
                                nCell.iCapacity.Add(0);
                            }
                        }
                        break;

                    case ECellType.GC_DO:
                    case ECellType.GC_YPIVR1:
                    case ECellType.GC_YPIVR2:
                    case ECellType.GC_H2N2Switch:
                    case ECellType.GC_IR2:
                        string[] sAB2 = nCell.Linker.Split(',');
                        for (int i = 0; i < sAB2.Length; i++)
                        {
                            int k = 0;
                            foreach (XmlElement item in childNode.ChildNodes)
                            {
                                string sVarName = item.GetAttribute("Name");
                                if (sAB2[i] == item.GetAttribute("Name") && item.GetAttribute("Driver") == "NJ301")
                                {
                                    nCell.iLinker.Add(Convert.ToInt32(item.GetAttribute("ByteAddr")) - 1000);
                                    nCell.iLinker.Add(Convert.ToInt32(item.GetAttribute("BitAddr")));
                                    k++;
                                    break;
                                }
                            }
                            if (k == 0)
                            {
                                nCell.iLinker.Add(-1000);
                                nCell.iLinker.Add(0);
                            }
                        }
                        break;

                    case ECellType.GC_datetime:
                        nCell.iLinker.Add(6052);
                        break;

                    case ECellType.GC_Jump:
                        nCell.iLinker.Add(6053);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CLayer.InitFromXml:" + ex.Message);
            }
        }
Exemple #2
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string     sNew  = dGV1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                int        iCol  = e.ColumnIndex;
                int        iRow  = e.RowIndex;
                CLayerCell nCell = LayerMod.ListCell[iRow];
                switch (iCol)
                {
                //    0       1         2         3         4          5         6       7
                //{ "序号", "名称","关联变量", "项类型", "数据类型", "缺省值", "变比", "值范围" };
                case 5:    //缺省值
                    string message = "";
                    bool   aa      = nCell.CheckExcel(sNew, ref message);
                    if (!aa)
                    {
                        MessageBox.Show(message, "错误");
                        dGV1.Rows[iRow].Cells[iCol].Value = sOld;
                        return;
                    }
                    break;

                case 6:    //变比
                    try
                    {
                        double f1 = Convert.ToDouble(dGV1.Rows[iRow].Cells[iCol].Value.ToString());
                    }
                    catch (Exception ex1)
                    {
                        MessageBox.Show(ex1.Message + "\r\n请重新输入", "格式错误");
                        dGV1.Rows[iRow].Cells[iCol].Value = sOld;
                        return;
                    }
                    break;

                case 7:    //值范围
                    try
                    {
                        string str1 = dGV1.Rows[iRow].Cells[iCol].Value.ToString();
                        str1 = str1.Replace(',', ',');
                        str1 = str1.Replace(';', ',');
                        str1 = str1.Replace(':', ',');
                        str1 = str1.Replace(';', ',');
                        str1 = str1.Replace(':', ',');
                        string[] str2 = str1.Split(',');
                        if (str2.Length < 2)
                        {
                            MessageBox.Show("值范围不能少于2个,不同值之间请用','分开", "格式错误");
                            dGV1.Rows[iRow].Cells[iCol].Value = sOld;
                            return;
                        }
                    }
                    catch (Exception ex1)
                    {
                        MessageBox.Show(ex1.Message + "\r\n请重新输入", "格式错误");
                        dGV1.Rows[iRow].Cells[iCol].Value = sOld;
                        return;
                    }
                    break;

                default:
                    break;
                }
                if (!bSave)
                {
                    if (sNew != sOld)
                    {
                        bSave            = true;
                        toolSave.Enabled = bSave;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "格式错误");
            }
            //ECellType
        }
Exemple #3
0
        public CLayerCell Clone()
        {
            CLayerCell obj = (CLayerCell)this.MemberwiseClone();

            return(obj);
        }