private void txt_Nombre_SelectedValueChanged(object sender, EventArgs e) { int b = 0; if (txt_Nombre.SelectedIndex > 0) { Int32 CodArt = Convert.ToInt32(txt_Nombre.SelectedValue); cArticulo art = new Clases.cArticulo(); DataTable trdo = art.GetArticuloxCodArt(CodArt); if (trdo.Rows.Count > 0) { if (trdo.Rows[0]["CodArticulo"].ToString() != "") { b = 1; txtCodigo.Text = trdo.Rows[0]["CodArticulo"].ToString(); txt_Nombre.SelectedValue = txtCodigo.Text; txt_CodigoBarra.Text = trdo.Rows[0]["CodigoBarra"].ToString(); txt_Codigo.Text = trdo.Rows[0]["Codigo"].ToString(); txt_Stock.Text = trdo.Rows[0]["Stock"].ToString(); } } if (b == 1) { PuedeAgregar = false; txtCantidad.Text = ""; txtCantidad.Focus(); } } }
private void txt_Nombre_KeyPress(object sender, KeyPressEventArgs e) { int Operacion = 0; if (CmbTipoOperacion.SelectedIndex > 0) { Operacion = Convert.ToInt32(CmbTipoOperacion.SelectedValue); } if (e.KeyChar == Convert.ToChar(Keys.Enter)) { PuedeAgregar = true; if (txt_Nombre.SelectedIndex > 0) { Int32 CodArt = Convert.ToInt32(txt_Nombre.SelectedValue); cArticulo art = new Clases.cArticulo(); DataTable trdo = art.GetArticuloxCodArt(CodArt); if (trdo.Rows.Count > 0) { txtCodigo.Text = trdo.Rows[0]["CodArticulo"].ToString(); //txt_Nombre.Text = trdo.Rows[0]["Nombre"].ToString(); txt_CodigoBarra.Text = trdo.Rows[0]["CodigoBarra"].ToString(); // txt_Codigo.Text = trdo.Rows[0]["Codigo"].ToString(); txt_Stock.Text = trdo.Rows[0]["Stock"].ToString(); if (Operacion == 1) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (Operacion == 2) { txtPrecio.Text = trdo.Rows[0]["PrecioTarjeta"].ToString(); Double Precio = Convert.ToDouble(trdo.Rows[0]["PrecioTarjeta"].ToString()); Precio = Precio - 0.10 * Precio; txtDescuento.Text = Precio.ToString(); } if (Operacion == 3) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (txtPrecio.Text != "") { Double Precio = Convert.ToDouble(txtPrecio.Text); Precio = Math.Round(Precio, 0); txtPrecio.Text = Precio.ToString(); } if (txtDescuento.Text != "") { Double Precio = Convert.ToDouble(txtDescuento.Text); Precio = Math.Round(Precio, 0); txtDescuento.Text = Precio.ToString(); } txtCantidad.Focus(); } } } }
private void CargarGrilla(string Nombre, string CodigoBarra) { cArticulo art = new Clases.cArticulo(); DataTable trdo = art.GetArticulo(Nombre, CodigoBarra); Grilla.DataSource = trdo; Grilla.Columns[0].Visible = false; Grilla.Columns[1].Width = 270; }
private void CargarGrilla(string Nombre, string CodigoBarra, string Codigo) { string Tabla = ""; if (chkLibreria.Checked == true) { Tabla = "Articulo"; } else { Tabla = "Juguete"; } Int32?CodMarca = null; if (cmbMarca.SelectedIndex > 0) { CodMarca = Convert.ToInt32(cmbMarca.SelectedValue); } cFunciones fun = new cFunciones(); cArticulo art = new Clases.cArticulo(); cJuguete jug = new cJuguete(); DataTable trdo = new DataTable(); if (Tabla == "Articulo") { trdo = art.GetDetalleArticulo(Nombre, CodigoBarra, Codigo, Tabla); } if (Tabla == "Juguete") { trdo = jug.GetDetalleArticulo(Nombre, CodigoBarra, Codigo, CodMarca); } trdo = fun.TablaaMiles(trdo, "PrecioEfectivo"); trdo = fun.TablaaMiles(trdo, "PrecioTarjeta"); trdo = fun.TablaaMiles(trdo, "Descuento"); Grilla.DataSource = trdo; Grilla.Columns[0].Visible = false; Grilla.Columns[5].Visible = false; Grilla.Columns[3].Width = 410; Grilla.Columns[6].HeaderText = "Tarjeta"; Grilla.Columns[8].HeaderText = "Efectivo/Deb"; DataGridViewCellStyle style = new DataGridViewCellStyle(); style.Font = new Font(Grilla.Font, FontStyle.Bold); Grilla.Columns[8].DefaultCellStyle = style; //Grilla.Rows[8].DefaultCellStyle = style; }
private void Buscar() { if (txtArticulo.Text == "") { Mensaje("Debe ingresar un art{iculo"); return; } string Nombre = txtArticulo.Text; cArticulo art = new Clases.cArticulo(); DataTable trdo = art.GetArticuloxNombre(Nombre); trdo = fun.TablaaMiles(trdo, "PorEfe"); trdo = fun.TablaaMiles(trdo, "PorTar"); trdo = fun.TablaaMiles(trdo, "Costo"); trdo = fun.TablaaMiles(trdo, "PrecioEfectivo"); trdo = fun.TablaaMiles(trdo, "PrecioTarjeta"); Grilla.DataSource = trdo; string Ancho = "0;0;0;40;10;10;10;10;10;10"; fun.AnchoColumnas(Grilla, Ancho); }
private void btnGrabar_Click(object sender, EventArgs e) { if (txtDescripcion.Text == "") { Mensaje("Ingresar descripcion"); return; } string Nombre = txtDescripcion.Text; Double? Costo = null; Double? Precio = null; int? CodColor = null; string Ruta = txtRuta.Text; int? CodTipoPrenda = null; string CodigoBarra = null; cArticulo art = new Clases.cArticulo(); cCodigoBarra objCodBarra = new cCodigoBarra(); if (txtPrecioVenta.Text != "") { Precio = Convert.ToDouble(txtPrecioVenta.Text); } if (cmbColor.SelectedIndex > 0) { CodColor = Convert.ToInt32(cmbColor.SelectedValue); } if (CmbTipoPrenda.SelectedIndex > 0) { CodTipoPrenda = Convert.ToInt32(CmbTipoPrenda.SelectedValue); } CodigoBarra = txtCodigoBarra.Text; art.Insertar(Nombre, Costo, Precio, CodColor, Ruta, CodTipoPrenda, CodigoBarra); if (txtCodigoBarra.Text != "") { objCodBarra.Insertar(ImagenCodigo, 1, 2); } Mensaje("Datos grabados correctamente"); Limpiar(); }
private void BuscarLibreriaxCodigo(string Codigo) { int b = 0; int Operacion = 0; if (CmbTipoOperacion.SelectedIndex > 0) { Operacion = Convert.ToInt32(CmbTipoOperacion.SelectedValue); } cArticulo art = new Clases.cArticulo(); DataTable trdo = art.GetArticuloxCodigo(Codigo); if (trdo.Rows.Count > 0) { b = 1; txtCodigo.Text = trdo.Rows[0]["CodArticulo"].ToString(); txt_Nombre.SelectedValue = trdo.Rows[0]["CodArticulo"].ToString(); txt_CodigoBarra.Text = trdo.Rows[0]["CodigoBarra"].ToString(); txt_Nombre.Text = trdo.Rows[0]["Nombre"].ToString(); txt_Stock.Text = trdo.Rows[0]["Stock"].ToString(); if (Operacion == 1) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (Operacion == 2) { txtPrecio.Text = trdo.Rows[0]["PrecioTarjeta"].ToString(); Double Precio = Convert.ToDouble(trdo.Rows[0]["PrecioTarjeta"].ToString()); Precio = Precio - 0.10 * Precio; txtDescuento.Text = Precio.ToString(); } if (Operacion == 3) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (txtPrecio.Text != "") { Double Precio = Convert.ToDouble(txtPrecio.Text); Precio = Math.Round(Precio, 0); txtPrecio.Text = Precio.ToString(); } if (txtDescuento.Text != "") { Double Precio = Convert.ToDouble(txtDescuento.Text); Precio = Math.Round(Precio, 0); txtDescuento.Text = Precio.ToString(); } if (b == 1) { PuedeAgregar = true; txtCantidad.Focus(); } } else { txtCodigo.Text = ""; // if (txt_Nombre.Items.Count > 0) // txt_Nombre.SelectedIndex = 0; txt_CodigoBarra.Text = ""; txt_Nombre.Text = ""; txt_Stock.Text = ""; txtDescuento.Text = ""; txtPrecio.Text = ""; //txtCantidad.Text = ""; } }
private void txt_Nombre_SelectedIndexChanged(object sender, EventArgs e) { Boolean EsJuguete = false; if (radioJugueteria.Checked == true) { EsJuguete = true; } int b = 0; int Operacion = 0; if (CmbTipoOperacion.SelectedIndex > 0) { Operacion = Convert.ToInt32(CmbTipoOperacion.SelectedValue); } if (Cargando == false) { if (EsJuguete == false) { if (txt_Nombre.SelectedIndex > 0) { Int32 CodArt = Convert.ToInt32(txt_Nombre.SelectedValue); cArticulo art = new Clases.cArticulo(); DataTable trdo = art.GetArticuloxCodArt(CodArt); if (trdo.Rows.Count > 0) { b = 1; radioLibreria.Checked = true; radioJugueteria.Checked = false; txtCodigo.Text = trdo.Rows[0]["CodArticulo"].ToString(); //txt_Nombre.Text = trdo.Rows[0]["Nombre"].ToString(); txt_CodigoBarra.Text = trdo.Rows[0]["CodigoBarra"].ToString(); // txt_Codigo.Text = trdo.Rows[0]["Codigo"].ToString(); txt_Stock.Text = trdo.Rows[0]["Stock"].ToString(); if (Operacion == 1) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (Operacion == 2) { txtPrecio.Text = trdo.Rows[0]["PrecioTarjeta"].ToString(); Double Precio = Convert.ToDouble(trdo.Rows[0]["PrecioTarjeta"].ToString()); Precio = Precio - 0.10 * Precio; txtDescuento.Text = Precio.ToString(); } if (Operacion == 3) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (txtPrecio.Text != "") { Double Precio = Convert.ToDouble(txtPrecio.Text); Precio = Math.Round(Precio, 0); txtPrecio.Text = Precio.ToString(); } if (txtDescuento.Text != "") { Double Precio = Convert.ToDouble(txtDescuento.Text); Precio = Math.Round(Precio, 0); txtDescuento.Text = Precio.ToString(); } PuedeAgregar = true; txtCantidad.Focus(); } } } if (EsJuguete == true) { //busco juguete radioLibreria.Checked = false; radioJugueteria.Checked = true; Int32 CodArt = Convert.ToInt32(txt_Nombre.SelectedValue); cJuguete jug = new cJuguete(); DataTable trdo = jug.GetArticuloxCodArt(CodArt); if (trdo.Rows.Count > 0) { txtCodigo.Text = trdo.Rows[0]["CodArticulo"].ToString(); //txt_Nombre.Text = trdo.Rows[0]["Nombre"].ToString(); txt_CodigoBarra.Text = trdo.Rows[0]["CodigoBarra"].ToString(); // txt_Codigo.Text = trdo.Rows[0]["Codigo"].ToString(); txt_Stock.Text = trdo.Rows[0]["Stock"].ToString(); if (Operacion == 1) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (Operacion == 2) { txtPrecio.Text = trdo.Rows[0]["PrecioTarjeta"].ToString(); Double Precio = Convert.ToDouble(trdo.Rows[0]["PrecioTarjeta"].ToString()); Precio = Precio - 0.10 * Precio; txtDescuento.Text = Precio.ToString(); } if (Operacion == 3) { txtPrecio.Text = trdo.Rows[0]["PrecioEfectivo"].ToString(); } if (txtPrecio.Text != "") { Double Precio = Convert.ToDouble(txtPrecio.Text); Precio = Math.Round(Precio, 0); txtPrecio.Text = Precio.ToString(); } if (txtDescuento.Text != "") { Double Precio = Convert.ToDouble(txtDescuento.Text); Precio = Math.Round(Precio, 0); txtDescuento.Text = Precio.ToString(); } PuedeAgregar = true; txtCantidad.Focus(); } } } }
private void Grabar() { int TipoOp = Convert.ToInt32(CmbTipoOperacion.SelectedValue); SqlTransaction Transaccion; SqlConnection con = new SqlConnection(cConexion.GetConexion()); con.Open(); Transaccion = con.BeginTransaction(); DateTime Fecha = Convert.ToDateTime(txtFecha.Text); Int32? CodCliente = null; Double ImporteEfectivo = 0; Double ImporteTarjeta = 0; cCliente cli = new cCliente(); Int32 CodVenta = 0; Int32? CodTarjeta = null; if (TipoOp == 2) { ImporteTarjeta = Convert.ToDouble(txtTotal.Text); CodTarjeta = Convert.ToInt32(CmbTarjeta.SelectedValue); } if (TipoOp == 1) { ImporteEfectivo = Convert.ToDouble(txtTotal.Text); } if (TipoOp == 3) { ImporteEfectivo = Convert.ToDouble(txtTotal.Text); } Int32 CodArticulo = 0; Double Precio = 0; Int32 Cantidad = 0; Double Subtotal = 0; Double Descuento = 0; Double PorDescuento = 0; Double TotalConDescuento = 0; int Libreria = 0; if (txtPordescuento.Text != "") { PorDescuento = Convert.ToDouble(txtPordescuento.Text); } if (txtTotalDescuento.Text != "") { Descuento = Convert.ToDouble(txtTotalDescuento.Text); } if (txtTotalConDescuento.Text != "") { TotalConDescuento = Convert.ToDouble(txtTotalConDescuento.Text); } cArticulo objArt = new Clases.cArticulo(); string Cupon = txtCupon.Text; // string Col = "CodArticulo;Nombre;Precio;Cantidad;Subtotal"; cVenta venta = new cVenta(); cJuguete jug = new Clases.cJuguete(); try { CodVenta = venta.InsertarVenta(con, Transaccion, ImporteEfectivo, Fecha, ImporteEfectivo, ImporteTarjeta , CodTarjeta, CodCliente, Cupon, Descuento, PorDescuento, TotalConDescuento); for (int i = 0; i < tbVenta.Rows.Count; i++) { CodArticulo = Convert.ToInt32(tbVenta.Rows[i]["CodArticulo"].ToString()); Precio = Convert.ToDouble(tbVenta.Rows[i]["Precio"].ToString()); Cantidad = Convert.ToInt32(tbVenta.Rows[i]["Cantidad"].ToString()); Subtotal = Convert.ToDouble(tbVenta.Rows[i]["Subtotal"].ToString()); Libreria = Convert.ToInt32(tbVenta.Rows[i]["Libreria"].ToString()); if (Libreria == 1) { venta.InsertarDetalleVenta(con, Transaccion, CodVenta, Cantidad, Precio, CodArticulo, Subtotal); objArt.ActualizarStockResta(con, Transaccion, CodArticulo, Cantidad); } else { venta.InsertarDetalleVentaJuguete(con, Transaccion, CodVenta, Cantidad, Precio, CodArticulo, Subtotal); jug.ActualizarStockResta(con, Transaccion, CodArticulo, Cantidad); } } Transaccion.Commit(); con.Close(); Mensaje("Datos grabados correctamente"); Limpiar(); } catch (Exception exa) { Transaccion.Rollback(); con.Close(); Mensaje("Hubo un error en el proceso de grabacion"); Mensaje(exa.Message); } }
private void GrabarPresupuesto() { SqlTransaction Transaccion; SqlConnection con = new SqlConnection(cConexion.GetConexion()); con.Open(); Transaccion = con.BeginTransaction(); DateTime Fecha = Convert.ToDateTime(txtFechaAltaOrden.Text); Int32? CodCliente = null; cCliente cli = new cCliente(); Int32 CodPresupuesto = 0; Int32 CodArticulo = 0; Double Precio = 0; Int32 Cantidad = 0; Double Subtotal = 0; Double Total = 0; if (txtTotal.Text != "") { Total = Convert.ToDouble(txtTotal.Text); } cArticulo objArt = new Clases.cArticulo(); string Cupon = txtCupon.Text; Double Descuento = 0; Double PorDescuento = 0; Double TotalConDescuento = 0; string FormaPago = ""; if (txtPordescuento.Text != "") { PorDescuento = Convert.ToDouble(txtPordescuento.Text); } if (txtTotalDescuento.Text != "") { Descuento = Convert.ToDouble(txtTotalDescuento.Text); } if (txtTotalConDescuento.Text != "") { TotalConDescuento = Convert.ToDouble(txtTotalConDescuento.Text); } // string Col = "CodArticulo;Nombre;Precio;Cantidad;Subtotal"; cPresupuesto pre = new cPresupuesto(); try { if (txtNombre.Text != "") { if (txtCodCliente.Text == "") { CodCliente = GrabarCliente(con, Transaccion); } else { ModificarCliente(con, Transaccion); CodCliente = Convert.ToInt32(txtCodCliente.Text); } } FormaPago = GetFormaPago(); CodPresupuesto = pre.InsertarPresupuesto(con, Transaccion, Total, Fecha , CodCliente, Descuento, PorDescuento, TotalConDescuento, FormaPago); Principal.CodigoSenia = CodPresupuesto.ToString(); string NroPresupuesto = "0001-" + GetNroPresupueto(CodPresupuesto.ToString()); pre.ActualizarNroPresupuesto(con, Transaccion, CodPresupuesto, NroPresupuesto); for (int i = 0; i < tbVenta.Rows.Count; i++) { CodArticulo = Convert.ToInt32(tbVenta.Rows[i]["CodArticulo"].ToString()); Precio = Convert.ToDouble(tbVenta.Rows[i]["Precio"].ToString()); Cantidad = Convert.ToInt32(tbVenta.Rows[i]["Cantidad"].ToString()); Subtotal = Convert.ToDouble(tbVenta.Rows[i]["Subtotal"].ToString()); pre.InsertarDetalle(con, Transaccion, CodPresupuesto, Cantidad, Precio, CodArticulo, Subtotal); } Transaccion.Commit(); con.Close(); Mensaje("Datos grabados correctamente"); Limpiar(); FrmReporte frm = new SistemaFact.FrmReporte(); frm.Show(); // this.GetJugadorxCodigoTableAdapter.Fill(this.DataSet1.GetJugadorxCodigo, Codigo); } catch (Exception exa) { Transaccion.Rollback(); con.Close(); Mensaje("Hubo un error en el proceso de grabacion"); Mensaje(exa.Message); } }
private void Leer() { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string str = ""; int rCnt = 0; int cCnt = 0; int rw = 0; int cl = 0; string Ruta = txt_Ruta.Text; // string Ruta = "C:\\SISTEMA\\LISTA.xlsx"; // string Ruta = "D:\\AG\\LISTA.xlsx"; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(Ruta, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; rw = range.Rows.Count; cl = range.Columns.Count; string Codigo = ""; Int32? Id = 0; int Stock = 0; Double PrecioVenta = 0; string Nombre = ""; string Tipo = ""; Int32 CodTipo = 0; cTipo objTipo = new cTipo(); cJoya joya = new Clases.cJoya(); Double? Costo = null; cArticulo Articulo = new Clases.cArticulo(); for (rCnt = 2; rCnt <= rw; rCnt++) { for (cCnt = 1; cCnt <= cl; cCnt++) { txtProceso.Text = rCnt.ToString(); switch (cCnt) { case 1: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Id = (Int32)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } break; case 2: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Nombre = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Nombre = null; } break; case 3: Tipo = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // string[] vec = tip.Split(); // Tipo = vec[0]; break; case 5: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { //Codigo Codigo = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // string[] vec = Cod.Split(); ; //Codigo = vec[0]; } break; case 6: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Stock = (Int32)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Stock = 0; } break; case 9: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { PrecioVenta = (Double)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { PrecioVenta = 0; } break; } } Nombre = Nombre.Replace("'", ""); CodTipo = objTipo.GetCodxNombre(Tipo); if (CodTipo == -1) { if (Tipo != "") { CodTipo = objTipo.Insertar(Tipo); } } if (joya.Existexid(Convert.ToInt32(Id)) == false) { joya.Insertar(Nombre, CodTipo, Convert.ToInt32(Id), Stock, PrecioVenta, Codigo); } } string msj = "Filas recorridos " + rCnt.ToString(); MessageBox.Show(msj); xlWorkBook.Close(true, null, null); xlApp.Quit(); // Marshal.ReleaseComObject(xlWorkSheet); // Marshal.ReleaseComObject(xlWorkBook); // Marshal.ReleaseComObject(xlApp); }
private void LeerVendedores() { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string str = ""; int rCnt = 0; int cCnt = 0; int rw = 0; int cl = 0; string Ruta = txt_Ruta.Text; // string Ruta = "C:\\SISTEMA\\LISTA.xlsx"; // string Ruta = "D:\\AG\\LISTA.xlsx"; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(Ruta, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; rw = range.Rows.Count; cl = range.Columns.Count; string NroDocumento = ""; string Nombre = ""; string Apellido = ""; Double Telefono = 0; string Direccion = ""; string Ciudad = ""; string Provincia = ""; Int32 CodProvincia = 0; Int32 CodCiudad = 0; cProvincia objProvincia = new cProvincia(); cCiudad objCiudad = new cCiudad(); cVendedor vend = new cVendedor(); string Codigo = ""; Int32? Id = 0; cArticulo Articulo = new Clases.cArticulo(); for (rCnt = 2; rCnt <= rw; rCnt++) { for (cCnt = 1; cCnt <= cl; cCnt++) { txtProceso.Text = rCnt.ToString(); switch (cCnt) { case 1: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Id = (Int32)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } break; case 2: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { NroDocumento = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // NroDocumento = NroDocumento.Replace (".",""); } else { NroDocumento = ""; } break; case 3: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Nombre = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Nombre = ""; } // string[] vec = tip.Split(); // Tipo = vec[0]; break; case 4: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { //Codigo Apellido = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // string[] vec = Cod.Split(); ; //Codigo = vec[0]; } else { Apellido = ""; } break; case 8: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Direccion = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Direccion = ""; } break; case 9: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Ciudad = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Ciudad = ""; } break; case 10: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Provincia = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Provincia = ""; } break; case 22: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Telefono = (Double)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Telefono = 0; } break; } } Nombre = Nombre.Replace("'", ""); CodProvincia = objProvincia.GetCodxNombre(Provincia); if (CodProvincia == -1) { if (Provincia != "") { CodProvincia = objProvincia.Insertar(Provincia); } } CodCiudad = objCiudad.GetCodxNombre(Ciudad); if (CodCiudad == -1) { if (Ciudad.Trim() != "") { CodCiudad = objCiudad.Insertar(Ciudad, CodProvincia); } } cVendedor ven = new cVendedor(); if (ven.Existe(NroDocumento) == false) { ven.Insertar(NroDocumento, Apellido, Nombre, Telefono.ToString(), CodCiudad, Direccion); } } string msj = "Filas recorridos " + rCnt.ToString(); MessageBox.Show(msj); xlWorkBook.Close(true, null, null); xlApp.Quit(); // Marshal.ReleaseComObject(xlWorkSheet); // Marshal.ReleaseComObject(xlWorkBook); // Marshal.ReleaseComObject(xlApp); }
private void Leer() { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string str = ""; int rCnt = 0; int cCnt = 0; int rw = 0; int cl = 0; string Ruta = txt_Ruta.Text; // string Ruta = "C:\\SISTEMA\\LISTA.xlsx"; // string Ruta = "D:\\AG\\LISTA.xlsx"; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(Ruta, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; rw = range.Rows.Count; cl = range.Columns.Count; Int32? Codigo = null; string Codigobarra = null; Double? Precio = null; string Nombre = ""; Double? Costo = null; cArticulo Articulo = new Clases.cArticulo(); for (rCnt = 2; rCnt <= rw; rCnt++) { for (cCnt = 1; cCnt <= cl; cCnt++) { txtProceso.Text = rCnt.ToString(); switch (cCnt) { case 1: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Codigo = (Int32)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Codigo = null; } break; case 2: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Codigobarra = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Codigobarra = null; } break; case 3: Nombre = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; break; case 6: if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null) { Costo = (Double)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; } else { Costo = null; } break; } // str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // MessageBox.Show(str); } Articulo.InsertarArticulo(Codigo.ToString(), Codigobarra, Nombre, Costo); } string msj = "Filas recorridos " + rCnt.ToString(); MessageBox.Show(msj); xlWorkBook.Close(true, null, null); xlApp.Quit(); // Marshal.ReleaseComObject(xlWorkSheet); // Marshal.ReleaseComObject(xlWorkBook); // Marshal.ReleaseComObject(xlApp); }