public Vestuario SelectID(Vestuario vestuario) { try { string command = string.Format("Select ID, Nome, Descricao from Vestuario where ID=@ID"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int32).Value = vestuario.ID; using (var reader = cmdInsert.ExecuteReader()) { if (reader.Read()) { vestuario = new Vestuario(reader.GetInt32("ID"), reader.GetString("Nome"), reader.GetString("Descricao"), null); } } return(vestuario); } catch { return(new Vestuario()); } finally { Con.Fechar(); } }
public Dictionary <string, int> ListarNumerosNomeID(Vestuario vestuario) { try { string command = string.Format("Select ID, Numero from Numero_Vestuario where Id_Vestuario=@ID group by Numero"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = vestuario.ID; Dictionary <string, int> LNumeros = new Dictionary <string, int>(); using (var reader = cmdInsert.ExecuteReader()) { while (reader.Read()) { LNumeros.Add(reader.GetString("Numero"), reader.GetInt32("ID")); } } return(LNumeros); } catch { return(new Dictionary <string, int>()); } finally { Con.Fechar(); } }
public DataTable Select(Vestuario vestuario) { try { string command = string.Format("Select Vestuario.ID, Vestuario.Nome as Vestuario, Vestuario.Descricao as 'Descrição', " + "group_Concat(Numero_Vestuario.numero) as Numeros from Vestuario left join Numero_Vestuario on " + "Numero_Vestuario.Id_Vestuario=Vestuario.ID where Vestuario.Nome like @Nome group by Vestuario.Nome " + "order by Vestuario.Nome"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@Nome", MySqlDbType.VarChar).Value = vestuario.Nome + "%"; DataTable dtVestuarios = new DataTable(); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmdInsert); dataAdapter.Fill(dtVestuarios); return(dtVestuarios); } catch { return(null); } finally { Con.Fechar(); } }
private void Selecionar(Vestuario vestuario) { NVestuario nVestuario = new NVestuario(); dgvLista.DataSource = nVestuario.Select(vestuario); if ((dgvLista.DataSource != null) && (dgvLista.Columns.Contains("ID"))) { dgvLista.Columns["ID"].Visible = false; } }
public string Update(Vestuario vestuario) { try { using (MySqlTransaction trans = Con.Abrir().BeginTransaction()) { string command = "Update Vestuario set Nome=@Nome, Descricao=@Descricao where ID=@IdVestuario"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Transaction = trans; cmdInsert.Parameters.Add("@IdVestuario", MySqlDbType.Int16).Value = vestuario.ID; cmdInsert.Parameters.Add("@Nome", MySqlDbType.VarChar).Value = vestuario.Nome; cmdInsert.Parameters.Add("@Descricao", MySqlDbType.VarChar).Value = vestuario.Descricao; cmdInsert.ExecuteNonQuery(); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = 0; cmdInsert.Parameters.Add("@Numero", MySqlDbType.VarChar); foreach (var item in vestuario.Numeros) { if (item.ID == 0) { cmdInsert.CommandText = "Insert into Numero_Vestuario(Id_Vestuario, Numero) values (@IdVestuario, @Numero)"; cmdInsert.Parameters["@Numero"].Value = item.Numero; } else { cmdInsert.Parameters["ID"].Value = item.ID; cmdInsert.CommandText = "Update set Numero=@Numero where ID=@ID)"; cmdInsert.Parameters["@Numero"].Value = item.Numero; } cmdInsert.ExecuteNonQuery(); } trans.Commit(); return("OK"); } } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
public List <EcomendaItens> SelectItemsEncomenda(Ecomenda ecomenda) { try { string command = string.Format("Select Serie.ID as IdSerie, Serie.Nome as Serie, Farda.ID as IdFarda, " + "Farda.Nome as Farda, Numero_Vestuario.ID as IdNumero, Vestuario.ID as IdVestuario, " + "Vestuario.Nome as Vestuario, Numero_Vestuario.Numero, " + "EcomendaItems.Quantidade from EcomendaItems inner join Serie on EcomendaItems.Id_Serie=Serie.ID " + "inner join Farda on EcomendaItems.Id_Farda = Farda.ID inner join Numero_Vestuario on " + "Numero_Vestuario.ID=EcomendaItems.Id_Numero_Vestuario inner join Vestuario on " + "Vestuario.ID=Numero_Vestuario.Id_Vestuario where EcomendaItems.Id_Ecomenda=@ID group by EcomendaItems.ID;"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int32).Value = ecomenda.ID; List <EcomendaItens> lEcomendas = new List <EcomendaItens>(); using (var reader = cmdInsert.ExecuteReader()) { while (reader.Read()) { Serie serie = new Serie(reader.GetInt32("IdSerie"), reader.GetString("Serie")); Farda farda = new Farda(reader.GetInt32("IdFarda"), reader.GetString("Farda")); Vestuario vestuario = new Vestuario(reader.GetInt32("IdVestuario"), reader.GetString("Vestuario")); NumeroVestuario numeroVestuario = new NumeroVestuario(reader.GetInt32("IdNumero"), vestuario, reader.GetString("Numero")); int quantidade = reader.GetInt32("Quantidade"); EcomendaItens ecomendaIt = new EcomendaItens() { Serie = serie, Farda = farda, NumeroVestuario = numeroVestuario, Quantidade = quantidade }; lEcomendas.Add(ecomendaIt); } } return(lEcomendas); } catch { return(null); } finally { Con.Fechar(); } }
public List <NumeroMilitar> ListarNumeroMilitar(Militar militar) { try { string command = string.Format("Select Militar_Numero.ID, Militar.ID as IdMilitar, Militar.Nome as " + "Militar, Farda.ID as IdFarda, Farda.Nome as Farda, Numero_Vestuario.ID as IdNumeroVestuario, " + "Vestuario.ID as IdVestuario, Vestuario.Nome as Vestuario, Numero_Vestuario.Numero " + "from Militar_Numero inner join Militar on Militar.ID=Militar_Numero.Id_Militar inner join Farda " + "on Farda.ID=Militar_Numero.Id_Farda inner join Numero_Vestuario on Numero_Vestuario.ID=" + "Militar_Numero.Id_Numero_Vestuario inner join Vestuario on Numero_Vestuario.Id_Vestuario=" + "Vestuario.ID where Militar.ID=@IdMilitar group by Numero_Vestuario.ID order by Farda.Nome"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@IdMilitar", MySqlDbType.Int32).Value = militar.ID; List <NumeroMilitar> LNumeroMilitar = new List <NumeroMilitar>(); using (var reader = cmdInsert.ExecuteReader()) { while (reader.Read()) { Militar militarN = new Militar(reader.GetInt32("IdMilitar"), reader.GetString("Militar")); Farda farda = new Farda(reader.GetInt32("IdFarda"), reader.GetString("Farda")); Vestuario vestuario = new Vestuario(reader.GetInt32("IdVestuario"), reader.GetString("Vestuario")); NumeroVestuario numeroVestuario = new NumeroVestuario(reader.GetInt32("IdNumeroVestuario"), vestuario, reader.GetString("Numero")); NumeroMilitar numeroMilitar = new NumeroMilitar(reader.GetInt32("ID"), militarN, numeroVestuario, farda); LNumeroMilitar.Add(numeroMilitar); } } return(LNumeroMilitar); } catch { return(new List <NumeroMilitar>()); } finally { Con.Fechar(); } }
public string Delete(Vestuario vestuario) { try { string command = "Delete from Vestuario where ID=@ID"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = vestuario.ID; cmdInsert.ExecuteNonQuery(); return("OK"); } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
public string Insert(Vestuario vestuario) { try { using (MySqlTransaction trans = Con.Abrir().BeginTransaction()) { string command = "Insert into Vestuario(Nome, Descricao) values(@Nome, @Descricao)"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Transaction = trans; cmdInsert.Parameters.Add("@Nome", MySqlDbType.VarChar).Value = vestuario.Nome; cmdInsert.Parameters.Add("@Descricao", MySqlDbType.VarChar).Value = vestuario.Descricao; cmdInsert.ExecuteNonQuery(); int id = (int)cmdInsert.LastInsertedId; cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = id; cmdInsert.Parameters.Add("@Numero", MySqlDbType.VarChar); cmdInsert.CommandText = "Insert into Numero_Vestuario(Id_Vestuario, Numero) values (@ID, @Numero)"; foreach (var item in vestuario.Numeros) { cmdInsert.Parameters["@Numero"].Value = item.Numero; cmdInsert.ExecuteNonQuery(); } trans.Commit(); return(id.ToString()); } } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
public Dictionary <string, int> ListarNumerosNomeID(Vestuario vestuario) { return(DVestuario.ListarNumerosNomeID(vestuario)); }
public Vestuario SelectID(Vestuario vestuario) { return(DVestuario.SelectID(vestuario)); }
public DataTable Select(Vestuario vestuario) { return(DVestuario.Select(vestuario)); }
public string Delete(Vestuario vestuario) { return(DVestuario.Delete(vestuario)); }
public string Update(Vestuario vestuario) { return(DVestuario.Update(vestuario)); }
public string Insert(Vestuario vestuario) { return(DVestuario.Insert(vestuario)); }
public List <EcomendaItens> SelectTotalEncomendar(EcomendaItens ecomendaItens) { try { string filtro = ""; if (ecomendaItens.Farda.ID > 0) { filtro += " and Farda.ID=@IdFarda"; } if (!string.IsNullOrWhiteSpace(ecomendaItens.NumeroVestuario.Numero)) { filtro += " and Numero_Vestuario.Numero like @Numero"; } if (ecomendaItens.NumeroVestuario.Vestuario.ID > 0) { filtro += " and Vestuario.ID=@IdVestuario"; } string command = string.Format("Select Farda.ID as IdFarda, Farda.Nome as Farda, Vestuario.ID as IdVestuario, " + "Vestuario.Nome as Vestuario, Numero_Vestuario.ID as IdNumero, Numero_Vestuario.Numero, " + "count(Militar.ID) as Total from Numero_Vestuario inner join " + "Militar_Numero on Numero_Vestuario.ID = Militar_Numero.Id_Numero_Vestuario inner join Farda " + "on Farda.ID=Militar_Numero.Id_Farda inner join Militar on Militar.ID=Militar_Numero.Id_Militar " + "inner join Vestuario on Vestuario.ID=Numero_Vestuario.Id_Vestuario where Vestuario.ID>0 {0} " + "group by Vestuario.Nome, Numero_Vestuario.Numero", filtro); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@IdFarda", MySqlDbType.Int32).Value = ecomendaItens.Farda.ID; cmdInsert.Parameters.Add("@Numero", MySqlDbType.VarChar).Value = ecomendaItens.NumeroVestuario.Numero + "%"; cmdInsert.Parameters.Add("@IdVestuario", MySqlDbType.Int32).Value = ecomendaItens.NumeroVestuario.Vestuario.ID; List <EcomendaItens> lEcomendas = new List <EcomendaItens>(); using (var reader = cmdInsert.ExecuteReader()) { while (reader.Read()) { Farda farda = new Farda(reader.GetInt32("IdFarda"), reader.GetString("Farda")); Vestuario vestuario = new Vestuario(reader.GetInt32("IdVestuario"), reader.GetString("Vestuario")); NumeroVestuario numeroVestuario = new NumeroVestuario(reader.GetInt32("IdNumero"), vestuario, reader.GetString("Numero")); int quantidade = reader.GetInt32("Total"); EcomendaItens ecomenda = new EcomendaItens() { Farda = farda, NumeroVestuario = numeroVestuario, Quantidade = quantidade }; lEcomendas.Add(ecomenda); } } return(lEcomendas); } catch { return(null); } finally { Con.Fechar(); } }