void setActivitati(int id_profesor) { if (activitati.Count != 0) { activitati.Clear(); } using (DbConnection connection = factory.CreateConnection()) { connection.ConnectionString = ConnString; connection.Open(); DbCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM Activitati WHERE id_profesor = @id_profesor"; command.Parameters.Clear(); DbParameter parameterId = command.CreateParameter(); parameterId.DbType = System.Data.DbType.Int32; parameterId.Value = id_profesor; command.Parameters.Add(parameterId); DbDataReader reader = command.ExecuteReader(); while (reader.Read()) { Activitate a = new Activitate(reader.GetValue(1).ToString(), reader.GetValue(2).ToString(), reader.GetValue(3).ToString(), reader.GetValue(4).ToString(), reader.GetValue(5).ToString(), reader.GetValue(6).ToString()); activitati.Add(a); } connection.Close(); } }
void insereazaInTree(Activitate a) { if (a.getZiua() == "Luni") { treeViewActivitati.Nodes[0].Nodes.Add(a.ToString()); } else if (a.getZiua() == "Marti") { treeViewActivitati.Nodes[1].Nodes.Add(a.ToString()); } else if (a.getZiua() == "Miercuri") { treeViewActivitati.Nodes[2].Nodes.Add(a.ToString()); } else if (a.getZiua() == "Joi") { treeViewActivitati.Nodes[3].Nodes.Add(a.ToString()); } else if (a.getZiua() == "Vineri") { treeViewActivitati.Nodes[4].Nodes.Add(a.ToString()); } }
private void button1_Click(object sender, EventArgs e) { Adauga add = new Adauga(); add.ShowDialog(); Activitate a = add.GetActivitate(); activitati.Add(a); if (add.getStatus()) { using (DbConnection connection = factory.CreateConnection()) { connection.ConnectionString = ConnString; connection.Open(); DbCommand command = connection.CreateCommand(); command.CommandText = "SELECT MAX(Nr_activitate) FROM Activitati"; int nrAct = (int)command.ExecuteScalar(); command.CommandText = "INSERT INTO Activitati VALUES(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8)"; command.Parameters.Clear(); DbParameter p1 = command.CreateParameter(); p1.DbType = DbType.Int32; p1.Value = nrAct + 1; command.Parameters.Add(p1); DbParameter p2 = command.CreateParameter(); p2.DbType = DbType.String; p2.Value = a.getTip(); command.Parameters.Add(p2); DbParameter p3 = command.CreateParameter(); p3.DbType = DbType.String; p3.Value = a.getMaterie(); command.Parameters.Add(p3); DbParameter p4 = command.CreateParameter(); p4.DbType = DbType.String; p4.Value = a.getOra(); command.Parameters.Add(p4); DbParameter p5 = command.CreateParameter(); p5.DbType = DbType.String; p5.Value = a.getGrupa(); command.Parameters.Add(p5); DbParameter p6 = command.CreateParameter(); p6.DbType = DbType.String; p6.Value = a.getZiua(); command.Parameters.Add(p6); DbParameter p7 = command.CreateParameter(); p7.DbType = DbType.String; p7.Value = a.getSala(); command.Parameters.Add(p7); DbParameter p8 = command.CreateParameter(); p8.DbType = DbType.Int32; p8.Value = add.getIdProfesor(); command.Parameters.Add(p8); command.ExecuteNonQuery(); MessageBox.Show("S-a adaugat: " + a.ToString()); } } }