Esempio n. 1
0
        public List <DataClass.PatientClass> GetPatientList()
        {
            List <DataClass.PatientClass> result = new List <DataClass.PatientClass>();

            using (SqlConnection conn = new SqlConnection(CommonFunctions.GetConnectionString()))
            {
                using (SqlCommand cmd = new SqlCommand {
                    CommandText = "SelectPatientList", CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    try
                    {
                        if (conn.State != System.Data.ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        ;
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                DataClass.PatientClass pX = new DataClass.PatientClass();
                                pX.firstName   = reader.GetString(reader.GetOrdinal("FirstName"));
                                pX.LastName    = reader.GetString(reader.GetOrdinal("LastName"));
                                pX.dateOfBirth = reader.GetDateTime(reader.GetOrdinal("DateOfBirth"));
                                pX.pxID        = reader.GetGuid(reader.GetOrdinal("PxID"));
                                result.Add(pX);
                            }
                        }
                    }
                    finally
                    {
                        if (conn.State != System.Data.ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                        ;
                    }
                }
            }

            return(result);
        }
Esempio n. 2
0
        public bool UpdatePatient(DataClass.PatientClass patient)
        {
            bool success = false;

            using (SqlConnection conn = new SqlConnection(CommonFunctions.GetConnectionString()))
            {
                using (SqlCommand cmd = new SqlCommand {
                    CommandText = "InsertPatient", CommandType = System.Data.CommandType.StoredProcedure
                })
                {
                    cmd.Parameters.AddWithValue("@PxID", patient.pxID);
                    cmd.Parameters.AddWithValue("@FirstName", patient.firstName);
                    cmd.Parameters.AddWithValue("@LastName", patient.LastName);
                    cmd.Parameters.AddWithValue("@DateOfBirth", patient.dateOfBirth);
                    try
                    {
                        if (conn.State != System.Data.ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        ;
                        int rowsUpdated = cmd.ExecuteNonQuery();
                        if (rowsUpdated > 0)
                        {
                            success = true;
                        }
                        ;
                    }
                    finally
                    {
                        if (conn.State != System.Data.ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                        ;
                    }
                }
            }

            return(success);
        }