GestionDeDommerceInformatique/Gestion de commerce Informa.../GestionStock.cs

85 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GestionDeCommerceInfoClasseBDDNCouches.DataLayer;
using GestionDeCommerceInfoClasseBDDNCouches;
namespace Gestion_de_commerce_Informatique
{
public partial class GestionStock : UserControl
{
BDDAccesArticle bddArticle = new BDDAccesArticle(Settings1.Default.ChaineDeConnection);
private DataTable dtArticle;
private BindingSource bsArticle;
public GestionStock()
{
InitializeComponent();
this.BackColor = Color.Transparent;
bsArticle = new BindingSource();
RemplirDVG(dgvArticle);
}
private void dgvUser_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void RemplirDVG(DataGridView dgv)
{
dtArticle = new DataTable();
dtArticle.Columns.Add(new DataColumn("idArt", System.Type.GetType("System.Int32")));
dtArticle.Columns.Add("NomArticle");
dtArticle.Columns.Add("Valeur");
dtArticle.Columns.Add("Stock");
List<Article> larticles;
larticles = bddArticle.ListArticles();
foreach (Article Tmp in larticles)
dtArticle.Rows.Add(Tmp.ID, Tmp.Designation, $"{Math.Round(Tmp.PrixHTVA,2)}€", Tmp.Stock);
bsArticle.DataSource = dtArticle;
dgv.DataSource = bsArticle;
}
public void RemplirDVG()
{
RemplirDVG(dgvArticle);
}
private void txtBoxRecherche_KeyUp(object sender, EventArgs e)
{
string rowFilter = string.Format("[{0}] LIKE '%{1}%'", "NomArticle", txtBoxRecherche.text);//https://10tec.com/articles/datagridview-filter.aspx
dtArticle.DefaultView.RowFilter = rowFilter;
}
private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
ConfigurationStock win = new ConfigurationStock(bddArticle);
win.ShowDialog();
dtArticle.Rows.Add(win.article.ID, win.article.Designation, $"{Math.Round(win.article.PrixHTVA, 2)}€");
}
private void dgvArticle_DoubleClick(object sender, EventArgs e)
{
if (dgvArticle.SelectedRows.Count > 0)
{
ConfigurationStock win = new ConfigurationStock(bddArticle.LireArticle(int.Parse(dgvArticle.SelectedRows[0].Cells[0].Value.ToString())), bddArticle);
win.ShowDialog();
dgvArticle.SelectedRows[0].Cells[1].Value = win.article.Designation;
dgvArticle.SelectedRows[0].Cells[2].Value = $"{Math.Round(win.article.PrixHTVA,2)}€";
dgvArticle.SelectedRows[0].Cells[3].Value = win.article.Stock;
}
}
}
}