private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { dataGridView1.ClearSelection(); string date; if (e.KeyChar == 13) { DataTable dt = new DataTable(); date = textBox1.Text; dt = USER.BuscarUsuario(date); try { dataGridView1.Rows.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { dataGridView1.Rows.Add(dt.Rows[i][0]); dataGridView1.Rows[i].Cells[0].Value = dt.Rows[i][0].ToString(); dataGridView1.Rows[i].Cells[1].Value = dt.Rows[i][1].ToString(); dataGridView1.Rows[i].Cells[2].Value = dt.Rows[i][2].ToString(); dataGridView1.Rows[i].Cells[3].Value = dt.Rows[i][3].ToString(); dataGridView1.Rows[i].Cells[4].Value = dt.Rows[i][4].ToString(); dataGridView1.Rows[i].Cells[5].Value = dt.Rows[i][5].ToString(); dataGridView1.Rows[i].Cells[6].Value = dt.Rows[i][6].ToString(); dataGridView1.Rows[i].Cells[7].Value = dt.Rows[i][7].ToString(); } dataGridView1.ClearSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Imprimir(object sender, PrintPageEventArgs e) { DataGridViewRow dgvRow = dataGridView1.CurrentRow; Font font = new Font("Arial", 10); Font font1 = new Font("Arial", 10, FontStyle.Bold); Font font2 = new Font("Arial", 20, FontStyle.Bold); int ancho = 1500; int y = 100; int x = 50; Image img = Image.FromFile("img.png"); e.Graphics.DrawImage(img, new Rectangle(x, y += 20, 200, 70)); DataTable dt = new DataTable(); String ruc_empresa = Program.ruc_empresa, money = rbnSoles.Checked == true ? "SOLES" : "DOLARES"; dt = USER.BuscarUsuario(ruc_empresa); for (int i = 0; i < dt.Rows.Count; i++) { dataGridView1.Rows.Add(dt.Rows[i][0]); e.Graphics.DrawString(dt.Rows[i][1].ToString(), font1, Brushes.Black, new RectangleF(x, y += 80, ancho, 20)); // nombre de la empresa PROCOMP BUSINESS e.Graphics.DrawString(dt.Rows[i][4].ToString(), font, Brushes.Black, new RectangleF(x, y += 20, ancho, 20)); // DIRECCION DE LA EMPRESA e.Graphics.DrawString(dt.Rows[i][2].ToString(), font, Brushes.Black, new RectangleF(x, y += 20, ancho, 20)); } int a = 100; e.Graphics.DrawString("RUC " + ruc_empresa, font2, Brushes.Black, new RectangleF(x + 700, a += 30, ancho, 30)); // ruc de la empresa e.Graphics.DrawString(" " + cbxTipoDocumento.Text, font2, Brushes.Black, new RectangleF(x + 700, a += 30, ancho, 30)); // tipo de comprobante e.Graphics.DrawString(" ELECTRONICA", font2, Brushes.Black, new RectangleF(x + 700, a += 30, ancho, 30)); e.Graphics.DrawString(" " + lblSerie.Text + " - " + numero, font2, Brushes.Black, new RectangleF(x + 700, a += 30, ancho, 30)); // serie y numero //------------------------------------------------------- int c = y; e.Graphics.DrawString("CLIENTE", font1, Brushes.Black, new RectangleF(x, y += 40, ancho, 20)); e.Graphics.DrawString("RUC ", font1, Brushes.Black, new RectangleF(x, y += 20, ancho, 20)); e.Graphics.DrawString("DENOMINACION", font1, Brushes.Black, new RectangleF(x, y += 20, ancho, 20)); e.Graphics.DrawString("DIRECCION ", font1, Brushes.Black, new RectangleF(x, y += 20, ancho, 20)); e.Graphics.DrawString(": " + txtRucCliente.Text, font, Brushes.Black, new RectangleF(x + 150, c += 60, ancho, 20)); // ruc del cliente e.Graphics.DrawString(": " + txtNombreCliente.Text, font, Brushes.Black, new RectangleF(x + 150, c += 20, ancho, 20)); // nombre del cliente e.Graphics.DrawString(": " + txtDireccionCliente.Text, font, Brushes.Black, new RectangleF(x + 150, c += 20, 500, 50)); // direccion del cliente int b = a; e.Graphics.DrawString("FECHA EMISION ", font1, Brushes.Black, new RectangleF(x + 700, a += 50, ancho, 20)); //fecha de eemision e.Graphics.DrawString("FECHA DE VENC. ", font1, Brushes.Black, new RectangleF(x + 700, a += 20, ancho, 20)); // fecha de pago e.Graphics.DrawString("MONEDA ", font1, Brushes.Black, new RectangleF(x + 700, a += 20, ancho, 20)); // tipo de moneda e.Graphics.DrawString(": " + Convert.ToString(fechaEmision), font, Brushes.Black, new RectangleF(x + 850, b += 50, ancho, 20)); //fecha de eemision e.Graphics.DrawString(": " + Convert.ToString(dtpFechaPago.Value), font, Brushes.Black, new RectangleF(x + 850, b += 20, ancho, 20)); // fecha de pago e.Graphics.DrawString(": " + money, font, Brushes.Black, new RectangleF(x + 850, b += 20, ancho, 20)); // tipo de moneda //----------------------------------------------------------------- int d = y, f = y, g = y, h = y, k = y, p = y; e.Graphics.DrawString("CANT.", font1, Brushes.Black, new RectangleF(x, y += 80, ancho, 20)); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString(Convert.ToString(dataGridView1.Rows[i].Cells[3].Value), font, Brushes.Black, new RectangleF(x + 10, y += 20, ancho, 20)); } e.Graphics.DrawString(" UM ", font1, Brushes.Black, new RectangleF(x + 80, d += 80, ancho, 20)); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString(Convert.ToString(dataGridView1.Rows[i].Cells[5].Value), font, Brushes.Black, new RectangleF(x + 80, d += 20, ancho, 20)); } e.Graphics.DrawString(" COD. ", font1, Brushes.Black, new RectangleF(x + 140, f += 80, 200, 20)); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString(Convert.ToString(dataGridView1.Rows[i].Cells[2].Value), font, Brushes.Black, new RectangleF(x + 140, f += 20, ancho, 20)); } e.Graphics.DrawString(" DESCRIPCION ", font1, Brushes.Black, new RectangleF(x + 280, g += 80, ancho, 20)); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString(Convert.ToString(dataGridView1.Rows[i].Cells[4].Value), font, Brushes.Black, new RectangleF(x + 280, g += 20, ancho, 20)); } e.Graphics.DrawString(" V/U ", font1, Brushes.Black, new RectangleF(x + 750, h += 80, ancho, 20)); for (int i = 0; i < dataGridView1.Rows.Count - 2; i++) { e.Graphics.DrawString(Convert.ToString(Convert.ToDecimal(dataGridView1.Rows[i].Cells[7].Value)), font, Brushes.Black, new RectangleF(x + 750, h += 20, ancho, 20)); } e.Graphics.DrawString(" P/U ", font1, Brushes.Black, new RectangleF(x + 850, k += 80, ancho, 20)); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString(Convert.ToString(dataGridView1.Rows[i].Cells[6].Value), font, Brushes.Black, new RectangleF(x + 850, k += 20, ancho, 20)); } e.Graphics.DrawString("IMPORTE", font1, Brushes.Black, new RectangleF(x + 950, p += 80, ancho, 20)); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString(Convert.ToString(dataGridView1.Rows[i].Cells[9].Value), font, Brushes.Black, new RectangleF(x + 950, p += 20, ancho, 20)); } e.Graphics.DrawString("GRAVADA S/ " + txtSubTotalVentas.Text, font1, Brushes.Black, new RectangleF(x + 750, y += 50, ancho, 20)); // sub total e.Graphics.DrawString("IGV 18.00% S/ " + txtIGV.Text, font1, Brushes.Black, new RectangleF(x + 750, y += 20, ancho, 20)); // igv e.Graphics.DrawString("TOTAL S/ " + txtImporteTotal.Text, font1, Brushes.Black, new RectangleF(x + 750, y += 20, ancho, 20)); // total e.Graphics.DrawString("-----GRACIAS POR SU PREFERENCIA------", font, Brushes.Black, new RectangleF(x + 200, y += 100, ancho, 20)); Limpiar1(); }