Пример #1
0
        private async Task StartTurnSession(Update update, Employee employee)
        {
            TurnSessionData session = new TurnSessionData();

            employee.DialogSession = session;
            await employee.DialogSession.CreateSession(_sqlServer, employee);

            StringBuilder sb = new StringBuilder();

            if (employee.Turn == null)
            {
                sb.Append("Вы находитесь вне смены");
            }
            else
            {
                sb.Append("Ваша смена началась ").Append(employee.Turn.BeginDateTime.ToTelegramReportString());
            }

            TurnSessionData.Employees employees = null;
            if (employee.IsManager)
            {
                employees = await session.GetEmployeesStatus(employee, _sqlServer);

                sb.AppendLine().AppendLine();
                GetEmployeesTurnStatusMessageForManager(employees, sb);
            }

            string text = sb.ToString();
            ReplyKeyboardMarkup keyboard = employee.DialogSession.GetKeyboardMarkup(employee, employees);
            await _telegramClient.SendTextMessageAsync(update.Message.From.Id, text, ParseMode.Html, false, false, 0, keyboard, _cts.Token);

            await this.WriteMessageLog(new MessageLog(text, employee, keyboard));
        }
Пример #2
0
        private void GetEmployeesTurnStatusMessageForManager(TurnSessionData.Employees employees, StringBuilder sb)
        {
            if (employees.InTurn.Count > 0)
            {
                sb.AppendLine("<b>Сотрудники в смене</b> (в скобках команда для вывода из смены):");

                foreach (TurnEmployee te in employees.InTurn)
                {
                    sb.Append(te.FirstName).Append(" ").Append(te.LastName).Append(", ").Append(te.GroupName).Append(" (-").Append(te.EmployeeId).AppendLine(")");
                }
            }

            if (employees.NotInTurn.Count > 0)
            {
                sb.AppendLine("<b>Сотрудники вне смены</b> (в скобках команда для ввода в смену):");

                foreach (TurnEmployee te in employees.NotInTurn)
                {
                    sb.Append(te.FirstName).Append(" ").Append(te.LastName).Append(", ").Append(te.GroupName).Append(" (+").Append(te.EmployeeId).AppendLine(")");
                }
            }
        }
Пример #3
0
        private async Task TurnEnterExitEmployee(Update update, Employee employee, string command)
        {
            TurnSessionData session = (TurnSessionData)employee.DialogSession;

            bool isCorrect = true;

            if (command.Length < 2 || command[0] != '-' && command[0] != '+')
            {
                isCorrect = false;
            }

            bool isEnter    = (command[0] == '+');
            int  employeeId = 0;

            if (isCorrect)
            {
                for (int i = 1; i < command.Length; i++)
                {
                    if (!char.IsDigit(command[i]))
                    {
                        isCorrect = false;
                        break;
                    }
                }

                if (isCorrect)
                {
                    if (!int.TryParse(command.Substring(1), out employeeId))
                    {
                        isCorrect = false;
                    }
                }
            }

            int retVal = 0;

            if (isCorrect)
            {
                using (SqlConnection conn = _sqlServer.GetConnection())
                {
                    await conn.OpenAsync();

                    using (SqlCommand cmd = _sqlServer.GetSpCommand("telegram.DialogSession_Turn_EnterExitEmployee", conn))
                    {
                        cmd.AddIntParam("@ManagerId", employee.Id);
                        cmd.AddBigIntParam("@ManagerTelegramId", employee.TelegramUserId);
                        cmd.AddNVarCharParam("@ManagerName", 101, employee.GetFullName());
                        cmd.AddIntParam("@EmployeeId", employeeId);
                        cmd.AddIntParam("@PlaceId", employee.Place.Id);
                        cmd.AddBitParam("@IsEnter", isEnter);
                        SqlParameter retValParam = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        retVal = retValParam.GetInt32OrDefault();
                    }
                }

                isCorrect = (retVal >= 0);
            }

            if (isCorrect)
            {
                string text;
                if (retVal == 1)
                {
                    text = "Сотрудник уже вошёл в смену";
                }
                else if (retVal == 2)
                {
                    text = "Сотрудник уже вышел из смены";
                }
                else
                {
                    text = "Команда успешно выполнена";
                }

                ReplyKeyboardMarkup keyboard = GetStandardKeyboardMarkup(employee);
                await _telegramClient.SendTextMessageAsync(update.Message.From.Id, text, ParseMode.Default, false, false, 0, keyboard, _cts.Token);

                await this.WriteMessageLog(new MessageLog(text, employee, keyboard));
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                if (retVal == -1)
                {
                    sb.Append("Вы не можете управлять сменами сотрудников. Нажмите кнопку <b>Назад</b>");
                }
                else if (retVal == -2)
                {
                    sb.Append("Сотрудник не принадлежит вашему заведению. Исправьте или нажмите кнопку <b>Назад</b>");
                }
                else
                {
                    sb.Append("Вы ввели неизвестную команду. Исправьте или нажмите кнопку <b>Назад</b>");
                }

                TurnSessionData.Employees employees = null;
                if (retVal != -1)
                {
                    employees = await session.GetEmployeesStatus(employee, _sqlServer);

                    sb.AppendLine().AppendLine();
                    this.GetEmployeesTurnStatusMessageForManager(employees, sb);
                }

                string text = sb.ToString();
                ReplyKeyboardMarkup keyboard = employee.DialogSession.GetKeyboardMarkup(employee, employees);
                await _telegramClient.SendTextMessageAsync(update.Message.From.Id, text, ParseMode.Html, false, false, 0, keyboard, _cts.Token);

                await this.WriteMessageLog(new MessageLog(text, employee, keyboard));
            }
        }