Ejemplo n.º 1
0
        //todo: return new Keyword?
        public Patch LoadPatch(int PatchOID)
        {
            //create typed data objects
            DSNyMPH.tbPatchesDataTable _dtPatch = new DSNyMPH.tbPatchesDataTable();

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

            if (_dtPatch.Rows.Count == 0)
            {
                return(new Patch());
            }
            else
            {
                //map row to object
                return(MapRowToPatch(_dtPatch.Rows[0]));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes the specified Patch from the database.
        /// </summary>
        /// <param name="Item">The Patch to delete.</param>
        /// <returns>The number of records affected. This will be -1 if an exception occurs.</returns>
        public int DeletePatch(Patch Item)
        {
            //TODO: Cleanup orphaned records.
            int _result = 0;

            //verify not null and OID isn't null
            if ((Item != null) && (Item.OID != -1))
            {
                //create typed data objects
                DSNyMPH.tbPatchesDataTable _dtPatch = new DSNyMPH.tbPatchesDataTable();

                try
                {
                    using (tbPatchesTableAdapter _taPatch = new tbPatchesTableAdapter())
                    {
                        //fill typed table with instance(s) of this Patch
                        _taPatch.FillByOID(_dtPatch, Item.OID);

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

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

            return(_result);
        }
Ejemplo n.º 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);
        }