Exemplo n.º 1
0
        /// <summary>
        /// Saves data to storage.
        /// All exceptions are bubbled up.
        /// </summary>
        public async static Task <bool> SaveAsync <T>(string _connectionString,
                                                      StorageConfig storageConfig,
                                                      Dictionary <string, object> keys,
                                                      T dataObject) where T : class
        {
            {
                using (var sqlServerClient = new SQLServerClient(_connectionString, storageConfig))
                {
                    var readData = await GetAsync <T>(_connectionString, storageConfig, keys);

                    if (readData != null)
                    {
                        Copy(dataObject, readData);
                        sqlServerClient.Update <T>(readData);
                    }
                    else
                    {
                        sqlServerClient.Add <T>(dataObject);
                    }

                    await sqlServerClient.SaveChangesAsync();
                }
            }

            return(true);
        }
        private void Button_PatientSearch_Click(object sender, RoutedEventArgs e)
        {
            Patients_Data.ItemsSource = null;
            if (Input_PESELBox.Text.Length == 11)
            {
                patients = new List <Patient>();
                nip      = Input_NIPBox.Text;
                string connectionString;

                if (RegClass.CheckNIP(nip))
                {
                    connectionString = FirmLocalDataBase.FindFirmConnectionByNIP(nip);
                }
                else
                {
                    if (nip != "")
                    {
                        connectionString = FirmLocalDataBase.FindFirmConnectionByName(nip);
                    }
                    else
                    {
                        connectionString = null;
                    }
                }


                if (connectionString != null)
                {
                    long pesel = 0;
                    if (RegClass.CheckPESEL(Input_PESELBox.Text))
                    {
                        pesel = Convert.ToInt64(Input_PESELBox.Text);
                    }
                    if (pesel != 0)
                    {
                        Patient patientToAdd = Task.Factory.StartNew(() =>
                        {
                            return(SQLServerClient.GetPatient(pesel, connectionString));
                        }).Result;


                        if (patientToAdd != null)
                        {
                            patients.Add(patientToAdd);
                            Patients_Data.ItemsSource = patients;
                        }
                    }
                }
                else
                {
                    ///błąd źle wpisanego peselu
                }
            }
        }
Exemplo n.º 3
0
 public async static Task <T> GetAsync <T>(string _connectionString,
                                           StorageConfig storageConfig,
                                           Dictionary <string, object> keys) where T : class
 {
     {
         using (var sqlServerClient = new SQLServerClient(_connectionString, storageConfig))
         {
             return(await sqlServerClient.FindAsync <T>(GetKeys <T>(keys, sqlServerClient)));
         }
     }
 }
Exemplo n.º 4
0
        public async static Task <List <T> > GetListAsync <T>(string _connectionString,
                                                              StorageConfig storageConfig,
                                                              string queryId,
                                                              List <string> parameters = null,
                                                              bool deleteAll           = false,
                                                              List <object> selector   = null,
                                                              string udfQuery          = "") where T : class
        {
            var query = FormatQuery <T>(_connectionString, storageConfig, queryId, parameters);

            using (var sqlServerClient = new SQLServerClient(_connectionString, storageConfig))
            {
                return(await sqlServerClient.GetDataAsync <T>(_connectionString, query, selector));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Delete data from storage
        /// </summary>
        public static async Task <bool> DeleteAsync <T>(string _connectionString,
                                                        StorageConfig storageConfig,
                                                        Dictionary <string, object> keys) where T : class
        {
            {
                using (var sqlServerClient = new SQLServerClient(_connectionString, storageConfig))
                {
                    var readData = await GetAsync <T>(_connectionString, storageConfig, keys);

                    if (readData != null)
                    {
                        sqlServerClient.Remove <T>(readData);
                        await sqlServerClient.SaveChangesAsync();
                    }
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public async static Task <bool> RunQueryAsync <T>(string _connectionString,
                                                          StorageConfig storageConfig,
                                                          string queryId,
                                                          List <string> parameters = null,
                                                          bool deleteAll           = false,
                                                          List <object> selector   = null,
                                                          string udfQuery          = "") where T : class
        {
            var query = FormatQuery <T>(_connectionString, storageConfig, queryId, parameters);

            using (var sqlServerClient = new SQLServerClient(_connectionString, storageConfig))
            {
                if (await sqlServerClient.RunQueryAsync(query))
                {
                    return(true);
                }
                return(false);
            }
        }