示例#1
0
        public DataTable BuscarNombreCliente(DFactura Factura)
        {
            DataTable DtResultado = new DataTable("tblFactura");
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                SqlCon.ConnectionString = Conexion.Cn;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "spbuscar_factura_nombrescliente";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParTextoBuscar = new SqlParameter();
                ParTextoBuscar.ParameterName = "@textobuscar";
                ParTextoBuscar.SqlDbType = SqlDbType.VarChar;
                ParTextoBuscar.Size = 100;
                ParTextoBuscar.Value = Factura.TextoBuscar;
                SqlCmd.Parameters.Add(ParTextoBuscar);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);
            }
            catch
            {
                DtResultado = null;
            }
            return DtResultado;
        }
示例#2
0
        public DataTable BusquedaAvanzada(DFactura Factura)
        {
            DataTable DtResultado = new DataTable("tblFactura");
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                SqlCon.ConnectionString = Conexion.Cn;
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.CommandText = "spbuscar_factura_nombreyfecha";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParTextoBuscar = new SqlParameter();
                ParTextoBuscar.ParameterName = "@textobuscar";
                ParTextoBuscar.SqlDbType = SqlDbType.VarChar;
                ParTextoBuscar.Size = 100;
                ParTextoBuscar.Value = Factura.TextoBuscar;
                SqlCmd.Parameters.Add(ParTextoBuscar);

                SqlParameter ParFechaDesde = new SqlParameter();
                ParFechaDesde.ParameterName = "@fechabuscardesde";
                ParFechaDesde.SqlDbType = SqlDbType.VarChar;
                ParFechaDesde.Size = 50;
                ParFechaDesde.Value = Factura.FechaDesde;
                SqlCmd.Parameters.Add(ParFechaDesde);

                SqlParameter ParFechaHasta = new SqlParameter();
                ParFechaHasta.ParameterName = "@fechabuscarhasta";
                ParFechaHasta.SqlDbType = SqlDbType.VarChar;
                ParFechaHasta.Size = 50;
                ParFechaHasta.Value = Factura.FechaHasta;
                SqlCmd.Parameters.Add(ParFechaHasta);

                SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd);
                SqlDat.Fill(DtResultado);
            }
            catch
            {
                DtResultado = null;
            }
            return DtResultado;
        }
        public bool InsertarFactura(DFactura factura)
        {
            int           rpta   = 0;
            string        cadena = "sp_insertar_factura";
            SqlConnection cn     = new SqlConnection();

            try
            {
                // code here
                cn.ConnectionString = Conexion.conectar;
                cn.Open();

                using (SqlCommand cmd = new SqlCommand(cadena, cn))
                {
                    cmd.Parameters.AddWithValue("@serie", factura.Serie);
                    cmd.Parameters.AddWithValue("@correlativo", factura.Correlativo);
                    cmd.Parameters.AddWithValue("@idventa", factura.IdVenta);
                    cmd.CommandType = CommandType.StoredProcedure;

                    rpta = cmd.ExecuteNonQuery();
                    if (rpta == 1)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error ... ???", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);

                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(false);
        }
示例#4
0
        }//fin editar

        //metodo eliminar
        public string Eliminar(DFactura Factura)
        {//inicio eliminar
            string        rpta   = "";
            SqlConnection SqlCon = new SqlConnection();

            try
            {
                //conexion
                SqlCon.ConnectionString = Conexion.Cn;
                SqlCon.Open();
                //establecer el comando
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "speliminar_factura";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParId_Factura = new SqlParameter();
                ParId_Factura.ParameterName = "@id_factura";
                ParId_Factura.SqlDbType     = SqlDbType.Int;
                ParId_Factura.Value         = Factura.Id_factura;
                SqlCmd.Parameters.Add(ParId_Factura);

                rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO SE HA ELIMINADO EL REGISTRO";
            }
            catch (Exception ex)
            {
                rpta = ex.Message + ex.StackTrace;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }
            return(rpta);
        }//fin eliminar
示例#5
0
        }//fin insertar

        //metodo editar
        public string Editar(DFactura Factura)
        {//inicio editar
            string        rpta   = "";
            SqlConnection SqlCon = new SqlConnection();

            try
            {
                //conexion
                SqlCon.ConnectionString = Conexion.Cn;
                SqlCon.Open();
                //establecer el comando
                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection  = SqlCon;
                SqlCmd.CommandText = "speditar_factura";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                //parametros
                SqlParameter ParId_Factura = new SqlParameter();
                ParId_Factura.ParameterName = "@id_factura";
                ParId_Factura.SqlDbType     = SqlDbType.Int;
                ParId_Factura.Value         = Factura.Id_factura;
                SqlCmd.Parameters.Add(ParId_Factura);

                SqlParameter ParId_Cliente = new SqlParameter();
                ParId_Cliente.ParameterName = "@id_cliente";
                ParId_Cliente.SqlDbType     = SqlDbType.Int;
                ParId_Cliente.Value         = Factura.Id_cliente;
                SqlCmd.Parameters.Add(ParId_Cliente);

                SqlParameter ParFecha_Venta = new SqlParameter();
                ParFecha_Venta.ParameterName = "@fecha_venta";
                ParFecha_Venta.SqlDbType     = SqlDbType.DateTime;
                ParFecha_Venta.Value         = Factura.Fecha_venta;
                SqlCmd.Parameters.Add(ParFecha_Venta);

                SqlParameter ParCosto_Total = new SqlParameter();
                ParCosto_Total.ParameterName = "@costo_total";
                ParCosto_Total.SqlDbType     = SqlDbType.Decimal;
                ParCosto_Total.Value         = Factura.Costo_total;
                SqlCmd.Parameters.Add(ParCosto_Total);

                SqlParameter ParNumero_Factura = new SqlParameter();
                ParNumero_Factura.ParameterName = "@numero_factura";
                ParNumero_Factura.SqlDbType     = SqlDbType.Int;
                ParNumero_Factura.Value         = Factura.Numero_factura;
                SqlCmd.Parameters.Add(ParNumero_Factura);

                SqlParameter ParComprobante_Exposicion = new SqlParameter();
                ParComprobante_Exposicion.ParameterName = "@comprobante_exposicion";
                ParComprobante_Exposicion.SqlDbType     = SqlDbType.Int;
                ParComprobante_Exposicion.Value         = Factura.Comprobante_exposicion;
                SqlCmd.Parameters.Add(ParComprobante_Exposicion);

                SqlParameter ParId_Tipo_Pago = new SqlParameter();
                ParId_Tipo_Pago.ParameterName = "@id_tipo_pago";
                ParId_Tipo_Pago.SqlDbType     = SqlDbType.Int;
                ParId_Tipo_Pago.Value         = Factura.Id_tipo_pago;
                SqlCmd.Parameters.Add(ParId_Tipo_Pago);

                SqlParameter ParEmite_Factura = new SqlParameter();
                ParEmite_Factura.ParameterName = "@emite_factura";
                ParEmite_Factura.SqlDbType     = SqlDbType.Int;
                ParEmite_Factura.Value         = Factura.Emite_factura;
                SqlCmd.Parameters.Add(ParEmite_Factura);

                SqlParameter ParTipo_Factura = new SqlParameter();
                ParTipo_Factura.ParameterName = "@tipo_factura";
                ParTipo_Factura.SqlDbType     = SqlDbType.Int;
                ParTipo_Factura.Value         = Factura.Tipo_factura;
                SqlCmd.Parameters.Add(ParTipo_Factura);



                //ejecutar el codigo
                rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "HA FALLADO LA EDICION DEL REGISTRO";
            }
            catch (Exception ex)
            {
                rpta = ex.Message + ex.StackTrace;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }
            return(rpta);
        }//fin editar
示例#6
0
          public string Insertar(DFactura Factura, List<DDetalle_Factura> Detalle)
        {
            string rta = "";
            SqlConnection SqlCon = new SqlConnection();
            try
            {
                SqlCon.ConnectionString = Conexion.Cn;
                SqlCon.Open();
                SqlTransaction SqlTra = SqlCon.BeginTransaction();

                SqlCommand SqlCmd = new SqlCommand();
                SqlCmd.Connection = SqlCon;
                SqlCmd.Transaction = SqlTra;
                SqlCmd.CommandText = "spinsertar_factura";
                SqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParIdFactura = new SqlParameter();
                ParIdFactura.ParameterName = "@idfactura";
                ParIdFactura.SqlDbType = SqlDbType.Int;
                ParIdFactura.Direction = ParameterDirection.Output;
                SqlCmd.Parameters.Add(ParIdFactura);

                SqlParameter ParNombre = new SqlParameter();
                ParNombre.ParameterName = "@fecha";
                ParNombre.SqlDbType = SqlDbType.DateTime;
                ParNombre.Value = Factura.FechaFactura;
                SqlCmd.Parameters.Add(ParNombre);

                SqlParameter ParIdCliente = new SqlParameter();
                ParIdCliente.ParameterName = "@idcliente";
                ParIdCliente.SqlDbType = SqlDbType.Int;
                ParIdCliente.Value = Factura.PersonaId;
                SqlCmd.Parameters.Add(ParIdCliente);

                SqlParameter ParNombreCliente = new SqlParameter();
                ParNombreCliente.ParameterName = "@nombrecliente";
                ParNombreCliente.SqlDbType = SqlDbType.VarChar;
                ParNombreCliente.Size = 100;
                ParNombreCliente.Value = Factura.ClienteNombre;
                SqlCmd.Parameters.Add(ParNombreCliente);

                SqlParameter ParIdEmpleado = new SqlParameter();
                ParIdEmpleado.ParameterName = "@idempleado";
                ParIdEmpleado.SqlDbType = SqlDbType.Int;
                ParIdEmpleado.Value = Factura.EmpleadoId;
                SqlCmd.Parameters.Add(ParIdEmpleado);

                SqlParameter ParNombreEmpleado = new SqlParameter();
                ParNombreEmpleado.ParameterName = "@nombreempleado";
                ParNombreEmpleado.SqlDbType = SqlDbType.VarChar;
                ParNombreEmpleado.Size = 100;
                ParNombreEmpleado.Value = Factura.EmpleadoNombre;
                SqlCmd.Parameters.Add(ParNombreEmpleado);

                SqlParameter ParLegajo = new SqlParameter();
                ParLegajo.ParameterName = "@legajoempleado";
                ParLegajo.SqlDbType = SqlDbType.Int;
                ParLegajo.Value = Factura.EmpleadoLegajo;
                SqlCmd.Parameters.Add(ParLegajo);

                SqlParameter ParTotal = new SqlParameter();
                ParTotal.ParameterName = "@total";
                ParTotal.SqlDbType = SqlDbType.Money;
                ParTotal.Value = Factura.Total;
                SqlCmd.Parameters.Add(ParTotal);

                rta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO se ingreso el registro";

                if (rta.Equals("OK"))
                {
                    //Obtengo el id de factura generado
                    this.IdFactura = Convert.ToInt32(SqlCmd.Parameters["@idfactura"].Value);
                    foreach (DDetalle_Factura det in Detalle)
                    {
                        det.IdFactura = this.IdFactura;
                        //Lamo al metodo insertar de la clase DDetalle_factura
                        rta = det.Insertar(det, ref SqlCon, ref SqlTra);
                        if (!rta.Equals("OK"))
                        {
                            break;
                        }
                    }
                }
                if (rta.Equals("OK"))
                {
                    SqlTra.Commit();
                }
                else
                {
                    SqlTra.Rollback();
                }
            }
            catch (Exception ex)
            {
                rta = ex.Message;
            }
            finally
            {
                if (SqlCon.State == ConnectionState.Open) SqlCon.Close();
            }
            return rta;
        }