private void button2_Click(object sender, EventArgs e) { ExportWithExel rp = new ExportWithExel(); //datos del cliente //detalles fac try{ for (int i = 0; i < dgv.Rows.Count; i++) { report datos = new report(); datos.FECHA = (string)this.dgv.Rows[i].Cells[0].Value; //fecha datos.RET = (string)this.dgv.Rows[i].Cells[1].Value; //no fac datos.CODIGO = (string)this.dgv.Rows[i].Cells[2].Value; //codigo fac datos.DESCRPP = (string)this.dgv.Rows[i].Cells[3].Value; //descripcion fac datos.fax = (string)this.dgv.Rows[i].Cells[4].Value; //lote datos.PRESENTACION = (string)this.dgv.Rows[i].Cells[5].Value; //presentacion datos.CANTIDAD = (string)this.dgv.Rows[i].Cells[6].Value.ToString(); //catidad datos.PRECIOU = (string)this.dgv.Rows[i].Cells[7].Value; //costo datos.SUB = (string)this.dgv.Rows[i].Cells[8].Value; //costo total datos.ITBIS = (string)this.dgv.Rows[i].Cells[9].Value; //precio datos.PRECIOT = (string)this.dgv.Rows[i].Cells[10].Value; //precio total datos.telefono = (string)this.dgv.Rows[i].Cells[11].Value; //utilidad datos.ORDEN = ""; datos.VALID = ""; rp.Inf.Add(datos); } rp.ShowDialog(); dgv.DataSource = sql.MuestraRegsitros(); } catch (Exception loer) { MessageBox.Show("Algo Va Mal..." + loer); } }
private void button6_Click(object sender, EventArgs e) { if (con_filas == 0) { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtcliente.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtRNC.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtdireccion.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txttelefono.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } //dtalles else if (txtrets.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtvalid.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtfe.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtor.Text == "") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtfor.Text == "Forma") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (lblcant.Text == "Existencia") { MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { //generame el ret conexion.Open(); SqlCommand lopo = new SqlCommand("INSERT INTO Regimenes values('" + txtrets.Text + "')", conexion); lopo.ExecuteNonQuery(); conexion.Close(); maxregimenesesp lp = new maxregimenesesp(); lp.ShowDialog(); if (lp.DialogResult == DialogResult.OK) { txtrets.Text = lp.dgv.Rows[lp.dgv.CurrentRow.Index].Cells[0].Value.ToString(); txtvalid.Text = lp.dgv2.Rows[lp.dgv2.CurrentRow.Index].Cells[0].Value.ToString(); } //continua con la factura } catch (Exception l) { MessageBox.Show("" + l.Message); } if (con_filas != 0) { try { //llenar reistros string cmd = "INSERT INTO Fac VALUES ('" + txtfe.Text + "', '" + txtvalid.Text + "', '" + txtor.Text + "', '" + txtfor.Text + "', '" + lbltip.Text + "')"; DataSet ds = ConsultasSQL.Ejecutar(cmd); //fin llenar registro Ganancia = 0; Ganancia0 = 0; decimal precio_c; decimal precio_v; int Cant_Tomada; //llenar fac && fin llenar registro foreach (DataGridViewRow Fila in dgv.Rows) { cmd = "INSERT INTO DEfac VALUES ( '" + txtrets.Text + "','" + Fila.Cells[0].Value.ToString() + "', '" + Fila.Cells[1].Value.ToString() + "', '" + Fila.Cells[2].Value.ToString() + "', '" + Fila.Cells[3].Value.ToString() + "', '" + Fila.Cells[4].Value.ToString() + "', 'NULL', 'NULL', '" + txttotalll.Text + "' )"; ds = ConsultasSQL.Ejecutar(cmd); //Buscame algunos campos necesarios PARA EL RPORTE SqlCommand comando = new SqlCommand("SELECT * FROM Productos WHERE Codigo = @Cod", conexion); comando.Parameters.AddWithValue("@Cod", Fila.Cells[0].Value.ToString()); conexion.Open(); SqlDataReader regsitro = comando.ExecuteReader(); if (regsitro.Read()) { LOTEee = regsitro["Lote"].ToString(); lblpreventa.Text = regsitro["Precio_Compra"].ToString(); } conexion.Close(); //primer calculo de cantidad por precio precio_c = Convert.ToDecimal(lblpreventa.Text); Cant_Tomada = Convert.ToInt32(Fila.Cells[1].Value.ToString()); Ganancia0 = precio_c * Cant_Tomada;//ya tengo mi ganancia 0 //calcular utilidad precio_c = Convert.ToDecimal(lblpreventa.Text); precio_v = Convert.ToDecimal(Fila.Cells[5].Value.ToString()); if (precio_v < Ganancia0) { Ganancia = 0; } else if (precio_v == Ganancia0) { Ganancia = 0; } else { Ganancia = precio_v - Ganancia0; } //actualiza cantidad double exi; double to; int cant; exi = Convert.ToInt32(lblcant.Text); cant = Convert.ToInt32(Fila.Cells[1].Value.ToString()); to = exi - cant; conexion.Open(); SqlCommand raro = new SqlCommand(@"update Productos set Existencia = '" + to.ToString() + "' where Codigo = @toma ", conexion); raro.CommandType = CommandType.Text; raro.Parameters.AddWithValue(@"toma", Fila.Cells[0].Value.ToString()); raro.ExecuteNonQuery(); to = 0; conexion.Close(); //actualizar cantidad //registrame la factura conexion.Open(); //Fecha_Factura //Num_Fac //Codigo_Producto //Descripcion //Lote_Producto //presentacion //Cant_Tomada //Costo //CostoTotal //Precio //Precio_Total SqlCommand comand = new SqlCommand("INSERT INTO Registros VALUES ('" + fechaa4.ToString() + "', '" + txtrets.Text + "', '" + Fila.Cells[0].Value.ToString() + "', '" + Fila.Cells[3].Value.ToString() + "', '" + LOTEee.ToString() + "', '" + Fila.Cells[2].Value.ToString() + "' ,'" + Fila.Cells[1].Value.ToString() + "', '" + lblpreventa.Text + "', '" + Ganancia0.ToString("N2", new CultureInfo("en-US")) + "', '" + Fila.Cells[4].Value.ToString() + "', '" + Fila.Cells[5].Value.ToString() + "', '" + Ganancia.ToString("N2", new CultureInfo("en-US")) + "' )", conexion); comand.ExecuteNonQuery(); conexion.Close(); } //calculame la Utilidad //continua ReporteRegimenesESP rp = new ReporteRegimenesESP(); //detalles fac for (int i = 0; i < dgv.Rows.Count; i++) { report datos = new report(); datos.Cliente = txtcliente.Text; datos.RNC = txtRNC.Text; datos.direccion = txtdireccion.Text; datos.telefono = txttelefono.Text; //datos del tipo fac datos.RET = txtrets.Text; datos.VALID = txtvalid.Text; datos.FECHA = txtfe.Text; datos.ORDEN = txtor.Text; datos.FORMA = txtfor.Text; datos.CODIGO = (string)this.dgv.Rows[i].Cells[0].Value; datos.CANTIDAD = (string)this.dgv.Rows[i].Cells[1].Value; datos.PRESENTACION = (string)this.dgv.Rows[i].Cells[2].Value; datos.DESCRPP = (string)this.dgv.Rows[i].Cells[3].Value; datos.PRECIOU = (string)this.dgv.Rows[i].Cells[4].Value; datos.PRECIOT = txttotalll.Text; rp.DatosRE.Add(datos); } rp.ShowDialog(); Nuevo(); } catch (Exception error) { MessageBox.Show("Algo Va mal... " + error); } } } }