Exemplo n.º 1
0
        private void InitBalance()
        {
            decimal balance = 0;
            var     conn    = HospitalConnection.CreateDbConnection();
            //must be done
            string SQLcmd = "dbo.ShowBalance";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.Text);
                    cmd.Parameters.Add("@PassportID", SqlDbType.SmallMoney).Value = PassportID;

                    using (var reader = (SqlDataReader)cmd.ExecuteReader())
                    {
                        balance = (decimal)reader["Balance"];
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            Balance = balance;
        }
Exemplo n.º 2
0
        public void ChangePrice(Medicine medicine, decimal price)
        {
            if (price < 0)
            {
                throw new Exception("Price must be poisitive.");
            }

            var    conn = HospitalConnection.CreateDbConnection();
            string sSQL = "sp_UpdateMedicine";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL, CommandType.StoredProcedure);

                    cmd.Parameters.Add("@Name", SqlDbType.Char, 20).Value       = medicine.Name;
                    cmd.Parameters.Add("@NewPrice", SqlDbType.SmallMoney).Value = price;

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 3
0
        public override void ChangeBalance(decimal moneyToAdd)       // Can be negative
        {
            Balance += moneyToAdd;

            var conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.changeBalanceDoctor";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value = PassportID;
                    cmd.Parameters.Add("@Balance", SqlDbType.SmallMoney).Value = Balance;

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 4
0
        //End Constructor//

        public void AddMedicine(Medicine medicine)
        {
            var    conn = HospitalConnection.CreateDbConnection();
            string sSQL = "sp_AddMedecine";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL, CommandType.StoredProcedure);


                    cmd.Parameters.Add("@Name", SqlDbType.Char, 20).Value           = medicine.Name;
                    cmd.Parameters.Add("@Country", SqlDbType.Char, 20).Value        = medicine.Country;
                    cmd.Parameters.Add("@ExpirationDate", SqlDbType.DateTime).Value = medicine.ExpiryDate;
                    cmd.Parameters.Add("@Price", SqlDbType.SmallMoney).Value        = medicine.Price;
                    //cmd.Parameters.Add("@Picture", SqlDbType.VarBinary, (1 << 20)).Value = medicine.Picture;

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 5
0
        public void changePassword(string newPassword)
        {
            Password = newPassword;

            var conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.ChangeDoctorPassword";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value   = PassportID;
                    cmd.Parameters.Add("@Password", SqlDbType.VarChar, 20).Value = Password;


                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 6
0
        private void Initialization()
        {
            Patients = new Dictionary <DateTime, Patient>();
            var conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.ShowDoctorQueue";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value = PassportID;
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Patient patient = new Patient((string)reader["Name"], (string)reader["Surname"], (string)reader["PassportID"],
                                                          (string)reader["Address"], (DateTime)reader["DateOfBirth"]);
                            DateTime date = (DateTime)reader["Time"];
                            Patients.Add(date, patient);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 7
0
        public List <Doctor> SearchBySpeciality(string Speciality)
        {
            List <Doctor> doctors = new List <Doctor>();
            var           conn    = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.FindDoctorBySpeciality";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@Speciality", SqlDbType.VarChar, 20).Value = Speciality;

                    using (var reader = (SqlDataReader)cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            doctors.Add(new Doctor((string)reader["Name"], (string)reader["Surname"], (string)reader["PassportID"],
                                                   (string)reader["Speciality"], (DateTime)reader["DateOfApproval"], (decimal)reader["ConsultationCost"]));      //incompatibility between databases and classes
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(doctors);
        }
Exemplo n.º 8
0
        public List <string> GetMedicines()
        {
            List <string> allMedicine = new List <string>();
            var           conn        = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.LoadMedicineNames";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);

                    using (var reader = (SqlDataReader)cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            allMedicine.Add((string)reader["Name"]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(allMedicine);
        }
Exemplo n.º 9
0
        public static Doctor SignIn(string login, string password)
        {
            Doctor doc        = null;
            var    connection = HospitalConnection.CreateDbConnection();
            string sSQL       = "dbo.SignInDoctor";

            try
            {
                using (connection)
                {
                    connection.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(connection, sSQL, CommandType.StoredProcedure);


                    cmd.Parameters.Add("@login", SqlDbType.VarChar, 20).Value    = login;
                    cmd.Parameters.Add("@password", SqlDbType.VarChar, 20).Value = password;

                    using (var reader = (SqlDataReader)cmd.ExecuteReader())
                    {
                        reader.Read();
                        if (!reader.HasRows)
                        {
                            throw new Exception("Wrong password or login.");
                        }
                        else
                        {
                            string   passportID       = (string)reader["PassportID"];
                            string   name             = (string)reader["Name"];
                            string   surname          = (string)reader["Surname"];
                            decimal  balance          = (decimal)reader["Balance"];
                            byte[]   picture          = (reader["Picture"] == System.DBNull.Value ? null : (byte[])reader["Picture"]);
                            string   phoneNumber      = (string)reader["PhoneNumber"];
                            string   speciality       = (string)reader["Speciality"];
                            DateTime getEmployed      = (DateTime)reader["DateOfApproval"];
                            DateTime dateOfBirth      = (DateTime)reader["DateOfBirth"];
                            decimal  consultationCost = (decimal)reader["ConsultationCost"];

                            doc             = new Doctor(name, surname, passportID, speciality, getEmployed, consultationCost);
                            doc.Login       = login;
                            doc.Password    = password.Substring(0, 20);
                            doc.Picture     = picture;
                            doc.DateOfBirth = dateOfBirth;
                            doc.PhoneNumber = phoneNumber;
                            doc.Balance     = balance;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(doc);
        }
Exemplo n.º 10
0
        //End Constructor//

        // Methods //

        public static Patient SignIn(string login, string password)
        {
            Patient patient = null;
            string  SQlcmd  = "dbo.SignInPatient";
            var     conn    = HospitalConnection.CreateDbConnection();

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQlcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@Login", SqlDbType.VarChar, 20).Value    = login;
                    cmd.Parameters.Add("@Password", SqlDbType.VarChar, 20).Value = password;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        if (!reader.HasRows)
                        {
                            throw new Exception("Wrong password or login.");
                        }
                        else
                        {
                            string   passportID    = (string)reader["PassportID"];
                            string   name          = (string)reader["Name"];
                            string   surname       = (string)reader["Surname"];
                            decimal  balance       = (decimal)reader["Balance"];
                            byte[]   picture       = (reader["Picture"] == System.DBNull.Value ? null : (byte[])reader["Picture"]);
                            string   phoneNumber   = (string)reader["PhoneNumber"];
                            string   address       = (string)reader["Address"];
                            DateTime dateOfBirth   = (DateTime)reader["DateOfBirth"];
                            string   insuranceCard = (string)reader["InsuranceCard"];

                            patient               = new Patient(name, surname, passportID, address, dateOfBirth);
                            patient.Login         = login;
                            patient.Password      = password.Substring(0, 20);
                            patient.InsurenceCard = insuranceCard;
                            patient.Picture       = picture;
                            patient.PhoneNumber   = phoneNumber;
                            patient.Balance       = balance;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(patient);
        }
Exemplo n.º 11
0
        //End Constructor//


        // Methods //
        public void WriteDiagnosis(Patient patient, Diagnosis diagnose)
        {
            var    conn  = HospitalConnection.CreateDbConnection();
            string sSQL  = "sp_WriteDiagnosInDiagnoses";
            string sSQL1 = "dbo.sp_GetDiagnoseID";
            string sSQL2 = "sp_AddMedicineInAssignedTo";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL, CommandType.StoredProcedure);

                    cmd.Parameters.Add("@description", SqlDbType.NVarChar, 20).Value = diagnose.Disease;
                    cmd.Parameters.Add("@dateOfDiagnoses", SqlDbType.DateTime).Value = diagnose.DiagnoseDate;
                    cmd.Parameters.Add("@patientID", SqlDbType.Char, 9).Value        = patient.PassportID;
                    cmd.Parameters.Add("@doctorID", SqlDbType.Char, 9).Value         = this.PassportID;
                    cmd.ExecuteNonQuery();

                    var cmd1 = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL1, CommandType.StoredProcedure);

                    int param = -1;
                    //cmd1.Parameters.Add("@diagID", SqlDbType.Int).Value = param;
                    using (var reader = cmd1.ExecuteReader()) {
                        reader.Read();
                        param = (int)reader["mx"];
                    }

                    var cmd2 = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL2, CommandType.StoredProcedure);


                    foreach (var elem in diagnose.PrescribedMedicines)
                    {
                        cmd2.Parameters.Add("@diagnoseID", SqlDbType.Int).Value        = param;
                        cmd2.Parameters.Add("@medicine", SqlDbType.NVarChar, 20).Value = elem.Key.Name;
                        cmd2.Parameters.Add("@cnt", SqlDbType.Int).Value = elem.Value;
                        cmd2.ExecuteNonQuery();
                        cmd2.Parameters.Clear();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 12
0
        //End Constructor//


        // Methods //
        public static bool CheckPassportID(string passportID)
        {
            int existInDB = 0;
            var conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.FindPatientPasspordID";

            using (conn)
            {
                conn.Open();
                var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                cmd.Parameters.Add("@passpordID", SqlDbType.Char, 9).Value = passportID;
                var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;

                cmd.ExecuteNonQuery();

                existInDB = (int)returnParameter.Value;
            }

            if (existInDB == 1)
                throw new Exception("Invallid Passport ID\n");

            //////////////////////////

            conn = HospitalConnection.CreateDbConnection();

            SQLcmd = "dbo.FindDoctorPasspordID";

            using (conn)
            {
                conn.Open();
                var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                cmd.Parameters.Add("@passpordID", SqlDbType.Char, 9).Value = passportID;
                var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;

                cmd.ExecuteNonQuery();

                existInDB = (int)returnParameter.Value;
            }

            if (existInDB == 1)
                throw new Exception("Invallid Passport ID\n");

            return true;
        }
Exemplo n.º 13
0
        public static Medicine GetMedicine(string name)
        {
            Medicine med        = null;
            var      connection = HospitalConnection.CreateDbConnection();
            string   sSQL       = "dbo.LoadMedicineByName";

            try
            {
                using (connection)
                {
                    connection.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(connection, sSQL, CommandType.StoredProcedure);


                    cmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = name;

                    using (var reader = (SqlDataReader)cmd.ExecuteReader())
                    {
                        reader.Read();
                        if (!reader.HasRows)
                        {
                            throw new Exception("Medicine not found!");
                        }
                        else
                        {
                            string   Name       = (string)reader["Name"];
                            string   Country    = (string)reader["Country"];
                            DateTime ExpiryDate = (DateTime)reader["ExpirationDate"];
                            decimal  Price      = (decimal)reader["Price"];
                            byte[]   Picture    = (reader["Picture"] == System.DBNull.Value ? null : (byte[])reader["Picture"]);

                            med         = new Medicine(Name, Country, Price, ExpiryDate);
                            med.Picture = Picture;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(med);
        }
Exemplo n.º 14
0
        public List <Doctor> ShowDoctors()
        {
            List <Doctor> docs = new List <Doctor>();
            var           conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "sp_AllDoctors";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string   name           = (string)reader["Name"];
                            string   surname        = (string)reader["surname"];
                            string   passportID     = (string)reader["PassportID"];
                            DateTime dateOfapproval = (DateTime)reader["DateOfApproval"];
                            decimal  balance        = (decimal)reader["Balance"];
                            decimal  consCost       = (decimal)reader["ConsultationCost"];
                            byte[]   pic            = (reader["Picture"] == System.DBNull.Value ? null : (byte[])reader["Picture"]);
                            string   phoneNumber    = (string)reader["PhoneNumber"];
                            string   speciality     = (string)reader["Speciality"];

                            Doctor pat = new Doctor(name, surname, passportID, speciality, dateOfapproval, consCost);
                            docs.Add(pat);
                        }
                    }
                }
                return(docs);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(docs);
        }
Exemplo n.º 15
0
        //  End Properties  //


        //Constructor//
        public Doctor(string name, string surname, string passportID, string login, string password,
                      string speciality, DateTime getEmployed, decimal consultationCost, DateTime dateOfBirth, string phoneNumber)
            : base(name, surname, passportID, login, password)
        {
            PhoneNumber      = phoneNumber;
            Speciality       = speciality;
            GetEmployed      = getEmployed;
            ConsultationCost = consultationCost;
            DateOfBirth      = dateOfBirth;

            Initialization();
            string SQlcmd = "dbo.insertDoctor";
            var    conn   = HospitalConnection.CreateDbConnection();

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQlcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 20).Value           = name;
                    cmd.Parameters.Add("@Surname", SqlDbType.NVarChar, 20).Value        = surname;
                    cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value          = passportID;
                    cmd.Parameters.Add("@Login", SqlDbType.VarChar, 20).Value           = login;
                    cmd.Parameters.Add("@Password", SqlDbType.VarChar, 20).Value        = password;
                    cmd.Parameters.Add("@DateOfBirth", SqlDbType.DateTime).Value        = dateOfBirth;
                    cmd.Parameters.Add("@Speciality", SqlDbType.VarChar, 20).Value      = speciality;
                    cmd.Parameters.Add("@ConsultationCost", SqlDbType.SmallMoney).Value = consultationCost;
                    cmd.Parameters.Add("@GetEmployed", SqlDbType.DateTime).Value        = getEmployed;
                    cmd.Parameters.Add("@PhoneNumber", SqlDbType.Char, 9).Value         = phoneNumber;


                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                throw new Exception("Passport ID must contain only digits and the length must be 9 characters!");
            }
        }
Exemplo n.º 16
0
        public static bool CheckDoctorLogin(string login)
        {
            int existInDB = 0;
            var conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.FindDoctorLogin";

            using (conn)
            {
                conn.Open();
                var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                cmd.Parameters.Add("@login", SqlDbType.VarChar, 20).Value = login;
                var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.ReturnValue;

                cmd.ExecuteNonQuery();

                existInDB = (int)returnParameter.Value;
            }

            return existInDB != 1;
        }
Exemplo n.º 17
0
        public List <Medicine> ShowMedicine()
        {
            List <Medicine> meds = new List <Medicine>();
            var             conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "sp_AllMedicine";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string   name           = (string)reader["Name"];
                            string   country        = (string)reader["Country"];
                            DateTime expirationDate = (DateTime)reader["ExpirationDate"];
                            decimal  price          = (decimal)reader["Price"];
                            byte[]   pic            = (reader["Picture"] == System.DBNull.Value ? null : (byte[])reader["Picture"]);


                            Medicine med = new Medicine(name, country, price, expirationDate);
                            med.Picture = pic;
                            meds.Add(med);
                        }
                    }
                }
                return(meds);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(meds);
        }
Exemplo n.º 18
0
        public void DeleteDoctor(Doctor doctor)
        {
            var    conn = HospitalConnection.CreateDbConnection();
            string sSQL = "sp_DeleteDoctor";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL, CommandType.StoredProcedure);

                    cmd.Parameters.Add("@passportID", SqlDbType.Char, 9).Value = doctor.PassportID;

                    cmd.ExecuteNonQuery();
                }
            }

            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 19
0
        public void DeleteMedicine(Medicine medicine)
        {
            var    conn = HospitalConnection.CreateDbConnection();
            string sSQL = "sp_DeleteMedicine";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL, CommandType.StoredProcedure);

                    cmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = medicine.Name;

                    cmd.ExecuteNonQuery();
                }
            }

            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 20
0
        public override void AddPicture(byte[] pic)
        {
            string sSQL = "dbo.DoctorAddPicture";

            this.Picture = pic;

            try
            {
                var conn = HospitalConnection.CreateDbConnection();
                conn.Open();

                var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL, CommandType.StoredProcedure);

                cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value       = this.PassportID;
                cmd.Parameters.Add("@Pic", SqlDbType.VarBinary, (1 << 20)).Value = this.Picture;

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 21
0
        // End Properties  //

        //Constructor//

        public Patient(string name, string surname, string passportID, string login,
                       string password, string address, string insuranceCard,
                       DateTime dateOfBirth, string phoneNumber) : base(name, surname, passportID, login, password)
        {
            Address       = address;
            InsurenceCard = insuranceCard;
            DateOfBirth   = dateOfBirth;
            PhoneNumber   = phoneNumber;

            Initialization();
            string SQlcmd = "dbo.insertPatient";
            var    conn   = HospitalConnection.CreateDbConnection();

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQlcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 20).Value     = name;
                    cmd.Parameters.Add("@Surname", SqlDbType.NVarChar, 20).Value  = surname;
                    cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value    = passportID;
                    cmd.Parameters.Add("@Login", SqlDbType.VarChar, 20).Value     = login;
                    cmd.Parameters.Add("@Password", SqlDbType.VarChar, 20).Value  = password;
                    cmd.Parameters.Add("@PhoneNumber", SqlDbType.Char, 9).Value   = phoneNumber;
                    cmd.Parameters.Add("@InsuranceCard", SqlDbType.Char, 9).Value = insuranceCard;
                    cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 20).Value  = address;
                    cmd.Parameters.Add("@DateOfBirth", SqlDbType.DateTime).Value  = dateOfBirth;

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                throw new Exception("Passport ID must contain only digits and the length must be 9 characters!");
            }
        }
Exemplo n.º 22
0
        public List <Patient> ShowPatient()
        {
            List <Patient> patients = new List <Patient>();
            var            conn     = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.SeeMyPatients";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value = PassportID;

                    using (var reader = (SqlDataReader)cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string   n   = (string)reader["Name"];
                            string   s   = (string)reader["Surname"];
                            string   p   = (string)reader["PassportID"];
                            string   a   = (string)reader["Address"];
                            DateTime d   = (DateTime)reader["DateOfBirth"];
                            Patient  pat = new Patient(n, s, p, a, d);
                            patients.Add(pat);
                        }
                    }
                }
                return(patients);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(patients);
        }
Exemplo n.º 23
0
        public void newPatient(Patient patient, DateTime dTime)
        {
            Patients[dTime] = patient;
            var conn = HospitalConnection.CreateDbConnection();

            string SQLcmd = "dbo.AddPatientToQueue";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@DocID", SqlDbType.Char, 9).Value = PassportID;
                    cmd.Parameters.Add("@PatID", SqlDbType.Char, 9).Value = patient.PassportID;
                    cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = dTime;
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 24
0
        public List <Diagnosis> PatientDiagnosis(Patient patient)
        {
            List <Diagnosis> result = null;

            var conn = HospitalConnection.CreateDbConnection();

            string sSQl2 = "dbo.GetDiagnoseMedicine";
            string sSQL1 = "dbo.GetDiagnose";

            Dictionary <Medicine, int> medList = new Dictionary <Medicine, int>();


            DateTime diagnoseDate = new DateTime(1997, 5, 6);
            string   disease      = "";
            int      diagnoseID   = -1;

            try
            {
                using (conn)
                {
                    conn.Open();


                    var cmd2 = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQL1, CommandType.StoredProcedure);

                    cmd2.Parameters.Add("@patientID", SqlDbType.VarChar, 9).Value = patient.PassportID;

                    using (var reader2 = (SqlDataReader)cmd2.ExecuteReader())
                    {
                        if (reader2.HasRows)
                        {
                            while (reader2.Read())
                            {
                                disease      = reader2.GetString(reader2.GetOrdinal("Description"));
                                diagnoseDate = reader2.GetDateTime(reader2.GetOrdinal("DateOfDiagnosis"));
                                diagnoseID   = reader2.GetInt32(reader2.GetOrdinal("DiagnosesId"));
                            }
                        }
                    }

                    var cmd = (SqlCommand)HospitalConnection.CreateDbCommand(conn, sSQl2, CommandType.StoredProcedure);
                    cmd.Parameters.Add("@patientID", SqlDbType.VarChar, 9).Value = patient.PassportID;
                    cmd.Parameters.Add("@diagnoseID", SqlDbType.Int).Value       = diagnoseID;
                    using (var reader = (SqlDataReader)cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        if (reader.HasRows)
                        {
                            bool hasMoreResults = true;

                            while (hasMoreResults)
                            {
                                while (reader.Read())
                                {
                                    string   nameMed    = reader.GetString(reader.GetOrdinal("name")).ToString();
                                    string   countryMed = reader.GetString(reader.GetOrdinal("country")).ToString();
                                    decimal  priceMed   = reader.GetDecimal(reader.GetOrdinal("price"));
                                    DateTime expiryDate = reader.GetDateTime(reader.GetOrdinal("expiryDate"));
                                    int      count      = reader.GetInt32(reader.GetOrdinal("count"));

                                    Medicine m = new Medicine(nameMed, countryMed, priceMed, expiryDate);
                                    medList.Add(m, count);
                                }

                                hasMoreResults = reader.NextResult();
                            }
                        }
                    }
                }
                result.Add(new Diagnosis(disease, diagnoseDate, medList));

                return(result);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return(result);
        }
Exemplo n.º 25
0
        private void Initialization()
        {
            List <Diagnosis> history = new List <Diagnosis>();

            var       conn     = HospitalConnection.CreateDbConnection();
            Diagnosis diagnose = null;
            string    SQLcmd0  = "dbo.ReadMyHistory";

            try
            {
                using (conn)
                {
                    conn.Open();
                    var cmd0 = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd0, CommandType.StoredProcedure);
                    cmd0.Parameters.Add("@PassportID", SqlDbType.Char, 9).Value = PassportID;

                    using (var reader0 = (SqlDataReader)cmd0.ExecuteReader())
                    {
                        while (reader0.Read())
                        {
                            string SQLcmd1 = "dbo.Drugs";



                            var cmd1 = (SqlCommand)HospitalConnection.CreateDbCommand(conn, SQLcmd1, CommandType.StoredProcedure);
                            cmd1.Parameters.Add("@DiagnosisID", SqlDbType.Int).Value = reader0["DiagnosesID"];

                            using (var reader1 = (SqlDataReader)cmd1.ExecuteReader())
                            {
                                if (reader1.HasRows)
                                {
                                    bool hasMoreResults = true;

                                    Dictionary <Medicine, int> medicine = new Dictionary <Medicine, int>();

                                    //while (hasMoreResults)
                                    {
                                        while (reader1.Read())
                                        {
                                            string   n   = (string)reader1["Name"];
                                            string   c   = (string)reader1["Country"];
                                            decimal  p   = (decimal)reader1["Price"];
                                            DateTime e   = (DateTime)reader1["ExpirationDate"];
                                            Medicine med = new Medicine(n, c, p, e);
                                            if (medicine.ContainsKey(med))
                                            {
                                                medicine[med]++;
                                            }
                                            else
                                            {
                                                medicine[med] = 1;
                                            }
                                        }
                                        diagnose = new Diagnosis((string)reader0["Description"], (DateTime)reader0["DateOfDiagnosis"], medicine);
                                        history.Add(diagnose);

                                        hasMoreResults = reader1.NextResult();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            MyHistory = history;
        }