示例#1
0
        public static AnotherDayLessons GetAnotherDayLessons(UsersInfoForSelectsAndInserts person, string anotherDayName)
        {
            AnotherDayLessons anotherDayLessons;

            var con = new MySqlConnection(constr);
            var cmd = new MySqlCommand();

            try
            {
                OpenAndConfigureConnection(ref con, ref cmd);
                logger.Info("Successfully opened and configured Connection in GetAnotherDayLessons");

                BeginTransaction(cmd);
                logger.Info("Successfully began the transaction in GetAnotherDayLessons");


                anotherDayLessons =
                    SelectAnotherDaySchedule(anotherDayName, person, cmd);
                logger.Info("Successfully selected anotherDaySchedule in GetAnotherDayLessons");


                EndSuccessfulTransaction(cmd);
                logger.Info("Transaction was successfully ended in GetAnotherDayLessons");
            }
            finally
            {
                con.Close();
                cmd.Dispose();
            }

            return(anotherDayLessons);
        }
示例#2
0
        public static InlineKeyboardForFreeWeekDay GetKeyboardWithRelevantLessonsForAutomaticRefresh(
            string chatID)
        {
            UsersInfoForSelectsAndInserts person =
                new UsersInfoForSelectsAndInserts(chat_id: chatID);

            logger.Info($"In GetKeyboardWithRelevantLessonsForAutomaticRefresh function. user info:{chatID}");

            try
            {
                TodayLessons lessons;

                lessons = MySQL.GetTodaySchedule(person, Program.todayDayName, false);

                if (lessons.NumOfLessonToday == 0)
                {
                    return(new InlineKeyboardForFreeWeekDay());
                }
                logger.Info($"No lessons today keyboard was sent to " +
                            $"{chatID}.");

                inlineKeyboardForSchedule = new InlineKeyboardForSchedule(lessons);
            }
            catch (MySqlException ex)
            {
                logger.Error($"Error occured in GettingKeyboardWithRelevantLessons, with users data = {person}" +
                             $"and with and exception text = {ex}");
            }

            logger.Info($"Keyboard for schedule was sent to {chatID}");
            return(inlineKeyboardForSchedule);
        }
示例#3
0
        public static InlineKeyboardForFreeWeekDay GetKeyboardWithRelevantLessons(Telegram.Bot.Args.MessageEventArgs e,
                                                                                  bool CheckIfUserExists = false)
        {
            UsersInfoForSelectsAndInserts person =
                new UsersInfoForSelectsAndInserts(chat_id: e.Message.Chat.Id.ToString());

            logger.Info($"In GetKeyboardWithRelevantLessons function. user info:" +
                        $" {e.Message.From.FirstName} {e.Message.From.LastName} {e.Message.From.Id}");

            try
            {
                TodayLessons lessons;

                lessons = MySQL.GetTodaySchedule(person, Program.todayDayName, CheckIfUserExists);

                if (lessons != null)
                {
                    if (lessons.NumOfLessonToday == 0)
                    {
                        return(GetKeyboardForFreeWeekDay(e));
                    }

                    inlineKeyboardForSchedule = new InlineKeyboardForSchedule(lessons);

                    logger.Info($"No lessons today keyboard was sent to " +
                                $"{e.Message.From.FirstName} {e.Message.From.LastName} {e.Message.From.Id}.");
                }
            }
            catch (MySqlException ex)
            {
                logger.Error($"Error occured in GettingKeyboardWithRelevantLessons, with users data = {person}" +
                             $"and with checkIfUserExists = {CheckIfUserExists}" +
                             $"and exception text = {ex}");
            }


            if (inlineKeyboardForSchedule == null)
            {
                Bot.botClient.SendTextMessageAsync(
                    chatId: e.Message.Chat,
                    text: "You aren't registered!");
                e.Message.Text = "/start";
                logger.Info("Users isn't registered");
                return(null);
            }

            SendWordSchedule(e);

            logger.Info($"Keyboard for schedule was sent to" +
                        $" {e.Message.From.FirstName} {e.Message.From.LastName} {e.Message.From.Id} ");
            return(inlineKeyboardForSchedule);
        }
示例#4
0
        public static TodayLessons GetTodaySchedule(UsersInfoForSelectsAndInserts person, string todayDayName,
                                                    bool CheckIfUserExists = false)
        {
            TodayLessons todayLessons;

            var con = new MySqlConnection(constr);
            var cmd = new MySqlCommand();

            try
            {
                OpenAndConfigureConnection(ref con, ref cmd);
                logger.Info("Successfully opened and configured Connection in GetTodaySchedule");

                BeginTransaction(cmd);
                logger.Info("Successfully began the transaction in GetTodaySchedule");


                if (CheckIfUserExists)
                {
                    if (!CheckIfUserAlreadyRegistered(person, cmd))
                    {
                        return(null);
                    }
                }

                todayLessons =
                    SelectTodaySchedule(person, todayDayName, cmd);
                logger.Info("Successfully selected todays schedule in GetTodaySchedule");


                EndSuccessfulTransaction(cmd);
                logger.Info("Transaction was successfully ended in GetTodaySchedule");
            }
            finally
            {
                con.Close();
                cmd.Dispose();
            }

            return(todayLessons);
        }
示例#5
0
        public static InlineKeyboardForFreeWeekDay EndRegistrationGetKeyboardWithRelevantLessons(
            Telegram.Bot.Args.MessageEventArgs e,
            string[] Name_Of_Choosen_Objects = null)
        {
            UsersInfoForSelectsAndInserts person =
                new UsersInfoForSelectsAndInserts(chat_id: e.Message.Chat.Id.ToString());

            logger.Info($"In EndRegistrationGetKeyboardWithRelevantLessons function. user info:" +
                        $" {e.Message.From.FirstName} {e.Message.From.LastName} {e.Message.From.Id}");

            try
            {
                TodayLessons lessons;

                lessons = MySQL.InsertingNonRequiredLessonsAndGettingTodaySchedule(
                    Name_Of_Choosen_Objects, person, Program.todayDayName);

                if (lessons.NumOfLessonToday == 0)
                {
                    return(GetKeyboardForFreeWeekDay(e));
                }

                inlineKeyboardForSchedule = new InlineKeyboardForSchedule(lessons);
            }
            catch (MySqlException ex)
            {
                logger.Error($"Error occured in EndRegistrationGetKeyboardWithRelevantLessons, " +
                             $"with users data = {person}" +
                             $"and with NameOfChoosenObjects = {string.Join(',', Name_Of_Choosen_Objects)} " +
                             $"and exception text = {ex}");
            }

            SendWordSchedule(e);

            logger.Info($"Keyboard for schedule was sent to" +
                        $" {e.Message.From.FirstName} {e.Message.From.LastName} {e.Message.From.Id} ");

            return(inlineKeyboardForSchedule);
        }
示例#6
0
        public static TodayLessons InsertingNonRequiredLessonsAndGettingTodaySchedule(string[] lessonList,
                                                                                      UsersInfoForSelectsAndInserts person, string todayDayName)
        {
            TodayLessons todayLessons;

            var con = new MySqlConnection(constr);
            var cmd = new MySqlCommand();

            try
            {
                OpenAndConfigureConnection(ref con, ref cmd);
                logger.Info("Successfully opened and configured Connection in InsertingNonRequiredLessonsAndGettingToday");

                BeginTransaction(cmd);
                logger.Info("Successfully began the transaction in InsertingNonRequiredLessonsAndGettingToday");


                InsertNonRequiredLessons(lessonList, person, cmd);
                logger.Info("Successfully inserted non required lessons info in InsertingNonRequiredLessonsAndGettingToday");

                todayLessons =
                    SelectTodaySchedule(person, todayDayName, cmd);
                logger.Info("Successfully selected todays lessons  in InsertingNonRequiredLessonsAndGettingToday");

                EndSuccessfulTransaction(cmd);
                logger.Info("Transaction was successfully ended in InsertingNonRequiredLessonsAndGettingToday");
            }
            finally
            {
                con.Close();
                cmd.Dispose();
            }

            return(todayLessons);
        }
示例#7
0
        private void Bot_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e)
        {
            if (!Keyboards.ContainsKey(e.CallbackQuery.From.Id))
            {
                Keyboards[e.CallbackQuery.From.Id] = new UsersKeyboards();
            }

            if (e.CallbackQuery.Data == "_")
            {
                botClient.AnswerCallbackQueryAsync(e.CallbackQuery.Id);
                return;
            }

            if (Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForRegistration != null &&
                Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForRegistration.MessageID == e.CallbackQuery.Message.MessageId)
            {
                logger.Info("User wants to switch to usuall keyboard for schedule.");

                Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForRegistration.UpdateKeybordChoosen(e.CallbackQuery.Data);
                botClient.EditMessageReplyMarkupAsync(
                    chatId: e.CallbackQuery.Message.Chat,
                    messageId: e.CallbackQuery.Message.MessageId,
                    replyMarkup: Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForRegistration.Keyboard
                    );
                botClient.AnswerCallbackQueryAsync(e.CallbackQuery.Id);
                return;
            }

            if (e.CallbackQuery.Data == "NextDay" && Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule != null)
            {
                UsersInfoForSelectsAndInserts person = new UsersInfoForSelectsAndInserts(
                    chat_id: e.CallbackQuery.Message.Chat.Id.ToString());

                string lessons = Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.NextDay(person);

                #region EditingMessageWithAnotherDayLessons
                if (Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.NextDayMessageID != 0)
                {
                    botClient.EditMessageTextAsync(
                        chatId: e.CallbackQuery.Message.Chat,
                        messageId: Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.NextDayMessageID,
                        text: lessons,
                        parseMode: Telegram.Bot.Types.Enums.ParseMode.Html
                        );
                }
                else
                {
                    Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.NextDayMessageID
                        = botClient.SendTextMessageAsync(
                              chatId: e.CallbackQuery.Message.Chat,
                              text: lessons,
                              parseMode: Telegram.Bot.Types.Enums.ParseMode.Html).Result.MessageId;
                }

                #endregion

                botClient.AnswerCallbackQueryAsync(e.CallbackQuery.Id);
            }

            if (Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule is InlineKeyboardForSchedule &&
                Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.MessageID == e.CallbackQuery.Message.MessageId)
            {
                var keyboard = (InlineKeyboardForSchedule)Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule;

                switch (e.CallbackQuery.Data)
                {
                case "Refresh":
                    logger.Info("User pressed Refresh button.");

                    keyboard.Refresh();

                    #region DeleteTextMessageWithAnotherDayLessons
                    botClient.DeleteMessageAsync(
                        chatId: e.CallbackQuery.Message.Chat,
                        messageId: Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.NextDayMessageID);
                    Keyboards[e.CallbackQuery.From.Id].inlineKeyboardForSchedule.NextDayMessageID = 0;

                    #endregion

                    botClient.EditMessageReplyMarkupAsync(
                        chatId: e.CallbackQuery.Message.Chat,
                        messageId: e.CallbackQuery.Message.MessageId,
                        replyMarkup: keyboard.Keyboard
                        );
                    break;

                case "NextLesson":
                    logger.Info("User pressed NextLesson button.");

                    keyboard.NextLesson();

                    botClient.EditMessageReplyMarkupAsync(
                        chatId: e.CallbackQuery.Message.Chat,
                        messageId: e.CallbackQuery.Message.MessageId,
                        replyMarkup: keyboard.Keyboard
                        );
                    break;
                }
                botClient.AnswerCallbackQueryAsync(e.CallbackQuery.Id);
                return;
            }
        }