Esempio n. 1
0
        /// <summary>
        /// Converts <see cref="System.Data.DataRow"/> to <see cref="PatientInfoRow"/>.
        /// </summary>
        /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
        /// <returns>A reference to the <see cref="PatientInfoRow"/> object.</returns>
        protected virtual PatientInfoRow MapRow(DataRow row)
        {
            PatientInfoRow mappedObject = new PatientInfoRow();
            DataTable      dataTable    = row.Table;
            DataColumn     dataColumn;

            // Column "Id"
            dataColumn = dataTable.Columns["Id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Id = (int)row[dataColumn];
            }
            // Column "Name"
            dataColumn = dataTable.Columns["Name"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Name = (string)row[dataColumn];
            }
            // Column "Address"
            dataColumn = dataTable.Columns["Address"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Address = (string)row[dataColumn];
            }
            // Column "DateOfBirth"
            dataColumn = dataTable.Columns["DateOfBirth"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.DateOfBirth = (System.DateTime)row[dataColumn];
            }
            // Column "Phone"
            dataColumn = dataTable.Columns["Phone"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Phone = (int)row[dataColumn];
            }
            // Column "EmergencyContact"
            dataColumn = dataTable.Columns["EmergencyContact"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.EmergencyContact = (int)row[dataColumn];
            }
            // Column "DateOfRegistration"
            dataColumn = dataTable.Columns["DateOfRegistration"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.DateOfRegistration = (System.DateTime)row[dataColumn];
            }
            return(mappedObject);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new record into the <c>PatientInfo</c> table.
        /// </summary>
        /// <param name="value">The <see cref="PatientInfoRow"/> object to be inserted.</param>
        public virtual void Insert(PatientInfoRow value)
        {
            SqlCommand cmd = _db.CreateCommand("dbo._PatientInfo_Insert", true);

            AddParameter(cmd, "Name", value.Name);
            AddParameter(cmd, "Address", value.Address);
            AddParameter(cmd, "DateOfBirth",
                         value.IsDateOfBirthNull ? DBNull.Value : (object)value.DateOfBirth);
            AddParameter(cmd, "Phone",
                         value.IsPhoneNull ? DBNull.Value : (object)value.Phone);
            AddParameter(cmd, "EmergencyContact",
                         value.IsEmergencyContactNull ? DBNull.Value : (object)value.EmergencyContact);
            AddParameter(cmd, "DateOfRegistration",
                         value.IsDateOfRegistrationNull ? DBNull.Value : (object)value.DateOfRegistration);
            value.Id = Convert.ToInt32(cmd.ExecuteScalar());
        }
Esempio n. 3
0
        /// <summary>
        /// Updates a record in the <c>PatientInfo</c> table.
        /// </summary>
        /// <param name="value">The <see cref="PatientInfoRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(PatientInfoRow value)
        {
            SqlCommand cmd = _db.CreateCommand("dbo._PatientInfo_Update", true);

            AddParameter(cmd, "Name", value.Name);
            AddParameter(cmd, "Address", value.Address);
            AddParameter(cmd, "DateOfBirth",
                         value.IsDateOfBirthNull ? DBNull.Value : (object)value.DateOfBirth);
            AddParameter(cmd, "Phone",
                         value.IsPhoneNull ? DBNull.Value : (object)value.Phone);
            AddParameter(cmd, "EmergencyContact",
                         value.IsEmergencyContactNull ? DBNull.Value : (object)value.EmergencyContact);
            AddParameter(cmd, "DateOfRegistration",
                         value.IsDateOfRegistrationNull ? DBNull.Value : (object)value.DateOfRegistration);
            AddParameter(cmd, "Id", value.Id);
            return(0 != cmd.ExecuteNonQuery());
        }
Esempio n. 4
0
        public virtual void  Search(PatientInfoRow value)
        {
            SqlCommand cmd = _db.CreateCommand("dbo.PatientInfoSearchAll", true);

            AddParameter(cmd, "Name", value.Name);
            //AddParameter(cmd, "Address", value.Address);
            AddParameter(cmd, "DateOfBirth",
                         value.IsDateOfBirthNull ? DBNull.Value : (object)value.DateOfBirth);
            // AddParameter(cmd, "Phone",
            // value.IsPhoneNull ? DBNull.Value : (object)value.Phone);
            // AddParameter(cmd, "EmergencyContact",
            //   value.IsEmergencyContactNull ? DBNull.Value : (object)value.EmergencyContact);
            //AddParameter(cmd, "DateOfRegistration",
            //  value.IsDateOfRegistrationNull ? DBNull.Value : (object)value.DateOfRegistration);
            //MapRecords(CreateGetAllCommand());
            //  PatientInfoRow[] tempArray = MapRecords(cmd);
            // MapRecords(cmd);
            //cmd.ExecuteNonQuery();
            //value.Id = Convert.ToInt32(cmd.ExecuteScalar());
        }
Esempio n. 5
0
        /// <summary>
        /// Reads data from the provided data reader and returns
        /// an array of mapped objects.
        /// </summary>
        /// <param name="reader">The <see cref="System.Data.SqlDataReader"/> object to read data from the table.</param>
        /// <param name="startIndex">The index of the first record to map.</param>
        /// <param name="length">The number of records to map.</param>
        /// <param name="totalRecordCount">A reference parameter that returns the total number
        /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param>
        /// <returns>An array of <see cref="PatientInfoRow"/> objects.</returns>
        protected virtual PatientInfoRow[] MapRecords(SqlDataReader reader,
                                                      int startIndex, int length, ref int totalRecordCount)
        {
            if (0 > startIndex)
            {
                throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.");
            }
            if (0 > length)
            {
                throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.");
            }

            int idColumnIndex                 = reader.GetOrdinal("Id");
            int nameColumnIndex               = reader.GetOrdinal("Name");
            int addressColumnIndex            = reader.GetOrdinal("Address");
            int dateOfBirthColumnIndex        = reader.GetOrdinal("DateOfBirth");
            int phoneColumnIndex              = reader.GetOrdinal("Phone");
            int emergencyContactColumnIndex   = reader.GetOrdinal("EmergencyContact");
            int dateOfRegistrationColumnIndex = reader.GetOrdinal("DateOfRegistration");

            System.Collections.ArrayList recordList = new System.Collections.ArrayList();
            int ri = -startIndex;

            while (reader.Read())
            {
                ri++;
                if (ri > 0 && ri <= length)
                {
                    PatientInfoRow record = new PatientInfoRow();
                    recordList.Add(record);

                    record.Id = Convert.ToInt32(reader.GetValue(idColumnIndex));
                    if (!reader.IsDBNull(nameColumnIndex))
                    {
                        record.Name = Convert.ToString(reader.GetValue(nameColumnIndex));
                    }
                    if (!reader.IsDBNull(addressColumnIndex))
                    {
                        record.Address = Convert.ToString(reader.GetValue(addressColumnIndex));
                    }
                    if (!reader.IsDBNull(dateOfBirthColumnIndex))
                    {
                        record.DateOfBirth = Convert.ToDateTime(reader.GetValue(dateOfBirthColumnIndex));
                    }
                    if (!reader.IsDBNull(phoneColumnIndex))
                    {
                        record.Phone = Convert.ToInt32(reader.GetValue(phoneColumnIndex));
                    }
                    if (!reader.IsDBNull(emergencyContactColumnIndex))
                    {
                        record.EmergencyContact = Convert.ToInt32(reader.GetValue(emergencyContactColumnIndex));
                    }
                    if (!reader.IsDBNull(dateOfRegistrationColumnIndex))
                    {
                        record.DateOfRegistration = Convert.ToDateTime(reader.GetValue(dateOfRegistrationColumnIndex));
                    }

                    if (ri == length && 0 != totalRecordCount)
                    {
                        break;
                    }
                }
            }

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return((PatientInfoRow[])(recordList.ToArray(typeof(PatientInfoRow))));
        }
Esempio n. 6
0
 /// <summary>
 /// Deletes the specified object from the <c>PatientInfo</c> table.
 /// </summary>
 /// <param name="value">The <see cref="PatientInfoRow"/> object to delete.</param>
 /// <returns>true if the record was deleted; otherwise, false.</returns>
 public bool Delete(PatientInfoRow value)
 {
     return(DeleteByPrimaryKey(value.Id));
 }