Exemplo n.º 1
0
        public frmUpPedido(int strcodigo)
        {
            //emp = be;
            InitializeComponent();

               // txtCodVendedor.Text = be.Id.ToString();
            //txtNomVendedor.Text = be.Nombres + " " + be.Apellidos;

            ped = pdl.getpedido(strcodigo);

            cli = clibl.getcliente(ped.IDCliente);

            txtCodCliente.Text = cli.IdCliente.ToString();
            txtNombreCliente.Text = cli.Nombre.ToString();
            /*NO SE CARGA EL ALMACEN POR QUE NO SE GUARDA*/
            //al = albl.getalmacen(ped.);

            modbe = modbl.getmodalidad(cli.IDModalidadCredito);

            txtmodalidad.Text = modbe.Descripcion;

            emp = empbl.getvendedor(ped.IDVendedor);
            txtCodVendedor.Text = emp.Id.ToString();
            txtNomVendedor.Text = emp.Nombres.ToString();

            dtdetalle.Columns.Add("Codigo", typeof(String));
            dtdetalle.Columns.Add("Nombre", typeof(String));
            dtdetalle.Columns.Add("Precio", typeof(Double));
            dtdetalle.Columns.Add("Cantidad", typeof(Int32));
            dtdetalle.Columns.Add("DetallePedidoId", typeof(Int32));

            actualizarDetalle();
            actualizarmontos();
        }
        /* void procesandoProgresabar() {
            progressBar1.RunWorkerAsync();
        }*/
        private void button3_Click(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();

            PedidoBL pbl = new PedidoBL();
            FacturaBL facBl = new FacturaBL();
            FacturaBE factbe = new FacturaBE();
            PedidoBE pedbe = new PedidoBE();
            DataTable dtdetallepedidos = new DataTable();

            if (dtpedidos.Rows.Count >=1)
            {

                Boolean procesados = false;

                DataGridViewCheckBoxCell oCell;
                foreach(DataGridViewRow row in dataGridView1.Rows)
                {
                    dtdetallepedidos.Clear();
                    dtdetallefactura.Clear();

                    //Boolean data = Convert.ToBoolean(int.Parse(row.Cells[0].ToString()));
                    oCell = row.Cells["item"] as DataGridViewCheckBoxCell;
                    bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value);

                    int codigo = int.Parse(row.Cells["Numero_Pedido"].Value.ToString());
                    int codigotipocp = int.Parse(row.Cells["codtipodocumento"].Value.ToString());

                    if (bChecked)
                    {

                        procesados = true;
                        pedbe = pbl.getpedido(codigo);
                        dtdetallepedidos = pbl.obtenerDetalledPedidos_completo(codigo);

                        factbe = rellenarfactura(pedbe);
                        factbe.TipoCP = codigotipocp;
                        //construirDetallefactura(dtdetallefactura);
                        dtdetallefactura = rellenardetfactura(dtdetallepedidos);

                        if (facBl.insertFacturaDetalleXLote(factbe, dtdetallefactura))
                        {
                            pbl.updateestadopedido(codigo, "FACTURADO");

                            MessageBox.Show("Pedido Proceso :" + codigo);

                        }

                    }

                }

                if (!procesados)
                {
                    progressBar1.Value = 100;
                    MessageBox.Show("Seleccionar un pedido para su procesamiento");
                    backgroundWorker1.CancelAsync();
                    progressBar1.Value = 0;
                }
                else
                {
                    MessageBox.Show("Proceso Finalizado");
                    backgroundWorker1.CancelAsync();
                    progressBar1.Value = 0;
                    ACTUALIZARREGISTROS();
                }

            }
        }
        public FacturaBE rellenarfactura(PedidoBE pebe)
        {
            FacturaBE fctbe = new FacturaBE();

            fctbe.FacturaId = 0;
            fctbe.ClienteId = pebe.IDCliente;
            fctbe.FechaEmision = pebe.FechaEmision;
            fctbe.FechaEntrega = pebe.FechaEntrega;
            fctbe.ModalidadCreditoId = pebe.IDModalidadCredito;
            fctbe.FechaPago = pebe.FechaPago;
            fctbe.Credito = pebe.Credito;

            fctbe.Direccion = pebe.Direccion;
            fctbe.IdVendedor = pebe.IDVendedor;
            fctbe.Observacion = pebe.Observacion;
            fctbe.ValorVenta = 0;
            fctbe.PrecioIncluyeImpuesto = pebe.PrecioIncluyeImpuesto;
            fctbe.DireccionEntrega = pebe.DireccionEntrega;
            fctbe.EstadoFacturacion = "FACTURADO POR LOTE";
            fctbe.Subtotal = 0;
            fctbe.Total = 0;
            fctbe.MontoIGV = 0;
            fctbe.Observaciones = "GENERADO DESDE PEDIDO/"+pebe.PKID;
            fctbe.CodigoReq = 1;
            fctbe.CodigoSolAtencion = 1;
            fctbe.CodigoFormato = 0;

            return fctbe;
        }
Exemplo n.º 4
0
        private void Button8_Click(object sender, EventArgs e)
        {
            if  (txtCodCliente.Text == "") { MessageBox.Show("Debe seleccionar un Cliente", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCodCliente.Focus(); this.Cursor = Cursors.Default; return; }
            if (dtgDetalleProd.Rows.Count == 0)
            {
                MessageBox.Show("Debe Ingresar Items", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnNuevo2.Focus();
                this.Cursor = Cursors.Default;
                return;
            }

            else
                ped = new PedidoBE();

               int cocli = emp.Id;
            DateTime fecemision = DateTimePicker1.Value;
            DateTime fecentrega = DateTimePicker2.Value;

            //ped.IDModalidadCredito = emp.codmodalidad;
            //ped.Credito = true;
            //ped.Direccion = txtDireccion.Text;
            //ped.IDVendedor = int.Parse(txtCodVendedor.Text);
            //ped.Observacion = "kjhjkh";
            //ped.PrecioIncluyeImpuesto = true;
            //ped.EstadoFacturacion = "REGISTRADO";
            //ped.DireccionEntrega = txtDireccionEntrega.Text;

            PedidoBL pbl = new PedidoBL();

            DialogResult dialogResult = MessageBox.Show("ADVERTENCIA :::::: ¿Desea Actualizar el pedido?", "Confirmación", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                Boolean valor = pbl.uptpedido(ped.PKID, cocli, fecemision, fecentrega);

                if (valor == true)
                {

                    MessageBox.Show("Pedido actualizado satisfactoriamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();

                }
                else
                {
                    MessageBox.Show("Problema con el registro de Pedido , Comunciarse con [email protected]", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                }
            }
        }
Exemplo n.º 5
0
        private void Button8_Click(object sender, EventArgs e)
        {
            if  (txtCodCliente.Text == "") { MessageBox.Show("Debe seleccionar un Cliente", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCodCliente.Focus(); this.Cursor = Cursors.Default; return; }
            if (txtCodVendedor.Text == "") { MessageBox.Show("Debe seleccionar un Vendedor", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCodVendedor.Focus(); this.Cursor = Cursors.Default; return; }
            if (txtCodAlmacen.Text == "") { MessageBox.Show("Debe Ingresar un Almacen", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCodAlmacen.Focus(); this.Cursor = Cursors.Default; return; }
            if (txtDireccionEntrega.Text == "") { MessageBox.Show("Debe Ingresar una Dirección de entrega", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); this.SelectTabWithoutFocus(this.TabControl1.TabPages[1]); ; this.Cursor = Cursors.Default; return; }
            if (dtgDetalleProd.Rows.Count == 0)
            {
                MessageBox.Show("Debe Ingresar Items", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnNuevo2.Focus();
                this.Cursor = Cursors.Default;
                return;
            }

            else
                ped = new PedidoBE();

                ped.IDCliente = emp.Id;
            ped.FechaEmision = DateTimePicker1.Value;
            ped.FechaEntrega = DateTimePicker2.Value;
            ped.FechaPago = DateTimePicker1.Value;

            ped.IDModalidadCredito = emp.codmodalidad;
            ped.Credito = true;
            ped.Direccion = txtDireccion.Text;
            ped.IDVendedor = int.Parse(txtCodVendedor.Text);
            ped.Observacion = "kjhjkh";
            ped.PrecioIncluyeImpuesto = true;
            ped.EstadoFacturacion = "PENDIENTE";
            ped.DireccionEntrega = txtDireccionEntrega.Text;

            ped.CodAlmacen = int.Parse(txtCodAlmacen.Text);
            string codigo = cbMonedas.SelectedValue.ToString();
            ped.CodMoneda = int.Parse(codigo);

            ped.EstadoAprobacion = "";

            PedidoBL pbl = new PedidoBL();

            Boolean valor =  pbl.insertPedido(ped, dtdetalle);

            if (valor == true)
            {

               MessageBox.Show("Pedido guardado satisfactoriamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            this.Close();

            }
            else
            {
                MessageBox.Show("Problema con el registro de Pedido , Comunciarse con [email protected]", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                 }
        }
Exemplo n.º 6
0
        public Boolean insertPedidoDetalle(PedidoBE be,DataTable dt)
        {
            String con = appventa.Default.Setting;

            using (SqlConnection connection = new SqlConnection(con))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                SqlTransaction transaction;

                // Start a local transaction.
                transaction = connection.BeginTransaction("SampleTransaction");

                // Must assign both transaction object and connection
                // to Command object for a pending local transaction
                command.Connection = connection;
                command.Transaction = transaction;

                try
                {
                    command.CommandText =
                                   "sp_vt_insertpedido";
                    command.CommandType = CommandType.StoredProcedure;

                    SqlParameter OutputParam = new SqlParameter("@CodCodigo", SqlDbType.Int);
                    OutputParam.Direction = ParameterDirection.Output;command.Parameters.Add(OutputParam);

                    command.Parameters.Add(
              new SqlParameter("@IDcliente", be.IDCliente));
                    command.Parameters.Add(
              new SqlParameter("@fechaemision", be.FechaEmision));
                    command.Parameters.Add(
              new SqlParameter("@fechaentrega", be.FechaEntrega));
                    command.Parameters.Add(
              new SqlParameter("@idmoddalidadcredito", be.IDModalidadCredito));
                    command.Parameters.Add(
              new SqlParameter("@fechapago", be.FechaPago));
                          command.Parameters.Add(
              new SqlParameter("@credito", be.Credito));
                          command.Parameters.Add(
              new SqlParameter("@direccion", be.Direccion));
                          command.Parameters.Add(
              new SqlParameter("@idvendedor", be.IDVendedor));
                          command.Parameters.Add(
              new SqlParameter("@observacion", be.Observacion));
                          command.Parameters.Add(
              new SqlParameter("@precioincluyeim", be.PrecioIncluyeImpuesto));
                          command.Parameters.Add(
              new SqlParameter("@estadofactura", be.EstadoFacturacion));
                          command.Parameters.Add(
              new SqlParameter("@direccionentrega", be.DireccionEntrega));

                          command.Parameters.Add(
                   new SqlParameter("@estadoAprobacion", be.EstadoAprobacion));
                          command.Parameters.Add(
                   new SqlParameter("@codmoneda", be.CodMoneda));
                          command.Parameters.Add(
                   new SqlParameter("@codalmacen", be.CodAlmacen));

                    command.ExecuteNonQuery();

                    int codigo = int.Parse(command.Parameters["@CodCodigo"].Value.ToString());

                    if (codigo == 0)
                    {
                        codigo = 1;}

                    /*EL DETALLE*/

                    foreach (DataRow row in dt.Rows)
                {
                    command.CommandText = "sp_vt_insertdetpedido";

                    command.CommandType = CommandType.StoredProcedure;

                    String stridproducto = (row[0].ToString());

                    int codigoperu = prodao.ObtenerCodigoIDProducto(stridproducto);

                    double cantidad = double.Parse(row[3].ToString());
                    double precio = double.Parse(row[2].ToString());

                        command.Parameters.Clear();
               command.Parameters.Add(
              new SqlParameter("@idproducto", codigoperu ));
                    command.Parameters.Add(
              new SqlParameter("@cantidad", cantidad));
                    command.Parameters.Add(
             new SqlParameter("@precio", precio));
                    command.Parameters.Add(
              new SqlParameter("@observacion", "BLABLABLA"));
                    command.Parameters.Add(
              new SqlParameter("@IdPedido", codigo));

                    command.Parameters.Add(
             new SqlParameter("@ListaPrecioId", 1));

                    command.ExecuteNonQuery();
                }

                    // Attempt to commit the transaction.
                    transaction.Commit();
                    Console.WriteLine("Both records are written to database.");

                    return true;
                }
                catch (Exception ex)
                {
                    try
                    {
                        transaction.Rollback();
                        return false;
                    }
                    catch (Exception ex2)
                    {
                        return false;

                        // This catch block will handle any errors that may have occurred
                        // on the server that would cause the rollback to fail, such as
                        // a closed connection.
                        Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                        Console.WriteLine("  Message: {0}", ex2.Message);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public PedidoBE getPedido(int id)
        {
            PedidoBE be = new PedidoBE();

            SqlConnection con = DConexion.obtenerBD();

            string textoCmd = "sp_vt_getpedido";

            SqlCommand cmd = new SqlCommand(textoCmd, con);

            cmd.CommandType = CommandType.StoredProcedure;

            // 3. add parameter to command, which
            // will be passed to the stored procedure
            cmd.Parameters.Add(
                new SqlParameter("@codpedido", id));

            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                while (dr.Read())
                {

                    if (object.ReferenceEquals(dr["PedidoId"], DBNull.Value))
                    {
                        be.PKID = 0;
                    }
                    else
                    {
                        be.PKID = int.Parse(dr["PedidoId"].ToString());
                    }

                     if (object.ReferenceEquals(dr["ClienteId"], DBNull.Value))
                    {
                        be.IDCliente = 0;
                    }
                    else
                    {
                        be.IDCliente = int.Parse(dr["ClienteId"].ToString());
                    }

                     if (object.ReferenceEquals(dr["FechaEmision"], DBNull.Value))
                    {

                    }
                    else
                     {
                         be.FechaEmision = DateTime.Parse((dr["FechaEmision"].ToString()));
                     }

                     if (object.ReferenceEquals(dr["FechaEntrega"], DBNull.Value))
                    {

                    }
                    else
                    {
                        be.FechaEntrega = DateTime.Parse((dr["FechaEntrega"].ToString()));
                    }

                     if (object.ReferenceEquals(dr["ModalidadCreditoId"], DBNull.Value))
                    {
                       // be.IDModalidadCredito = 0;
                    }
                    else
                    {
                        be.IDModalidadCredito = int.Parse(dr["ModalidadCreditoId"].ToString());
                    }

                     if (object.ReferenceEquals(dr["FechaPago"], DBNull.Value))
                    {
                        //be. = 0;
                    }
                    else
                    {
                        be.FechaPago = DateTime.Parse(dr["FechaPago"].ToString());
                    }

                     if (object.ReferenceEquals(dr["Credito"], DBNull.Value))
                    {
                       // be.Credito = true;
                    }
                    else
                    {
                        be.Credito = Boolean.Parse(dr["Credito"].ToString());
                    }

                     if (object.ReferenceEquals(dr["Direccion"], DBNull.Value))
                    {
                        be.Direccion = "";
                    }
                    else
                    {
                        be.Direccion = dr["Direccion"].ToString();
                    }

                     if (object.ReferenceEquals(dr["IdVendedor"], DBNull.Value))
                    {
                        be.IDVendedor = 0;
                    }
                    else
                    {
                        be.IDVendedor = int.Parse(dr["IdVendedor"].ToString());
                    }

                     if (object.ReferenceEquals(dr["MonedaId"], DBNull.Value))
                     {
                         be.CodMoneda = 0;
                     }
                     else
                     {
                         be.CodMoneda = int.Parse(dr["MonedaId"].ToString());
                     }

                     if (object.ReferenceEquals(dr["AlmacenId"], DBNull.Value))
                     {
                         be.CodAlmacen = 0;
                     }
                     else
                     {
                         be.CodAlmacen = int.Parse(dr["AlmacenId"].ToString());
                     }

                     if (object.ReferenceEquals(dr["Observacion"], DBNull.Value))
                    {
                        be.Observacion = "";
                    }
                    else
                    {
                        be.Observacion = dr["Observacion"].ToString();
                    }

                     if (object.ReferenceEquals(dr["PrecioIncluyeImpuesto"], DBNull.Value))
                    {
                        //be.PrecioIncluyeImpuesto = 0;
                    }
                    else
                    {
                        be.PrecioIncluyeImpuesto = Boolean.Parse(dr["PrecioIncluyeImpuesto"].ToString());
                    }

                     if (object.ReferenceEquals(dr["EstadoFacturacion"], DBNull.Value))
                    {
                        be.EstadoFacturacion = "";
                    }
                    else
                    {
                        be.EstadoFacturacion = dr["EstadoFacturacion"].ToString();
                    }

                     if (object.ReferenceEquals(dr["DireccionEntrega"], DBNull.Value))
                    {
                        be.DireccionEntrega = "";
                    }
                    else
                    {
                        be.DireccionEntrega = dr["DireccionEntrega"].ToString();
                    }

                }
            }

            return be;
        }