Ejemplo n.º 1
0
        private void ItemAddDataBlock_Click(object sender, EventArgs e)
        {
            try
            {
                Server    chCurrent = null;
                DataBase  dvCurrent = null;
                XAddTable dbFrm     = null;
                if (treeViewSI.SelectedNode == null)
                {
                    return;
                }

                int Level = treeViewSI.SelectedNode.Level;
                switch (Level)
                {
                case 1:
                    chCurrent = objServerManager.GetBySQLServerName(treeViewSI.SelectedNode.Parent.Text);
                    dvCurrent = DataBaseManager.GetByDataBaseName(chCurrent, treeViewSI.SelectedNode.Text);
                    break;

                case 2:
                    chCurrent = objServerManager.GetBySQLServerName(treeViewSI.SelectedNode.Parent.Parent.Text);
                    dvCurrent = DataBaseManager.GetByDataBaseName(chCurrent, treeViewSI.SelectedNode.Parent.Text);
                    break;
                }
                dbFrm = new XAddTable(chCurrent, dvCurrent);
                dbFrm.eventTableChanged += db =>
                {
                    try
                    {
                        TreeNode dbNode = new TreeNode(db.TableName)
                        {
                            StateImageIndex = 2
                        };
                        switch (Level)
                        {
                        case 1:
                            treeViewSI.SelectedNode.Nodes.Add(dbNode);
                            IsDataChanged = true;
                            break;

                        case 2:
                            treeViewSI.SelectedNode.Parent.Nodes.Add(dbNode);
                            IsDataChanged = true;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        EventscadaException?.Invoke(GetType().Name, ex.Message);
                    }
                };
                dbFrm.ShowDialog();
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(GetType().Name, ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void treeViewSI_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                if (e.Button != System.Windows.Forms.MouseButtons.Left)
                {
                    return;
                }

                int      Level        = treeViewSI.SelectedNode.Level;
                string   selectedNode = treeViewSI.SelectedNode.Text;
                Server   chCurrent    = null;
                DataBase dvCurrent    = null;
                Table    dbCurrent    = null;
                switch (Level)
                {
                case 0:
                    chCurrent = objServerManager.GetBySQLServerName(selectedNode);
                    XAddServer chFrm = new XAddServer(objServerManager, chCurrent);
                    chFrm.eventSQLServerChanged += ch =>
                    {
                        treeViewSI.SelectedNode.Text = ch.ServerName;
                    };
                    chFrm.StartPosition = FormStartPosition.CenterScreen;
                    chFrm.ShowDialog();
                    break;

                case 1:
                    chCurrent = objServerManager.GetBySQLServerName(treeViewSI.SelectedNode.Parent.Text);
                    dvCurrent = DataBaseManager.GetByDataBaseName(chCurrent, selectedNode);
                    XAddDataBase dvFrm = new XAddDataBase(chCurrent, dvCurrent);
                    dvFrm.eventDataBaseChanged += dv =>
                    {
                        treeViewSI.SelectedNode.Text = dv.DataBaseName;
                    };
                    dvFrm.StartPosition = FormStartPosition.CenterScreen;
                    dvFrm.ShowDialog();
                    break;

                case 2:
                    chCurrent = objServerManager.GetBySQLServerName(treeViewSI.SelectedNode.Parent.Parent.Text);
                    dvCurrent = DataBaseManager.GetByDataBaseName(chCurrent, treeViewSI.SelectedNode.Parent.Text);
                    dbCurrent = TableManager.GetByTableName(dvCurrent, selectedNode);
                    XAddTable dbFrm = new XAddTable(chCurrent, dvCurrent, dbCurrent);
                    dbFrm.eventTableChanged += db =>
                    {
                        treeViewSI.SelectedNode.Text = db.TableName;
                        DGMonitorForm.Rows.Clear();

                        foreach (Column item in dbCurrent.Columns)
                        {
                            string[] row = { string.Format("{0}", item.ColumnId), item.ColumnName, item.TagName, item.DataBlock, item.Device, item.Channel, item.Cycle, item.Description };

                            DGMonitorForm.Rows.Add(row);
                        }
                    };
                    dbFrm.StartPosition = FormStartPosition.CenterScreen;
                    dbFrm.ShowDialog();
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(GetType().Name, ex.Message);
            }
        }