예제 #1
0
        public void Post_PatientMirror(Mirrors m, string pStr, DateTime pUp)
        {
            MySqlConnection c;

            if ((c = Open()) == null)
            {
                return;
            }
            MySqlCommand com = c?.CreateCommand();

            try {
                bool rowExists = false;
                com.CommandText = String.Format("SELECT key_edit FROM mirrors WHERE accession = '{0}'",
                                                m.Accession);
                MySqlDataReader dr = com.ExecuteReader();
                rowExists = dr.Read();
                if (rowExists && dr.GetValue(0).ToString() != Utility.HashMD5(m.PasswordEdit))
                {
                    Dispose(c, com, dr);
                    return;
                }
                dr.Close();

                com = c?.CreateCommand();
                if (rowExists)
                {
                    com.CommandText =
                        "UPDATE mirrors SET " +
                        "accession = ?accession, key_access = ?key_access, key_edit = ?key_edit, " +
                        "patient = ?patient, updated = ?updated, client_ip = ?client_ip, client_user = ?client_user " +
                        String.Format("WHERE accession = '{0}'", m.Accession);
                }
                else
                {
                    com.CommandText =
                        "INSERT INTO mirrors " +
                        "(accession, key_access, key_edit, patient, updated, client_ip, client_user) " +
                        "VALUES " +
                        "(?accession, ?key_access, ?key_edit, ?patient, ?updated, ?client_ip, ?client_user)";
                }

                string ipAddress = new WebClient().DownloadString("http://icanhazip.com").Trim();
                com.Parameters.Add("?accession", MySqlDbType.VarChar).Value   = m.Accession;
                com.Parameters.Add("?key_access", MySqlDbType.VarChar).Value  = Utility.HashMD5(m.PasswordAccess);
                com.Parameters.Add("?key_edit", MySqlDbType.VarChar).Value    = Utility.HashMD5(m.PasswordEdit);
                com.Parameters.Add("?patient", MySqlDbType.LongText).Value    = Utility.EncryptAES(pStr);
                com.Parameters.Add("?updated", MySqlDbType.VarChar).Value     = Utility.DateTime_ToString(pUp);
                com.Parameters.Add("?client_ip", MySqlDbType.VarChar).Value   = Utility.HashMD5(ipAddress);
                com.Parameters.Add("?client_user", MySqlDbType.VarChar).Value = Utility.HashMD5(Environment.UserName);

                com.ExecuteNonQuery();

                Dispose(c, com, dr);
                return;
            } catch {
                Close(c);
                return;
            }
        }
예제 #2
0
        public Patient Get_PatientMirror(Mirrors m)
        {
            MySqlConnection c;

            if ((c = Open()) == null)
            {
                return(null);
            }
            MySqlCommand com = c?.CreateCommand();

            try {
                string s = Utility.HashMD5(m.PasswordAccess);
                com.CommandText = String.Format("SELECT updated, patient FROM mirrors WHERE accession = '{0}' AND key_access = '{1}'",
                                                m.Accession, Utility.HashMD5(m.PasswordAccess));
                MySqlDataReader dr = com.ExecuteReader();

                if (!dr.Read() || dr.FieldCount < 2)
                {
                    Dispose(c, com, dr);
                    return(null);
                }

                DateTime serverUpdated = Utility.DateTime_FromString(dr.GetValue(0).ToString());
                if (DateTime.Compare(serverUpdated, m.PatientUpdated) <= 0)
                {
                    Dispose(c, com, dr);
                    return(null);
                }

                m.ServerQueried  = DateTime.UtcNow;
                m.PatientUpdated = serverUpdated;
                Patient p = new Patient();
                p.Load_Process(Utility.DecryptAES(dr.GetValue(1).ToString()));

                Dispose(c, com, dr);
                return(p);
            } catch {
                Close(c);
                return(null);
            }
        }