ATMLDataAccessLibrary.db.daos.SignalDAO.hasAttribute C# (CSharp) Method

hasAttribute() public method

public hasAttribute ( int signalId, String attributeName ) : bool
signalId int
attributeName String
return bool
        public bool hasAttribute( int? signalId, String attributeName )
        {
            int count = 0;
            String sql = "SELECT count(*) FROM signal_attribute_master WHERE signal_id = ? AND attribute_name = ?";
            OleDbParameter[] dbParams = { CreateParameter(dbSignalAttribute._SIGNAL_ID, signalId),
                                          CreateParameter(dbSignalAttribute._ATTRIBUTE_NAME, attributeName ) };
            using (OleDbDataReader reader = ExecuteSqlQuery( sql, dbParams ))
            {
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        count = reader.GetInt32( 0 );
                    }
                    reader.Close();
                    reader.Dispose();
                }
            }
            return count>0;
        }

Usage Example

        public void SaveSignalModel()
        {
            //Check Database for _TSF.name
            //If not found add it
            //walk through attributes
            //check for attribute names
            //if not found add them

            var dao = new SignalDAO();
            dbSignal dataSignal = dao.getSignal( _name, _signalNameSpace );
            dbSignal baseSignal = dao.getSignal( _baseSignalName, _baseSignalNameSpace );
            if (dataSignal == null)
            {
                dataSignal = new dbSignal();
                dataSignal.parentSignalId = baseSignal != null ? baseSignal.signalId : 0;
                dataSignal.xmlns = _signalNameSpace;
                dataSignal.signalName = _name;
                dataSignal.uuid = Guid.Parse( _tsf.uuid );
                dataSignal.save();
            }

            foreach (SignalAttribute attr in _attributes)
            {
                bool hasAttribute = dao.hasAttribute( dataSignal.signalId, attr.Name );
                dbSignalAttribute dbAttribute;
                if (!hasAttribute)
                    dbAttribute = new dbSignalAttribute();
                else
                    dbAttribute = dao.GetAttribute( dataSignal.signalId, attr.Name );

                dbAttribute.DataState = hasAttribute ? BASEBean.eDataState.DS_EDIT : BASEBean.eDataState.DS_ADD;
                dbAttribute.attributeName = attr.Name;
                dbAttribute.signalId = dataSignal.signalId;
                dbAttribute.defaultValue = attr.DefaultValue;
                dbAttribute.fixedValue = attr.FixedValue;
                dbAttribute.type = attr.SchemaType;
                dbAttribute.save();
            }
        }