IV.2.2. CODE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Windows.Forms;
namespace SEDADOPHTA
{
public partial class FPrincipale : Form
{
ClassConnexion pconect = new ClassConnexion();
OdbcCommand command;
OdbcDataReader reader;
string a, b, c, d, e;
string zcdmal,zcdfait,point;
int i, j,k,l,x,nligne,ncolone,nbrligne,nbrcol;
string[] tab; string[] t;
string[] t1; string[] t2; string[] t3; string[] t4;
string[] tas; string[] tes;
string[] tf; string[] tr; string[,] filter;
Boolean etat;
public FPrincipale()
{
InitializeComponent();
PCreerUser.Visible = false; PAutres.Visible =
false;
POuverture.Visible = false; PFait.Visible = false;
PMaladie.Visible = false; PRegle.Visible = false;
PPrescription.Visible = false; PGmodifier.Visible =
false;
PTavant.Visible = false;
//CONTROLE DE MODIFICATION
zcode.KeyPress+=new
KeyPressEventHandler(zcode_KeyPress);
}
private void zcode_KeyPress(object sender, EventArgs
e)
{
if (((KeyPressEventArgs)e).KeyChar ==
(int)Keys.Enter)
{
}
}
private void BYes_Click(object sender, EventArgs e)
{
string user = zuser.Text.ToUpperInvariant();
string password =
zpassword.Text.ToUpperInvariant();
if (user == "ADMIN" & password=="SYSTEME")
{
PCreerUser.Visible = true;
PAcces.Hide();
}
private void BCancel_Click(object sender, EventArgs e)
{
zuser.Clear(); zpassword.Clear();
}
private void BModifier_Click(object sender, EventArgs
e)
{
a = zcode.Text.ToUpperInvariant();
b = znom.Text.ToUpperInvariant();
c = zpasword.Text.ToUpperInvariant();
ClassAuthentification p = new
ClassAuthentification(a, b, c);
p.modifier();
zcode.Clear(); znom.Clear(); zpasword.Clear();
BModifier.Visible = false; BSave.Visible = true;
BSupprimer.Visible = false;
}
private void BSupprimer_Click(object sender, EventArgs
e)
{
a = zcode.Text.ToUpperInvariant();
b = znom.Text.ToUpperInvariant();
c = zpasword.Text.ToUpperInvariant();
ClassAuthentification p = new
ClassAuthentification(a, b, c);
p.supprimer();
zcode.Clear(); znom.Clear(); zpasword.Clear();
BModifier.Visible = false; BSave.Visible = true;
BSupprimer.Visible = false;
}
}
private void suppmaladie()
{
DialogResult repons = MessageBox.Show("Voulez vous
supprimer cette information
?","Alerte",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(repons==DialogResult.Yes)
{
pconect.conect.Open();
int index = Data.CurrentCell.RowIndex;
string res = "delete from t_maladie where
id_malade="+Data.Rows[index].Cells["dnumero"].Value+"";
command = new OdbcCommand(res);
command.Connection = pconect.conect;
command.ExecuteNonQuery();
pconect.conect.Close();
}
}
{
tf = new string[1000];
tr=new string[1000]; //libelle
faits
//MessageBox.Show("auto=" + t1[l]);
pconect.conect.Open();
string ras1 = "select nom_faits from t_faits
where id_faits="+t3[l]+"";
command = new OdbcCommand(ras1);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while(reader.Read())
{
tas=new string[reader.FieldCount];
for (i = 0; i < reader.FieldCount;i++
)
{
tas[i]=reader[i]+"";
}
}
pconect.conect.Close();
//libelle malade
pconect.conect.Open();
string ras2 = "select nom_maladie from
t_maladie where id_malade=" + t4[l] + "";
command = new OdbcCommand(ras2);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while (reader.Read())
{
tes = new string[reader.FieldCount];
for (i = 0; i < reader.FieldCount;
i++)
{
tes[i] = reader[i] + "";
}
}
pconect.conect.Close();
a = "Si \t" + tas[0];
Datar.Rows.Add(new string[] { t1[l], t2[l],
a, "" });
}//fin libelle
b = "Alors";
Datar.Rows.Add(new string[] { "", "Conclusion",
b, tes[0] });
}//FIN FOR DISTINCT
}
private void suppregle()
{
DialogResult repons = MessageBox.Show("Voulez vous
supprimer cette information ?", "Alerte", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (repons == DialogResult.Yes)
{
pconect.conect.Open();
int index = Datar.CurrentCell.RowIndex;
string res = "delete from t_regle where id_auto="
+ Datar.Rows[index].Cells["idauto"].Value + "";
command = new OdbcCommand(res);
command.Connection = pconect.conect;
command.ExecuteNonQuery();
pconect.conect.Close();
}
}
private void BUCancel_Click(object sender, EventArgs
e)
{
rdbmaladie.Checked = false; rdbfait.Checked = false;
rdbregle.Checked = false; rdbprescription.Checked = false;
Data.Rows.Clear(); PGmodifier.Hide();
Datar.Rows.Clear(); grbregle.Visible = false;
trid.Clear(); combrfait.Items.Clear(); combrmaladie.Items.Clear();
Affecter.Visible = false;
}
private void Bdelete_Click(object sender, EventArgs e)
{
if(point=="maladie")
{
suppmaladie();
Data.Rows.Clear(); rdbmaladie.Checked = false;
}
else if (point == "fait")
{
suppfait();
Data.Rows.Clear(); rdbfait.Checked = false;
}
else if (point == "prescription")
{
suppprescrire();
Data.Rows.Clear(); rdbprescription.Checked =
false;
}
else if(point=="regle")
{
suppregle();
Datar.Rows.Clear(); rdbregle.Checked = false;
Affecter.Visible = false; trid.Clear();
combrfait.Items.Clear(); combrmaladie.Items.Clear();
grbregle.Visible = false;
}
}
private void Affecter_Click(object sender, EventArgs
e)
{
affecteregle();
}
private void affecteregle()
{
int index = Datar.CurrentCell.RowIndex;
a =(string)
Datar.Rows[index].Cells["id_regle"].Value;
trid.Text = a;
}
private void combrfait_SelectedIndexChanged(object
sender, EventArgs e)
{
pconect.conect.Open();
string res = "select id_faits from t_faits where
nom_faits='" + combrfait.Text + "'";
command = new OdbcCommand(res);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while (reader.Read())
{
tab = new string[reader.FieldCount];
for (i = 0; i < reader.FieldCount; i++)
{
zcdfait = reader[i] + "";
}
}
pconect.conect.Close();
}
private void combrmaladie_SelectedIndexChanged(object
sender, EventArgs e)
{
pconect.conect.Open();
string res = "select id_malade from t_maladie where
nom_maladie='" + combrmaladie.Text + "'";
command = new OdbcCommand(res);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while (reader.Read())
{
tab = new string[reader.FieldCount];
for (i = 0; i < reader.FieldCount; i++)
{
zcdmal = reader[i] + "";
}
}
pconect.conect.Close();
}
private void SChainageAvant_Click(object sender,
EventArgs e)
{
PTavant.Visible = true;
PMaladie.Hide(); PFait.Hide(); PRegle.Hide();
PPrescription.Hide();
PGmodifier.Hide();
}
private void ztraiter_TextChanged(object sender,
EventArgs e)
{
a = ztraiter.Text.ToUpperInvariant();
if (a != "")
{
recherchetraiter();
}
else if (a == "") { datatraiter.Rows.Clear(); }
}
private void recherchetraiter()
{
pconect.conect.Open();
string res = "select nom_faits,id_faits from t_faits
";//where nom_faits like '"+a+"%'
command = new OdbcCommand(res);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while(reader.Read())
{
tab=new string[reader.FieldCount];
for (i = 0; i < reader.FieldCount;i++ )
{
tab[i]=reader[i]+"";
}
if(tab[0]!="")
{
datatraiter.Rows.Add(new object[] {
tab[1],tab[0],false });
}
}
a = "";
pconect.conect.Close();
nligne = datatraiter.Rows.Count;
ncolone = datatraiter.Columns.Count;
}
private void button2_Click(object sender, EventArgs e)
{
datatraiter.Rows.Clear();
PTavant.Hide();
}
private void trtreche_Click(object sender, EventArgs
e)
{
traitement();
}
private void traitement()
filter=new string[1000,1000];
j = 0;
for (i = 0; i < nligne-1;i++ )
{
etat=(Boolean)datatraiter.Rows[i].Cells["Cnetat"].Value;
if(etat==true)
{
a =
(string)datatraiter.Rows[i].Cells["idref"].Value;
tf[j] = a;
j++;
//MessageBox.Show("cdfait="+a);
}
//FILTRAGE DE LA SELECTION
for (x = 0; x <nbrligne ;x++ )
{
//MessageBox.Show("ligne=" + x);
for (k = 0; k < nbrcol; k++)
{
//MessageBox.Show("data=" + filter[x,k]);
if(filter[x,k]==filter[x+1,k])
{
b=filter[x,k];
}
else if(filter[x,k]!="")
{
c=filter[0,0];
}
//MessageBox.Show("k=" +k);
}
}//Fin filtrage*/
if (b != "")
{
pconect.conect.Open();
string res = "select id_malade from t_regle where
id_regle='"+b+"'";
command = new OdbcCommand(res);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while(reader.Read())
{
tab=new string[reader.FieldCount];
for (i = 0; i < reader.FieldCount;i++ )
{
tab[i]=reader[i]+"";
}
d = tab[0];
}
pconect.conect.Close();
//AFFICHE NOM MALADE A PARTIR DE REGLE
pconect.conect.Open();
string req = "select nom_maladie from t_maladie
where id_malade=" + d + "";
command = new OdbcCommand(req);
command.Connection = pconect.conect;
reader = command.ExecuteReader();
while (reader.Read())
{
tab = new string[reader.FieldCount];
for (l = 0; l < reader.FieldCount; l++)
{
tab[l] = reader[l] + "";
}
}
pconect.conect.Close();
MessageBox.Show("La maladie est "+tab[0]+",
merci" );
}}}}
|