public CotizacionBe Obtener(int empresaId, int cotizacionId, SqlConnection cn) { CotizacionBe item = null; using (SqlCommand cmd = new SqlCommand("dbo.usp_cotizacion_obtener", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@empresaId", empresaId.GetNullable()); cmd.Parameters.AddWithValue("@cotizacionId", cotizacionId.GetNullable()); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { item = new CotizacionBe(); if (dr.Read()) { item.EmpresaId = dr.GetData <int>("EmpresaId"); item.CotizacionId = dr.GetData <int>("CotizacionId"); item.FechaHoraEmision = dr.GetData <DateTime>("FechaHoraEmision"); item.SerieId = dr.GetData <int>("SerieId"); item.NroComprobante = dr.GetData <int>("NroComprobante"); item.ClienteId = dr.GetData <int>("ClienteId"); item.PersonalId = dr.GetData <int>("PersonalId"); item.MonedaId = dr.GetData <int>("MonedaId"); item.TotalImporte = dr.GetData <decimal>("TotalImporte"); item.FlagAnulado = dr.GetData <bool>("FlagAnulado"); } } } } return(item); }
public bool GuardarCotizacion(CotizacionBe registro) { //Cada parámetro que tiene un "out int?" tiene que que inicializarse con nulo, porque el "int?" acepta valores nulos bool respuesta = cotizacionBl.GuardarCotizacion(registro); return(respuesta); }
public bool GuardarCotizacion(CotizacionBe registro) { bool seGuardo = false; try { using (TransactionScope scope = new TransactionScope()) { cn.Open(); int codigoCotizacion = 0, nroComprobante = 0; seGuardo = cotizacionDa.GuardarCotizacion(registro, cn, out codigoCotizacion, out nroComprobante); if (registro.ListaCotizacionDetalle != null && seGuardo) { foreach (CotizacionDetalleBe item in registro.ListaCotizacionDetalle) { if (item.CodigoCotizacion == 0) { item.CodigoCotizacion = codigoCotizacion; } seGuardo = cotizacionDetalleDa.GuardarCotizacionDetalle(item, cn); if (!seGuardo) { break; } } } if (registro.ListaCotizacionDetalleEliminar != null && seGuardo) { foreach (int codigoCotizacionDetalle in registro.ListaCotizacionDetalleEliminar) { seGuardo = cotizacionDetalleDa.EliminarCotizacionDetalle(codigoCotizacionDetalle, registro.UsuarioModi, cn); if (!seGuardo) { break; } } } if (seGuardo) { scope.Complete(); } } } catch (Exception ex) { log.Error(ex.Message); } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } return(seGuardo); }
public List <CotizacionBe> Buscar(int empresaId, string nombresCompletosPersonal, string razonSocialCliente, DateTime fechaHoraEmisionDesde, DateTime fechaHoraEmisionHasta, int pagina, int cantidadRegistros, string columnaOrden, string ordenMax, SqlConnection cn, out int totalRegistros) { totalRegistros = 0; List <CotizacionBe> lista = null; using (SqlCommand cmd = new SqlCommand("usp_cotizacion_buscar", cn)) { // Instanciando a la funcion CommandType cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@empresaId", empresaId.GetNullable()); cmd.Parameters.AddWithValue("@nombresCompletosPersonal", nombresCompletosPersonal.GetNullable()); cmd.Parameters.AddWithValue("@razonSocialCliente", razonSocialCliente.GetNullable()); cmd.Parameters.AddWithValue("@fechaHoraEmisionDesde", fechaHoraEmisionDesde.GetNullable()); cmd.Parameters.AddWithValue("@fechaHoraEmisionHasta", fechaHoraEmisionHasta.GetNullable()); cmd.Parameters.AddWithValue("@pagina", pagina.GetNullable()); cmd.Parameters.AddWithValue("@cantidadRegistros", cantidadRegistros.GetNullable()); cmd.Parameters.AddWithValue("@columnaOrden", columnaOrden.GetNullable()); cmd.Parameters.AddWithValue("@ordenMax", ordenMax.GetNullable()); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { lista = new List <CotizacionBe>(); while (dr.Read()) { CotizacionBe item = new CotizacionBe(); item.Fila = dr.GetData <int>("Fila"); item.CotizacionId = dr.GetData <int>("CotizacionId"); item.SerieId = dr.GetData <int>("SerieId"); item.Serie = new SerieBe(); item.Serie.SerieId = dr.GetData <int>("SerieId"); item.Serie.Serial = dr.GetData <string>("SerialSerie"); item.NroComprobante = dr.GetData <int>("NroComprobante"); //item.NroPedido = dr.GetData<string>("NroPedido"); item.FechaHoraEmision = dr.GetData <DateTime>("FechaHoraEmision"); //Para personal antes de asignarlo hay que instanciar item.Personal = new PersonalBe(); item.Personal.NombresCompletos = dr.GetData <string>("NombresCompletosPersonal"); item.Cliente = new ClienteBe(); item.Cliente.RazonSocial = dr.GetData <string>("RazonSocialCliente"); item.TotalImporte = dr.GetData <decimal>("TotalImporte"); item.FlagAnulado = dr.GetData <bool>("FlagAnulado"); lista.Add(item); totalRegistros = dr.GetData <int>("Total"); } } } } return(lista); }
private void mitGenerarGuiaRemision_Click(object sender, EventArgs e) { MenuItem mitControl = (MenuItem)sender; int codigoCotizacion = (int)mitControl.Tag; CotizacionBe cotizacion = cotizacionBl.ObtenerCotizacion(codigoCotizacion, true); FrmMantenimientoGuiaRemision frm = new FrmMantenimientoGuiaRemision(null, cotizacion); frm.ShowInTaskbar = false; frm.BringToFront(); DialogResult dr = frm.ShowDialog(); if (dr == DialogResult.OK) { BuscarCotizaciones(); } }
public bool AnularCotizacion(CotizacionBe registro) { bool seGuardo = false; { try { cn.Open(); seGuardo = cotizacionDa.Anular(registro, cn); cn.Close(); } catch (Exception ex) { seGuardo = false; } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } } return(seGuardo); }
public CotizacionBe ObtenerCotizacion(int empresaId, int cotizacionId, bool conSerie = false, bool conMoneda = false, bool conCliente = false, bool conPersonal = false, bool conListaDetalleCotizacion = false) { CotizacionBe item = null; try { cn.Open(); item = cotizacionDa.Obtener(empresaId, cotizacionId, cn); if (item != null) { if (conSerie) { item.Serie = serieDa.Obtener(empresaId, item.SerieId, cn); } if (conMoneda) { item.Moneda = monedaDa.Obtener(item.MonedaId, cn); } if (conCliente) { item.Cliente = clienteDa.Obtener(empresaId, item.ClienteId, cn); } if (conPersonal) { item.Personal = personalDa.Obtener(empresaId, item.PersonalId, cn); } if (conListaDetalleCotizacion) { item.ListaCotizacionDetalle = cotizacionDetalleDa.Listar(empresaId, item.CotizacionId, cn); } } cn.Close(); } catch (Exception) { item = null; } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } return(item); }
public bool GuardarCotizacion(CotizacionBe registro, SqlConnection cn, out int codigoCotizacion, out int nroComprobante) { codigoCotizacion = 0; nroComprobante = 0; bool seGuardo = false; try { using (SqlCommand cmd = new SqlCommand("dbo.usp_cotizacion_guardar", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter { ParameterName = "@codigoCotizacion", Value = registro.CodigoCotizacion.GetNullable(), Direction = ParameterDirection.InputOutput }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@nroComprobante", Value = registro.NroComprobante.GetNullable(), SqlDbType = SqlDbType.Int, Direction = ParameterDirection.InputOutput }); cmd.Parameters.AddWithValue("@fechaHoraEmision", registro.FechaHoraEmision.GetNullable()); cmd.Parameters.AddWithValue("@nroPedido", registro.NroPedido.GetNullable()); cmd.Parameters.AddWithValue("@codigoCliente", registro.CodigoCliente.GetNullable()); cmd.Parameters.AddWithValue("@codigoVendedor", registro.CodigoVendedor.GetNullable()); cmd.Parameters.AddWithValue("@codigoSupervisor", registro.CodigoSupervisor.GetNullable()); cmd.Parameters.AddWithValue("@codigoMoneda", registro.CodigoMoneda.GetNullable()); cmd.Parameters.AddWithValue("@totalImporte", registro.TotalImporte.GetNullable()); cmd.Parameters.AddWithValue("@usuarioModi", registro.UsuarioModi.GetNullable()); int filasAfectadas = cmd.ExecuteNonQuery(); seGuardo = filasAfectadas > 0; if (seGuardo) { codigoCotizacion = (int)cmd.Parameters["@codigoCotizacion"].Value; nroComprobante = (int)cmd.Parameters["@nroComprobante"].Value; } } } catch (Exception ex) { log.Error(ex.Message); } return(seGuardo); }
public CotizacionBe ObtenerCotizacion(int codigoCotizacion, bool withDetalle = false) { CotizacionBe item = null; try { cn.Open(); item = cotizacionDa.ObtenerCotizacion(codigoCotizacion, cn); if (withDetalle) { item.ListaCotizacionDetalle = cotizacionDetalleDa.ListarCotizacionDetalle(codigoCotizacion, cn); } } catch (Exception ex) { log.Error(ex.Message); } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } return(item); }
public CotizacionBe ObtenerCotizacion(int codigoCotizacion, SqlConnection cn) { CotizacionBe item = null; try { using (SqlCommand cmd = new SqlCommand("dbo.usp_cotizacion_obtener", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@codigoCotizacion", codigoCotizacion.GetNullable()); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { item = new CotizacionBe(); if (dr.Read()) { item.CodigoCotizacion = dr.GetData <int>("CodigoCotizacion"); item.NroComprobante = dr.GetData <int>("NroComprobante"); item.FechaHoraEmision = dr.GetData <DateTime>("FechaHoraEmision"); item.NroPedido = dr.GetData <string>("NroPedido"); item.CodigoCliente = dr.GetData <int>("CodigoCliente"); item.CodigoVendedor = dr.GetData <int>("CodigoVendedor"); item.CodigoSupervisor = dr.GetData <int>("CodigoSupervisor"); item.CodigoMoneda = dr.GetData <int>("CodigoMoneda"); item.TotalImporte = dr.GetData <decimal>("TotalImporte"); item.FlagActivo = dr.GetData <bool>("FlagActivo"); } } } } } catch (Exception ex) { log.Error(ex.Message); } return(item); }
private void btnGuardar_Click(object sender, EventArgs e) { bool estaValidado = ValidarFormulario(); if (!estaValidado) { return; } CotizacionBe registro = new CotizacionBe(); if (codigoCotizacion.HasValue) { registro.CodigoCotizacion = codigoCotizacion.Value; } registro.FechaHoraEmision = dtpFechaHoraEmision.Value; registro.NroComprobante = int.Parse(string.IsNullOrEmpty(txtNroComprobante.Text.Trim()) ? "0" : txtNroComprobante.Text.Trim()); registro.NroPedido = txtNroPedido.Text.Trim(); registro.CodigoMoneda = int.Parse(cbbCodigoMoneda.SelectedValue.ToString()); registro.CodigoCliente = codigoCliente.Value; registro.CodigoVendedor = codigoVendedor.Value; registro.CodigoSupervisor = codigoSupervisor; registro.ListaCotizacionDetalle = listaDetalle; registro.ListaCotizacionDetalleEliminar = listaDetalleInicial == null ? null : listaDetalleInicial.Where(x => listaDetalle.Count(y => y.CodigoCotizacionDetalle == x.CodigoCotizacionDetalle) == 0).Select(x => x.CodigoCotizacionDetalle).ToArray(); registro.TotalImporte = listaDetalle.Sum(x => x.Importe); bool seGuardoRegistro = cotizacionBl.GuardarCotizacion(registro); if (seGuardoRegistro) { DialogResult = MessageBox.Show("¡El registro se guardó correctamente!", "¡Bien hecho!", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } else { MessageBox.Show("¡Ocurrió un error! Contáctese con el administrador del sistema", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool Anular(CotizacionBe registro, SqlConnection cn) { bool seGuardo = false; try { using (SqlCommand cmd = new SqlCommand("dbo.usp_cotizacion_anular", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@empresaId", registro.EmpresaId.GetNullable()); cmd.Parameters.AddWithValue("@cotizacionId", registro.CotizacionId.GetNullable()); cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable()); int filasAfectadas = cmd.ExecuteNonQuery(); seGuardo = filasAfectadas > 0; } } catch (Exception ex) { seGuardo = false; } return(seGuardo); }
void CargarCotizacion() { CotizacionBe item = cotizacionBl.ObtenerCotizacion(codigoCotizacion.Value, true); dtpFechaHoraEmision.Value = item.FechaHoraEmision; txtNroComprobante.Text = item.NroComprobante.ToString("00000000"); txtNroPedido.Text = item.NroPedido; cbbCodigoMoneda.SelectedValue = item.CodigoMoneda.ToString(); codigoCliente = item.CodigoCliente; CargarCliente(codigoCliente); codigoVendedor = item.CodigoVendedor; CargarVendedor(codigoVendedor); chkTieneSupervisor.Checked = item.CodigoSupervisor != null; codigoSupervisor = item.CodigoSupervisor; CargarSupervisor(codigoSupervisor); listaDetalleInicial = item.ListaCotizacionDetalle; listaDetalle = item.ListaCotizacionDetalle; ListarCotizacionDetalle(); }
public bool Guardar(CotizacionBe registro, SqlConnection cn, out int?cotizacionId) { cotizacionId = null; bool seGuardo = false; try { using (SqlCommand cmd = new SqlCommand("dbo.usp_cotizacion_guardar", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter { ParameterName = "@cotizacionId", SqlDbType = SqlDbType.Int, Value = registro.CotizacionId.GetNullable(), Direction = ParameterDirection.InputOutput }); cmd.Parameters.AddWithValue("@empresaId", registro.EmpresaId.GetNullable()); cmd.Parameters.AddWithValue("@serieId", registro.SerieId.GetNullable()); cmd.Parameters.AddWithValue("@nroComprobante", registro.NroComprobante.GetNullable()); cmd.Parameters.AddWithValue("@monedaId", registro.MonedaId.GetNullable()); cmd.Parameters.AddWithValue("@clienteID", registro.ClienteId.GetNullable()); cmd.Parameters.AddWithValue("@personalId", registro.PersonalId.GetNullable()); cmd.Parameters.AddWithValue("@totalImporte", registro.TotalImporte.GetNullable()); cmd.Parameters.AddWithValue("@usuario", registro.Usuario.GetNullable()); int filasAfectadas = cmd.ExecuteNonQuery(); seGuardo = filasAfectadas > 0; if (seGuardo) { cotizacionId = (int?)cmd.Parameters["@cotizacionId"].Value; } } } catch (Exception ex) { seGuardo = false; } return(seGuardo); }
public List <CotizacionBe> BuscarCotizacion(DateTime?fechaEmisionDesde, DateTime?fechaEmisionHasta, string numero, string nroDocIdentidadCliente, string nombresCliente, bool flagActivo, SqlConnection cn) { List <CotizacionBe> resultados = null; try { using (SqlCommand cmd = new SqlCommand("dbo.usp_cotizacion_buscar", cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@fechaEmisionDesde", fechaEmisionDesde.GetNullable()); cmd.Parameters.AddWithValue("@fechaEmisionHasta", fechaEmisionHasta.GetNullable()); cmd.Parameters.AddWithValue("@numero", numero.GetNullable()); cmd.Parameters.AddWithValue("@nroDocumentoIdentidadCliente", nroDocIdentidadCliente.GetNullable()); cmd.Parameters.AddWithValue("@nombresCliente", nombresCliente.GetNullable()); cmd.Parameters.AddWithValue("@flagActivo", flagActivo.GetNullable()); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.HasRows) { resultados = new List <CotizacionBe>(); while (dr.Read()) { CotizacionBe item = new CotizacionBe(); item.Fila = dr.GetData <int>("Fila"); item.CodigoCotizacion = dr.GetData <int>("CodigoCotizacion"); item.FechaHoraEmision = dr.GetData <DateTime>("FechaHoraEmision"); item.NroComprobante = dr.GetData <int>("NroComprobante"); item.NroPedido = dr.GetData <string>("NroPedido"); item.CodigoCliente = dr.GetData <int>("CodigoCliente"); item.Cliente = new ClienteBe(); item.Cliente.CodigoCliente = dr.GetData <int>("CodigoCliente"); item.Cliente.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadCliente"); item.Cliente.TipoDocumentoIdentidad = new TipoDocumentoIdentidadBe(); item.Cliente.TipoDocumentoIdentidad.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadCliente"); item.Cliente.TipoDocumentoIdentidad.Descripcion = dr.GetData <string>("DescripcionTipoDocumentoIdentidadCliente"); item.Cliente.NroDocumentoIdentidad = dr.GetData <string>("NroDocumentoIdentidadCliente"); item.Cliente.Nombres = dr.GetData <string>("NombresCliente"); item.Cliente.FlagActivo = dr.GetData <bool>("FlagActivoCliente"); item.NroDocumentoIdentidadCliente = dr.GetData <string>("NroDocumentoIdentidadCliente"); item.DescripcionTipoDocumentoIdentidadCliente = dr.GetData <string>("DescripcionTipoDocumentoIdentidadCliente"); item.CodigoVendedor = dr.GetData <int>("CodigoVendedor"); item.Vendedor = new PersonalBe(); item.Vendedor.CodigoPersonal = dr.GetData <int>("CodigoVendedor"); item.Vendedor.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadVendedor"); item.Vendedor.TipoDocumentoIdentidad = new TipoDocumentoIdentidadBe(); item.Vendedor.TipoDocumentoIdentidad.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadVendedor"); item.Vendedor.TipoDocumentoIdentidad.Descripcion = dr.GetData <string>("DescripcionTipoDocumentoIdentidadVendedor"); item.Vendedor.NroDocumentoIdentidad = dr.GetData <string>("NroDocumentoIdentidadVendedor"); item.Vendedor.Nombres = dr.GetData <string>("NombresVendedor"); item.Vendedor.FlagActivo = dr.GetData <bool>("FlagActivoVendedor"); item.NroDocumentoIdentidadVendedor = dr.GetData <string>("NroDocumentoIdentidadVendedor"); item.DescripcionTipoDocumentoIdentidadVendedor = dr.GetData <string>("DescripcionTipoDocumentoIdentidadVendedor"); item.CodigoSupervisor = dr.GetData <int?>("CodigoSupervisor"); if (item.CodigoSupervisor.HasValue) { item.Supervisor = new PersonalBe(); item.Supervisor.CodigoPersonal = dr.GetData <int>("CodigoSupervisor"); item.Supervisor.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadSupervisor"); item.Supervisor.TipoDocumentoIdentidad = new TipoDocumentoIdentidadBe(); item.Supervisor.TipoDocumentoIdentidad.CodigoTipoDocumentoIdentidad = dr.GetData <int>("CodigoTipoDocumentoIdentidadSupervisor"); item.Supervisor.TipoDocumentoIdentidad.Descripcion = dr.GetData <string>("DescripcionTipoDocumentoIdentidadSupervisor"); item.Supervisor.NroDocumentoIdentidad = dr.GetData <string>("NroDocumentoIdentidadSupervisor"); item.Supervisor.Nombres = dr.GetData <string>("NombresSupervisor"); item.Supervisor.FlagActivo = dr.GetData <bool>("FlagActivoSupervisor"); } item.NroDocumentoIdentidadSupervisor = dr.GetData <string>("NroDocumentoIdentidadSupervisor"); item.DescripcionTipoDocumentoIdentidadSupervisor = dr.GetData <string>("DescripcionTipoDocumentoIdentidadSupervisor"); item.CodigoMoneda = dr.GetData <int>("CodigoMoneda"); item.TotalImporte = dr.GetData <decimal>("TotalImporte"); item.FlagActivo = dr.GetData <bool>("FlagActivo"); resultados.Add(item); } } } } } catch (Exception ex) { log.Error(ex.Message); } return(resultados); }
public FrmMantenimientoGuiaRemision(int?codigoGuiaRemision = null, CotizacionBe cotizacion = null) { InitializeComponent(); this.codigoGuiaRemision = codigoGuiaRemision; this.cotizacion = cotizacion; }
public bool AnularCotizacion(CotizacionBe registro) { bool respuesta = cotizacionBl.AnularCotizacion(registro); return(respuesta); }
public bool GuardarCotizacion(CotizacionBe registro) { int? cotizacionId = null; bool seGuardo = false; { try { using (TransactionScope scope = new TransactionScope()) { cn.Open(); seGuardo = cotizacionDa.Guardar(registro, cn, out cotizacionId); // Si seGuardo es True entonces if (seGuardo) { if (registro.ListaCotizacionDetalleEliminados != null) { foreach (int cotizacionDetalleId in registro.ListaCotizacionDetalleEliminados) { CotizacionDetalleBe registroDetalleEliminar = new CotizacionDetalleBe(); registroDetalleEliminar.EmpresaId = registro.EmpresaId; registroDetalleEliminar.CotizacionId = (int)cotizacionId; registroDetalleEliminar.CotizacionDetalleId = cotizacionDetalleId; registroDetalleEliminar.Usuario = registro.Usuario; seGuardo = cotizacionDetalleDa.Eliminar(registroDetalleEliminar, cn); if (!seGuardo) { break; } } } // Si la Lista de Detalle es diferente de Null if (registro.ListaCotizacionDetalle != null) { //Entonces recorro la misma Lista de detalle con el Item foreach (var item in registro.ListaCotizacionDetalle) { item.CotizacionId = (int)cotizacionId; item.EmpresaId = registro.EmpresaId; item.Usuario = registro.Usuario; seGuardo = cotizacionDetalleDa.Guardar(item, cn); //seGuardo = new if (!seGuardo) { break; } } } } if (seGuardo) { scope.Complete(); } cn.Close(); } } catch (Exception ex) { seGuardo = false; } finally { if (cn.State == ConnectionState.Open) { cn.Close(); } } } return(seGuardo); }