Example #1
0
        /// <summary>
        /// This method writes the Data to the Location.
        /// </summary>
        /// <param name="Location">The path and filename to write data to.</param>
        /// <param name="Data">The data to write to the file.</param>
        /// <returns>True if write operation succeeded, otherwise false.</returns>
        public static bool Write(string Location, string Data)
        {
            try
            {
                File.WriteAllText(Location, Data);
            }
            catch (Exception ex)
            {
                _elh.WriteEvent(string.Format("Exception occurred while writing to {0}. Exception details: {1}", Location, ex.Message), EventLogEntryType.Error);
            }

            return(File.Exists(Location));
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// Persists an instance of Patch to the database.
        /// </summary>
        /// <param name="Item">A Patch instance to add or update. If added, this Patch will have its OID property assigned.</param>
        /// <returns>The number of rows affected; this will be -1 if an exception occurs.</returns>
        public int SavePatch(ref Patch Item)
        {
            //TODO: update related records.
            //TODO: Use DataSet object for related records.
            int _result = 0;

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

                try
                {
                    using (tbPatchesTableAdapter _taPatches = new tbPatchesTableAdapter())
                    {
                        //set connection object
                        _taPatches.Connection = _conn;

                        //fill typed table with instance(s) of this Patch
                        _taPatches.FillByOID(_dtPatch, Item.OID);

                        //If no records are returned, add this Keyword to the datatable.
                        if (_dtPatch.Count == 0)
                        {
                            DSNyMPH.tbPatchesRow _row = _dtPatch.NewtbPatchesRow();

                            //set properties
                            MapPatchToRow(Item, ref _row);

                            _dtPatch.AddtbPatchesRow(_row);
                            //update changes to datatable using table adapter
                            _result = _taPatches.Update(_dtPatch);

                            //update PatchOID
                            Item.OID = FindPatchOID(Item);
                        }
                        else
                        {
                            //should only be one instance
                            DSNyMPH.tbPatchesRow _row = (DSNyMPH.tbPatchesRow)_dtPatch.Rows[0];

                            MapPatchToRow(Item, ref _row);

                            //update changes to datatable using table adapter
                            _result = _taPatches.Update(_dtPatch);
                        }
                    }
                }
                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);
        }