コード例 #1
0
ファイル: ViewEvents.cs プロジェクト: Abduvokhid/MoneyApp
 public ViewEvents(bool recurring)
 {
     InitializeComponent();
     isRecurring = recurring;
     Text        = Strings.RecurringEvents;
     if (isRecurring == true)
     {
         lv_events.Columns.Add("Status Type");
         lv_events.Columns.Add("End Date");
         recurringEventRepository = RecurringEventRepository.Instance;
     }
     ResizeColumns();
     eventRepository = EventRepository.Instance;
 }
コード例 #2
0
        private async void _getRecurringEvents()
        {
            RecurringEventRepository recurringEventRepository = new RecurringEventRepository();
            List <RecurringEvent>    listOfRecurringEvent     = await Task.Run(() => recurringEventRepository.GetEvents(UserSession.UserData.Id));

            EventListView.Items.Clear();
            foreach (RecurringEvent recurringEvent in listOfRecurringEvent)
            {
                ListViewItem listView = new ListViewItem(new string[] { recurringEvent.Name, recurringEvent.Type, recurringEvent.EventDate.ToString() })
                {
                    Tag = recurringEvent
                };
                EventListView.Items.Add(listView);
            }
        }
コード例 #3
0
        private async void EventActionForm_Load(object sender, EventArgs e)
        {
            ContactRepository contactRepository = new ContactRepository();

            _eventRepository          = new EventRepository();
            _recurringEventRepository = new RecurringEventRepository();

            List <Contact> contactList = await Task.Run(() => contactRepository.GetContacts(UserSession.UserData.Id));

            CmbContact.DataSource    = contactList;
            CmbContact.DisplayMember = "Name";

            if (_recurringStatus)
            {
                _setContactForEvent(contactList, _recurringEvent);
            }
            else
            {
                _setContactForEvent(contactList, _eventInfo);
            }
        }
コード例 #4
0
        public async void _checkRecurringEvent()
        {
            EventRepository          _eventRepository          = new EventRepository();
            RecurringEventRepository _recurringEventRepository = new RecurringEventRepository();
            List <RecurringEvent>    recurringEventList        = _recurringEventRepository.GetEvents(UserSession.UserData.Id);

            foreach (RecurringEvent recurringEvent in recurringEventList)
            {
                int noOfDays = (DateTime.Now - UserSession.UserData.LastAccessDate).Days;

                DateTime recurringTime = UserSession.UserData.LastAccessDate;
                TimeSpan timeSpan      = new TimeSpan(recurringEvent.EventDate.Hour, recurringEvent.EventDate.Minute, recurringEvent.EventDate.Second);
                recurringTime = recurringTime.Date + timeSpan;

                for (int i = 0; i <= noOfDays; i++)
                {
                    if (recurringEvent.Status.Equals("Weekly"))
                    {
                        if (recurringTime.DayOfWeek != recurringEvent.EventDate.DayOfWeek)
                        {
                            recurringTime = recurringTime.AddDays(1);
                            continue;
                        }
                    }

                    if (recurringEvent.Status.Equals("Monthly"))
                    {
                        if (recurringTime.Day != recurringEvent.EventDate.Day)
                        {
                            recurringTime = recurringTime.AddDays(1);
                            continue;
                        }
                    }

                    if (recurringEvent.Status.Equals("Yearly"))
                    {
                        string recurringTimeString = recurringTime.ToString("dd/MM");
                        string createdDateString   = recurringEvent.EventDate.ToString("dd/MM");
                        if (!recurringTimeString.Equals(createdDateString))
                        {
                            recurringTime = recurringTime.AddDays(1);
                            continue;
                        }
                    }

                    if (recurringTime > UserSession.UserData.LastAccessDate && recurringTime <= DateTime.Now && recurringTime > recurringEvent.EventDate)
                    {
                        _messageStatus = await Task.Run(() => _eventRepository.AddEvent(new Event
                        {
                            Name      = recurringEvent.Name,
                            Location  = recurringEvent.Location,
                            Type      = recurringEvent.Type,
                            EventDate = recurringTime,
                            Note      = recurringEvent.Note,
                            ContactId = recurringEvent.ContactId,
                            UserId    = recurringEvent.UserId
                        }));

                        RecurringBackground.ReportProgress(1, "New Event has been Added");
                    }
                    recurringTime = recurringTime.AddDays(1);
                }
            }
        }
コード例 #5
0
ファイル: MoneyApp.cs プロジェクト: Abduvokhid/MoneyApp
        private void ShowEventsForDate(DateTime d)
        {
            pl_events.Controls.OfType <Panel>().ToList().ForEach(p => p.Dispose());

            pl_events.VerticalScroll.Maximum   = 0;
            pl_events.AutoScroll               = false;
            pl_events.HorizontalScroll.Maximum = 0;
            pl_events.HorizontalScroll.Visible = false;
            pl_events.AutoScroll               = true;

            RecurringEventRepository recurringEventRepository = RecurringEventRepository.Instance;
            List <RecurringEvent>    events = recurringEventRepository.GetRecurringEvents(Instances.User.ID);

            List <RecurringEvent> newList = new List <RecurringEvent>();

            events.ForEach(e =>
            {
                switch (e.Status)
                {
                case "Daily":
                    newList.Add(e);
                    break;

                case "Weekly":
                    if (e.CreatedDate.DayOfWeek == d.DayOfWeek)
                    {
                        newList.Add(e);
                    }
                    break;

                case "Monthly":
                    if (e.CreatedDate.Day == d.Day)
                    {
                        newList.Add(e);
                    }
                    break;

                case "Yearly":
                    if (e.CreatedDate.Month == d.Month && e.CreatedDate.Day == d.Day)
                    {
                        newList.Add(e);
                    }
                    break;
                }
            });

            newList = newList.OrderBy(e => e.CreatedDate.TimeOfDay).ToList();

            if (newList.Count == 0)
            {
                newList.Add(new RecurringEvent());
            }

            int now = 0;

            newList.ForEach(e =>
            {
                Panel p    = new Panel();
                p.Width    = pl_events.Width;
                p.Height   = 40;
                p.Location = new Point(0, now);
                now       += p.Height;

                Label name      = new Label();
                name.TextAlign  = ContentAlignment.MiddleLeft;
                string nameText = "";
                if (e.ID > 0)
                {
                    nameText = e.Name;
                    if (e.Type)
                    {
                        nameText += " at ";
                    }
                    else
                    {
                        nameText += " by ";
                    }
                    nameText += e.CreatedDate.ToString("HH:mm");
                }
                else
                {
                    nameText       = d.Date == DateTime.Now.Date ? "No events for today!" : "No events for this day!";
                    name.TextAlign = ContentAlignment.MiddleCenter;
                }
                name.Text      = nameText;
                name.ForeColor = Color.FromArgb(109, 116, 129);
                name.Font      = new Font("Roboto", 10F, FontStyle.Regular, GraphicsUnit.Point, 204);
                name.Location  = new Point(0, 0);
                name.Size      = new Size(p.Width, p.Height);
                name.Padding   = new Padding(15, 0, 0, 0);
                p.Controls.Add(name);

                Panel b     = new Panel();
                b.Width     = p.Width;
                b.Height    = 1;
                b.Location  = new Point(0, 0);
                b.BackColor = Color.FromArgb(228, 232, 241);
                p.Controls.Add(b);
                b.BringToFront();

                pl_events.Controls.Add(p);
            });

            Panel line = new Panel();

            line.Width     = pl_events.Width;
            line.Height    = 1;
            line.Location  = new Point(0, now);
            line.BackColor = Color.FromArgb(228, 232, 241);
            pl_events.Controls.Add(line);
            line.BringToFront();
        }
コード例 #6
0
ファイル: MoneyApp.cs プロジェクト: Abduvokhid/MoneyApp
        private async void DoRecurringEvent()
        {
            EventRepository          transactionRepository    = EventRepository.Instance;
            RecurringEventRepository recurringEventRepository = RecurringEventRepository.Instance;

            if (Instances.User == null)
            {
                return;
            }
            List <RecurringEvent> recurringEvents = recurringEventRepository.GetRecurringEvents(Instances.User.ID);

            foreach (RecurringEvent recurringEvent in recurringEvents)
            {
                if (Instances.User == null)
                {
                    return;
                }
                if (DateTime.Now > recurringEvent.EndDate && recurringEvent.EndDate != DateTime.MinValue)
                {
                    continue;
                }
                DateTime accTime = Instances.User.LastAccessDate;
                DateTime nowTime = DateTime.Now;
                int      days    = (nowTime - accTime).Days;
                DateTime recTime = Instances.User.LastAccessDate;
                TimeSpan ts      = new TimeSpan(
                    recurringEvent.CreatedDate.Hour,
                    recurringEvent.CreatedDate.Minute,
                    recurringEvent.CreatedDate.Second
                    );
                recTime = recTime.Date + ts;
                for (int i = 0; i <= days; i++)
                {
                    if (recurringEvent.Status.Equals("Weekly"))
                    {
                        if (recTime.DayOfWeek != recurringEvent.CreatedDate.DayOfWeek)
                        {
                            recTime = recTime.AddDays(1);
                            continue;
                        }
                    }
                    if (recurringEvent.Status.Equals("Monthly"))
                    {
                        if (recTime.Day != recurringEvent.CreatedDate.Day)
                        {
                            recTime = recTime.AddDays(1);
                            continue;
                        }
                    }
                    if (recurringEvent.Status.Equals("Yearly"))
                    {
                        string recTimeString     = recTime.ToString("dd/MM");
                        string createdDateString = recurringEvent.CreatedDate.ToString("dd/MM");
                        if (!recTimeString.Equals(createdDateString))
                        {
                            recTime = recTime.AddDays(1);
                            continue;
                        }
                    }
                    if (recTime > accTime && recTime <= nowTime && recTime > recurringEvent.CreatedDate)
                    {
                        if (Instances.User == null)
                        {
                            return;
                        }
                        await Task.Run(() => transactionRepository.AddEvent(new Event
                        {
                            Name        = recurringEvent.Name,
                            UserID      = recurringEvent.UserID,
                            ContactID   = recurringEvent.ContactID,
                            Type        = recurringEvent.Type,
                            Location    = recurringEvent.Location,
                            Note        = recurringEvent.Note,
                            CreatedDate = recTime
                        }));

                        bw_recurring.ReportProgress(1, "New event has been added!");
                    }
                    recTime = recTime.AddDays(1);
                }
            }
        }
コード例 #7
0
ファイル: AddEditEvent.cs プロジェクト: Abduvokhid/MoneyApp
        private async void UpdateRecurringEvent()
        {
            if (tbx_name.Text.Equals(""))
            {
                MessageBox.Show(Strings.ErrorEmptyName);
                return;
            }

            RecurringEventRepository eventRepository = RecurringEventRepository.Instance;

            temporaryRecurringEvent.Name        = tbx_name.Text;
            temporaryRecurringEvent.TypeName    = cbx_type.Text;
            temporaryRecurringEvent.Location    = tbx_location.Text;
            temporaryRecurringEvent.CreatedDate = dtp_date.Value;
            temporaryRecurringEvent.Note        = rtbx_note.Text;
            RecurringEvent recurringEvent = new RecurringEvent();

            recurringEvent.Status  = cbx_frequency.Text;
            recurringEvent.EndDate = dtp_enddate.Value;

            if (temporaryRecurringEvent.TypeName.Equals("Task"))
            {
                temporaryRecurringEvent.Type = false;
            }
            else
            {
                temporaryRecurringEvent.Type = true;
            }

            Contact contact = (Contact)cbx_contact.SelectedItem;

            if (contact == null)
            {
                if (string.IsNullOrWhiteSpace(cbx_contact.Text))
                {
                    temporaryRecurringEvent.ContactID = 0;
                }
                else
                {
                    ContactRepository contactRepository = ContactRepository.Instance;
                    temporaryRecurringEvent.ContactID = await Task.Run(() => contactRepository.AddContact(new Contact {
                        Name = cbx_contact.Text, UserID = Instances.User.ID
                    }));
                }
            }
            else
            {
                temporaryRecurringEvent.ContactID = contact.ID;
            }

            if (chbx_infinite.Checked)
            {
                temporaryRecurringEvent.EndDate = DateTime.MinValue;
            }
            else
            {
                temporaryRecurringEvent.EndDate = dtp_enddate.Value;
            }

            temporaryRecurringEvent.Status = cbx_frequency.Text;

            bool result = false;

            result = await Task.Run(() => eventRepository.EditRecurringEvent(temporaryRecurringEvent));

            if (temporaryRecurringEvent.ID > 0 && result)
            {
                MessageBox.Show(Strings.EditRecurringEventOkay, Strings.Success);
                Dispose();
            }
            else
            {
                MessageBox.Show(Strings.SomethingError, Strings.Error);
            }
        }