Пример #1
0
        //-----------------------------------------------
        void WriteValue(object sender, EventArgs e)
        {
            CEntiteSnmp entiteSnmp = EditedElement as CEntiteSnmp;

            if (entiteSnmp != null)
            {
                CResultAErreur result = MajChamps(true);
                if (!result)
                {
                    CFormAlerte.Afficher(result.Erreur);
                    return;
                }
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entiteSnmp, ((CChampCustom)WndSnmp.FieldZone.Variable).Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null)
                {
                    result = rel.WriteSnmpValue();
                    if (!result)
                    {
                        CFormAlerte.Afficher(result.Erreur);
                    }
                    else
                    {
                        ReadSnmpValue(this, null);
                        MyUpdateValeursCalculees();
                    }
                }
            }
        }
Пример #2
0
        //-------------------------------------------------------------------
        public override CResultAErreur TraitementAvantSauvegarde(CContexteDonnee contexte)
        {
            CResultAErreur result = base.TraitementAvantSauvegarde(contexte);

            if (!result)
            {
                return(result);
            }
            DataTable table = contexte.Tables[GetNomTable()];

            if (table == null)
            {
                return(result);
            }
            HashSet <DataRow>     rowsAgent          = null;
            ArrayList             lstRows            = new ArrayList(table.Rows);
            HashSet <CEntiteSnmp> entitesARecalculer = new HashSet <CEntiteSnmp>();

            foreach (DataRow row in lstRows)
            {
                if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added)
                {
                    if (rowsAgent == null)
                    {
                        rowsAgent = CAgentSnmpServeur.GetTableAgentsAMettreAJourToSnmp(contexte, true);
                    }
                    if (rowsAgent != null)
                    {
                        CRelationEntiteSnmp_ChampCustom rel = new CRelationEntiteSnmp_ChampCustom(row);
                        CEntiteSnmp entite = rel.ElementAChamps as CEntiteSnmp;
                        if (entite != null)
                        {
                            entitesARecalculer.Add(entite);
                            rowsAgent.Add(entite.AgentSnmp.Row.Row);
                        }
                    }
                }
            }

            foreach (CEntiteSnmp entite in entitesARecalculer)
            {
                entite.RecalcLibelle();
            }
            return(result);
        }
Пример #3
0
        //------------------------------------------------------------------------
        public object GetObjectValueForGrid(object element)
        {
            CEntiteSnmp entite = element as CEntiteSnmp;

            if (entite != null)
            {
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entite, m_wndChampCustom.ChampCustom.Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null)
                {
                    string strRetour = rel.Valeur == null ? "" : rel.Valeur.ToString();
                    strRetour += "  (";
                    object val = rel.LastSnmpValue;
                    return(val);
                }
            }
            if (m_wndChampCustom != null)
            {
                return(m_wndChampCustom.GetObjectValueForGrid(element));
            }
            return("");
        }
Пример #4
0
        //--------------------------------------------------------------------
        private void UpdateDateSNMP()
        {
            DateTime?                dtOld   = null;
            CSchemaReseau            schema  = m_stackCheminsReseau.Peek();
            CListeCouplesEntiteChamp couples = schema.GetListeValeursSnmpAffichees();

            foreach (CCoupleEntiteSnmp_Champ couple in couples)
            {
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(couple.Entite, couple.ChampCustom.Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null && rel.DateSynchroSnmp != null)
                {
                    if (dtOld == null || rel.DateSynchroSnmp.DateTimeValue < dtOld.Value)
                    {
                        dtOld = rel.DateSynchroSnmp.DateTimeValue;
                    }
                }
            }
            m_bHasSnmpEntities  = couples.Count > 0;
            m_panelSNMP.Visible = m_bHasSnmpEntities;
            m_lastSnmpUpdate    = dtOld;
            UpdateLabelSnmpUpdate();
        }
Пример #5
0
        //-------------------------------------
        protected override void  MyUpdateValeursCalculees()
        {
            if (m_controleSnmp == null)
            {
                return;
            }
            CEntiteSnmp entiteSnmp = EditedElement as CEntiteSnmp;

            if (entiteSnmp == null)
            {
                return;
            }

            CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entiteSnmp, ((CChampCustom)WndSnmp.FieldZone.Variable).Id) as CRelationEntiteSnmp_ChampCustom;

            if (m_createur != null && m_controleSnmp != null)
            {
                m_createur.SetTooltip(m_controleSnmp, "");
            }
            if (rel == null)
            {
                m_controleSnmp.Visible = false;
                m_imageWarning.Visible = false;
            }
            else
            {
                CDateTimeEx dt = rel.DateSynchroSnmp;
                if (dt != null)
                {
                    if (m_createur != null && m_controleSnmp != null)
                    {
                        m_createur.SetTooltip(m_controleSnmp, I.T("Last updated : @1 @2|20317",
                                                                  dt.DateTimeValue.ToShortDateString(),
                                                                  dt.DateTimeValue.ToLongTimeString()));
                    }
                }
                m_controleSnmp.Visible = true;
                object val = rel.LastSnmpValue;
                if (val == null)
                {
                    m_controleSnmp.Text = "";
                }
                else
                {
                    if (WndSnmp.ChampCustom.IsChoixParmis())
                    {
                        m_controleSnmp.Text = WndSnmp.ChampCustom.DisplayFromValue(val);
                    }
                    else if (m_controleSnmp is CheckBox)
                    {
                        ((CheckBox)m_controleSnmp).Checked = (val is bool) ? (bool)val : false;
                    }
                    else
                    {
                        m_controleSnmp.Text = val.ToString();
                    }
                }
                string strVal1 = m_wndChamp.Value != null?m_wndChamp.Value.ToString() : "";

                string strVal2 = val != null?val.ToString() : "";

                if (strVal1 != strVal2 && rel.DateSynchroSnmp != null)
                {
                    m_imageWarning.Visible = true;
                    m_controleSnmp.Width   = m_wndChamp.Control.Width - 16;
                }
                else
                {
                    m_imageWarning.Visible = false;
                    m_controleSnmp.Width   = m_wndChamp.Control.Width;
                }
            }
        }
Пример #6
0
        //------------------------------------------------------------------------
        public bool Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, object element)
        {
            CEntiteSnmp entite = element as CEntiteSnmp;

            if (entite != null)
            {
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entite, m_wndChampCustom.ChampCustom.Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null)
                {
                    int       nWidthChampCustom = Math.Max((cellBounds.Width * m_wndChampCustom.Size.Width) / Math.Max(Size.Width, 1), 10);
                    object    val     = rel.Valeur;
                    object    valSnmp = rel.LastSnmpValue;
                    Rectangle rct     = new Rectangle(new Point(0, 0), new Size(nWidthChampCustom, cellBounds.Height));
                    rct.Offset(cellBounds.Location);
                    Pen   pen = new Pen(Color.Black, 1);
                    Brush br  = new SolidBrush(m_wndChampCustom.BackColor);
                    graphics.FillRectangle(br, rct);
                    graphics.DrawRectangle(pen, rct);

                    br.Dispose();

                    StringFormat format = new StringFormat();
                    format.LineAlignment = StringAlignment.Center;
                    format.Alignment     = StringAlignment.Near;
                    br = new SolidBrush(m_wndChampCustom.ForeColor);
                    graphics.DrawString(val == null ? "" : val.ToString(), m_wndChampCustom.Font, br, rct, format);
                    br.Dispose();
                    string strVal1 = val != null?val.ToString() : "";

                    string strVal2 = valSnmp != null?valSnmp.ToString() : "";

                    bool bHasDif = strVal1 != strVal2 && rel.DateSynchroSnmp != null;
                    rct = cellBounds;
                    rct.Offset(nWidthChampCustom, 0);
                    rct.Size = new Size(rct.Size.Width - nWidthChampCustom, rct.Size.Height);
                    if (bHasDif)
                    {
                        rct.Size = new Size(rct.Size.Width - 16, rct.Size.Height);
                    }
                    br = new SolidBrush(m_wndValeurAutre.BackColor);
                    graphics.FillRectangle(br, rct);
                    graphics.DrawRectangle(pen, rct);
                    br.Dispose();
                    pen.Dispose();
                    br = new SolidBrush(m_wndValeurAutre.ForeColor);
                    graphics.DrawString(valSnmp == null ? "" : valSnmp.ToString(), m_wndValeurAutre.Font, br, rct, format);
                    format.Dispose();
                    br.Dispose();
                    if (bHasDif)
                    {
                        rct = new Rectangle(cellBounds.Right - 16, cellBounds.Top, 16, cellBounds.Height);
                        br  = new SolidBrush(BackColor);
                        graphics.FillRectangle(br, rct);
                        br.Dispose();
                        rct.Location = new Point(rct.Left, rct.Top + rct.Height / 2 - 8);
                        rct.Height   = 16;
                        graphics.DrawImage(Resource.alerte, rct);
                    }
                    return(false);
                }
            }
            return(true);
        }