private void BOk_Click(object sender, EventArgs e) { if (mark == null) { mark = new Mark(); mark.id = 0; } mark.person = ((Person)CPerson.SelectedItem).id; mark.subject = ((Subject)CSubject.SelectedItem).id; mark.mark = Int32.Parse(CMark.Text); }
private Mark ParseMark(DbDataReader dr) { Mark m = new Mark(); m.id = dr.GetInt32(0); m.person = dr.GetInt32(1); m.subject = dr.GetInt32(2); m.mark = dr.GetInt32(3); return m; }
public Object SaveMark(Mark m) { if (!m.Validate()) { throw new InvalidRequestFormat("Структура Mark заполена некорректно"); } DbCommand dc = connection.CreateCommand(); if (m.id > 0) { dc.CommandText = "update mark set person_id = ?, subject_id = ?, mark = ? where id = ?;"; DbParameter par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.person; dc.Parameters.Add(par); par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.subject; dc.Parameters.Add(par); par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.mark; dc.Parameters.Add(par); par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.id; dc.Parameters.Add(par); dc.ExecuteNonQuery(); } else { dc.CommandText = "insert into mark (person_id, subject_id, mark) values(?, ?, ?) returning id;"; DbParameter par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.person; dc.Parameters.Add(par); par = dc.CreateParameter(); par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.subject; dc.Parameters.Add(par); par = dc.CreateParameter(); par.DbType = DbType.Int32; par.Value = m.mark; dc.Parameters.Add(par); m.id = (int)dc.ExecuteScalar(); } return m; }