code C#
code C#
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
namespace GestionConge.Classes
{
class ClsGlossiaire
{
public static ClsGlossiaire _instance = null;
SqlConnection con = null;
SqlCommand cmd = null;
SqlDataAdapter dt = null;
SqlDataReader dr = null;
Clsconnexion cnx = null;
DataSet ds = null;
dt.Fill(ds);
con.Close();
return ds.Tables[0];
}
public void chargementComboBox(ComboBox cmb, string nomChamp, string
nomTable)
{
innitialiseconnect();
if (!con.State.ToString().Trim().ToLower().Equals("open")) con.Open();
using (IDbCommand cmd = con.CreateCommand())
{
cmd.CommandText = @"select distinct " + nomChamp + " from " +
nomTable + "";
IDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
string de = rd[nomChamp].ToString();
cmb.Items.Add(de);
}
rd.Close();
rd.Dispose();
cmd.Dispose();
}
}
public string GetID(String champ, String table, String champcondition1,
String valeur1)
{
string _id = string.Empty;
innitialiseconnect();
if (!con.State.ToString().Trim().ToLower().Equals("open")) con.Open();
try
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT DISTINCT " + champ + " FROM " + table + "
WHERE " + champcondition1 + " = @valeur1";
cmd.Parameters.Add(new SqlParameter("@valeur1",
SqlDbType.NVarChar)).Value = valeur1;
SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.HasRows)
while (dr.Read())
_id = dr.GetFieldValue<object>(0).ToString();
cmd.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
return _id.ToString();
}
private static void setParameter(SqlCommand cmd, string name, DbType type,
int length, object paramValue)
{
IDbDataParameter a = cmd.CreateParameter();
a.ParameterName = name;
a.Size = length;
a.DbType = type;
if (paramValue == null)
{
if (!a.IsNullable)
{
a.DbType = DbType.String;
}
a.Value = DBNull.Value;
}
else
a.Value = paramValue;
cmd.Parameters.Add(a);
}
public DataTable recherche_Infromation(string NomTable, string Nom, string
Postnom, string Prenom, string recherche)
{
innitialiseconnect();
if (!con.State.ToString().ToLower().Equals("open")) con.Open();
cmd = new SqlCommand("select * from " + NomTable + " WHERE " + Nom + "
LIKE '%" + recherche + "%' or " + Postnom + " LIKE '%" + recherche + "%' or " +
Prenom + " LIKE '%" + recherche + "%' ", con);
dt = null;
dt = new SqlDataAdapter(cmd);
ds = new DataSet();
dt.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataSet get_Report_X(string nomTable, string nomchamp, int valchamp)
{
DataSet dst;
try
{
innitialiseconnect();
if (!con.State.ToString().ToLower().Equals("open")) con.Open();
cmd = new SqlCommand("SELECT * FROM " + nomTable + " WHERE " +
nomchamp + "=@valchamp", con);
cmd.Parameters.AddWithValue("@valchamp", valchamp);
dt = new SqlDataAdapter(cmd);
dst = new DataSet();
dt.Fill(dst, nomTable);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
dt.Dispose(); con.Close();
}
return dst;
}
try
{
innitialiseconnect();
if (!con.State.ToString().Trim().ToLower().Equals("open"))
con.Open();
try
{
innitialiseconnect();
if (!con.State.ToString().Trim().ToLower().Equals("open"))
con.Open();
cmd.Parameters.Add(new SqlParameter("@champcondition",
SqlDbType.NVarChar)).Value = valeur;
SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.Read())
{
frmHome p = new frmHome();
p.Show();
}
else
{
MessageBox.Show("Connexion Echoué");
}
dr.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}