Example #1
0
        private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int colIndex = e.ColumnIndex;
            int rowIndex = e.RowIndex;

            if (rowIndex >= 0)
            {
                if (1 == colIndex)
                {
                    bool   isSelected = (bool)this.dataGridView.Rows[rowIndex].Cells["IsSelected"].EditedFormattedValue;
                    string name       = this.dataGridView.Rows[rowIndex].Cells["DPTName"].Value.ToString();
                    if (isSelected)
                    {
                        if (name.Length <= 0)
                        {
                            MessageBox.Show(ResourceMng.GetString("Message42"), ResourceMng.GetString("Message4"), MessageBoxButtons.OK);
                            this.dataGridView.Rows[rowIndex].Cells["IsSelected"].Value = false;
                        }
                        else
                        {
                            string address = this.dataGridView.Rows[rowIndex].Cells["KnxAddress"].Value as string;
                            bool   isExsit = MyCache.AddressIsExsit(address);
                            if (isExsit)
                            {
                                MessageBox.Show(string.Format(ResourceMng.GetString("Message44"), address), ResourceMng.GetString("Message4"), MessageBoxButtons.OK);
                                this.dataGridView.Rows[rowIndex].Cells["IsSelected"].Value = false;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        private void ResetParameter()
        {
            this.curPageNode     = null;
            this.curSelectedNode = null;
            if (null != this.curSTPage)
            {
                this.curSTPage.Parent.Controls.Remove(this.curSTPage);
                this.curSTPage = null;
            }

            //this.curSTPanel = null;
            //this.curFrameControl = null;

            MyCache.ResetVariable();
        }
        /// <summary>
        /// 修改组地址信息
        /// </summary>
        private void ModifyAddress()
        {
            if (this.dgvGroupAddress.SelectedRows.Count > 0)
            {
                int            rowIndex = this.dgvGroupAddress.SelectedRows[0].Cells[0].RowIndex;
                var            item     = this.dgvGroupAddress.SelectedRows[0].DataBoundItem as MgGroupAddress;
                EdGroupAddress address  = MyCache.GetGroupAddress(item.Id);
                if (null != address)
                {
                    FrmGroupAddress frm = new FrmGroupAddress(DataStatus.Modify);
                    frm.Address = address;
                    var dlgResult = frm.ShowDialog(this);

                    if (dlgResult == DialogResult.OK)
                    {
                        /* 刷新修改的行 */
                        MgGroupAddress disAddress = new MgGroupAddress(frm.Address);
                        this.dgvGroupAddress.Rows[rowIndex].Cells[1].Value  = disAddress.Id;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[2].Value  = disAddress.Name;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[3].Value  = disAddress.KnxAddress;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[4].Value  = disAddress.DPTName;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[5].Value  = disAddress.IsCommunication;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[6].Value  = disAddress.IsRead;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[7].Value  = disAddress.IsWrite;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[8].Value  = disAddress.IsTransmit;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[9].Value  = disAddress.IsUpgrade;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[10].Value = disAddress.Priority;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[11].Value = disAddress.DefaultValue;
                        this.dgvGroupAddress.Rows[rowIndex].Cells[12].Value = disAddress.ReadTimeSpan;

                        this.dgvGroupAddress.EndEdit();

                        //Changed = true;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// 解析ETS文件
        /// </summary>
        /// <param name="etsProjectFile"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static List <ImGroupAddr> ParseEtsProjectFile(string etsProjectFile, BackgroundWorker worker)
        {
            List <ImGroupAddr> listAddress = new List <ImGroupAddr>();

            // 如果文件存在
            if (File.Exists(etsProjectFile) == true)
            {
                worker.ReportProgress(0, ResourceMng.GetString("TextIsUnziping"));

                // 在当前位置解压文件
                string directoryName = Path.GetDirectoryName(etsProjectFile);
                ZipHelper.UnZipDir(etsProjectFile, directoryName);

                worker.ReportProgress(0, ResourceMng.GetString("TextIsCaluculating"));

                // 查找 0.xml 文件
                const string addressFileName = "0.xml";
                var          addressFiles    = Directory.GetFiles(directoryName, addressFileName, SearchOption.AllDirectories);

                if (addressFiles.Length > 0)
                {
                    string addressFile = addressFiles[0];
                    var    addressXDoc = XDocument.Load(addressFile);
                    addressXDoc.Element("KNX");
                    XNamespace xns = addressXDoc.Root.Name.Namespace;

                    // 从导入的ETS项目中获取group address
                    var groupAddress = from item in addressXDoc.Root.Descendants(xns + attrGroupAddress)
                                       select new ImGroupAddr
                    {
                        Id         = item.Attribute(attrId).Value,
                        Name       = item.Attribute(attrName).Value,
                        KnxAddress = item.Attribute(attrAddress).Value,
                        DPTName    = (null != item.Attribute(attrDatapointType)) ? item.Attribute(attrDatapointType).Value : "",
                    };

                    // 获取数据类型
                    var comObjectInstanceRef = (from item in addressXDoc.Descendants(xns + strSend)
                                                let xElement = item.Parent
                                                               where xElement != null
                                                               select new
                    {
                        GroupAddressRefId = item.Attribute(strGroupAddressRefId).Value,
                        ComObjectInstanceRefId = xElement.Parent.Attribute(strRefId).Value,
                    }).ToLookup(p => p.GroupAddressRefId, p => p.ComObjectInstanceRefId);

                    Dictionary <string, XDocument> xDocs = new Dictionary <string, XDocument>();

                    int   len = groupAddress.ToList().Count;
                    float i   = 0;

                    /* 获取组地址的大小 */
                    foreach (var address in groupAddress.ToList())
                    {
                        ImGroupAddr addr = new ImGroupAddr();
                        addr.Id         = address.Id;
                        addr.Name       = address.Name;
                        addr.KnxAddress = KNXAddressHelper.AddressToString(Convert.ToUInt16(address.KnxAddress));
                        addr.DPTName    = address.DPTName;
                        float f = i++ / len;

                        worker.ReportProgress((int)(f * 100), ResourceMng.GetString("TextIsImportingGroupAddress") + " " + address.Name + " " + addr.KnxAddress);

                        if (comObjectInstanceRef.Contains(address.Id))
                        {
                            var comObjectInstanceRefId = comObjectInstanceRef[address.Id].First <string>();

                            var index1 = comObjectInstanceRefId.IndexOf('_');
                            var index2 = comObjectInstanceRefId.IndexOf('_', index1 + 1);
                            var index3 = comObjectInstanceRefId.IndexOf('_', index2 + 1);
                            var comObjectInstanceFile = comObjectInstanceRefId.Substring(0, index2);
                            var comObjectInstanceId   = comObjectInstanceRefId.Substring(0, index3);

                            var manufacturerDataFiles = Directory.GetFiles(directoryName, comObjectInstanceFile + ".xml", SearchOption.AllDirectories);
                            if (manufacturerDataFiles.Length > 0)
                            {
                                string    manufacturerDataFile = manufacturerDataFiles[0];
                                XDocument manufacturerDataXDoc;
                                if (xDocs.ContainsKey(manufacturerDataFile))
                                {
                                    manufacturerDataXDoc = xDocs[manufacturerDataFile];
                                }
                                else
                                {
                                    manufacturerDataXDoc = XDocument.Load(manufacturerDataFile);
                                    xDocs.Add(manufacturerDataFile, manufacturerDataXDoc);
                                }

                                var comObject = (from p in manufacturerDataXDoc.Descendants(xns + strComObject)
                                                 where p.Attribute(attrId).Value == comObjectInstanceId
                                                 select p).FirstOrDefault();
                                parseComObject(addr, comObject);

                                var comObjectRef = (from p in manufacturerDataXDoc.Descendants(xns + strComObjectRef)
                                                    where p.Attribute(attrId).Value == comObjectInstanceRefId
                                                    select p).FirstOrDefault();
                                parseComObject(addr, comObjectRef);
                            }

                            parseDatapointType(addr);
                        }
                        else
                        {
                            parseDatapointType(addr);
                            addr.IsSelected = false;
                        }

                        bool isExsit = MyCache.AddressIsExsit(addr.KnxAddress);
                        if (isExsit)
                        {
                            addr.IsSelected = false;
                        }

                        listAddress.Add(addr);
                    }
                }
            }

            return(listAddress);
        }
        private void dgvGroupAddress_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            int rowIndex = e.RowIndex;
            int colIndex = e.ColumnIndex;

            if (rowIndex >= 0)
            {
                if (13 == colIndex)
                {
                    string         Id   = this.dgvGroupAddress.Rows[rowIndex].Cells["Id"].Value as string;
                    EdGroupAddress addr = MyCache.GetGroupAddress(Id);
                    if ((null != addr) && (null != addr.Actions))
                    {
                        //画单元格的边界线
                        Point   p1 = new Point(e.CellBounds.Left + e.CellBounds.Width, e.CellBounds.Top);
                        Point   p2 = new Point(e.CellBounds.Left + e.CellBounds.Width, e.CellBounds.Top + e.CellBounds.Height);
                        Point   p3 = new Point(e.CellBounds.Left, e.CellBounds.Top + e.CellBounds.Height);
                        Point[] ps = new Point[] { p1, p2, p3 };
                        using (Brush gridBrush = new SolidBrush(this.dgvGroupAddress.GridColor))
                        {
                            using (Pen gridLinePen = new Pen(gridBrush, 2))
                            {
                                Font   font          = new Font("宋体", 9, FontStyle.Regular);//自定义字体
                                string seperator     = ";";
                                SizeF  sizeSeperator = e.Graphics.MeasureString(seperator, font);
                                float  startPos      = .0f;

                                //判断当前行是否为选中行,如果为选中行,则要修改图片的背景色和文字的字体颜色
                                if ((null != this.dgvGroupAddress.CurrentRow) && (this.dgvGroupAddress.CurrentRow.Index == e.RowIndex))
                                {
                                    using (Brush backColorBrush = new SolidBrush(Color.FromArgb(051, 153, 255)))
                                    {
                                        //以背景色填充单元格
                                        e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
                                        e.Graphics.DrawLines(gridLinePen, ps);

                                        foreach (DatapointActionNode action in addr.Actions)
                                        {
                                            if (startPos >= e.CellBounds.Width)
                                            {
                                                break;
                                            }

                                            if (startPos > 0)
                                            {
                                                e.Graphics.DrawString(seperator, font, Brushes.White, new RectangleF(e.CellBounds.Left + startPos,
                                                                                                                     e.CellBounds.Top + (e.CellBounds.Height - sizeSeperator.Height) / 2, e.CellBounds.Width - startPos,
                                                                                                                     sizeSeperator.Height), StringFormat.GenericDefault);
                                                startPos += sizeSeperator.Width;
                                            }

                                            SizeF sizeText = e.Graphics.MeasureString(action.Name, font);
                                            e.Graphics.DrawString(action.Name, font, Brushes.White, new RectangleF(e.CellBounds.Left + startPos,
                                                                                                                   e.CellBounds.Top + (e.CellBounds.Height - sizeText.Height) / 2, e.CellBounds.Width - startPos,
                                                                                                                   sizeText.Height), StringFormat.GenericDefault);
                                            startPos += sizeText.Width;
                                        }

                                        e.Handled = true;
                                    }
                                }
                                else
                                {
                                    using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor))
                                    {
                                        e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
                                        e.Graphics.DrawLines(gridLinePen, ps);

                                        foreach (DatapointActionNode action in addr.Actions)
                                        {
                                            if (startPos >= e.CellBounds.Width)
                                            {
                                                break;
                                            }

                                            if (startPos > 0)
                                            {
                                                e.Graphics.DrawString(seperator, font, Brushes.Black, new RectangleF(e.CellBounds.Left + startPos,
                                                                                                                     e.CellBounds.Top + (e.CellBounds.Height - sizeSeperator.Height) / 2, e.CellBounds.Width - startPos,
                                                                                                                     sizeSeperator.Height), StringFormat.GenericDefault);
                                                startPos += sizeSeperator.Width;
                                            }

                                            if (startPos >= e.CellBounds.Width)
                                            {
                                                break;
                                            }

                                            SizeF sizeText = e.Graphics.MeasureString(action.Name, e.CellStyle.Font);
                                            e.Graphics.DrawString(action.Name, e.CellStyle.Font, Brushes.Blue, new RectangleF(e.CellBounds.Left + startPos,
                                                                                                                              e.CellBounds.Top + (e.CellBounds.Height - sizeText.Height) / 2, e.CellBounds.Width - startPos,
                                                                                                                              sizeText.Height), StringFormat.GenericDefault);
                                            startPos += sizeText.Width;
                                        }

                                        e.Handled = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }