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
|
public partial class Form1 : Form
{
private List<Form> ownedForms = new List<Form>();
public Form1()
{
InitializeComponent();
ownedForms.Add(new Form2());
ownedForms.Add(new Form3());
foreach (var item in ownedForms)
{
this.AddOwnedForm(item);
}
}
private void btnLoadProduits_Click(object sender, EventArgs e)
{
this.dataGridView1.DataSource = Program.StoreDB.ProduitTable;
}
private void btnShowForm2_Click(object sender, EventArgs e)
{
ownedForms[0].Show();
}
private void btnShowForm3_Click(object sender, EventArgs e)
{
ownedForms[1].Show();
}
private void btnAddProduit_Click(object sender, EventArgs e)
{
//Produit prod = new Produit() { Description = "newDesc", HostName = "new item", PortFTP = "1500" };
DataRow dr = Program.StoreDB.ProduitTable.NewRow();
dr["Description"] = "newDesc";
dr["HostName"] = "new item";
dr["PortFTP"] = "1500";
Program.StoreDB.AddProduit(dr);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (var item in ownedForms)
{
this.RemoveOwnedForm(item);
}
}
}
public partial class Form2 : Form
{
//FORM OWNED 1
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.dataGridView1.DataSource = Program.StoreDB.ProduitTable;
}
private void btnHide_Click(object sender, EventArgs e)
{
this.Hide();
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
}
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
this.listBox1.DataSource = Program.StoreDB.ProduitTable;
this.listBox1.DisplayMember = "HostName";
}
private void btnHide_Click(object sender, EventArgs e)
{
this.Hide();
}
private void btnDeleteProduit_Click(object sender, EventArgs e)
{
if (this.listBox1.SelectedIndex < 0) return;
DataRowView drview = this.listBox1.SelectedItem as DataRowView;
if (drview != null)
{
Program.StoreDB.RemoveProduit(drview.Row);
}
}
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
} |
Partager