1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| string connectionString = "Data Source=SERVEUR;Initial Catalog=BD_TRS;Integrated Security=True";
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
GetList();
}
public void GetList()
{
DataTable dtOps = new DataTable();
DataView dvOps = dtOps.DefaultView;
dtOps.Clear();
string strQueryDatas;
SqlConnection con = new SqlConnection(connectionString);
strQueryDatas = "SELECT * FROM [BD].[dbo].[VIEW] WHERE SsSect = 'A' OR SsSect = 'B' ORDER BY CASE WHEN PriorOF = '' THEN 2 ELSE 1 END, PriorOF ,DatOpe ASC";
SqlDataAdapter adOps = new SqlDataAdapter(strQueryDatas, con);
adOps.Dispose();
// J'effectue ma requête pour mettre ma vue dans un tableau !
try
{
con.Open();
SqlCommand sqlCmd = new SqlCommand(strQueryDatas, con);
sqlCmd.CommandTimeout = 500;
adOps.SelectCommand = sqlCmd;
adOps.Fill(dtOps);
adOps.Dispose();
sqlCmd.Dispose();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
int top = 50;
int left = 100;
// Je créé une liste de mon contrôle utilisateur créé ci-dessus Operations
List<Operations> Ops = new List<Operations>();
DateTime dtNow = DateTime.Now;
// Je boucle pour le nombre d'enregistrement que j'ai dans mon dataview
for (int i = 0; i < dvOps.Count; i++)
{
// Je créé un enregistrement pour chaque ligne de ma datavue et je remplie les données ce qui me créé 1 contrôle utilisateur "Operations" pour chaque ligne SQL. Tout ça fonctionne.
Operations op1 = new Operations();
op1.NoOfOp = dvOps[i]["NumOF"].ToString().Trim() + " - " + dvOps[i]["NumOP"].ToString();
op1.DescriptionOp = dvOps[i]["DesOpe"].ToString().Trim();
op1.NoArticle = dvOps[i]["NumArt"].ToString().Trim();
op1.Date = dvOps[i]["DateFormatee"].ToString().Trim();
op1.PcesPoste = Convert.ToString(Convert.ToDouble(String.Format("{0:0}", dvOps[i]["QtePoste"].ToString().Trim()))) + " pces";
op1.TpsPoste = Convert.ToString(Convert.ToDouble(String.Format("{0:0.00}", dvOps[i]["TpsChargePoste"].ToString()))) + " Hrs";
op1.Client = dvOps[i]["NomClient"].ToString().Trim();
op1.TypeOp = dvOps[i]["MAKTX"].ToString();
op1.Priorite = dvOps[i]["PriorOF"].ToString();
op1.Poste = dvOps[i]["SsSect"].ToString();
DateTime dt = Convert.ToDateTime(dvOps[i]["DateFormatee"]);
TimeSpan t = dtNow.Date - dt.Date;
if (Convert.ToDouble(t.TotalDays) > 3)
op1.RetardAvanceCol = Color.Red;
else if (Convert.ToDouble(t.TotalDays) < 4 && Convert.ToDouble(t.TotalDays) > -1)
op1.RetardAvanceCol = Color.Orange;
op1.RetardAvanceText = Convert.ToString(Math.Abs(Convert.ToDouble(t.TotalDays))) + " jrs";
op1.NoOfClick += new EventHandler(lblNoOf_NoOfClick);
// Je place mes éléments pour pas qu'ils soient l'un sur l'autre.
op1.Left = left;
op1.Top = top;
Ops.Add(op1);
pnlListe.Controls.Add(op1);
top += op1.Height + 10;
}
lblNbOps.Text = dvOps.Count.ToString() + " OPs";
}
// Je créé ici une méthode pour me permettre le clique
protected void lblNoOf_NoOfClick(object sender, EventArgs e)
{
// Je souhaite ici pouvoir retourner le texte d'un des champs, c'est égal lequel, remplis dans la fonction ci-dessus.
lblNbOps.Text = (string)((Label)sender).Text;
} |
Partager