LevelOS-Core/UI/Dashboards/Configurações/Servicos/TelegramClienteCadastroPanel.cs

134 lines
5.1 KiB
C#

using CPM;
using MLL;
using System;
using System.Drawing;
using System.Windows.Forms;
using UI;
namespace UI
{
public partial class TelegramClienteCadastroPanel : FormularioModelo
{
private ModeloTelegramCliente _tg = new ModeloTelegramCliente();
// Controles - Básicos
private LV_TEXTBOX1 txtId, txtNome, txtChatId;
private ComboBox cbTipo;
private CheckBox chkAtivo;
// Controles - Bot API (Simples)
private LV_TEXTBOX1 txtBotToken;
// Controles - User API (Avançado)
private LV_TEXTBOX1 txtApiId, txtApiHash, txtTelefone, txtSession;
// Controles - Info
private LV_TEXTBOX1 txtCriadoEm, txtAtualizadoEm;
private Button btnTestarBot;
public TelegramClienteCadastroPanel()
{
this.Titulo = "Integração com Telegram (Bot & User API)";
MontarInterface();
}
private void MontarInterface()
{
// --- SEÇÃO 1: Identificação ---
content.Controls.Add(CreateSectionHeader("CONFIGURAÇÃO GERAL", 20));
txtId = AddInput(content, "ID", 20, 50, 70, 30, true);
txtNome = AddInput(content, "NOME DA INTEGRAÇÃO", 100, 50, 320, 30);
Label lblTipo = new Label { Text = "TIPO DE CONTA", Location = new Point(435, 33), AutoSize = true };
cbTipo = new ComboBox
{
Location = new Point(435, 50),
Size = new Size(150, 30),
DropDownStyle = ComboBoxStyle.DropDownList,
FlatStyle = FlatStyle.Flat
};
cbTipo.Items.AddRange(new object[] { "BOT (API)", "USER (SESSION)" });
cbTipo.SelectedIndex = 0;
content.Controls.Add(lblTipo);
content.Controls.Add(cbTipo);
txtChatId = AddInput(content, "ID DO CHAT DESTINO (CHAT_ID)", 600, 50, 160, 30);
chkAtivo = new CheckBox { Text = "ATIVO", Location = new Point(770, 66), AutoSize = true, Checked = true };
content.Controls.Add(chkAtivo);
// --- SEÇÃO 2: Bot API ---
content.Controls.Add(CreateSectionHeader("BOT API (SIMPLES)", 115));
txtBotToken = AddInput(content, "BOT TOKEN (FORNECIDO PELO @BOTFATHER)", 20, 145, 565, 30);
btnTestarBot = new Button
{
Text = "🔔 Testar Envio",
Location = new Point(600, 161),
Size = new Size(160, 30),
BackColor = Color.FromArgb(0, 136, 204), // Azul Telegram
ForeColor = Color.White,
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI", 9, FontStyle.Bold)
};
btnTestarBot.Click += (s, e) => MessageBox.Show("Enviando mensagem de teste via Telegram...");
content.Controls.Add(btnTestarBot);
// --- SEÇÃO 3: User API / MTProto (Avançado) ---
content.Controls.Add(CreateSectionHeader("USER API / MTPROTO (AVANÇADO)", 210));
txtApiId = AddInput(content, "API ID", 20, 240, 120, 30);
txtApiHash = AddInput(content, "API HASH", 150, 240, 300, 30);
txtTelefone = AddInput(content, "TELEFONE (+55...)", 460, 240, 180, 30);
txtSession = AddInput(content, "SESSION STRING (PARA CONEXÕES PERSISTENTES)", 20, 295, 815, 30);
txtSession.PasswordChar = '●';
// --- SEÇÃO 4: Rodapé ---
content.Controls.Add(CreateSectionHeader("HISTÓRICO", 360));
txtCriadoEm = AddInput(content, "CRIADO EM", 20, 390, 185, 30, true);
txtAtualizadoEm = AddInput(content, "ÚLT. ATUALIZAÇÃO", 215, 390, 185, 30, true);
content.Height = 450;
// Logica visual para alternar campos
cbTipo.SelectedIndexChanged += (s, e) => {
bool isBot = cbTipo.SelectedIndex == 0;
txtBotToken.Enabled = isBot;
txtApiId.Enabled = !isBot;
txtApiHash.Enabled = !isBot;
txtTelefone.Enabled = !isBot;
txtSession.Enabled = !isBot;
};
}
private void PreencherModel()
{
_tg.Nome = txtNome.Text;
_tg.Tipo = cbTipo.Text;
_tg.BotToken = txtBotToken.Text;
_tg.ApiId = int.TryParse(txtApiId.Text, out int aid) ? aid : 0;
_tg.ApiHash = txtApiHash.Text;
_tg.Telefone = txtTelefone.Text;
_tg.SessionString = txtSession.Text;
_tg.ChatId = txtChatId.Text;
_tg.Ativo = chkAtivo.Checked;
}
protected override void OnNovo()
{
_tg = new ModeloTelegramCliente();
txtNome.Focus();
}
protected override void OnSalvar()
{
PreencherModel();
MessageBox.Show("Configuração de Telegram salva com sucesso!", "LevelOS Messenger", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
protected override void OnAlterar() { }
protected override void OnExcluir() { }
protected override void OnLocalizar() { }
protected override void OnCancelar() { }
}
}