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();
        }
Exemple #2
0
 public Boolean insertPedido(PedidoBE be , DataTable dt)
 {
     return pd.insertPedidoDetalle(be, dt);
 }
        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);

                }
            }
        }
        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;

            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);

                 }
        }
        public Boolean insertPedidoDetalle(PedidoBE be,DataTable dt)
        {
            String con = app.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.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.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);
                    }
                }
            }
        }
        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["EmpleadoId"], DBNull.Value))
                    {
                        be.IDVendedor = 0;
                    }
                    else
                    {
                        be.IDVendedor = int.Parse(dr["EmpleadoId"].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;
        }