База данных для хранения и обработки информации, которая требуется типичной психиатрической больнице, страница 24

                                       public static int AddNewPatient(DbPatient information)

                                       {

                                                           int historyID = -1;

                                                           using (OracleConnection connection = GetConnection())

                                                           {

                                                                               OracleTransaction transaction = connection.BeginTransaction();

                                                                               try

                                                                               {

                                                                                                  information.ID = executePersonAddition(information, connection, transaction);

                                                                                                  historyID = executePatientAddition(information, connection, transaction);

                                                                                                  transaction.Commit();

                                                                               }

                                                                               catch (Exception excpt)

                                                                               {

                                                                                                  transaction.Rollback();

                                                                                                  throw excpt;

                                                                               }

                                                           }

                                                           return historyID;

                                       }

                                       /// <summary>

                                       /// Добавление нового сотрудника с имеющейся записью в таблице ЧЕЛОВЕК

                                       /// </summary>

                                       /// <param name="information">инфа о новом пациенте</param>

                                       public static void AddNewPatientFromExistingPerson(DbPatient information)

                                       {

                                                           using (OracleConnection connection = GetConnection())

                                                           {

                                                                               executePatientAddition(information, connection, null);

                                                           }

                                       }

                                       /// <summary>

                                       /// Выписка больного

                                       /// </summary>

                                       /// <param name="information"></param>

                                       public static void DischargePatient(DbPatient information, int inspectedId)

                                       {

                                                           using (OracleConnection connection = GetConnection())

                                                           using (OracleCommand cmd = new OracleCommand("DischargePatient", connection))

                                                           {

                                                                               cmd.CommandType = CommandType.StoredProcedure;

                                                                               cmd.Parameters.AddWithValue("pID", information.HistoryID);

                                                                               cmd.Parameters.AddWithValue("pОСМОТРЕВШИЙ_ID", inspectedId);

                                                                               cmd.ExecuteNonQuery();

                                                           }

                                       }

                                       #region common blocks

                                       private static int executePersonAddition(DbPerson information, OracleConnection connection, OracleTransaction transaction)

                                       {

                                                           using (OracleCommand cmd = new OracleCommand("CreateNewPerson", connection, transaction))

                                                           {

                                                                               cmd.CommandType = CommandType.StoredProcedure;

                                                                               cmd.Parameters.AddWithValue("pФАМИЛИЯ", information.Surname);

                                                                               cmd.Parameters.AddWithValue("pИМЯ", information.Name);

                                                                               cmd.Parameters.AddWithValue("pОТЧЕСТВО", information.Patronymic ?? (object)DBNull.Value);

                                                                               cmd.Parameters.AddWithValue("pПАСПОРТ", information.Passport);

                                                                               cmd.Parameters.Add("pID", OracleType.Int32).Direction = ParameterDirection.Output;

                                                                               cmd.ExecuteNonQuery();

                                                                               return (int)cmd.Parameters["pID"].Value;

                                                           }

                                       }