Beispiel #1
0
        /// <summary>
        /// Adds or Updates the RBC Time.
        /// </summary>
        /// <param name="td">The Time Data to Add/Update. If the ItemId is -1 it will automatically add it.</param>
        /// <returns>[true] if successful, otherwise [false].</returns>
        public static bool AddOrUpdateTime(ref RBCTimeData td)
        {
            if (td.ItemID < 0)
            {
                return(AddTime(ref td));
            }
            using (var db = new RBCTimeDataContext()) {
                try {
                    int i        = td.ItemID;
                    var tdUpdate = db.RBCTimeDataItems.Single(s => s.ItemId == i);
                    if (tdUpdate == null)
                    {
                        return(AddTime(ref td));
                    }

                    tdUpdate.Minutes = td.Minutes;
                    tdUpdate.Notes   = td.Notes;
                    tdUpdate.Date    = td.Date;

                    db.SubmitChanges();
                    return(true);
                } catch (InvalidOperationException) {
                    return(AddTime(ref td));
                } catch {
                    return(false);
                }
            }
        }
Beispiel #2
0
 private static RBCTimeDataItem Copy(RBCTimeData td)
 {
     return(new RBCTimeDataItem {
         /*ItemId = td.ItemID,*/
         Date = td.Date,
         Minutes = td.Minutes,
         Notes = td.Notes
     });
 }
Beispiel #3
0
 public static bool DeleteTime(RBCTimeData td)
 {
     //
     if (td.ItemID < 0)
     {
         return(false);
     }
     return(DeleteTime(td.ItemID));
 }
		public bool DeleteTime()
		{
			bool v = _rbcTimeData.ItemID >= 0 && RBCTimeDataInterface.DeleteTime(RBCTimeData);
			if (v) {
				_rbcTimeData = null;
				OnPropertyChanged("RBCTimeData");
			}
			return v;
		}
Beispiel #5
0
 private static bool AddTime(ref RBCTimeData td)
 {
     //throw new NotImplementedException();
     using (var db = new RBCTimeDataContext()) {
         var newTd = Copy(td);
         db.RBCTimeDataItems.InsertOnSubmit(newTd);
         db.SubmitChanges();
         td.ItemID = newTd.ItemId;
         return(td.ItemID >= 0);
     }
 }
		private static bool AddTime(ref RBCTimeData td)
		{
			//throw new NotImplementedException();
			using (var db = new RBCTimeDataContext()) {
				var newTd = Copy(td);
				db.RBCTimeDataItems.InsertOnSubmit(newTd);
				db.SubmitChanges();
				td.ItemID = newTd.ItemId;
				return td.ItemID >= 0;
			}
		}
Beispiel #7
0
        public static RBCTimeData[] GetRBCTimeEntries(DateTime fromDate, DateTime toDate, SortOrder sortOrder)
        {
            //throw new NotImplementedException();
            using (var db = new RBCTimeDataContext()) {
                try {
                    var rtd = from x in db.RBCTimeDataItems
                              where x.Date >= fromDate && x.Date <= toDate
                              orderby x.Date
                              select x;

                    return(!rtd.Any() ? null : rtd.Select(i => RBCTimeData.Copy(i)).ToArray());
                } catch { return(null); }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Gets the RBC Time Data for a given itemID.
 /// </summary>
 /// <param name="itemID">The item ID to look up.</param>
 /// <returns>The time data for the given item id.</returns>
 public static RBCTimeData GetRBCTimeData(int itemID)
 {
     //
     if (itemID < 0)
     {
         return(null);
     }
     using (var db = new RBCTimeDataContext()) {
         try {
             var rtd = db.RBCTimeDataItems.Single(s => s.ItemId == itemID);
             if (rtd == null)
             {
                 return(null);
             }
             return(RBCTimeData.Copy(rtd));
         } catch {
             return(null);
         }
     }
 }
		/// <summary>
		/// Adds or Updates the RBC Time.
		/// </summary>
		/// <param name="td">The Time Data to Add/Update. If the ItemId is -1 it will automatically add it.</param>
		/// <returns>[true] if successful, otherwise [false].</returns>
		public static bool AddOrUpdateTime(ref RBCTimeData td)
		{
			if (td.ItemID < 0) return AddTime(ref td);
			using (var db = new RBCTimeDataContext()) {
				try {
					int i = td.ItemID;
					var tdUpdate = db.RBCTimeDataItems.Single(s => s.ItemId == i);
					if (tdUpdate == null) return AddTime(ref td);

					tdUpdate.Minutes = td.Minutes;
					tdUpdate.Notes = td.Notes;
					tdUpdate.Date = td.Date;

					db.SubmitChanges();
					return true;

				} catch (InvalidOperationException) {
					return AddTime(ref td);
				} catch {
					return false;
				}
			}
		}
		public bool ConvertToRBCTime()
		{
			var rtd = new RBCTimeData {
				                          Minutes = TimeData.Minutes,
				                          Date = TimeData.Date,
				                          Notes = TimeData.Notes
			                          };
			return DeleteTime() && RBCTimeDataInterface.AddOrUpdateTime(ref rtd);
		}
		public static bool DeleteTime(RBCTimeData td) 
		{ 
			//
			if (td.ItemID < 0) return false;
		    return DeleteTime(td.ItemID);
		}
		private static RBCTimeDataItem Copy(RBCTimeData td)
		{
			return new RBCTimeDataItem {
				                           /*ItemId = td.ItemID,*/
				                           Date = td.Date,
				                           Minutes = td.Minutes,
				                           Notes = td.Notes
			                           };
		}