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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Collections;
namespace FundIHM_V2
{
public partial class Form1 : Form
{
private OleDbConnection conn;
DataSet myDataset;
OleDbDataAdapter adapterDataGrid;
OleDbDataAdapter adapterCombo;
OleDbCommandBuilder commandBuilderDataGrid;
public Form1()
{
InitializeComponent();
// titre de la fenêtre
this.Text = "Fund IHM V_2";
// dimensions de la fenêtre
this.Size = new System.Drawing.Size(1000, 500);
this.conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Q:\\Dev\\testDB.mdb;");
try
{
this.conn.Open();
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
//Associer Combo/datagridview au dataset, puis formater les colonnes du datagridview
buildCmbFundList();
}
// fonction de test
public static void Main(string[] args)
{
// on affiche le formulaire
Application.Run(new Form1());
}
//Associer Combo/datagridview au dataset, puis formater les colonnes du datagridview
private void buildCmbFundList()
{
adapterCombo = new OleDbDataAdapter("Select * From Mastername Order By MasterName", conn);
adapterDataGrid = new OleDbDataAdapter("select ID, tDate, Return, FundsManaged, NAV, LastUpdated from Performance where ID=2;", conn);
commandBuilderDataGrid = new OleDbCommandBuilder(adapterDataGrid);
//contiendra les noms des funds et la performance d'un seul
myDataset = new DataSet();
try
{
adapterCombo.Fill(myDataset, "Combo");
adapterDataGrid.Fill(myDataset, "DataGrid");
}
catch (Exception exp){
Console.WriteLine(exp.Message);
}
//liens dataset, composant graphique
this.cmbFundName.DataSource = myDataset.Tables[0];
this.dataGridView_FundList.DataSource = myDataset.Tables[1];
//formater les colonnes du datagridview
//Code de formatage
}
//changer les performances dans le datagridview en fonction de la selection du fund dans la combo
private void cmbFundName_SelectionChangeCommitted(object sender, EventArgs e)
{
this.conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Q:\\Dev\\testDB.mdb;");
OleDbDataAdapter adapterDataGrid = new OleDbDataAdapter("select ID, tDate, Return, FundsManaged, NAV, LastUpdated from Performance where ID=" + cmbFundName.SelectedValue.ToString() + ";", conn);
myDataset.Tables[1].Clear();
adapterDataGrid.Fill(myDataset, "DataGrid");
}
//Envoyer les modifications du datagridview vers la base
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
this.Validate();
adapterDataGrid.Update(myDataset.Tables[1]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
//ajouter l'ID du found dans la colonne cachee du datagridview avant envoie vers la base
private void dataGridView_FundList_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
this.dataGridView_FundList.CurrentRow.Cells[0].Value = this.cmbFundName.SelectedValue.ToString();
this.dataGridView_FundList.CurrentRow.Cells[5].Value = DateTime.Now;
}
private void dataGridView_FundList_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
this.dataGridView_FundList.CurrentRow.Cells[5].Value = DateTime.Now;
}
}
} |
Partager