private void REF_FACTURE_TextChanged(object sender, EventArgs e) { RefFac = REF_FACTURE.Text; string sqlcmd = "SELECT * FROM FAC_ACHAT WHERE ID_FAC=?"; try { OleDbCommand cmd = new OleDbCommand(sqlcmd, MainForm.DBKeepkool); cmd.Parameters.AddWithValue("?", RefFac); OleDbDataReader DrFac = cmd.ExecuteReader(); DrFac.Read(); if (DrFac.HasRows == false) { DETAILFAC.Hide(); NOM_FOURNISSEUR.Text = ""; DateFac.Value = DateTime.Now; dataGridView1.DataSource = ds; DETAILFAC.DataSource = null; } else { NOM_FOURNISSEUR.Text = DrFac.GetString(2); DateFac.Value = (DateTime)DrFac.GetValue(1); double TotalPrix = 0; int TotalQuante = 0; DETAILFAC.Show(); ds = new DataSet(); Da = CreateCustomerAdapter(MainForm.DBKeepkool); OleDbCommandBuilder CmdBuilder = new OleDbCommandBuilder(Da); Da.Fill(ds, "FACACHAT_DETAIL"); DETAILFAC.DataSource = ds; DETAILFAC.DataMember = "FACACHAT_DETAIL"; int index = DETAILFAC.Rows.Add(); for (int i = 0; i < DETAILFAC.RowCount; i++) { TotalQuante += (int)DETAILFAC.Rows[i].Cells[2].Value; TotalPrix += (int)DETAILFAC.Rows[i].Cells[2].Value * (double)DETAILFAC.Rows[i].Cells[3].Value; } DETAILFAC.Rows[index].Cells[2].Value = TotalQuante; DETAILFAC.Rows[index].Cells[3].Value = TotalPrix; } } catch { return; } }
private void DeleteFac_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Are you sure to delete this facture?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK) { string cmd = "DELETE FROM FAC_ACHAT WHERE ID_FAC=?"; OleDbCommand DBcmd = new OleDbCommand(cmd, MainForm.DBKeepkool); DBcmd.Parameters.AddWithValue("?", REF_FACTURE.Text); DBcmd.ExecuteNonQuery(); MessageBox.Show("Facture has been deleted!"); this.Controls.Clear(); InitializeComponent(); DETAILFAC.Hide(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void ADUSFacForm_Load(object sender, EventArgs e) { REF_FACTURE.AutoCompleteCustomSource = FacSuggestList(); Da = new OleDbDataAdapter(); DETAILFAC.Hide(); }