Exemple #1
0
 public Object SaveSubject(Subject s)
 {
     if (!s.Validate())
     {
         throw new InvalidRequestFormat("Структура Subject заполена некорректно");
     }
     DbCommand dc = connection.CreateCommand();
     if (s.id > 0)
     {
         dc.CommandText = "update subject set name = ?, teacher = ?, hour = ? where id = ?;";
         DbParameter par = dc.CreateParameter();
         par.DbType = DbType.String;
         par.Value = s.name;
         dc.Parameters.Add(par);
         par = dc.CreateParameter();
         par.DbType = DbType.String;
         par.Value = s.teacher;
         dc.Parameters.Add(par);
         par = dc.CreateParameter();
         par.DbType = DbType.Int32;
         par.Value = s.hour;
         dc.Parameters.Add(par);
         par = dc.CreateParameter();
         par.DbType = DbType.Int32;
         par.Value = s.id;
         dc.Parameters.Add(par);
         dc.ExecuteNonQuery();
     }
     else
     {
         dc.CommandText = "insert into subject (name, teacher, hour) values(?, ?, ?) returning id;";
         DbParameter par = dc.CreateParameter();
         par.DbType = DbType.String;
         par.Value = s.name;
         dc.Parameters.Add(par);
         par = dc.CreateParameter();
         par = dc.CreateParameter();
         par.DbType = DbType.String;
         par.Value = s.teacher;
         dc.Parameters.Add(par);
         par = dc.CreateParameter();
         par.DbType = DbType.Int32;
         par.Value = s.hour;
         dc.Parameters.Add(par);
         s.id = (int)dc.ExecuteScalar();
     }
     return s;
 }
Exemple #2
0
 private Subject ParseSubject(DbDataReader dr)
 {
     Subject s = new Subject();
     s.id = dr.GetInt32(0);
     s.name = dr.GetString(1);
     s.teacher = dr.GetString(2);
     s.hour = dr.GetInt32(3);
     return s;
 }
Exemple #3
0
 private Item GetItemFromSelectedRow(DataGridView grid)
 {
     DataGridViewRow row = grid.CurrentRow;
     if (row == null)
     {
         throw new Exception("Элемент не выбран в таблице");
     }
     if (grid == personGrid)
     {
         if (!Person.ValidatName(row.Cells["name"].Value) ||
             !Person.ValidatName(row.Cells["surname"].Value) ||
             !Person.ValidateCourse(row.Cells["cours"].Value) ||
             !Person.ValidatGroup(row.Cells["Group"].Value))
         {
             return null;
         }
         Person p = new Person();
         p.id = Int32.Parse(row.Cells[0].Value.ToString());
         p.name = row.Cells["name"].Value.ToString();
         p.surname = row.Cells["surname"].Value.ToString();
         p.group = Int32.Parse(row.Cells["Group"].Value.ToString());
         p.cours = Int32.Parse(row.Cells["cours"].Value.ToString());
         return p;
     }
     else if (grid == subjectGrid)
     {
         if (!Subject.ValidatName(row.Cells["SubjectName"].Value) ||
             !Subject.ValidatName(row.Cells["SubjectTeacher"].Value) ||
             !Subject.ValidateHour(row.Cells["SubjectHour"].Value))
         {
             return null;
         }
         Subject s = new Subject();
         s.id = Int32.Parse(row.Cells["SubjectId"].Value.ToString());
         s.name = row.Cells["SubjectName"].Value.ToString();
         s.teacher = row.Cells["SubjectTeacher"].Value.ToString();
         s.hour = Int32.Parse(row.Cells["SubjectHour"].Value.ToString());
         return s;
     }
     else if (grid == markGrid)
     {
         Mark m = (Mark)row.Cells["MarkId"].Value;
         return m;
     }
     return null;
 }