Beispiel #1
0
        public void AddShare(RegistryShare registryShare)
        {
            try
            {
                using (MySqlCommand dbComm = new MySqlCommand())
                {
                    dbComm.Connection  = new MySqlConnection(DAFconnection.GetConnectionType());
                    dbComm.CommandType = CommandType.Text;
                    dbComm.CommandText = SQL.RegistryScripts.AddShare;
                    foreach (var property in registryShare.GetType().GetProperties())
                    {
                        if (property.Name == "id_titolo")
                        {
                            dbComm.Parameters.AddWithValue("id_titolo", null);
                        }
                        else
                        {
                            dbComm.Parameters.AddWithValue(property.Name, property.GetValue(registryShare));
                        }
                    }

                    dbComm.Connection.Open();
                    dbComm.ExecuteNonQuery();
                    dbComm.Connection.Close();
                }
            }
            catch (MySqlException err)
            {
                throw new Exception(err.Message);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }
Beispiel #2
0
 public RegistryShare GetShareById(uint id)
 {
     try
     {
         using (MySqlDataAdapter dbAdapter = new MySqlDataAdapter())
         {
             dbAdapter.SelectCommand             = new MySqlCommand();
             dbAdapter.SelectCommand.Connection  = new MySqlConnection(DAFconnection.GetConnectionType());
             dbAdapter.SelectCommand.CommandType = CommandType.Text;
             dbAdapter.SelectCommand.CommandText = SQL.RegistryScripts.GetShareById;
             dbAdapter.SelectCommand.Parameters.AddWithValue("id_titolo", id);
             DataTable dt = new DataTable();
             dbAdapter.Fill(dt);
             RegistryShare registryShare = new RegistryShare();
             foreach (var property in registryShare.GetType().GetProperties())
             {
                 property.SetValue(registryShare, dt.Rows[0].Field <object>(property.Name));
             }
             return(registryShare);
         }
     }
     catch (MySqlException err)
     {
         throw new Exception(err.Message);
     }
     catch (Exception err)
     {
         throw new Exception(err.Message);
     }
 }
Beispiel #3
0
 public RegistryShareList GetRegistryShareList()
 {
     try
     {
         using (MySqlDataAdapter dbAdaptar = new MySqlDataAdapter())
         {
             dbAdaptar.SelectCommand             = new MySqlCommand();
             dbAdaptar.SelectCommand.Connection  = new MySqlConnection(DAFconnection.GetConnectionType());
             dbAdaptar.SelectCommand.CommandType = CommandType.Text;
             dbAdaptar.SelectCommand.CommandText = SQL.RegistryScripts.GetRegistryShareList;
             DataTable dt = new DataTable();
             dbAdaptar.Fill(dt);
             RegistryShareList RSL = new RegistryShareList();
             foreach (DataRow dr in dt.Rows)
             {
                 RegistryShare RS = new RegistryShare();
                 foreach (var property in RS.GetType().GetProperties())
                 {
                     property.SetValue(RS, dr.Field <object>(property.Name));
                 }
                 RSL.Add(RS);
             }
             return(RSL);
         }
     }
     catch (MySqlException err)
     {
         throw new Exception(err.Message);
     }
     catch (Exception err)
     {
         throw new Exception(err.Message);
     }
 }
Beispiel #4
0
        public RegistryShareList GetSharesByFirms(int[] id_aziende)
        {
            try
            {
                string where = "";
                foreach (int x in id_aziende)
                {
                    where += string.Format(" id_azienda = {0} OR ", x);
                }
                where = where.Remove(where.Length - 3, 3);

                using (MySqlDataAdapter dbAdaptar = new MySqlDataAdapter())
                {
                    dbAdaptar.SelectCommand             = new MySqlCommand();
                    dbAdaptar.SelectCommand.Connection  = new MySqlConnection(DAFconnection.GetConnectionType());
                    dbAdaptar.SelectCommand.CommandType = CommandType.Text;
                    dbAdaptar.SelectCommand.CommandText = string.Format(SQL.RegistryScripts.GetSharesByFirms, where);
                    DataTable dt = new DataTable();
                    dbAdaptar.Fill(dt);
                    RegistryShareList RSL = new RegistryShareList();
                    foreach (DataRow dr in dt.Rows)
                    {
                        RegistryShare RS = new RegistryShare();
                        foreach (var property in RS.GetType().GetProperties())
                        {
                            property.SetValue(RS, dr.Field <object>(property.Name));
                        }
                        RSL.Add(RS);
                    }
                    return(RSL);
                }
            }
            catch (MySqlException err)
            {
                throw new Exception(err.Message);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }