using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using MercatorUi;
using MercatorApi;
namespace SigCli
{
public class Customizer : MercatorUi.ICustomizers.IFormLoadCustomizer, MercatorUi.ICustomizers.IFormClosedCustomizer, MercatorUi.ICustomizers.IFormValidateCustomizer
{
public void FormLoadCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
MercatorUi.MovableControls.MovableTextBox textBoxPwd = (MercatorUi.MovableControls.MovableTextBox)sigForm.MovableControls["..."]; // ... = id du textbox mot de passe
textBoxPwd.ButtonCustom.Visible = true;
textBoxPwd.ButtonCustomClick += new EventHandler(textBoxPwd_ButtonCustomClick);
}
public void FormClosedCustomize(Form form)
{
MercatorUi.Forms.Sig.SigForm sigForm = (MercatorUi.Forms.Sig.SigForm)form;
MercatorUi.MovableControls.MovableTextBox textBoxPwd = (MercatorUi.MovableControls.MovableTextBox)sigForm.MovableControls["..."]; // ... = id du textbox mot de passe
textBoxPwd.ButtonCustomClick -= new EventHandler(textBoxPwd_ButtonCustomClick);
}
void textBoxPwd_ButtonCustomClick(object sender, EventArgs e)
{
MercatorUi.MovableControls.MovableTextBox textBox = (MercatorUi.MovableControls.MovableTextBox)sender;
if (textBox.Text.Trim() == "")
{
string pwd = Api.Ident();
textBox.Text = Api.Xsha1("coucou_gamin" + pwd);
MercatorUi.Dialogs.Stop(string.Format("Le mot de passe généré est \"{0}\" et a été copié vers les presse-papier.", pwd));
try
{
Clipboard.SetData(DataFormats.Text, pwd);
}
catch (Exception ex)
{
MercatorUi.Dialogs.Stop(ex.Message);
}
}
else
{
string pwd = MercatorUi.Dialogs.AskString("Remplacer le mot de passe actuel par ... ?", "").Trim();
if (pwd != "")
textBox.Text = Api.Xsha1("coucou_gamin" + pwd);
}
}
}
}