public static bool AddOrUpdateTime(ref TimeData td)
 {
     if (td.ItemId < 0)
     {
         return(AddTime(ref td));
     }
     return(UpdateTime(ref td));
 }
		public bool ConvertToRegularTime()
		{
			var td = new TimeData {
				                      Date = _rbcTimeData.Date,
				                      Minutes = _rbcTimeData.Minutes,
				                      Notes = _rbcTimeData.Notes
			                      };
			return DeleteTime() && TimeDataInterface.AddTime(ref td);
		}
		/// <summary>
		/// Adds the time.
		/// </summary>
		/// <param name="d">The d.</param>
		public static bool AddTime(ref TimeData d)
		{
			using (var db = new TimeDataContext(TimeDataContext.DBConnectionString)) {
				var newTd = TimeData.Copy(d);
				db.TimeDataItems.InsertOnSubmit(newTd);
				db.SubmitChanges();
				d.ItemId = newTd.ItemId;
				return newTd.ItemId > 0;
			}
		}
 /// <summary>
 /// Adds the time.
 /// </summary>
 /// <param name="d">The d.</param>
 public static bool AddTime(ref TimeData d)
 {
     using (var db = new TimeDataContext(TimeDataContext.DBConnectionString)) {
         var newTd = TimeData.Copy(d);
         db.TimeDataItems.InsertOnSubmit(newTd);
         db.SubmitChanges();
         d.ItemId = newTd.ItemId;
         return(newTd.ItemId > 0);
     }
 }
 /// <summary>
 /// Gets the time data item.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns>TimeData.</returns>
 public static TimeData GetTimeDataItem(int id)
 {
     using (var db = new TimeDataContext(TimeDataContext.DBConnectionString)) {
         try {
             TimeDataItem tdi = db.TimeDataItems.Single(s => s.ItemId == id);
             var          td  = TimeData.Copy(tdi);
             return(td);
         } catch (InvalidOperationException) {
             return(null);
         }
     }
 }
 internal static TimeDataItem Copy(TimeData d)
 {
     return(new TimeDataItem {
         Date = d.Date,
         BibleStudies = d.BibleStudies,
         Books = d.Books,
         Brochures = d.Brochures,
         Magazines = d.Magazines,
         Minutes = d.Minutes,
         Notes = d.Notes,
         ReturnVisits = d.ReturnVisits,
         Tracts = d.Tracts
     });
 }
        /// <summary>
        /// Loads the time report.
        /// </summary>
        /// <param name="entries">The entries.</param>
        public void LoadTimeReport(TimeData[] entries)
        {
            if (!IsTimeReportDataLoading) {
                IsTimeReportDataLoading = true;
                OnPropertyChanged("IsTimeReportDataLoading");
                icReport.Clear();
                lbTimeEntries.Clear();
                _timeReportTotal = 0;
            }


            int summaryMinTotal = 0;
            if (entries.Length <= 0) return;

            int month = entries[0].Date.Month;
            int year = entries[0].Date.Year;
            var summary = new TimeReportSummaryModel();
            var rtdEntries = new List<RBCTimeData>();
            //ListBox<int> rvList = new ListBox<int>();
            foreach (TimeData td in entries) {	//total regular time entries

                //build total number for the report.
                _timeReportTotal += td.Minutes;


                //summary data start
                if (month != td.Date.Month) {
                    summary.Time = string.Format(StringResources.TimeReport_HoursAndMinutes, (summaryMinTotal / 60), summaryMinTotal > 0 ? summaryMinTotal % 60 : 0);
                    summary.Minutes = summaryMinTotal;
                    summary.RBCHours = (RBCTimeDataInterface.GetMonthRBCTimeTotal(new DateTime(year, month, 1))) / 60.0;
                    RBCTimeData[] eee = RBCTimeDataInterface.GetRBCTimeEntries(new DateTime(year, month, 1), new DateTime(year, month, 1).AddMonths(1).AddDays(-1), SortOrder.DateNewestToOldest);
                    if (eee != null) rtdEntries.AddRange(eee);
                    icReport.Add(summary);
                    summary = new TimeReportSummaryModel();
                    month = td.Date.Month;
                    year = td.Date.Year;
                    summaryMinTotal = 0;
                }
                summary.Month = td.Date.ToString("MMMM", CultureInfo.CurrentUICulture).ToUpper();
                summary.Days++;
                summaryMinTotal += td.Minutes;
                summary.Magazines += td.Magazines;
                summary.BibleStudies += td.BibleStudies;
                summary.Books += td.Books;
                summary.Brochures += td.Brochures;
                summary.ReturnVisits += td.ReturnVisits;
                summary.Tracts += td.Tracts;
                //summary data end.

                //add the time data to the entries page.
                lbTimeEntries.Add(new TimeReportEntryViewModel {
                    Date = td.Date,
                    Hours = string.Format(StringResources.TimeReport_HoursAndMinutes, (td.Minutes / 60), td.Minutes > 0 ? td.Minutes % 60 : 0),
                    ItemId = td.ItemId,
                    Minutes = td.Minutes,
                    EditLink = string.Format("/View/RegularTime.xaml?id={0}", td.ItemId),
                    Notes = td.Notes,
                    MagazinesCount = td.Magazines,
                    BrochuresCount = td.Brochures,
                    BooksCount = td.Books,
                    TractsCount = td.Tracts,
                    RVsCount = td.ReturnVisits,
                    Type = TimeType.Regular
                });
            }

            RBCTimeData[] ee = RBCTimeDataInterface.GetRBCTimeEntries(new DateTime(year, month, 1), new DateTime(year, month, 1).AddMonths(1).AddDays(-1), SortOrder.DateNewestToOldest);
            if (ee != null) rtdEntries.AddRange(ee);
            summary.RBCHours = (RBCTimeDataInterface.GetMonthRBCTimeTotal(new DateTime(year, month, 1)) / 60.0);
            summary.Time = string.Format(StringResources.TimeReport_HoursAndMinutes, (summaryMinTotal / 60), summaryMinTotal > 0 ? summaryMinTotal % 60 : 0);
            summary.Minutes = summaryMinTotal;
            icReport.Add(summary);

            foreach (RBCTimeData e in rtdEntries) {
                //add time 
                _timeReportTotal += e.Minutes;
                lbTimeEntries.Add(new TimeReportEntryViewModel {
                    Date = e.Date,
                    Hours = string.Format(StringResources.TimeReport_AuxHoursAndMinutes, (int)e.Hours, e.Minutes > 0 ? e.Minutes % 60 : 0),
                    ItemId = e.ItemID,
                    Minutes = e.Minutes,
                    EditLink = string.Format("/View/RBCTime.xaml?id={0}", e.ItemID),
                    Notes = e.Notes,
                    MagazinesCount = -1,
                    BrochuresCount = -1,
                    BooksCount = -1,
                    RVsCount = -1,
                    TractsCount = -1,
                    Type = TimeType.Auxiliary
                });
            }
            TimeReportEntryViewModel[] lte = lbTimeEntries.OrderBy(s => s.Date.Date).ToArray();
            lbTimeEntries.Clear();
            foreach (TimeReportEntryViewModel l in lte) lbTimeEntries.Add(l);

            TimeReportChartData = new ObservableCollection<TimeChartInfo>();
            if (icReport.Count > 1) {
                foreach (TimeReportSummaryModel v in icReport) {
                    TimeReportChartData.Add(new TimeChartInfo { Header = new String(v.Month.Take(3).ToArray()), Time = (v.Minutes / 60.0) });
                }
            } else {
                foreach (TimeReportEntryViewModel v in lbTimeEntries) {
                    TimeReportChartData.Add(new TimeChartInfo { Header = string.Format("{0}/{1}", v.Date.Month, v.Date.Day), Time = (v.Minutes / 60.0) });
                }
            }
            OnPropertyChanged("TimeReportTotal");
            OnPropertyChanged("TimeReportGaugeValue");
            OnPropertyChanged("TimeReportGaugeGoalValue");
            OnPropertyChanged("TimeReportGoalText");
            OnPropertyChanged("TimeReportRemainingText");
            IsTimeReportDataLoading = false;
            OnPropertyChanged("IsTimeReportDataLoading");
            OnPropertyChanged("TimeReportChartData");
        }
		public bool DeleteTime()
		{
			bool v = _timeData.ItemId >= 0 && TimeDataInterface.DeleteTime(_timeData.ItemId);
			if (v) {
				_timeData = null;
				OnPropertyChanged("TimeData");
			}
			return v;
		}
		/// <summary>
		/// Updates the time.
		/// </summary>
		/// <param name="td">The td.</param>
		/// <returns>System.Int32.</returns>
		/// <exception cref="MyTimeDatabaseLib.TimeDataItemNotFoundException">Couldn't find the time data with that id.</exception>
		public static bool UpdateTime(ref TimeData td)
		{
			if (td.ItemId < 0) return AddTime(ref td);
			int itemId = td.ItemId;
			using (var db = new TimeDataContext(TimeDataContext.DBConnectionString)) {
				try {
					TimeDataItem tdi = db.TimeDataItems.Single(s => s.ItemId == itemId);

					tdi.BibleStudies = td.BibleStudies;
					tdi.Books = td.Books;
					tdi.Brochures = td.Brochures;
					tdi.Date = td.Date;
					tdi.Magazines = td.Magazines;
					tdi.Minutes = td.Minutes;
					tdi.Notes = td.Notes;
					tdi.ReturnVisits = td.ReturnVisits;
				        tdi.Tracts = td.Tracts;

					db.SubmitChanges();
					return true;
				} catch(InvalidOperationException) {
					return AddTime(ref td);
				} catch {
					throw new TimeDataItemNotFoundException("Couldn't find the time data with that id.");
				}
			}
		}
		internal static TimeDataItem Copy(TimeData d)
		{
			return new TimeDataItem {
				                        Date = d.Date,
				                        BibleStudies = d.BibleStudies,
				                        Books = d.Books,
				                        Brochures = d.Brochures,
				                        Magazines = d.Magazines,
				                        Minutes = d.Minutes,
				                        Notes = d.Notes,
				                        ReturnVisits = d.ReturnVisits,
                                                        Tracts = d.Tracts
			                        };
		}
		public static bool AddOrUpdateTime(ref TimeData td)
		{
			if (td.ItemId < 0) return AddTime(ref td);
			return UpdateTime(ref td);
		}
示例#12
0
        private void TimeAdditClickTapEvent()
        {
            if (_timerState == TimerState.Running) PauseTimer();
            TimeSpan t = TimerTimeSpan;

            if (t.TotalMinutes <= 0) {
                App.ToastMe(StringResources.MainPage_Messages_CantAddZeroMin);
                return;
            }

            var ts = TimeSpan.FromMinutes(App.Settings.roundTimeIncrement * Math.Ceiling(t.TotalMinutes / App.Settings.roundTimeIncrement));
            float m = float.Parse(t.TotalMinutes.ToString()) % App.Settings.roundTimeIncrement;
            if (m <= (App.Settings.roundTimeIncrement / 2.0)) t = TimeSpan.FromMinutes(ts.TotalMinutes - App.Settings.roundTimeIncrement);
            else t = ts;

            var minutes = (int)t.TotalMinutes;

            if (minutes <= 0) {
                App.ToastMe(StringResources.MainPage_Messages_CantAddZeroMin);
                return;
            }

            var td = new TimeData {
                Date = DateTime.Now,
                Minutes = minutes,
                Magazines = (int)tbMags.Value,
                Brochures = (int)tbBrochures.Value,
                Books = (int)tbBooks.Value,
                Tracts = (int)tbTracts.Value,
                BibleStudies = (int)tbBibleStudies.Value,
                ReturnVisits = (int)tbReturnVisits.Value,
                Notes = tbNotes.Text
            };

            try {
                int id;
                if (TimeDataInterface.IsDoubleDataEntry(DateTime.Now, out id) &&
                    MessageBox.Show(StringResources.AddRBCTimePage_AskForDoubleEntry, "", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK) {
                    var tdOld = TimeDataInterface.GetTimeDataItem(id);
                    tdOld.Minutes += td.Minutes;
                    tdOld.Magazines += td.Magazines;
                    tdOld.Brochures += td.Brochures;
                    tdOld.Books += td.Books;
                    tdOld.Tracts += td.Tracts;
                    tdOld.BibleStudies += td.BibleStudies;
                    tdOld.ReturnVisits += td.ReturnVisits;
                    tdOld.Notes += td.Notes.Length > 0 ? string.Format("\n\n{0}", td.Notes) : string.Empty;
                    TimeDataInterface.UpdateTime(ref tdOld);
                    var a = new TimeSpan(0, tdOld.Minutes, 0);
                    App.ToastMe(string.Format(StringResources.MainPage_Messages_AddedTime, a.Hours, a.Minutes));
                } else {
                    TimeDataInterface.AddTime(ref td);
                    App.ToastMe(string.Format(StringResources.MainPage_Messages_AddedTime, t.Hours, t.Minutes));
                }
                TimerStopClickTapEvent();
                ResetText();
            } catch (Exception ee) {
                throw ee;
            }
        }