Ejemplo n.º 1
0
        /// <summary>
        /// Maps an instance of Patch to a typed DataRow
        /// </summary>
        /// <param name="_Patch">An instance of Patch to create a typed DataRow for.</param>
        /// <param name="_Row">A referenced typed DataRow to assign values to.</param>
        public static void MapPatchToRow(Patch _Patch, ref DSNyMPH.tbPatchesRow _Row)
        {
            //map object to typed row.
            if (_Row != null)
            {
                _Row.PatchName        = _Patch.Name;
                _Row.OriginalLocation = _Patch.OriginalLocation;
                _Row.Rating           = _Patch.Rating;
                _Row.LastModified     = _Patch.LastModified;
                _Row.IsNew            = _Patch.IsNew;
                _Row.IsArchived       = _Patch.IsArchived;
                _Row.Description      = _Patch.Description;
                _Row.Usage            = _Patch.Usage;
                _Row.WhenCreated      = _Patch.WhenCreated;
                _Row.PatchName        = _Patch.Name;

                //TODO: Handle relationships with other objects
            }
        }
Ejemplo n.º 2
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);
        }