Exemplo n.º 1
0
        private void SetEachMouthEventDate(CallbackQuery _message)
        {
            _user     = BaseContext._User.Where(p => p.ID == _message.From.Id).FirstOrDefault();
            _tempDate = BaseContext._TempDate.Where(p => p.user.ID == _user.ID).FirstOrDefault();

            Thread myThread = new Thread(new ThreadStart(StartThreadEachMouthEvent));

            myThread.Start();             // запускаем поток
            myThread.Join();
        }
        public InlineKeyboardMarkup ShowReminder(System.Object message, DataBaseContext baseContext)
        {
            List <List <InlineKeyboardButton> > list = new List <List <InlineKeyboardButton> >();
            CallbackQuery mes = message as CallbackQuery;

            CommandText.ChouseAllEvent.Clear();

            System.Int32 i = 0;

            list.Add(new List <InlineKeyboardButton>());
            foreach (Reminder reminder in baseContext._Reminders.Include("user"))
            {
                if (reminder.user.ID == mes.From.Id)
                {
                    foreach (EventTime eventTime in baseContext._EventTimes.Include("reminder"))
                    {
                        if (eventTime.reminder != null)
                        {
                            if (eventTime.reminder.ID == reminder.ID)
                            {
                                TempDate tempDate = baseContext._TempDate.Where(p => p.user == reminder.user).FirstOrDefault();

                                try
                                {
                                    if (tempDate.date.Date == eventTime.dateTime.Date)
                                    {
                                        if (i >= 2)
                                        {
                                            list.Add(new List <InlineKeyboardButton>());
                                        }
                                        CommandText.ChouseAllEvent.Add(reminder.ID, reminder.Name.ToString());
                                        list[list.Count - 1].Add(new InlineKeyboardButton()
                                        {
                                            Text         = reminder.Name,
                                            CallbackData = reminder.ID + " " + CommandText.ChouseAllEvent[reminder.ID]
                                        });
                                        i++;
                                    }
                                }
                                catch
                                {
                                    System.Console.WriteLine("public InlineKeyboardMarkup ShowReminder(System.Object message)");
                                }
                            }
                        }
                    }
                }
            }
            list.Add(new List <InlineKeyboardButton>());
            list[list.Count - 1].Add(new InlineKeyboardButton()
            {
                Text = "Назад", CallbackData = CommandText.BackToCalendar
            });
            return(new InlineKeyboardMarkup(list));
        }
Exemplo n.º 3
0
        public AlgorithmCalendar(CallbackQuery _message)
        {
            _user      = BaseContext._User.Where(p => p.ID == _message.From.Id).FirstOrDefault();
            _tempDate  = BaseContext._TempDate.Where(p => p.user.ID == _message.From.Id).FirstOrDefault();
            _eventTime = null;
            _event     = BaseContext._Events.Where(p => p.user == _user).FirstOrDefault();
            _purpose   = BaseContext._Purposes.Where(p => p.user == _user).FirstOrDefault();
            _reminder  = BaseContext._Reminders.Where(p => p.user == _user).FirstOrDefault();

            SetDelegate();
        }
Exemplo n.º 4
0
        public async void Execute(TelegramBotClient botClient, System.Object message, Dictionary <System.Int32, IItemOrganizer> pairs, DataBaseContext baseContext)
        {
            CallbackQuery _message = message as CallbackQuery;

            User       users      = baseContext._User.Where(p => p.ID == _message.From.Id).FirstOrDefault();
            Statistics statistics = baseContext._Statistics.Where(p => p.user == users).FirstOrDefault(p => p.Day == System.DateTime.Today);
            TempDate   date       = baseContext._TempDate.Where(p => p.user == users).FirstOrDefault();

            if (statistics == null)
            {
                baseContext._Statistics.Add(new Statistics()
                {
                    user             = users,
                    Day              = System.DateTime.Today,
                    TimeInDayToRelax = new System.TimeSpan(0, 0, 0),
                    TimeInDayToWork  = new System.TimeSpan(0, 0, 0)
                });
            }
            baseContext.SaveChanges();

            PictureB picture = new PictureB();

            picture.SetPicture(users, _message, statistics, date, baseContext);

            System.String str = @"E:\Repo C#\Calendar\Calendar\" + _message.From.Id + ".jpeg";

            Bitmap bmp;

            using (MemoryStream ms = new MemoryStream(statistics.image))
            {
                bmp = new Bitmap(ms);

                bmp.Save(str, System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            FileStream stream = new FileStream(str, FileMode.Open);

            try
            {
                await botClient.SendPhotoAsync(_message.From.Id, stream, replyMarkup : inlineButton.BackToOrganizer);
            }
            catch
            {
                await botClient.EditMessageTextAsync(_message.From.Id, _message.Message.MessageId, "Нет статистики за этот день.", replyMarkup : inlineButton.StartMenu);
            }
            stream.Close();

            if (System.IO.File.Exists(str))
            {
                // If file found, delete it
                System.IO.File.Delete(str);
            }
        }
Exemplo n.º 5
0
        public async void SetTime(TelegramBotClient BotClient, Message _message, InlineButtonCalendar inlineButton, User users, DataBaseContext baseContext)
        {
            TempDate  tempDate  = baseContext._TempDate.Where(p => p.user == users).FirstOrDefault();
            Event     _event    = baseContext._Events.Where(p => p.user.ID == _message.From.Id).FirstOrDefault(p => p.Work == true);
            EventTime eventTime = baseContext._EventTimes.Where(p => p._event.ID == _event.ID).FirstOrDefault();

            try
            {
                System.TimeSpan time     = System.TimeSpan.Parse(_message.Text);
                System.TimeSpan timeSpan = tempDate.date.TimeOfDay;
                tempDate.date -= timeSpan;
                tempDate.date  = tempDate.date.Date + time;

                System.Console.WriteLine(tempDate.date);

                if (eventTime.Work == true)
                {
                    baseContext._EventTimes.Add(new EventTime()
                    {
                        _event = _event, dateTime = tempDate.date, Work = true
                    });
                }
                else
                {
                    eventTime.dateTime = tempDate.date;
                    eventTime.Work     = true;
                }

                if (_event.Busy == true)
                {
                    await BotClient.SendTextMessageAsync(_message.Chat.Id, "Время: " + _message.Text, replyMarkup : inlineButton.AddEventNotBusy);
                }
                else
                {
                    await BotClient.SendTextMessageAsync(_message.Chat.Id, "Время: " + _message.Text, replyMarkup : inlineButton.AddEventBusy);
                }
            }
            catch
            {
                await BotClient.SendTextMessageAsync(_message.Chat.Id, "Время введено неверно: " + _message.Text, replyMarkup : inlineButton.BackToCalendar);
            }
            baseContext.SaveChanges();
        }
Exemplo n.º 6
0
        private void SetTimeDefoult(User users, DataBaseContext baseContext)
        {
            TempDate tempDate = baseContext._TempDate.Where(p => p.user == users).FirstOrDefault();

            System.TimeSpan timeSpan = tempDate.date.TimeOfDay;
            tempDate.date -= timeSpan;
            System.TimeSpan time = System.TimeSpan.Parse("9:00");
            tempDate.date = tempDate.date + time;

            System.Console.WriteLine(tempDate.date);

            Event _event = baseContext._Events.Where(p => p.user == users).FirstOrDefault(p => p.Work == true);

            baseContext._EventTimes.Add(new EventTime()
            {
                _event = _event, dateTime = tempDate.date, Work = false
            });

            baseContext.SaveChanges();
        }
Exemplo n.º 7
0
        public void Dalete(CallbackQuery _message, DataBaseContext baseContext)
        {
            TempDate tempDate = baseContext._TempDate.Where(p => p.user.ID == _message.From.Id).FirstOrDefault();
            Purpose  purpose  = baseContext._Purposes.Where(p => p.user.ID == _message.From.Id).FirstOrDefault(p => p.Work == true);

            foreach (EventTime eventTime in baseContext._EventTimes.Include("_event"))
            {
                if (eventTime.reminder != null)
                {
                    if (eventTime.reminder.ID == purpose.ID)
                    {
                        if (eventTime.dateTime.Date == tempDate.date.Date)
                        {
                            baseContext._EventTimes.Remove(eventTime);
                        }
                    }
                }
            }
            baseContext._Purposes.Remove(purpose);
            baseContext.SaveChanges();
        }
        public async void Execute(TelegramBotClient botClient, System.Object message, System.Object keyValues, DataBaseContext baseContext)
        {
            CallbackQuery _message = message as CallbackQuery;
            Dictionary <System.Int32, Calendar> keyValues2 = keyValues as Dictionary <System.Int32, Calendar>;

            CommandText.MyData.Clear();
            keyValues2.Remove(_message.From.Id);
            User users = baseContext._User.Where(p => p.ID == _message.From.Id).FirstOrDefault();

            if (users != null)
            {
                TempDate tempDate = baseContext._TempDate.Where(p => p.user == users).FirstOrDefault();


                users.Work = 0;
                baseContext.SaveChanges();
                try
                {
                    baseContext._TempDate.Remove(tempDate);
                }
                catch
                {
                    System.Console.WriteLine("baseContext._TempDate.Remove(tempDate);");
                }
                baseContext.SaveChanges();
            }
            try
            {
                await botClient.EditMessageTextAsync(_message.From.Id, _message.Message.MessageId, "Привет друг мой, " + _message.From.FirstName, replyMarkup : inlineButton.Start);
            }
            catch
            {
                await botClient.SendTextMessageAsync
                (
                    _message.From.Id,
                    "Привет друг мой, " + _message.From.FirstName,
                    replyMarkup : inlineButton.Start
                );
            }
        }
Exemplo n.º 9
0
        public async void SetTime(TelegramBotClient BotClient, Message _message, InlineButtonCalendar inlineButton, User users, DataBaseContext baseContext)
        {
            TempDate tempDate = baseContext._TempDate.Where(p => p.user == users).FirstOrDefault();

            try
            {
                System.TimeSpan timeSpan = tempDate.date.TimeOfDay;
                tempDate.date -= timeSpan;
                System.TimeSpan time = System.TimeSpan.Parse(_message.Text);
                tempDate.date = tempDate.date.Date + time;

                System.Console.WriteLine(tempDate.date);
                foreach (Reminder temp in baseContext._Reminders.Include("user"))
                {
                    if (temp.Work == true)
                    {
                        EventTime eventTime = baseContext._EventTimes.Where(p => p.reminder.ID == temp.ID).FirstOrDefault();
                        if (eventTime.Work == true)
                        {
                            baseContext._EventTimes.Add(new EventTime()
                            {
                                reminder = temp, dateTime = tempDate.date, Work = true
                            });
                        }
                        else
                        {
                            eventTime.dateTime = tempDate.date;
                            eventTime.Work     = true;
                        }
                    }
                }
                await BotClient.SendTextMessageAsync(_message.Chat.Id, "Заголовок: " + Name, replyMarkup : inlineButton.AddReminder);

                baseContext.SaveChanges();
            }
            catch
            {
                System.Console.WriteLine("RemiderCal.cs - SetTime - Time");
            }
        }
        public InlineKeyboardMarkup ShowCategoryCalendar(System.Object message, DataBaseContext baseContext)
        {
            List <List <InlineKeyboardButton> > list = new List <List <InlineKeyboardButton> >();
            CallbackQuery mes = message as CallbackQuery;

            TempDate tempDate = baseContext._TempDate.Where(p => p.user.ID == mes.From.Id).FirstOrDefault();

            System.Boolean isEvent    = false;
            System.Boolean isPurpose  = false;
            System.Boolean isReminder = false;

            foreach (EventTime eventTime in baseContext._EventTimes)
            {
                if (eventTime.dateTime.Date == tempDate.date.Date)
                {
                    if (isEvent == false)
                    {
                        foreach (Event _event in baseContext._Events.Include("user"))
                        {
                            if (_event.user.ID == mes.From.Id)
                            {
                                if (eventTime._event != null)
                                {
                                    if (_event.ID == eventTime._event.ID)
                                    {
                                        list.Add(new List <InlineKeyboardButton>());
                                        list[list.Count - 1].Add(new InlineKeyboardButton()
                                        {
                                            Text = "Мероприятие", CallbackData = CommandText.ShowEvent
                                        });
                                        isEvent = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (isPurpose == false)
                    {
                        foreach (Purpose purpose in baseContext._Purposes.Include("user"))
                        {
                            if (purpose.user.ID == mes.From.Id)
                            {
                                if (eventTime.purpose != null)
                                {
                                    if (purpose.ID == eventTime.purpose.ID)
                                    {
                                        list.Add(new List <InlineKeyboardButton>());
                                        list[list.Count - 1].Add(new InlineKeyboardButton()
                                        {
                                            Text = "Цель", CallbackData = CommandText.ShowPurpose
                                        });
                                        isPurpose = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (isReminder == false)
                    {
                        foreach (Reminder reminder in baseContext._Reminders.Include("user"))
                        {
                            if (reminder.user.ID == mes.From.Id)
                            {
                                if (eventTime.reminder != null)
                                {
                                    if (reminder.ID == eventTime.reminder.ID)
                                    {
                                        list.Add(new List <InlineKeyboardButton>());
                                        list[list.Count - 1].Add(new InlineKeyboardButton()
                                        {
                                            Text = "Напоминание", CallbackData = CommandText.ShowReminder
                                        });
                                        isReminder = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            list.Add(new List <InlineKeyboardButton>());
            list[list.Count - 1].Add(new InlineKeyboardButton()
            {
                Text = "Назад", CallbackData = CommandText.BackToCalendar
            });
            return(new InlineKeyboardMarkup(list));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> GenerateReport()
        {
            DateTime parsedDate;
            DateTime TempDate;
            DateTime After30date;


            int    id            = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            string flourmillname = User.FindFirst(ClaimTypes.Name).Value;
            string username      = User.FindFirst(ClaimTypes.Name).Value;

            var lastReport = _context.Report.FromSqlRaw("SELECT * FROM Report WHERE  Flour_Mill_Name={0}", flourmillname).ToList();

            if (lastReport.Count != 0)
            {
                string dateNew = lastReport.Select(x => x.Report_Date).Max();

                string ReportDate    = dateNew;
                int    adminidReport = lastReport[0].AdministratorID;

                parsedDate  = DateTime.Parse(ReportDate);
                TempDate    = parsedDate;
                After30date = TempDate.AddDays(29);
                DateTime dateTimeNow = DateTime.Now;
                if (dateTimeNow.Date >= After30date.Date || adminidReport != id)
                {
                    var getReports = await
                                         (from admin in _context.Administrator
                                         join order in _context.Order on id equals order.AdministratorID
                                         where admin.Id == id
                                         select new
                    {
                        admin.Id,
                        admin.Username,

                        order.TotalTons,
                        order.Order_Date,
                        order.TotalPayment
                    }).ToListAsync();
                    double TotalBadges    = 0;
                    double TotalMyPayment = 0;

                    string   date       = DateTime.Now.ToString("M/d/yyyy");
                    DateTime nowAfter30 = DateTime.Now.AddDays(29);
                    for (int i = 0; i < getReports.Count; i++)
                    {
                        if (DateTime.Parse(getReports[i].Order_Date).Date <= nowAfter30.Date)
                        {
                            TotalBadges    += getReports[i].TotalTons;
                            TotalMyPayment += getReports[i].TotalPayment;
                        }
                    }
                    var report = new Report
                    {
                        AdministratorID         = id,
                        SuperVisorID            = 1,
                        TotalPayment            = TotalMyPayment.ToString(),
                        TotalBadgesForFlourMill = TotalBadges,
                        Flour_Mill_Name         = username,
                        Report_Date             = date
                    };

                    _context.Report.Add(report);
                    await _context.SaveChangesAsync();

                    return(Ok("Report Generated"));
                }
            }
            else if (lastReport.Count == 0)
            {
                var getReports = await
                                     (from admin in _context.Administrator
                                     join order in _context.Order on id equals order.AdministratorID
                                     where admin.Id == id
                                     select new
                {
                    admin.Id,

                    admin.Username,

                    order.TotalTons,
                    order.TotalPayment,
                    order.Order_Date
                }).ToListAsync();

                double TotalBadges    = 0;
                double TotalMyPayment = 0;

                string   date       = DateTime.Now.ToString("M/d/yyyy");
                DateTime nowAfter30 = DateTime.Now.AddDays(29);

                for (int i = 0; i < getReports.Count; i++)
                {
                    if (DateTime.Parse(getReports[i].Order_Date).Date <= nowAfter30.Date)
                    {
                        TotalBadges    += getReports[i].TotalTons;
                        TotalMyPayment += getReports[i].TotalPayment;
                    }
                }
                var report = new Report
                {
                    AdministratorID         = id,
                    SuperVisorID            = 1,
                    TotalPayment            = TotalMyPayment.ToString(),
                    TotalBadgesForFlourMill = TotalBadges,
                    Flour_Mill_Name         = username
                    ,
                    Report_Date = date
                };

                _context.Report.Add(report);
                await _context.SaveChangesAsync();

                return(Ok("Report Generated"));
            }
            return(BadRequest("Report only generated after 30 days"));
        }
Exemplo n.º 12
0
        public System.Boolean SetPicture(User users, System.Object message, Statistics statistics, TempDate date, DataBaseContext baseContext)
        {
            CallbackQuery _message = message as CallbackQuery;

            if (date.date != null)
            {
                if (statistics.Day == date.date)
                {
                    System.TimeSpan timeSpan  = statistics.TimeInDayToWork;
                    System.TimeSpan timeSpan2 = statistics.TimeInDayToRelax;

                    System.Int32 one = ((timeSpan.Hours * 3600) + (timeSpan.Minutes * 60) + timeSpan.Seconds);
                    System.Int32 two = ((timeSpan2.Hours * 3600) + (timeSpan2.Minutes * 60) + timeSpan2.Seconds);

                    System.Int32 x = (one * 360) / 86400;
                    System.Int32 y = (two * 360) / 86400;

                    System.String inaction = "Бездействие: " + (new System.TimeSpan(24, 0, 0) - (timeSpan + timeSpan2));
                    System.String work     = "Работа: " + timeSpan;
                    System.String relax    = "Отдых: " + timeSpan2;
                    System.String name     = ":Продуктивность дня";

                    Bitmap   myBitmap = new Bitmap(800, 800);                  //Создаем картинку
                    Graphics g        = Graphics.FromImage(myBitmap);

                    DrawEllipse(g, x, y);
                    DrawString(g, inaction, work, relax, name);

                    System.String str = @"E:\Repo C#\Calendar\Calendar\" + _message.From.Id + ".jpeg";

                    Save(str, myBitmap, statistics, baseContext);
                    Delete(str);
                    return(true);
                }
            }
            return(false);
        }