public DataTable Select(Farda farda) { try { string command = string.Format("Select Farda.ID, Farda.Nome as Farda, Farda.Descricao as 'Descrição'," + " group_concat(Vestuario.Nome) as Vestuarios from Farda Left join Vestuario_Farda on Vestuario_Farda.Id_Farda=Farda.ID Left join " + "Vestuario on Vestuario_Farda.Id_Vestuario=Vestuario.ID where Farda.Nome like @Nome group by Farda.ID order by Farda.Nome"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@Nome", MySqlDbType.VarChar).Value = farda.Nome + "%"; DataTable dtFardas = new DataTable(); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmdInsert); dataAdapter.Fill(dtFardas); return(dtFardas); } catch { return(null); } finally { Con.Fechar(); } }
public Dictionary <string, int> ListarVestuarioNomeID(Farda farda) { try { string command = string.Format("Select Vestuario.ID, Vestuario.Nome from Vestuario inner join Vestuario_Farda " + "on Vestuario_Farda.Id_Vestuario=Vestuario.ID inner join Farda on Farda.ID=Vestuario_Farda.Id_Farda " + "where Farda.ID=@ID group by Vestuario.Nome"); MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = farda.ID; Dictionary <string, int> LVestuario = new Dictionary <string, int>(); using (var reader = cmdInsert.ExecuteReader()) { while (reader.Read()) { LVestuario.Add(reader.GetString("Nome"), reader.GetInt32("ID")); } } return(LVestuario); } catch { return(new Dictionary <string, int>()); } finally { Con.Fechar(); } }
private void btnSalvar_Click(object sender, EventArgs e) { try { List <EcomendaItens> ecomendaItens = new List <EcomendaItens>(); foreach (DataGridViewRow row in dgvLista.Rows) { var farda = new Farda((int)row.Cells["IdFarda"].Value); var serie = new Serie((int)row.Cells["IdSerie"].Value); var numeroVestuario = new NumeroVestuario((int)row.Cells["IdNumero"].Value); int quantidade = (int)row.Cells["Quantidade"].Value; var itens = new EcomendaItens(farda, serie, numeroVestuario, quantidade); ecomendaItens.Add(itens); } Ecomenda ecomenda = new Ecomenda() { Descricao = txtDescricao.Text, DataCriacao = DateTime.Now, DataChegada = DateTime.Now, EcomendaItens = ecomendaItens, Militar = ElementosEstaticos.Militar }; NEcomenda nEcomenda = new NEcomenda(); string resposta = nEcomenda.Insert(ecomenda); int id = 0; if (!int.TryParse(resposta, out id)) { throw new InvalidOperationException(resposta); } //Imprimir DGVPrinter printer = new DGVPrinter(); printer.ListColumns = new List <string>() { "Serie", "Farda", "Vestuario", "Numero", "Quantidade" }; printer.Title = "Ecomenda de Vestuário"; printer.SubTitle = string.Format("Ecomenda nº E{0} {1}", id.ToString("00000"), DateTime.Now.ToString("dd-MMMM-yyyy hh:mm")); printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; printer.PageNumbers = true; printer.PageNumberInHeader = false; printer.PorportionalColumns = true; printer.HeaderCellAlignment = StringAlignment.Near; printer.Footer = ElementosEstaticos.Unidade.Nome; printer.FooterSpacing = 15; printer.PrintDataGridView(dgvLista); Limpar(); } catch (Exception ex) { MessageBox.Show("Um erro impedio a execução da operação.\r\nErro: " + ex.Message, ElementosEstaticos.Unidade.Nome, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Selecionar(Farda farda) { NFarda nFarda = new NFarda(); dgvLista.DataSource = nFarda.Select(farda); if ((dgvLista.DataSource != null) && (dgvLista.Columns.Contains("ID"))) { dgvLista.Columns["ID"].Visible = false; } }
private void btnSalvar_Click(object sender, EventArgs e) { try { List <StockVestuarioFarda> Lstock = new List <StockVestuarioFarda>(); foreach (DataGridViewRow row in dgvListaItems.Rows) { var farda = new Farda((int)row.Cells["IdFarda"].Value); var serie = new Serie((int)row.Cells["IdSerie"].Value); var numeroVestuario = new NumeroVestuario((int)row.Cells["IdNumero"].Value); int quantidade = (int)row.Cells["Quantidade"].Value; var itens = new StockVestuarioFarda(serie, farda, numeroVestuario, quantidade); Lstock.Add(itens); } MovimentoStock movimento = new MovimentoStock() { Descricao = "Entrada de Ecomenda nº " + txtCodigo.Text, DataMovimento = DateTime.Now, Militar = ElementosEstaticos.Militar, TipoMovimento = EnumList.TipoMovimento.Entrada }; foreach (var item in Lstock) { NStock nStock = new NStock(); string resposta = nStock.Insert(item, movimento); } //Imprimir DGVPrinter printer = new DGVPrinter(); printer.ListColumns = new List <string>() { "Serie", "Farda", "Vestuario", "Numero", "Quantidade" }; printer.Title = "Ecomenda de Vestuário"; printer.SubTitle = string.Format("{0} - {1}", movimento.Descricao, DateTime.Now.ToString("dd-MMMM-yyyy hh:mm")); printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; printer.PageNumbers = true; printer.PageNumberInHeader = false; printer.PorportionalColumns = true; printer.HeaderCellAlignment = StringAlignment.Near; printer.Footer = ElementosEstaticos.Unidade.Nome; printer.FooterSpacing = 15; printer.PrintDataGridView(dgvListaItems); Limpar(); } catch (Exception ex) { MessageBox.Show("Um erro impedio a execução da operação.\r\nErro: " + ex.Message, ElementosEstaticos.Unidade.Nome, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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 Update(Farda farda) { try { using (MySqlTransaction trans = Con.Abrir().BeginTransaction()) { string command = "Update Farda set Nome=@Nome, Descricao=@Descricao where ID=@ID"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Transaction = trans; cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = farda.ID; cmdInsert.Parameters.Add("@Nome", MySqlDbType.VarChar).Value = farda.Nome; cmdInsert.Parameters.Add("@Descricao", MySqlDbType.VarChar).Value = farda.Descricao; cmdInsert.ExecuteNonQuery(); cmdInsert.CommandText = "Delete from Vestuario_Farda where Id_Farda=@ID"; cmdInsert.ExecuteNonQuery(); cmdInsert.Parameters.Add("@IdVestuario", MySqlDbType.Int32); cmdInsert.CommandText = "Insert into Vestuario_Farda(Id_Farda, Id_Vestuario) values (@ID, @IdVestuario)"; foreach (var item in farda.Vestuarios) { cmdInsert.Parameters["@IdVestuario"].Value = item.ID; cmdInsert.ExecuteNonQuery(); } trans.Commit(); return("OK"); } } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
public string Delete(Farda farda) { try { string command = "Delete from Farda where ID=@ID"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = farda.ID; cmdInsert.ExecuteNonQuery(); return("OK"); } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
public string Insert(Farda farda) { try { using (MySqlTransaction trans = Con.Abrir().BeginTransaction()) { string command = "Insert into Farda(Nome, Descricao) values(@Nome, @Descricao)"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Transaction = trans; cmdInsert.Parameters.Add("@Nome", MySqlDbType.VarChar).Value = farda.Nome; cmdInsert.Parameters.Add("@Descricao", MySqlDbType.VarChar).Value = farda.Descricao; cmdInsert.ExecuteNonQuery(); int id = (int)cmdInsert.LastInsertedId; cmdInsert.Parameters.Add("@ID", MySqlDbType.Int32).Value = id; cmdInsert.Parameters.Add("@IdVestuario", MySqlDbType.Int32); cmdInsert.CommandText = "Insert into Vestuario_Farda(Id_Farda, Id_Vestuario) values (@ID, @IdVestuario)"; foreach (var item in farda.Vestuarios) { cmdInsert.Parameters["@IdVestuario"].Value = item.ID; cmdInsert.ExecuteNonQuery(); } trans.Commit(); return(id.ToString()); } } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
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(); } }
public Dictionary <string, int> ListarVestuarioNomeID(Farda farda) { return(DFarda.ListarVestuarioNomeID(farda)); }
public DataTable Select(Farda farda) { return(DFarda.Select(farda)); }
public string Delete(Farda farda) { return(DFarda.Delete(farda)); }
public string Update(Farda farda) { return(DFarda.Update(farda)); }
public string Insert(Farda farda) { return(DFarda.Insert(farda)); }