public RegistryShareTypeList GetRegistryShareTypeList() { 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.GetRegistryShareTypeList; DataTable dt = new DataTable(); dbAdaptar.Fill(dt); RegistryShareTypeList RSTL = new RegistryShareTypeList(); foreach (DataRow dr in dt.Rows) { RegistryShareType RST = new RegistryShareType(); RST.id_tipo_titolo = dr.Field <uint>("id_tipo_titolo"); RST.desc_tipo_titolo = dr.Field <string>("desc_tipo_titolo"); RSTL.Add(RST); } return(RSTL); } } catch (MySqlException err) { throw new Exception(err.Message); } catch (Exception err) { throw new Exception(err.Message); } }
public void UpdateShareType(RegistryShareType registryShareType) { try { using (MySqlCommand dbComm = new MySqlCommand()) { dbComm.Connection = new MySqlConnection(DAFconnection.GetConnectionType()); dbComm.CommandType = CommandType.Text; dbComm.CommandText = SQL.RegistryScripts.UpdateShareType; dbComm.Parameters.AddWithValue("id", registryShareType.id_tipo_titolo); dbComm.Parameters.AddWithValue("desc", registryShareType.desc_tipo_titolo); dbComm.Connection.Open(); dbComm.ExecuteNonQuery(); dbComm.Connection.Close(); } } catch (MySqlException err) { throw new Exception(err.Message); } catch (Exception err) { throw new Exception(err.Message); } }
/// <summary> /// E' l'evento di edit nella cella di descrizione della gestione /// se il modello ha un valore di id vuol dire che è in modifica /// se il valore è zero vuol dire che è un inserimento di nuova gestione /// </summary> /// <param name="sender">la cella di descrizione</param> /// <param name="e">la conferma o meno della modifica</param> public void CellChanged(object sender, DataGridCellEditEndingEventArgs e) { try { if (e.EditAction == DataGridEditAction.Commit) { registryShareType = ((RegistryShareType)e.Row.Item); if (registryShareType.id_tipo_titolo > 0) { _services.UpdateShareType(registryShareType); } else { _services.AddShareType(registryShareType.desc_tipo_titolo); _ShareTypeList = new ObservableCollection <RegistryShareType>(_services.GetRegistryShareTypeList()); } } } catch (Exception err) { MessageBox.Show("Errore nell'aggiornamento dei dati: " + err.Message); } }