/// <summary> /// Retorna todos os setores /// </summary> /// <param name="secretaria">retorna somente setores por secretaria</param> /// /// <returns></returns> public ObservableCollection <Secretarias> Secretarias(string secretaria) { var dataAccess = Instances.DataBase5(); ObservableCollection <Secretarias> lst = new ObservableCollection <Secretarias>(); try { dataAccess.ClearParameters(); dataAccess.AddParameters("@Sec", "%" + secretaria + "%"); foreach (DataRow dr in dataAccess.Read(@"SELECT * FROM Secretarias WHERE (Secretaria LIKE @Sec) ORDER BY Secretaria").Rows) { var setor = new Secretarias { Indice = (int)dr["Indice"], Secretaria = (string)dr["Secretaria"], Ativo = (bool)dr["Ativo"] }; lst.Add(setor); } return(lst); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return(null); } }
/// <summary> /// Adiciona novo setor no banco de dados. /// </summary> /// <param name="obj">grava o obj setores no banco</param> /// <returns></returns> public bool Gravar(Secretarias obj) { try { var dataAccess = Instances.DataBase5(); dataAccess.ClearParameters(); dataAccess.AddParameters("@Secretaria", obj.Secretaria); dataAccess.AddParameters("@Ativo", obj.Ativo); return(dataAccess.Write(@"INSERT INTO Secretarias (Secretaria, Ativo) VALUES (@Secretaria, @Ativo)")); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return(false); } }