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 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 Delete(NumeroVestuario numeroVestuario) { try { string command = "Delete from NumeroVestuario where ID=@ID"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@ID", MySqlDbType.Int16).Value = numeroVestuario.ID; cmdInsert.ExecuteNonQuery(); return("OK"); } catch (Exception ex) { return(ex.Message); } finally { Con.Fechar(); } }
public string Insert(NumeroVestuario numeroVestuario) { try { string command = "Insert into NumeroVestuario(Numero, IdVestuario) values(@Numero, @IdVestuario)"; MySqlCommand cmdInsert = new MySqlCommand(command, Con.Abrir()); cmdInsert.Parameters.Add("@Numero", MySqlDbType.VarChar).Value = numeroVestuario.Numero; cmdInsert.Parameters.Add("@IdVestuario", MySqlDbType.Int16).Value = numeroVestuario.Vestuario.ID; cmdInsert.ExecuteNonQuery(); return(cmdInsert.LastInsertedId.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(); } }