public details_Sortee(article_model item, Icloseall closeAll, int NumberOfDialogs) { InitializeComponent(); this.item = item; this.closeAll = closeAll; this.NumberOfDialogs = NumberOfDialogs; }
/* * When a user clicks on add button this method get exuted * what is does is it get the input and asinge them to an * model class and run a background aysnc */ private void gunaGradientButton1_Click(object sender, EventArgs e) { if (prix.Text == "" || quantitier.Text == "" || desination.Text == "" || pictureBox1.Image == null) { MessageBox.Show("Il faut remplire Quantitier , designation ,prix et image"); } else { progresbar.Show(); MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat); byte[] imag = ms.ToArray(); article_model item = new article_model(); item.Barcode1 = barcode.Text; if (desination.Text != "") { item.Nom = desination.Text; } item.Description_inter = reference_intrene.Text; item.Descroption_fabrication = reference_fabricant.Text; item.Code_fabrication = code_ean.Text; item.Prix = Double.Parse(prix.Text); if (quantitier.Text != "") { item.Quontitier1 = int.Parse(quantitier.Text); } item.Date_entre = DateTime.Parse(date.Value.ToShortDateString()); item.Img = imag; if (!add_data_worker.IsBusy) { add_data_worker.RunWorkerAsync(item); } } }
/* * retrive data and bind it to a datagridview * in the background thread */ private void view_worker_DoWork(object sender, DoWorkEventArgs e) { sqlcn SqlConnection = new sqlcn(); SqlDataReader datareader = SqlConnection.Data_View(e.Argument.ToString()); List <article_model> data = new List <article_model>(); while (datareader.Read()) { article_model item = new article_model(); item.Id = (int)datareader.GetValue(0); item.Barcode1 = (String)datareader.GetValue(1); item.Bon_entrer = (int)datareader.GetValue(2); item.Nom = (String)datareader.GetValue(3); item.Description_inter = (String)datareader.GetValue(4); item.Fourniseur = (string)datareader.GetValue(5); item.Descroption_fabrication = (String)datareader.GetValue(6); item.Code_fabrication = (String)datareader.GetValue(7); item.Prix = (double)datareader.GetValue(8); item.Quontitier1 = (int)datareader.GetValue(9); item.Date_entre = (DateTime)datareader.GetValue(10); item.Img = (Byte[])datareader.GetValue(11); 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; }
public add_success(article_model data) { prgf = @"Barcode " + data.Barcode1 + "\n Desination " + data.Nom + "\n quantitie " + data.Quontitier1 + "\n Prix " + data.Prix + "\n description_inter " + data.Description_inter + "\n descroption_fabrication " + data.Descroption_fabrication + "\n Date " + data.Date_entre; ; InitializeComponent(); }
private void update_data_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { progresbar.Hide(); article_model model = ((article_model)e.Result); add_success add_Success = new add_success(model); add_Success.ShowDialog(); }
private void update_data_DoWork(object sender, DoWorkEventArgs e) { article_model model = ((article_model)e.Argument); sqlcn sql = new sqlcn(); sql.update(model); e.Result = model; }
/* * start an async task to add data to database */ private void add_data_worker_DoWork(object sender, DoWorkEventArgs e) { article_model item = (article_model)e.Argument; SqlParameter[] param = new SqlParameter[11]; param[0] = new SqlParameter("@barcode", SqlDbType.VarChar, 40); param[0].Value = item.Barcode1; param[1] = new SqlParameter("@bon_entrer", SqlDbType.Int); param[1].Value = item.Bon_entrer; param[2] = new SqlParameter("@nom", SqlDbType.VarChar, 40); param[2].Value = item.Nom; param[3] = new SqlParameter("@description_inter", SqlDbType.VarChar, 40); param[3].Value = item.Description_inter; param[4] = new SqlParameter("@fourniseur", SqlDbType.VarChar, 40); param[4].Value = item.Barcode1; param[5] = new SqlParameter("@descroption_fabrication", SqlDbType.VarChar, 40); param[5].Value = item.Descroption_fabrication; param[6] = new SqlParameter("@code_fabrication", SqlDbType.Int); param[6].Value = int.Parse(item.Code_fabrication == "" ? "0" : item.Code_fabrication); param[7] = new SqlParameter("@prix", SqlDbType.Int); param[7].Value = item.Prix; param[8] = new SqlParameter("@Quontitier", SqlDbType.Int); param[8].Value = item.Quontitier1; param[9] = new SqlParameter("@date_entre", SqlDbType.Date); param[9].Value = item.Date_entre; param[10] = new SqlParameter("@img", SqlDbType.Image); param[10].Value = item.Img; remplire.openconx(); //foreach (var item in param) //{ // MessageBox.Show("" + item); //} int i = remplire.ExuteCommende("r_Article", param); remplire.closecnx(); List <object> parameters = new List <object>(); parameters.Add(i); parameters.Add(item); e.Result = parameters; }
public void update(article_model item) { SqlCommand macommende = new SqlCommand(); openconx(); macommende.Connection = cnn; macommende.CommandType = CommandType.Text; macommende.CommandText = @"UPDATE Artical SET Barcode = @barcode, nom = @nom, description_inter = @description_inter, descroption_fabrication = @descroption_fabrication, code_fabrication= @code_fabrication, prix= @prix, Quontitier= @Quontitier, date_entre= @date_entre, img= @img WHERE ref=" + item.Id; SqlParameter[] param = new SqlParameter[9]; param[0] = new SqlParameter("@barcode", SqlDbType.VarChar, 40); param[0].Value = item.Barcode1; param[1] = new SqlParameter("@nom", SqlDbType.VarChar, 40); param[1].Value = item.Nom; param[2] = new SqlParameter("@description_inter", SqlDbType.VarChar, 40); param[2].Value = item.Description_inter; param[3] = new SqlParameter("@descroption_fabrication", SqlDbType.VarChar, 40); param[3].Value = item.Descroption_fabrication; param[4] = new SqlParameter("@code_fabrication", SqlDbType.Int); param[4].Value = item.Code_fabrication; param[5] = new SqlParameter("@prix", SqlDbType.Int); param[5].Value = item.Prix; param[6] = new SqlParameter("@Quontitier", SqlDbType.Int); param[6].Value = item.Quontitier1; param[7] = new SqlParameter("@date_entre", SqlDbType.Date); param[7].Value = item.Date_entre; param[8] = new SqlParameter("@img", SqlDbType.Image); param[8].Value = item.Img; macommende.Parameters.AddRange(param); macommende.ExecuteNonQuery(); }
/* * when the user edite on a cell of datagridview */ private void view_data_CellValueChanged(object sender, DataGridViewCellEventArgs e) { DataGridViewCellCollection a = view_data.Rows[e.RowIndex].Cells; string value = a[2].Value.ToString(); progresbar.Show(); article_model model = new article_model(); model.Id = int.Parse(a[0].Value.ToString()); model.Bon_entrer = int.Parse(a[1].Value.ToString()); model.Barcode1 = a[2].Value.ToString(); model.Fourniseur = a[3].Value.ToString(); model.Nom = a[4].Value.ToString(); model.Description_inter = a[5].Value.ToString(); model.Descroption_fabrication = a[6].Value.ToString(); model.Code_fabrication = a[7].Value.ToString(); model.Prix = int.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; //article_model item = new article_model(); //item.Id = (int)datareader.GetValue(0); //item.Barcode1 = (String)datareader.GetValue(1); //item.Bon_entrer = (int)datareader.GetValue(2); //item.Nom = (String)datareader.GetValue(3); //item.Description_inter = (String)datareader.GetValue(4); //item.Fourniseur = (string)datareader.GetValue(5); //item.Descroption_fabrication = (String)datareader.GetValue(6); //item.Code_fabrication = (String)datareader.GetValue(7); //item.Prix = (double)datareader.GetValue(8); //item.Quontitier1 = (int)datareader.GetValue(9); //item.Date_entre = (DateTime)datareader.GetValue(10); //item.Img = (Byte[])datareader.GetValue(11); if (!update_data.IsBusy) { update_data.RunWorkerAsync(model); } }
/* * when the ayscn task of adding data complete */ private void add_data_worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { List <object> args = e.Result as List <object>; int RUN_CODE = (int)args[0]; article_model data = (article_model)args[1]; progresbar.Hide(); if (RUN_CODE == -1) { MessageBox.Show("Error en Entree"); } else { add_success dialog = new add_success(data); dialog.ShowDialog(); } _units.Controls_clear(bon_entre); }
public List <article_model> View(String cmnd) { List <article_model> data = new List <article_model>(); SqlCommand req = new SqlCommand(); openconx(); req.Connection = cnn; req.CommandType = CommandType.Text; // Changer le type de la requete en text (non pas procedure) req.CommandText = cmnd; req.Parameters.Clear(); datareader = req.ExecuteReader(); while (datareader.Read()) { article_model item = new article_model(); item.Id = (int)datareader.GetValue(0); item.Bon_entrer = (int)datareader.GetValue(1); item.Barcode1 = (String)datareader.GetValue(2); item.Nom = (String)datareader.GetValue(3); item.Description_inter = (String)datareader.GetValue(4); item.Fourniseur = (string)datareader.GetValue(5); item.Descroption_fabrication = (String)datareader.GetValue(6); item.Code_fabrication = (String)datareader.GetValue(7); item.Prix = (double)datareader.GetValue(8); item.Quontitier1 = (int)datareader.GetValue(9); item.Date_entre = (DateTime)datareader.GetValue(10); item.Img = (Byte[])datareader.GetValue(11); 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))); } return(data); }
public item(article_model data) { InitializeComponent(); this.data = 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(); } }