private void btnServicios_Click(object sender, EventArgs e) { try { PedidoDetalleBE oDetalle = new PedidoDetalleBE(); try { if (txtCantidadS.Value > 0 && decimal.Parse(txtServicio.Text) > 0) { var Aux = oList.Find(item => item.Producto.Id == int.Parse(cboServicios.SelectedValue.ToString()) && item.Tipo == "SERVICIO"); if (Aux == null) { var prod = oServicios.Find(item => item.Id == int.Parse(cboServicios.SelectedValue.ToString())); oDetalle.Sel = false; oDetalle.Id = 0; oDetalle.Tipo = "SERVICIO"; oDetalle.Entidad.Nombre = prod.Entidad.Nombre; oDetalle.Producto.Id = prod.Id; oDetalle.Producto.Nombre = prod.Nombre; oDetalle.Precio = decimal.Parse(txtServicio.Text); oDetalle.Cantidad = int.Parse(txtCantidadS.Text); oDetalle.Total = oDetalle.Cantidad * oDetalle.Precio; oDetalle.Reflec = string.Empty; oList.Add(oDetalle); ActualizaGrid(); LimpiarServicios(); } else { RadMessageBox.Show("No es posible agregar un servicio que ya existe en el pedido", this.Text, MessageBoxButtons.OK, RadMessageIcon.Info); } } else { RadMessageBox.Show("La cantidad a pedir y/o el precio deben ser mayor a 0", this.Text, MessageBoxButtons.OK, RadMessageIcon.Exclamation); } } catch (Exception ex) { RadMessageBox.Show("Ocurrió un error al agregar el servicio\n" + ex.Message, this.Text, MessageBoxButtons.OK, RadMessageIcon.Error); } } catch (Exception ex) { throw ex; } }
private void btnProductos_Click(object sender, EventArgs e) { PedidoDetalleBE oDetalle = new PedidoDetalleBE(); decimal Descto = 0; try { if (txtCantidadP.Value > 0 && decimal.Parse(txtPrecio.Text) > 0) { if (oReflejantes.Count > 0) { var Aux = oList.Find(item => item.Producto.Id == int.Parse(cboProductos.SelectedValue.ToString()) && item.Tipo == "PRODUCTO"); if (Aux == null) { var prod = oProductos.Find(item => item.Producto.Id == int.Parse(cboProductos.SelectedValue.ToString())); oDetalle.Sel = false; oDetalle.Id = 0; oDetalle.Tipo = "PRODUCTO"; oDetalle.Entidad.Nombre = prod.Entidad.Nombre; oDetalle.Producto.Id = prod.Producto.Id; oDetalle.Producto.Nombre = prod.Producto.Nombre; oDetalle.Accesorios.Id = int.Parse(cboAccesorios.SelectedValue.ToString()); oDetalle.Accesorios.Nombre = cboAccesorios.Text; oDetalle.Precio = decimal.Parse(txtPrecio.Text); oDetalle.Cantidad = int.Parse(txtCantidadP.Text); /* CÁLCULO DE DESCUENTOS */ if (Nacional) { /* SI ES CLIENTE VIP */ if (bool.Parse(txtVIP.Text)) { Descto = prod.Precio.AAA; } else { switch (oDetalle.Cantidad) { case int n when(n >= prod.Precio.CantidadVol && n < prod.Precio.CantidadMay): Descto = prod.Precio.Volumen; break; case int n when(n >= prod.Precio.CantidadMay): Descto = prod.Precio.Mayoreo; break; default: Descto = 0; break; } } oDetalle.Descto = (oDetalle.Cantidad * oDetalle.Precio) * Descto; oDetalle.Total = (oDetalle.Cantidad * oDetalle.Precio) - oDetalle.Descto; } string Reflejantes = string.Empty; oReflejantes.ForEach(item => { Reflejantes += item.Nombre + " / "; oDetalle.Reflejantes.Add(item); }); oDetalle.Reflec = Reflejantes.Substring(0, Reflejantes.Length - 2); oList.Add(oDetalle); ActualizaGrid(); LimpiarProductos(); } else { RadMessageBox.Show("No es posible agregar un producto que ya existe en el pedido", this.Text, MessageBoxButtons.OK, RadMessageIcon.Info); } } else { RadMessageBox.Show("No ha seleccionado reflejantes para el producto", this.Text, MessageBoxButtons.OK, RadMessageIcon.Exclamation); } } else { RadMessageBox.Show("La cantidad a pedir y/o el precio deben ser mayor a 0", this.Text, MessageBoxButtons.OK, RadMessageIcon.Exclamation); } } catch (Exception ex) { RadMessageBox.Show("Ocurrió un error al agregar el producto\n" + ex.Message, this.Text, MessageBoxButtons.OK, RadMessageIcon.Error); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { Boolean modificado = false; string codigo = this.dataGridView1.SelectedCells[0].Value.ToString(); if (origen == "frmUpPedido") { if (frmuppedido.dtdetalle.Rows.Count >= 1) { int cantidadnueva = 0; foreach (DataRow row in frmuppedido.dtdetalle.Rows) { string codigodetalle = row[0].ToString(); if (codigodetalle == codigo) { int pedidodetalle = int.Parse(row[4].ToString()); Double cantidad = Double.Parse(row[3].ToString()); int cantidad2 = int.Parse(cantidad.ToString()); row[3] = cantidad2 + 1; if (blped.updetallepedido(pedidodetalle, int.Parse(row[3].ToString()))) { MessageBox.Show( "Se agrego una cantidad detalle pedido debido a que el item que sea agregar ya existe"); modificado = true; } else { MessageBox.Show("No se pudo actualizar la cantidad, Comunicarse con el administrador del sistema"); this.Close(); } // row[3] = int.Parse(row[3].ToString()) + 1; // cantidadnueva = int.Parse(row[3].ToString()); // modificado = true; } } if (modificado == false) { int codigoProducto = pb.obteneridproducto(codigo); decimal precio = decimal.Parse(this.dataGridView1.SelectedCells[2].Value.ToString()); PedidoDetalleBE pedidoDetalleBE = new PedidoDetalleBE(); pedidoDetalleBE.idproducto = codigoProducto; pedidoDetalleBE.IdPedido = frmuppedido.ped.PKID; pedidoDetalleBE.cantidad = 1; pedidoDetalleBE.observacion ="Ingresado en la Modificacion del pedido" ; pedidoDetalleBE.total = precio; if (blped.inserdetpedido(pedidoDetalleBE)) { MessageBox.Show( "Se agrego una detalle al pedido"); } //frmpedido.dtdetalle.Rows.Add(codigo, // this.dataGridView1.SelectedCells[1].Value.ToString(), // Double.Parse(this.dataGridView1.SelectedCells[2].Value.ToString()), // 1); } } frmuppedido.actualizarDetalle(); frmuppedido.actualizarmontos(); this.Close(); } else if (origen == "frmUpComprobante") { if (frmUpComprobante.dtdetalle.Rows.Count >= 1) { int cantidadnueva = 0; foreach (DataRow row in frmUpComprobante.dtdetalle.Rows) { string codigodetalle = row[0].ToString(); if (codigodetalle == codigo) { int factdetalle = int.Parse(row[4].ToString()); Double cantidad = Double.Parse(row[3].ToString()); int cantidad2 = int.Parse(cantidad.ToString()); row[3] = cantidad2 + 1; if (facbl.updetalleFACTURA(factdetalle, int.Parse(row[3].ToString()))) { MessageBox.Show( "Se agrego una cantidad al detalle comprobate ,debido a que el item que sea agregar ya existe"); modificado = true; } else { MessageBox.Show("No se pudo actualizar la cantidad, Comunicarse con el administrador del sistema"); this.Close(); } // row[3] = int.Parse(row[3].ToString()) + 1; // cantidadnueva = int.Parse(row[3].ToString()); // modificado = true; } } if (modificado == false) { int codigoProducto = pb.obteneridproducto(codigo); decimal precio = decimal.Parse(this.dataGridView1.SelectedCells[2].Value.ToString()); FacturaDetalleBE pedidoDetalleBE = new FacturaDetalleBE(); pedidoDetalleBE.ProductoId = codigoProducto; pedidoDetalleBE.FacturaId = frmUpComprobante.ped.FacturaId; pedidoDetalleBE.Cantidad = 1; pedidoDetalleBE.Observacion = "Ingresado en la Modificacion del Comprobante de Pago"; pedidoDetalleBE.Valortotal = precio; if (facbl.insertDetalleFactura(pedidoDetalleBE)) { MessageBox.Show( "Se agrego una detalle al Comprobante de Pago"); } //frmpedido.dtdetalle.Rows.Add(codigo, // this.dataGridView1.SelectedCells[1].Value.ToString(), // Double.Parse(this.dataGridView1.SelectedCells[2].Value.ToString()), // 1); } } frmUpComprobante.actualizarDetalle(); frmUpComprobante.actualizarmontos(); this.Close(); } else if (origen == "frmPedido") { if (frmpedido.dtdetalle.Rows.Count >= 1) { foreach (DataRow row in frmpedido.dtdetalle.Rows) { String codigodetalle = row[0].ToString(); if (codigodetalle == codigo) { row[3] = int.Parse(row[3].ToString()) + 1; modificado = true; } } } if (modificado == true) { MessageBox.Show("Se Agregara una cantidad al producto"); } else { if (frmpedido.Name == "frmPedido") { frmpedido.dtdetalle.Rows.Add(codigo, this.dataGridView1.SelectedCells[1].Value.ToString(), Double.Parse(this.dataGridView1.SelectedCells[2].Value.ToString()), 1); } } frmpedido.actualizarDetalle(); frmpedido.actualizarmontos(); } else if (origen == "frmComprobanteVenta") { if (frmComprobanteVenta.dtdetalle.Rows.Count >= 1) { foreach (DataRow row in frmComprobanteVenta.dtdetalle.Rows) { String codigodetalle = row[0].ToString(); if (codigodetalle == codigo) { row[3] = int.Parse(row[3].ToString()) + 1; modificado = true; } } } if (modificado == true) { MessageBox.Show("Se Agregara una cantidad al producto"); } else { if (frmComprobanteVenta.Name == "frmComprobanteVenta") { frmComprobanteVenta.dtdetalle.Rows.Add(codigo, this.dataGridView1.SelectedCells[1].Value.ToString(), Double.Parse(this.dataGridView1.SelectedCells[2].Value.ToString()), 1); } } frmComprobanteVenta.actualizarDetalle(); frmComprobanteVenta.actualizarmontos(); } else if (origen == "frmCuotaVenta") { if (frmCuotaVenta.dtvendedor.Rows.Count >= 1) { ProductoBL pbl= new ProductoBL(); foreach (DataRow row in frmCuotaVenta.dtproducto.Rows) { String codpro = row[0].ToString(); String codvend = row[2].ToString(); string codigoreal = pbl.obteneridproducto(codigo).ToString(); if ((codigoreal == codpro) && (gstrvende == codvend)) { modificado = true; } } if (modificado) { MessageBox.Show("Producto ya agregado para el vendedor"); this.Close(); }else { int uid = pbl.obteneridproducto(codigo); frmCuotaVenta.dtproducto.Rows.Add(uid, this.dataGridView1.SelectedCells[1].Value.ToString(), gstrvende,0); frmCuotaVenta.actualizaProductos(gstrvende); this.Close(); } } } this.Close(); // this.Close(); //frmpedido.dtgDetalleProd.DataSource = null; //frmpedido.dtgDetalleProd.DataSource = frmpedido.dtDetPedido; //foreach (DataGridViewRow row in frmpedido.dtgDetalleProd.Rows) ; // double resultado = 0; //double total1 = 0; /*foreach (DataGridViewRow row in frmpedido.dtgDetalleProd.Rows) { resultado = (Convert.ToDouble(row.Cells["preciounitario"].Value) * Convert.ToDouble(row.Cells["cantidad"].Value)); row.Cells["total"].Value = resultado; total1 += Convert.ToDouble(row.Cells["total"].Value); frmpedido.txtafecto.Text = Convert.ToString(total1); frmpedido.txtimpuesto.Text = Convert.ToString(total1 * 0.18); frmpedido.txttotal.Text = Convert.ToString((total1 * 0.18) + total1); }*/ }
public Boolean insertDetalleFactura(PedidoDetalleBE be) { 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_insertdetpedido"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Clear(); command.Parameters.Add( new SqlParameter("@idproducto", be.idproducto)); command.Parameters.Add( new SqlParameter("@cantidad", be.cantidad)); command.Parameters.Add( new SqlParameter("@precio", be.total)); command.Parameters.Add( new SqlParameter("@observacion", be.observacion)); command.Parameters.Add( new SqlParameter("@IdPedido", be.IdPedido)); command.Parameters.Add( new SqlParameter("@ListaPrecioId", 1)); command.ExecuteNonQuery(); // Attempt to commit the transaction. transaction.Commit(); return true; } catch (Exception) { return false; } } return true; }
public List <PedidosBE> ENS_Cotizacion_Obtener(int IdCotizacion) { List <PedidosBE> oList = new List <PedidosBE>(); try { using (SqlConnection conn = new SqlConnection(RecuperarCadenaDeConexion("coneccionSQL"))) { conn.Open(); using (SqlCommand cmd = new SqlCommand(CONS_USP_ENS_COTIZACION_OBTENER, conn)) { cmd.Parameters.AddWithValue("@IdCotizacion", IdCotizacion); cmd.CommandType = CommandType.StoredProcedure; using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { PedidosBE obj = new PedidosBE(); /* ENCABEZADO DE COTIZACION */ obj.Id = int.Parse(reader["COT_Id"].ToString()); obj.Cliente.Id = int.Parse(reader["CLI_Id"].ToString()); obj.Cliente.Nombre = reader["CLI_Nombre"].ToString(); obj.Cliente.VIP = bool.Parse(reader["CLI_VIP"].ToString()); obj.Proyecto = reader["COT_Proyecto"].ToString(); obj.Semaforo = int.Parse(reader["COT_Semaforo"].ToString()); obj.Condiciones.Id = int.Parse(reader["CEX_Id"].ToString()); obj.Agente.Id = int.Parse(reader["AGE_Id"].ToString()); obj.Agente.Nombre = reader["AGE_Nombre"].ToString(); obj.DatosUsuario.FechaCreacion = DateTime.Parse(reader["Fecha"].ToString()); obj.Moneda.Moneda = reader["MON_Moneda"].ToString(); oList.Add(obj); } if (oList.Count > 0) { /* DETALLE DE COTIZACION */ if (reader.NextResult()) { while (reader.Read()) { PedidoDetalleBE oDetalle = new PedidoDetalleBE(); oDetalle.Id = int.Parse(reader["COD_Id"].ToString()); oDetalle.Tipo = reader["COD_Tipo"].ToString(); oDetalle.Entidad.Nombre = reader["ENT_Nombre"].ToString(); oDetalle.Producto.Id = int.Parse(reader["COD_Id_ProdServ"].ToString()); oDetalle.Producto.Nombre = reader["TPR_Nombre"].ToString(); oDetalle.Accesorios.Id = int.Parse(reader["ACC_Id"].ToString()); oDetalle.Accesorios.Nombre = reader["ACC_Nombre"].ToString(); oDetalle.Precio = decimal.Parse(reader["COD_Precio"].ToString()); oDetalle.Descto = decimal.Parse(reader["COD_Descto"].ToString()); oDetalle.Cantidad = int.Parse(reader["COD_Cantidad"].ToString()); oDetalle.Total = (oDetalle.Cantidad * oDetalle.Precio) - oDetalle.Descto; oList[0].Detalle.Add(oDetalle); } } /* REFLEJANTES DE COTIZACION */ if (oList[0].Detalle.Count > 0) { if (reader.NextResult()) { while (reader.Read()) { var aux = oList[0].Detalle.Find(item => item.Id == int.Parse(reader["COD_Id"].ToString())); if (aux != null) { aux.Reflec = reader["Tipo"].ToString(); aux.Reflejantes.Add(new Entidades.Catalogos.ReflejantesBE { Id = int.Parse(reader["COM_Id"].ToString()), Nombre = reader["Tipo"].ToString(), }); } } } } } } } } return(oList); } catch (Exception ex) { throw ex; } }
public Boolean inserdetpedido(PedidoDetalleBE be) { return pd.insertDetalleFactura(be); }