private void ArticleSorieView_DoWork(object sender, DoWorkEventArgs e) { sqlcn SqlConnection = new sqlcn(); SqlDataReader datareader = SqlConnection.Data_View(e.Argument.ToString()); List <Articl_sortie> data = new List <Articl_sortie>(); while (datareader.Read()) { Articl_sortie item = new Articl_sortie(); item.Id = (int)datareader.GetValue(0); item.Codeclient = (int)datareader.GetValue(2); item.Date_sortie = (DateTime)datareader.GetValue(3); item.Matricul = (String)datareader.GetValue(4); item.Quontitier1 = (int)datareader.GetValue(5); item.Barcode1 = (String)datareader.GetValue(7); item.Bon_entrer = (int)datareader.GetValue(8); item.Nom = (String)datareader.GetValue(9); item.Description_inter = (String)datareader.GetValue(11); item.Descroption_fabrication = (String)datareader.GetValue(12); item.Code_fabrication = (String)datareader.GetValue(13); item.Prix = (double)datareader.GetValue(14); item.Date_entre = (DateTime)datareader.GetValue(16); item.Img = (Byte[])datareader.GetValue(17); data.Add(item); // data.Add(new article_model((int)datareader.GetValue(0), (String)datareader.GetValue(1),(String) datareader.GetValue(2),(String) datareader.GetValue(3), (String)datareader.GetValue(4), (String)datareader.GetValue(5),(float) datareader.GetValue(6), (int)datareader.GetValue(7), (DateTime)datareader.GetValue(8),(byte[]) datareader.GetValue(9))); } e.Result = data; }
/* * when the user select a row o multiple rows of data grid view * it get stored in list of arcticle model * and if it unselected them the list get cleared */ private void view_data_SelectionChanged(object sender, EventArgs e) { if (view_data.SelectedRows.Count > 0) { selectedRows.Clear(); try { for (int i = 0; i < view_data.SelectedRows.Count; i++) { DataGridViewCellCollection a = view_data.SelectedRows[i].Cells; string value = a[2].Value.ToString(); article_model model = new article_model(); model.Id = int.Parse(a[0].Value.ToString()); model.Barcode1 = a[1].Value.ToString(); model.Bon_entrer = int.Parse(a[2].Value.ToString()); model.Nom = a[3].Value.ToString(); model.Description_inter = a[4].Value.ToString(); model.Fourniseur = a[5].Value.ToString(); model.Descroption_fabrication = a[6].Value.ToString(); model.Code_fabrication = a[7].Value.ToString(); model.Prix = double.Parse(a[8].Value.ToString()); model.Quontitier1 = int.Parse(a[9].Value.ToString()); model.Date_entre = DateTime.Parse(a[10].Value.ToString()); model.Img = (byte[])a[11].Value; selectedRows.Add(model); } } catch (Exception) { try { for (int i = 0; i < view_data.SelectedRows.Count; i++) { DataGridViewCellCollection a = view_data.SelectedRows[i].Cells; string value = a[2].Value.ToString(); Articl_sortie model = new Articl_sortie(); model.Id = int.Parse(a[0].Value.ToString()); model.Barcode1 = a[1].Value.ToString(); model.Nom = a[2].Value.ToString(); model.Description_inter = a[3].Value.ToString(); model.Descroption_fabrication = a[4].Value.ToString(); model.Code_fabrication = a[5].Value.ToString(); model.Prix = double.Parse(a[6].Value.ToString()); model.Quontitier1 = int.Parse(a[7].Value.ToString()); model.Date_entre = DateTime.Parse(a[8].Value.ToString()); model.Date_sortie = DateTime.Parse(a[9].Value.ToString()); model.Date_sortie = DateTime.Parse(a[9].Value.ToString()); model.Matricul = a[9].Value.ToString(); model.Img = (byte[])a[10].Value; model.Bon_entrer = int.Parse(a[11].Value.ToString()); // selectedRows.Add(model); } } catch (Exception) { //throw; } // throw; } } else { selectedRows.Clear(); } }