Esempio n. 1
0
        //todo: return new Keyword?
        public Keyword LoadKeyword(int KeywordOID)
        {
            //create typed data objects
            DSNyMPH.tbKeywordDataTable _dtKeyword = new DSNyMPH.tbKeywordDataTable();

            try
            {
                using (tbKeywordTableAdapter _taKeyword = new tbKeywordTableAdapter())
                {
                    //fill typed table
                    _taKeyword.FillByOID(_dtKeyword, KeywordOID);
                }
            }
            catch (Exception ex)
            {
                _elh.WriteEvent(string.Format("Exception occurred while getting Keywords with KeywordOID =  {0}. Exception details: {1}", KeywordOID.ToString(), ex.Message), EventLogEntryType.Error);
            }

            if (_dtKeyword.Rows.Count == 0)
            {
                return(new Keyword());
            }
            else
            {
                //cast typed table to keyword object
                return(MapRowToKeyword(_dtKeyword.Rows[0]));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes the specified Keyword from the database. Only custom Keywords can be deleted.
        /// </summary>
        /// <param name="Item">The Keyword to delete.</param>
        /// <returns>The number of records affected. This will be -1 if an exception occurs.</returns>
        public int DeleteKeyword(Keyword Item)
        {
            int _result = 0;

            //verify not null, isn't 'built-in' Keyword, and OID isn't null
            if ((Item != null) && (Item.IsCustom) && (Item.OID != -1))
            {
                //create typed data objects
                DSNyMPH.tbKeywordDataTable _dtKeyword = new DSNyMPH.tbKeywordDataTable();

                try
                {
                    using (tbKeywordTableAdapter _taKeyword = new tbKeywordTableAdapter())
                    {
                        //fill typed table with instance(s) of this Keyword
                        _taKeyword.FillByOID(_dtKeyword, Item.OID);

                        //If no records are returned, add this Keyword to the datatable.
                        if (_dtKeyword.Count == 1)
                        {
                            //should only be one instance
                            _dtKeyword.Rows[0].Delete();
                        }
                        else
                        {
                            //TODO: Shouldn't be multiple rows, but handle it better
                            throw new NotImplementedException("Handle multiple Keywords");
                        }
                        // update deletion changes to datatable using table adapter
                        _result = _taKeyword.Update(_dtKeyword);
                    }
                }
                catch (Exception ex)
                {
                    //write to logging
                    _elh.WriteEvent(string.Format("Exception occurred while deleting Keyword   {0}. Exception details: {1}", Item.ToString(), ex.Message), EventLogEntryType.Error);

                    _result = -1;
                }
            }
            else
            {
                _result = -1;
            }

            return(_result);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a list of Keyword instances belonging to a certain type.
        /// </summary>
        /// <param name="KeywordType">The type of Keyword to return.</param>
        /// <returns>A list of Keyword objects; this will be an empty list if an exception occurs.</returns>
        public List <Keyword> GetKeywordsByType(SDKCategories SDKType)
        {
            //create typed data objects
            DSNyMPH.tbKeywordDataTable _dtKeyword = new DSNyMPH.tbKeywordDataTable();

            try
            {
                //using (tbKeywordTableAdapter _taKeyword = new tbKeywordTableAdapter())
                //{
                //_taKeyword.Connection = _conn;
                ////fill typed table
                //_taKeyword.FillByType(_dtKeyword, SDKType.ToString());

                //use global table adapter to fill datatable
                _keywordTA.FillByType(_dtKeyword, SDKType.ToString());

                Console.WriteLine(_dtKeyword.Rows.Count);

                // }
            }
            catch (Exception ex)
            {
                _elh.WriteEvent(string.Format("Exception occurred while getting List of Keywords with KeywordType =  {0}. Exception details: {1}", SDKType.ToString(), ex.Message), EventLogEntryType.Error);
            }

            //create typed list with correct capacity
            List <Keyword> _keywords = new List <Keyword>(_dtKeyword.Rows.Count);

            foreach (DSNyMPH.tbKeywordRow _row in _dtKeyword.Rows)
            {
                //map datarow to Keyword object
                _keywords.Add(MapRowToKeyword(_row));
            }

            return(_keywords);
        }
Esempio n. 4
0
        /// <summary>
        /// Persists an instance of Keyword to the database.
        /// </summary>
        /// <param name="Item">A Keyword instance to add or update. If added, this Keyword will have its OID property assigned.</param>
        /// <returns>The number of rows affected; this will be -1 if an exception occurs.</returns>
        public int SaveKeyword(ref Keyword Item)
        {
            int _result = 0;

            if (Item != null)
            {
                //create typed data objects
                DSNyMPH.tbKeywordDataTable _dtKeyword = new DSNyMPH.tbKeywordDataTable();

                try
                {
                    using (tbKeywordTableAdapter _taKeyword = new tbKeywordTableAdapter())
                    {
                        //fill typed table with instance(s) of this Keyword
                        _taKeyword.FillByOID(_dtKeyword, Item.OID);

                        //If no records are returned, add this Keyword to the datatable.
                        if (_dtKeyword.Count == 0)
                        {
                            //add new row
                            //_result = _taKeyword.Insert(Item.Name, Item.IsCustom, Item.KeywordType.ToString());


                            DSNyMPH.tbKeywordRow _row = _dtKeyword.NewtbKeywordRow();

                            //TODO: review this process
                            //set properties
                            _row.KeywordName = Item.Name;
                            _row.KeywordType = Item.KeywordType.ToString();
                            _row.IsCustom    = Item.IsCustom;

                            _dtKeyword.AddtbKeywordRow(_row);
                            //update changes to datatable using table adapter
                            _result = _taKeyword.Update(_dtKeyword);

                            Item.OID = FindKeywordOID(Item);
                        }
                        else
                        {
                            //should only be one instance
                            //TODO: there's probably a better way to do this...
                            DSNyMPH.tbKeywordRow _row = (DSNyMPH.tbKeywordRow)_dtKeyword.Rows[0];

                            //TODO: review this process
                            //set properties
                            _row.KeywordName = Item.Name;
                            _row.KeywordType = Item.KeywordType.ToString();
                            _row.IsCustom    = Item.IsCustom;

                            //update changes to datatable using table adapter
                            _result = _taKeyword.Update(_dtKeyword);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //write to logging
                    _elh.WriteEvent(string.Format("Exception occurred while saving Keyword   {0}. Exception details: {1}", Item.ToString(), ex.Message), EventLogEntryType.Error);

                    _result = -1;
                }
            }
            else
            {
                _result = -1;
            }
            return(_result);
        }