using Newtonsoft.Json; using SvetoforVKBot.Models.Updates; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data.SqlClient; using System.Linq; using System.Security.Cryptography; using System.Text.RegularExpressions; using VkNet; using VkNet.Enums.SafetyEnums; using VkNet.Model.Attachments; using VkNet.Model.Keyboard; using VkNet.Model.RequestParams; namespace SvetoforVKBot.Models.Commands.ExpertLK { public class SelectParticipantsCommand : Command { public override string Name => "{\"button\":\"selectParticipants\"}"; public override void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db) { } public override void ExecutePL(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db) { var chatId = update.@object.message.from_id; MessagesSendParams @params = new MessagesSendParams(); var keyboardBuilder = new KeyboardBuilder().Clear(); List users = new List(); List chatIds = new List(); string name = ""; try { @params.Message = "Выберите участника.\n"; //SqlCommand getCons = new SqlCommand("SELECT * FROM PersonalConsultation WHERE chatId = @chatId;", Con); //getCons.Parameters.AddWithValue("@chatId", chatId); //SqlDataReader rgetCons = getCons.ExecuteReader(); //if (rgetCons.HasRows) //{ // while (rgetCons.Read()) // chatIds.Add(Convert.ToInt32(rgetCons["chatId"])); // rgetCons.Close(); //} //else // rgetCons.Close(); //if (chatIds.Count > 0) //{ // foreach (var c in chatIds) // { // SqlCommand getUser = new SqlCommand("SELECT * FROM Users WHERE chatId = @chatId;", Con); // getUser.Parameters.AddWithValue("@chatId", c); // SqlDataReader rgetUser = getUser.ExecuteReader(); // while (rgetUser.Read()) // users.Add(new UserObject() // { // id = Convert.ToInt32(rgetUser["id"]), // chatId = Convert.ToInt32(rgetUser["chatId"]), // fio = rgetUser["fio"].ToString(), // birthday = DateTime.Parse(rgetUser["birthday"].ToString()), // }); // rgetUser.Close(); // } // int btnRow = 0; // foreach (var u in users) // { // if (u.fio.Length >= 36) // name = u.fio.Substring(0, 35) + "..."; // else // name = u.fio; // keyboardBuilder // .AddButton(name, "selectParticipantInfo-"+ u.id, KeyboardButtonColor.Primary) // .AddLine(); // btnRow++; // if (btnRow == 8) // break; // } // keyboardBuilder // .AddButton("Назад", "selectExpertLK", KeyboardButtonColor.Default); //} //else //{ // keyboardBuilder // .AddButton("Назад", "selectExpertLK", KeyboardButtonColor.Default); //} @params.Keyboard = keyboardBuilder.Build(); @params.UserId = chatId; @params.RandomId = GetRandomId(); client.Messages.SendAsync(@params); } catch (Exception ee) { @params.Message = "Ошибка в SelectParticipantsCommand: " + ee.Message; @params.Attachments = null; @params.Keyboard = null; @params.UserId = 59111081; @params.RandomId = GetRandomId(); client.Messages.SendAsync(@params); } } } }