Esempio n. 1
0
        public void CreateMonitoring(Monitoring monitor)
        {
            using (SqlConnection conn = new SqlConnection(connString))
            {
                string sql = @"INSERT INTO dbo.Monitoring_To_Patient (
                            PatientId, EquipmentId, OtherEquipment
                            ) VALUES (
                            @PatientId, @EquipmentId, @OtherEquipment
                            )";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add("@PatientId", SqlDbType.Int).Value = monitor.PatientId;
                if (monitor.Equipment.Id == -1)
                    cmd.Parameters.Add("@EquipmentId", SqlDbType.Int).Value = DBNull.Value;
                else
                    cmd.Parameters.Add("@EquipmentId", SqlDbType.NVarChar).Value = monitor.Equipment.Id;

                if (monitor.OtherEquipment == null)
                    cmd.Parameters.Add("@OtherEquipment", SqlDbType.NVarChar).Value = DBNull.Value;
                else
                    cmd.Parameters.Add("@OtherEquipment", SqlDbType.NVarChar).Value = monitor.OtherEquipment;

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Esempio n. 2
0
        public int UpdateMonitoring(Monitoring monitor)
        {
            int returnNum = 0;
            using (SqlConnection conn = new SqlConnection(connString))
            {
                string sql = @"UPDATE dbo.Monitoring_To_Patient SET
                            EquipmentId = @EquipmentId, OtherEquipment = @OtherEquipment
                            WHERE
                            PatientId = @PatientId";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.Add("@PatientId", SqlDbType.Int).Value = monitor.PatientId;
                if (monitor.Equipment.Id == -1)
                    cmd.Parameters.Add("@EquipmentId", SqlDbType.Int).Value = DBNull.Value;
                else
                    cmd.Parameters.Add("@EquipmentId", SqlDbType.NVarChar).Value = monitor.Equipment.Id;

                if (monitor.OtherEquipment == null)
                    cmd.Parameters.Add("@OtherEquipment", SqlDbType.NVarChar).Value = DBNull.Value;
                else
                    cmd.Parameters.Add("@OtherEquipment", SqlDbType.NVarChar).Value = monitor.OtherEquipment;
                try
                {
                    conn.Open();
                    returnNum = cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    conn.Close();
                }
            }
            return returnNum;
        }