Exemplo n.º 1
0
        private void HandleBeginingMessage(string msg, TelegramBotClient bot)
        {
            switch (msg)
            {
            case "רשימת קניות":
                status = MessgesStatus.GroceryList;
                ReplyKeyboardMarkup ReplyGroceryKeyboardDefult = new[]
                {
                    new[] { "הוסף", "הסר", "הצג" },
                    new[] { "סיום" },
                };
                bot.SendTextMessageAsync(
                    msgId,
                    "ברוך הבא לרשימת הקניות שלך.." +
                    "אנא בחרי הוסף להוספת מוצר ת הסר להסרת מוצר " +
                    "הצג להצגת רשימת הקניות וסיום לחזור לתפריט הראשי",
                    replyMarkup: ReplyGroceryKeyboardDefult);
                break;

            case "הצג הוצאות":
                bot.SendTextMessageAsync(
                    msgId,
                    _expenses.ToString()
                    );
                break;

            case "הוצאה חדשה":
                status = MessgesStatus.NewExpense;
                ReplyKeyboardMarkup ReplyKeyboardnewExpans = new[] { "אשראי", "מזומן" };
                ReplyKeyboardnewExpans.OneTimeKeyboard = false;
                ReplyKeyboardnewExpans.ResizeKeyboard  = true;
                bot.SendTextMessageAsync(
                    msgId,
                    "אנא בחר סוג",
                    replyMarkup: ReplyKeyboardnewExpans);
                break;

            case "הוסף סוג הוצאה":
                status = MessgesStatus.AddNewExpensType;
                bot.SendTextMessageAsync(
                    msgId,
                    "הכנס שם הוצאה",
                    replyMarkup: new ReplyKeyboardRemove());
                return;

            default:
                ReplyKeyboardMarkup ReplyKeyboardDefult = new[]
                {
                    new[] { "הוצאה חדשה", "הצג הוצאות", "הוצאה קבועה חדשה" },
                    new[] { "כמה נשאר לי לבזבז.. ?", "האם חרגתי ? ", "הוסף סוג הוצאה" },
                    new[] { "רשימת קניות" },
                };

                bot.SendTextMessageAsync(
                    msgId,
                    "אנא בחר",
                    replyMarkup: ReplyKeyboardDefult);
                break;
            }
        }
Exemplo n.º 2
0
        public void ParseMessage(string msg, TelegramBotClient Bot)
        {
            if (msg == "?")
            {
                status = MessgesStatus.Begining;
            }
            switch (status)
            {
            case MessgesStatus.AddGroceryList:
            case MessgesStatus.DeleteGroceryList:
            case MessgesStatus.GroceryList:
                HandleGroceryListMessage(msg, Bot);
                break;

            case MessgesStatus.Begining:
                HandleBeginingMessage(msg, Bot);
                break;

            case MessgesStatus.NewExpense:
                HandleNewExpenseMessage(msg, Bot);
                break;

            case MessgesStatus.InsertExpensCategory:
                expense.Subject = msg;
                status          = MessgesStatus.InsertAmount;
                Bot.SendTextMessageAsync(
                    msgId,
                    "אנא הכנס סכום",
                    replyMarkup: new ReplyKeyboardRemove());
                break;

            case MessgesStatus.InsertAmount:
                HandleInsertAmountMessage(msg, Bot);
                break;

            case MessgesStatus.AddNewExpensType:
                status = MessgesStatus.Begining;
                NewExpenseTypeEvent.Invoke(msg);
                HandleBeginingMessage("?", Bot);
                break;
            }
        }
Exemplo n.º 3
0
        private void HandleInsertAmountMessage(string msg, TelegramBotClient bot)
        {
            double sum = 0.0;

            if (double.TryParse(msg, out sum))
            {
                expense.SetAmout(sum);
                status = MessgesStatus.Begining;
                NewExpenseEvent?.Invoke(expense);
                bot.SendTextMessageAsync(
                    msgId,
                    "תודה רבה נרשם בהצלחה");
                HandleBeginingMessage("?", bot);
            }
            else
            {
                bot.SendTextMessageAsync(
                    msgId,
                    "חלה שגיאה בקבלת הסכום אנא הקלד סכום חדש או ? להתחיל מהתחלה");
                return;
            }
        }
Exemplo n.º 4
0
        private void HandleNewExpenseMessage(string msg, TelegramBotClient bot)
        {
            status = MessgesStatus.InsertExpensCategory;
            switch (msg)
            {
            case "מזומן":
                expense = new Expense(ExpenseDirection.OutCome, expanseType.Cash, "");
                break;

            case "אשראי":
                expense = new Expense(ExpenseDirection.OutCome, expanseType.CreditCard, "");
                break;
            }
            int             step        = 3;
            var             types       = Expenses.GetExpensType();
            List <string[]> list        = new List <string[]>();
            var             completeRow = types.Length / 3;
            var             restRow     = types.Length % 3;

            for (int i = 0; i < completeRow; i++)
            {
                list.Add(new[] { types[(i)], types[(i) + 1], types[(i) + 2] });
            }
            if (restRow == 1)
            {
                list.Add(new[] { types[(completeRow * 3)] });
            }
            if (restRow == 2)
            {
                list.Add(new[] { types[(completeRow * 3)], types[(completeRow * 3) + 1] });
            }
            ReplyKeyboardMarkup ReplyKeyboardnewExpans = list.ToArray();

            bot.SendTextMessageAsync(
                msgId,
                "קטגוריה בבקשה ?",
                replyMarkup: ReplyKeyboardnewExpans);
            return;
        }
Exemplo n.º 5
0
        private void HandleGroceryListMessage(string msg, TelegramBotClient bot)
        {
            switch (status)
            {
            case MessgesStatus.GroceryList:
                switch (msg)
                {
                case "הוסף":
                {
                    status = MessgesStatus.AddGroceryList;
                    var             types       = GroceryList.Instance.Getproducts().ToArray();
                    List <string[]> list        = new List <string[]>();
                    var             completeRow = types.Length / 3;
                    var             restRow     = types.Length % 3;
                    list.Add(new[] { "סיום" });
                    for (int i = 0; i < completeRow; i++)
                    {
                        list.Add(new[] { types[(i)], types[(i) + 1], types[(i) + 2] });
                    }
                    if (restRow == 1)
                    {
                        list.Add(new[] { types[(completeRow * 3)] });
                    }
                    if (restRow == 2)
                    {
                        list.Add(new[] { types[(completeRow * 3)], types[(completeRow * 3) + 1] });
                    }
                    ReplyKeyboardMarkup ReplyGroceryKeyboardDefult = list.ToArray();
                    bot.SendTextMessageAsync(
                        msgId,
                        "בחר את אחד מהמוצרים ברשימה" +
                        "לסיום לחץ על סיום או רשום סיום",
                        replyMarkup: ReplyGroceryKeyboardDefult);
                }
                break;

                case "הסר":
                    status = MessgesStatus.DeleteGroceryList;
                    break;

                case "הצג":
                {
                    status = MessgesStatus.DeleteGroceryList;
                    var             types       = GroceryList.Instance.GetList().ToArray();
                    List <string[]> list        = new List <string[]>();
                    var             completeRow = types.Length / 3;
                    var             restRow     = types.Length % 3;
                    for (int i = 0; i < completeRow; i++)
                    {
                        list.Add(new[] { types[(i)], types[(i) + 1], types[(i) + 2] });
                    }
                    if (restRow == 1)
                    {
                        list.Add(new[] { types[(completeRow * 3)] });
                    }
                    if (restRow == 2)
                    {
                        list.Add(new[] { types[(completeRow * 3)], types[(completeRow * 3) + 1] });
                    }
                    list.Add(new[] { "סיום" });
                    ReplyKeyboardMarkup ReplyKeyboardnewExpans = list.ToArray();
                    bot.SendTextMessageAsync(
                        msgId,
                        "לחץ על אחד המוצרים כדי לסמן שנקרא או ע סיום לחזרה לתפריט",
                        replyMarkup: ReplyKeyboardnewExpans);
                    break;
                }

                case "סיום":
                    status = MessgesStatus.Begining;
                    HandleBeginingMessage("?", bot);
                    break;

                default:
                {
                    if (GroceryList.Instance.GetList().Contains(msg))
                    {
                        GroceryList.Instance.Remove(msg);
                        var types       = GroceryList.Instance.GetList().ToArray();
                        var list        = new List <string[]>();
                        var completeRow = types.Length / 3;
                        var restRow     = types.Length % 3;
                        for (int i = 0; i < completeRow; i++)
                        {
                            list.Add(new[] { types[(i)], types[(i) + 1], types[(i) + 2] });
                        }
                        if (restRow == 1)
                        {
                            list.Add(new[] { types[(completeRow * 3)] });
                        }
                        if (restRow == 2)
                        {
                            list.Add(new[] { types[(completeRow * 3)], types[(completeRow * 3) + 1] });
                        }
                        list.Add(new[] { "סיום" });
                        ReplyKeyboardMarkup ReplyKeyboardProductsnewExpans = list.ToArray();
                        bot.SendTextMessageAsync(
                            msgId,
                            $"{msg} הוסר בהצלחה",
                            replyMarkup: ReplyKeyboardProductsnewExpans);
                    }
                }
                break;
                }
                break;

            case MessgesStatus.AddGroceryList:
                if (msg == "סיום")
                {
                    HandleBeginingMessage("רשימת קניות", bot);
                    return;
                }
                else
                {
                    int quntety = 0;
                    if (int.TryParse(msg, out quntety))
                    {
                        productName = $"{msg}-{productName}";
                        GroceryList.Instance.Add(productName);
                        bot.SendTextMessageAsync(
                            msgId,
                            $"{productName} נוסף בהצלחה",
                            replyMarkup: new ReplyKeyboardRemove());
                        status = MessgesStatus.GroceryList;
                        HandleGroceryListMessage("הוסף", bot);
                    }
                    else
                    {
                        productName = msg;
                        ReplyKeyboardMarkup ReplyKeyboardProductsnewExpans = new[] {
                            new[] { "7", "8", "9" },
                            new[] { "4", "5", "6" },
                            new[] { "1", "2", "3" }
                        };
                        bot.SendTextMessageAsync(
                            msgId,
                            "הכנס כמות",
                            replyMarkup: ReplyKeyboardProductsnewExpans);
                    }
                }
                break;

            case MessgesStatus.DeleteGroceryList:
                if (msg == "סיום")
                {
                    HandleBeginingMessage("רשימת קניות", bot);
                    return;
                }

                if (GroceryList.Instance.GetList().Contains(msg))
                {
                    GroceryList.Instance.Remove(msg);
                    var types       = GroceryList.Instance.GetList().ToArray();
                    var list        = new List <string[]>();
                    var completeRow = types.Length / 3;
                    var restRow     = types.Length % 3;
                    for (int i = 0; i < completeRow; i++)
                    {
                        list.Add(new[] { types[(i)], types[(i) + 1], types[(i) + 2] });
                    }
                    if (restRow == 1)
                    {
                        list.Add(new[] { types[(completeRow * 3)] });
                    }
                    if (restRow == 2)
                    {
                        list.Add(new[] { types[(completeRow * 3)], types[(completeRow * 3) + 1] });
                    }
                    list.Add(new[] { "סיום" });
                    ReplyKeyboardMarkup ReplyKeyboardProductsnewExpans = list.ToArray();
                    bot.SendTextMessageAsync(
                        msgId,
                        $"{msg} הוסר בהצלחה",
                        replyMarkup: ReplyKeyboardProductsnewExpans);
                }
                break;

            default:
                break;
            }
        }