Esempio n. 1
0
        //[SoapHeader("Authentication", Required = true)]
        public bool FoodRequest(AuthHeader Authentication, string food_name)
        {
            if (Authentication == null || !Authentication.UserValidation())
            {
                throw new UnauthorizedAccessException();
            }
            var mySQLConn = new MySqlConnection(remoteAccess);

            mySQLConn.Open();
            var mySQLCommand = mySQLConn.CreateCommand();

            mySQLCommand.CommandText = $@"INSERT INTO temp_foodtable(food_name) values('{food_name}')";
            try
            {
                mySQLCommand.ExecuteNonQuery();
            }
            catch
            {
                return(false);
            }
            finally
            {
                mySQLConn.Close();
            }
            return(true);
        }
Esempio n. 2
0
 //[SoapHeader("Authentication", Required = true)]
 public DataSet GetFoodData(AuthHeader Authentication, string search_query)
 {
     if (Authentication == null || !Authentication.UserValidation())
     {
         throw new UnauthorizedAccessException();
     }
     try
     {
         var query = string.Empty;
         if (string.IsNullOrEmpty(search_query))
         {
             query = "SELECT * FROM foodtable";
         }
         else
         {
             query = $@"SELECT * FROM foodtable WHERE food_name LIKE '%{search_query}%'";
         }
         var mySQLConn = new MySqlConnection(remoteAccess);
         mySQLConn.Open();
         var tickets = new DataSet();
         var adapter = new MySqlDataAdapter(query, mySQLConn);
         adapter.Fill(tickets, "FoodTABLE");
         mySQLConn.Close();
         return(tickets);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 3
0
 //[SoapHeader("Authentication", Required = true)]
 public bool TestConnection(AuthHeader Authentication)
 {
     if (Authentication == null)
     {
         throw new UnauthorizedAccessException();
     }
     if (Authentication.UserValidation())
     {
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        //[SoapHeader("Authentication", Required = true)]
        public DataSet GetData(AuthHeader Authentication, string tableName)
        {
            if (Authentication == null || !Authentication.UserValidation())
            {
                throw new UnauthorizedAccessException();
            }
            try
            {
                var mySQLConn = new MySqlConnection(remoteAccess);
                mySQLConn.Open();
                var mySQLCommand = mySQLConn.CreateCommand();
                mySQLCommand.CommandText = $"SELECT ud_pass FROM usertable WHERE ud_email = '{Authentication.Username}' OR ud_name = '{Authentication.Username}'";
                if (ComparePassword(Authentication.Password, (string)mySQLCommand.ExecuteScalar()))
                {
                    List <object> returnData = new List <object>();
                    var           query      =
                        $"SELECT * FROM {tableName.ToLower()} " +
                        $"WHERE ud_id = (SELECT ud_id FROM usertable " +
                        $"               WHERE ud_email = '{Authentication.Username}' OR ud_name = '{Authentication.Username}')";
                    var tickets = new DataSet();
                    var adapter = new MySqlDataAdapter(query, mySQLConn);
                    adapter.Fill(tickets, tableName);

                    /*
                     * foreach (Data((TEMP_DiabetesTABLE)row) ((TEMP_DiabetesTABLE)row) in tickets.Tables[tableName].((TEMP_DiabetesTABLE)row)s)
                     * {
                     *  returnData.Add(((TEMP_DiabetesTABLE)row));
                     * }
                     */
                    return(tickets);
                }
                mySQLConn.Close();
                return(null);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 5
0
 //[SoapHeader("Authentication", Required = true)]
 public DataSet GetFoodExchangeData(AuthHeader Authentication, int id)
 {
     if (Authentication == null || !Authentication.UserValidation())
     {
         throw new UnauthorizedAccessException();
     }
     try
     {
         var query     = $@"SELECT * FROM foodtable WHERE food_id IN (SELECT foodexchange_id FROM foodexchangetable WHERE food_id = {id})";
         var mySQLConn = new MySqlConnection(remoteAccess);
         mySQLConn.Open();
         var tickets = new DataSet();
         var adapter = new MySqlDataAdapter(query, mySQLConn);
         adapter.Fill(tickets, "FoodTABLE");
         mySQLConn.Close();
         return(tickets);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Esempio n. 6
0
        //[SoapHeader("Authentication", Required = true)]
        public string[] SynchonizeData(AuthHeader Authentication, List <TEMP_DiabetesTABLE> tempDiabetes, List <TEMP_KidneyTABLE> tempKidney, List <TEMP_PressureTABLE> tempPressure)
        {
            if (Authentication == null || !Authentication.UserValidation())
            {
                throw new UnauthorizedAccessException();
            }
            object        result    = null;
            List <string> queryList = new List <string>();

            queryList.Add("START");
            try
            {
                var mySQLConn = new MySqlConnection(remoteAccess);
                mySQLConn.Open();
                var mySQLCommand = mySQLConn.CreateCommand();
                mySQLCommand.CommandText = $"SELECT ud_pass FROM usertable WHERE ud_email = '{Authentication.Username}' or ud_name = '{Authentication.Username}'";
                if (ComparePassword(Authentication.Password, (string)mySQLCommand.ExecuteScalar()))
                {
                    queryList.Add("ENTER");
                    queryList.Add($"Size of D{tempDiabetes.ToList().Count} K{tempKidney.ToList().Count} P{tempPressure.ToList().Count}");
                    mySQLCommand.CommandText = $"SELECT ud_id FROM usertable WHERE ud_email = '{Authentication.Username}' or ud_name = '{Authentication.Username}'";
                    var userID = (int)mySQLCommand.ExecuteScalar();
                    tempDiabetes.ForEach(row =>
                    {
                        if (((TEMP_DiabetesTABLE)row).mode == "I")
                        {
                            mySQLCommand.CommandText =
                                $"INSERT INTO diabetestable " +
                                $"values({((TEMP_DiabetesTABLE)row).fbs_id_pointer}" +
                                $",'{((TEMP_DiabetesTABLE)row).fbs_time_new.ToString("yyyy-MM-dd HH:mm:ss")}'" +
                                $",{((TEMP_DiabetesTABLE)row).fbs_fbs_new}" +
                                $",{((TEMP_DiabetesTABLE)row).fbs_fbs_lvl_new}" +
                                $",{((TEMP_DiabetesTABLE)row).fbs_fbs_sum_new}" +
                                $",{userID})";
                        }
                        else if (((TEMP_DiabetesTABLE)row).mode == "U")
                        {
                            mySQLCommand.CommandText =
                                $@"UPDATE diabetestable 
                                SET
                                    fbs_fbs = {row.fbs_fbs_new}
                                    ,fbs_fbs_sum = {row.fbs_fbs_sum_new}
                                    ,fbs_time = '{row.fbs_time_string_new}'
                                    ,fbs_fbs_lvl = {row.fbs_fbs_lvl_new}
                                WHERE 
                                    fbs_id = {row.fbs_id_pointer}
                                AND
                                    ud_id = {userID};
                                ";
                        }
                        else if (((TEMP_DiabetesTABLE)row).mode == "D")
                        {
                            mySQLCommand.CommandText =
                                $@"DELETE FROM diabetestable where fbs_id = {((TEMP_DiabetesTABLE)row).fbs_id_pointer} AND ud_id = {userID};";
                        }
                        try
                        {
                            queryList.Add(mySQLCommand.CommandText);
                            mySQLCommand.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            result = e.Message;
                            queryList.Add(e.Message);
                        }
                    });
                    tempKidney.ForEach(row =>
                    {
                        if (((TEMP_KidneyTABLE)row).mode == "I")
                        {
                            mySQLCommand.CommandText = $"" +
                                                       $"INSERT INTO kidneytable " +
                                                       $"values(" +
                                                       $"{((TEMP_KidneyTABLE)row).ckd_id_pointer}" +
                                                       $",'{((TEMP_KidneyTABLE)row).ckd_time_new.ToString("yyyy-MM-dd HH:mm:ss")}'" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_gfr_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_gfr_level_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_creatinine_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_bun_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_sodium_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_potassium_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_albumin_blood_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_albumin_urine_new}" +
                                                       $",{((TEMP_KidneyTABLE)row).ckd_phosphorus_blood_new}" +
                                                       $",{userID})";
                        }
                        else if (((TEMP_KidneyTABLE)row).mode == "U")
                        {
                            mySQLCommand.CommandText =
                                $@"UPDATE kidneytable
                        SET
                            ckd_time        = '{((TEMP_KidneyTABLE)row).ckd_time_string_new}'
                            ,ckd_gfr        = {((TEMP_KidneyTABLE)row).ckd_gfr_new}
                            ,ckd_gfr_level  = {((TEMP_KidneyTABLE)row).ckd_gfr_level_new}
                            ,ckd_creatinine = {((TEMP_KidneyTABLE)row).ckd_creatinine_new}
                            ,ckd_bun        = {((TEMP_KidneyTABLE)row).ckd_bun_new}
                            ,ckd_sodium     = {((TEMP_KidneyTABLE)row).ckd_sodium_new}
                            ,ckd_potassium  = {((TEMP_KidneyTABLE)row).ckd_potassium_new}
                            ,ckd_albumin_blood = {((TEMP_KidneyTABLE)row).ckd_albumin_blood_new}
                            ,ckd_albumin_urine = {((TEMP_KidneyTABLE)row).ckd_albumin_urine_new}
                            ,ckd_phosphorus_blood = {((TEMP_KidneyTABLE)row).ckd_phosphorus_blood_new}
                        WHERE 
                            ckd_id = {((TEMP_KidneyTABLE)row).ckd_id_pointer}
                        AND
                            ud_id = {userID};
                        ";
                        }
                        else if (((TEMP_KidneyTABLE)row).mode == "D")
                        {
                            mySQLCommand.CommandText =
                                $@"DELETE FROM kidneytable where ckd_id = {((TEMP_KidneyTABLE)row).ckd_id_pointer} AND ud_id = {userID};";
                        }
                        try
                        {
                            queryList.Add(mySQLCommand.CommandText);
                            mySQLCommand.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            result = e.Message;
                            queryList.Add(e.Message);
                        }
                    });
                    tempPressure.ForEach(row =>
                    {
                        if (((TEMP_PressureTABLE)row).mode == "I")
                        {
                            mySQLCommand.CommandText =
                                $"INSERT INTO pressuretable " +
                                $"values(" +
                                $"{((TEMP_PressureTABLE)row).bp_id_pointer}" +
                                $",'{((TEMP_PressureTABLE)row).bp_time_new.ToString("yyyy-MM-dd HH:mm:ss")}'" +
                                $",{((TEMP_PressureTABLE)row).bp_up_new}" +
                                $",{((TEMP_PressureTABLE)row).bp_lo_new}" +
                                $",{((TEMP_PressureTABLE)row).bp_hr_new}" +
                                $",{((TEMP_PressureTABLE)row).bp_up_lvl_new}" +
                                $",{((TEMP_PressureTABLE)row).bp_lo_lvl_new}" +
                                $",{((TEMP_PressureTABLE)row).bp_hr_lvl_new}" +
                                $",{userID}" +
                                $")";
                        }
                        else if (((TEMP_PressureTABLE)row).mode == "U")
                        {
                            mySQLCommand.CommandText =
                                $@"UPDATE pressuretable
                            SET
                               bp_time  = '{((TEMP_PressureTABLE)row).bp_time_string_new}'
                              ,bp_up    = {((TEMP_PressureTABLE)row).bp_up_new}
                              ,bp_lo    = {((TEMP_PressureTABLE)row).bp_lo_new}
                              ,bp_hr    = {((TEMP_PressureTABLE)row).bp_hr_new}
                              ,bp_up_lvl = {((TEMP_PressureTABLE)row).bp_up_lvl_new}
                              ,bp_lo_lvl = {((TEMP_PressureTABLE)row).bp_lo_lvl_new}
                              ,bp_hr_lvl = {((TEMP_PressureTABLE)row).bp_hr_lvl_new}
                            WHERE
                                bp_id = {((TEMP_PressureTABLE)row).bp_id_pointer}
                            AND
                                ud_id = {userID}
                        ";
                        }
                        else if (((TEMP_PressureTABLE)row).mode == "D")
                        {
                            mySQLCommand.CommandText =
                                $@"DELETE FROM pressuretable 
                            WHERE 
                                bp_id = {((TEMP_PressureTABLE)row).bp_id_pointer} 
                            AND 
                                ud_id = {userID};";
                        }
                        try
                        {
                            queryList.Add(mySQLCommand.CommandText);
                            mySQLCommand.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            result = e.Message;
                            queryList.Add(e.Message);
                        }
                    });
                }
                mySQLConn.Close();
            }
            catch (Exception e)
            {
                queryList.Add(e.Message);
            }
            return(queryList.ToArray());
        }