public bool GerarXML(Domain.NotaFiscal notaFiscal) { try { XmlSerializer serializador = new XmlSerializer(typeof(Domain.NotaFiscal)); StreamWriter stream = new StreamWriter($"C:/ArquivosXML/NFe{notaFiscal.NumeroNotaFiscal}_{notaFiscal.NomeCliente}"); serializador.Serialize(stream, notaFiscal); return(true); } catch { return(false); } }
public void Salvar(Domain.NotaFiscal notaFiscal) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = Connection; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "P_NOTA_FISCAL"; cmd.Parameters.Add(new SqlParameter("@pId", notaFiscal.Id) { Direction = System.Data.ParameterDirection.InputOutput }); cmd.Parameters.Add(new SqlParameter("@pNumeroNotaFiscal", notaFiscal.NumeroNotaFiscal)); cmd.Parameters.Add(new SqlParameter("@pSerie", notaFiscal.Serie)); cmd.Parameters.Add(new SqlParameter("@pNomeCliente", notaFiscal.NomeCliente)); cmd.Parameters.Add(new SqlParameter("@pEstadoDestino", notaFiscal.EstadoDestino)); cmd.Parameters.Add(new SqlParameter("@pEstadoOrigem", notaFiscal.EstadoOrigem)); int ret = cmd.ExecuteNonQuery(); notaFiscal.Id = (int)cmd.Parameters["@pId"].Value; cmd.Parameters.Clear(); foreach (Domain.NotaFiscalItem notaFiscalItem in notaFiscal.ItensDaNotaFiscal) { cmd.CommandText = "P_NOTA_FISCAL_ITEM"; cmd.Parameters.Add(new SqlParameter("@pId", notaFiscalItem.Id)); cmd.Parameters.Add(new SqlParameter("@pIdNotaFiscal", notaFiscal.Id)); cmd.Parameters.Add(new SqlParameter("@pCfop", notaFiscalItem.Cfop)); cmd.Parameters.Add(new SqlParameter("@pTipoIcms", notaFiscalItem.TipoIcms)); cmd.Parameters.Add(new SqlParameter("@pBaseIcms", notaFiscalItem.BaseIcms)); cmd.Parameters.Add(new SqlParameter("@pAliquotaIcms", notaFiscalItem.AliquotaIcms)); cmd.Parameters.Add(new SqlParameter("@pValorIcms", notaFiscalItem.ValorIcms)); cmd.Parameters.Add(new SqlParameter("@pBaseIpi", notaFiscalItem.BaseIpi)); cmd.Parameters.Add(new SqlParameter("@pAliquotaIpi", notaFiscalItem.AliquotaIpi)); cmd.Parameters.Add(new SqlParameter("@pValorIpi", notaFiscalItem.ValorIpi)); cmd.Parameters.Add(new SqlParameter("@pDesconto", notaFiscalItem.Desconto)); cmd.Parameters.Add(new SqlParameter("@pNomeProduto", notaFiscalItem.NomeProduto)); cmd.Parameters.Add(new SqlParameter("@pCodigoProduto", notaFiscalItem.CodigoProduto)); ret = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); } Connection.Close(); } }
public static int GravarNotaFiscal(Domain.NotaFiscal notaFiscal) { using (var _sqlCon = GetConn()) using (var sqlCmd = new SqlCommand("dbo.P_NOTA_FISCAL", _sqlCon)) { sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddRange(new[] { new SqlParameter("@pId", notaFiscal.Id) { Direction = ParameterDirection.InputOutput }, new SqlParameter("@pNumeroNotaFiscal", notaFiscal.NumeroNotaFiscal), new SqlParameter("@pSerie", notaFiscal.Serie), new SqlParameter("@pNomeCliente", notaFiscal.NomeCliente), new SqlParameter("@pEstadoDestino", notaFiscal.EstadoDestino), new SqlParameter("@pEstadoOrigem", notaFiscal.EstadoOrigem) }); _sqlCon.Open(); sqlCmd.ExecuteScalar(); return(Convert.ToInt32(sqlCmd.Parameters["@pId"].Value)); } }
public void SaveDB(Domain.NotaFiscal obj) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "P_NOTA_FISCAL"; SqlParameter output = new SqlParameter("@pId", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output, Value = obj.Id }; cmd.Parameters.Add(output); cmd.Parameters.Add(new SqlParameter("pNumeroNotaFiscal", obj.NumeroNotaFiscal)); cmd.Parameters.Add(new SqlParameter("pSerie", obj.Serie)); cmd.Parameters.Add(new SqlParameter("pNomeCliente", obj.NomeCliente)); cmd.Parameters.Add(new SqlParameter("pEstadoDestino", obj.EstadoDestino)); cmd.Parameters.Add(new SqlParameter("pEstadoOrigem", obj.EstadoOrigem)); ExecuteNonQuery(cmd); SaveDB(obj.ItensDaNotaFiscal); } }