private void button4_Click(object sender, EventArgs e)
{
dataGridView2.Rows.Clear();
Program.cmd.CommandText = "select * from bon_reception_marche where Date_reception between '" + dateTimePicker1.Value.Date + "' and '" + dateTimePicker2.Value.Date + "' and Id_marche in (select TOP 1 Id_marche from marche where Num_marche = '"+textBox1.Text+"')";
Program.dr = Program.cmd.ExecuteReader();
while (Program.dr.Read())
{
dataGridView2.Rows.Add(Program.dr[0],Program.dr[2], Program.dr[3], Program.dr[5], Program.dr[6], Program.dr[7], Program.dr[8], Program.dr[9], Program.dr[10], Program.dr[11], Program.dr[12]);
}
Program.dr.Close();
}
private void button1_Click(object sender, EventArgs e)
{
int colIndex = dataGridView2.Columns["CheckBox"].Index;
try
{
var rows = dataGridView2.Rows
.Cast<DataGridViewRow>()
.Where(row => row.Cells[colIndex].Value != null)
.Where(row => (bool)row.Cells[colIndex].Value)
.ToList();
foreach (DataGridViewRow row in rows)
insertRowData(row);
MessageBox.Show("c'est ajouté avec succés");
}
catch (FormatException)
{
MessageBox.Show("Only input numbers into the table!",
"Only Numbers", MessageBoxButtons.OK);
}
catch (Exception)
{
MessageBox.Show("There was an error while saving!",
"Error", MessageBoxButtons.OK);
}
}
private void insertRowData(DataGridViewRow row)
{
double montantValue = Convert.ToDouble(row.Cells["Column7"].Value);
int id_br_value = Convert.ToInt32(row.Cells["Column11"].Value);
string check;
if (checkBox1.Checked == true)
{
check = "O";
}
else
{
check = "N";
}
Program.cmd.Parameters.Clear();
Program.cmd.CommandText = "insert into attachement_marche (Id_bon_reception_marche,Id_marche,Num_attachement,Date_debut,Date_fin,Flag_dernier,Montant,User_create,Date_create) values ( " + id_br_value + ",(select TOP 1 Id_marche from marche where Num_marche = '" + textBox1.Text + "'),'" + textBox3.Text + "','" + dateTimePicker1.Value.Date + "','" + dateTimePicker1.Value.Date + "','" + check + "'," + montantValue + ",'" + values.username + "','" + DateTime.Now.Date + "')";
Program.cmd.ExecuteNonQuery();
}