public void adaugaInregistrareToolStripMenuItem_Click(object sender, EventArgs e, string nume) { Form_adauga_medic form_add_medic = new Form_adauga_medic(nume); form_add_medic.ShowDialog(); if (form_add_medic.DialogResult == DialogResult.OK) { OleDbConnection conexiune = new OleDbConnection(Provider); OleDbCommand comanda = new OleDbCommand(); comanda.Connection = conexiune; try { conexiune.Open(); comanda.Transaction = conexiune.BeginTransaction(); comanda.CommandText = "SELECT max(id_medic) FROM medici;"; int cod = Convert.ToInt32(comanda.ExecuteScalar()); comanda.CommandText = "INSERT INTO medici(id_medic,nume,varsta,ore_lucrate_pe_saptamana,salariul,numar_pacienti,departament) " + " VALUES (@id_medic,@nume,@varsta,@ore_lucrate_pe_saptamana,@salariul,@numar_pacienti,@departament);"; comanda.Parameters.Add("id_medic", OleDbType.Integer).Value = cod + 1; comanda.Parameters.Add("nume", OleDbType.Char).Value = nume; comanda.Parameters.Add("varsta", OleDbType.Integer).Value = form_add_medic.medic.Varsta; comanda.Parameters.Add("ore_lucrate_pe_saptamana", OleDbType.Double).Value = form_add_medic.medic.Ore_lucrate; comanda.Parameters.Add("salariul", OleDbType.Double).Value = form_add_medic.medic.Salariul; comanda.Parameters.Add("numar_pacienti", OleDbType.Integer).Value = nr_pacienti; comanda.Parameters.Add("departament", OleDbType.Char).Value = form_add_medic.medic.Departament; TreeNode newNode = new TreeNode(nume); treeView1.Nodes.Add(newNode); comanda.ExecuteNonQuery(); comanda.Transaction.Commit(); } catch (OleDbException ex) { MessageBox.Show(ex.Message); comanda.Transaction.Rollback(); } finally { conexiune.Close(); } UpdateList(); } }
private void modificaInregistrareToolStripMenuItem_Click(object sender, EventArgs e) { Form_adauga_medic form_Adauga_Medic = new Form_adauga_medic((Medici)listView1.SelectedItems[0].Tag); form_Adauga_Medic.ShowDialog(); if (form_Adauga_Medic.DialogResult == DialogResult.OK) { OleDbConnection conexiune = new OleDbConnection(Provider); OleDbCommand comanda = new OleDbCommand(); comanda.Connection = conexiune; try { conexiune.Open(); comanda.Transaction = conexiune.BeginTransaction(); //comanda.CommandText = "SELECT nume FROM medici WHERE id_medic = @id_m"; //comanda.Parameters.Add("id_medic", OleDbType.Integer).Value = Convert.ToInt32(((Medici)listView1.SelectedItems[0].Tag).Id_medic); // string nume_for_update = comanda.ExecuteNonQuery().ToString(); comanda.CommandText = "UPDATE medici SET nume = @nume, varsta=@varsta, ore_lucrate_pe_saptamana = @ore_lucrate,salariul = @salariul,departament=@dep WHERE id_medic=@id_medic"; comanda.Parameters.Add("nume", OleDbType.Char).Value = form_Adauga_Medic.medic.Nume; comanda.Parameters.Add("varsta", OleDbType.Integer).Value = form_Adauga_Medic.medic.Varsta; comanda.Parameters.Add("ore_lucrate", OleDbType.Double).Value = form_Adauga_Medic.medic.Ore_lucrate; comanda.Parameters.Add("salariul", OleDbType.Double).Value = form_Adauga_Medic.medic.Salariul; comanda.Parameters.Add("nume", OleDbType.Char).Value = form_Adauga_Medic.medic.Nume; comanda.Parameters.Add("id_medic", OleDbType.Integer).Value = Convert.ToInt32(((Medici)listView1.SelectedItems[0].Tag).Id_medic); int j = 0; while (j < treeView1.Nodes.Count && treeView1.Nodes[j].Name != form_Adauga_Medic.medic.Nume) { j++; } TreeNode node = new TreeNode(form_Adauga_Medic.medic.Nume); if (j == treeView1.Nodes.Count) { } else { treeView1.Nodes[j] = node; } comanda.ExecuteScalar(); comanda.Transaction.Commit(); } catch (OleDbException ex) { MessageBox.Show(ex.Message); comanda.Transaction.Rollback(); } finally { conexiune.Close(); } UpdateList(); } }