public formBaseMark()//string TabEnc, string TabLin { InitializeComponent(); try { //oTabEnc = TabEnc; //oTabLin = TabLin; textBoxButtonFecReg.Text = DateTime.Now.ToString("dd/MM/yyyy"); textBoxButtonFecVen.Text = DateTime.Now.ToString("dd/MM/yyyy"); textBoxButtonFecDoc.Text = DateTime.Now.ToString("dd/MM/yyyy"); /*consiciones de pago*/ DataTable dt = Conexion.Ejecutar_dt("SELECT * FROM CONPAG"); comboBoxConPag.DisplayMember = "Descri"; comboBoxConPag.ValueMember = "CodCon"; comboBoxConPag.DataSource = dt; } catch (Exception ex) { MessageBox.Show(ex.Message); ElogFormBase.save(this, ex); } //Data grid }
// Valida celdas private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { try { //Valida que las celdas de codigo y nombre de articulo queden vacias if (dataGridView1.Columns[e.ColumnIndex].Index == 1) { /* * if (String.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[0].FormattedValue.ToString()) && String.IsNullOrEmpty(e.FormattedValue.ToString())) * { * e.Cancel = true; * dataGridView1.Rows[e.RowIndex].ErrorText = "Insertar valor"; * * } */ } //validar cantidad numerico y mayor que 0 if (dataGridView1.Columns[e.ColumnIndex].Index == 2) { Double newInteger; if (!double.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger <= 0) { e.Cancel = true; dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer"; } } // validar precio if (dataGridView1.Columns[e.ColumnIndex].Index == 3) { Double newInteger; if (!double.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger <= 0) { e.Cancel = true; dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer"; } } //validar precio bruto if (dataGridView1.Columns[e.ColumnIndex].Index == 4) { Double newInteger; if (!double.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger <= 0) { e.Cancel = true; dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer"; } } } catch (Exception ex) { MessageBox.Show(ex.Message); ElogFormBase.save(this, ex); } }
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView1.CurrentCell.ColumnIndex == 0 || dataGridView1.CurrentCell.ColumnIndex == 1) { if (textBoxButtonCodCli.Text == "") { textBoxButtonCodCli.Focus(); MessageBox.Show("Ingresar Codigo de SN"); } else { dataGridView1.BeginEdit(true); } } } catch (Exception ex) { //MessageBox.Show(ex.Message); ElogFormBase.save(this, ex); } }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { switch (dataGridView1.Columns[e.ColumnIndex].Index) { case 0: if (dataGridView1.CurrentRow.Cells[0].Value != null) { // Busqueda de Articulo por codigo DataSet ds0 = ds_Art(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()); if (ds0.Tables[0].Rows.Count == 1) { dataGridView1.Rows[e.RowIndex].Cells[2].Value = 1.ToString("N2"); //cantidad dataGridView1.Rows[e.RowIndex].Cells[1].Value = ds0.Tables[0].Rows[0].ItemArray[1].ToString(); //nombre dataGridView1.Rows[e.RowIndex].Cells[4].Value = ds0.Tables[0].Rows[0].ItemArray[2].ToString(); //precio bruto dataGridView1.Rows[e.RowIndex].Cells[6].Value = ds0.Tables[0].Rows[0].ItemArray[4].ToString(); // unidad de medida // Consulta Ultimo presio atendido al mismo cliente DataSet ds1 = ds_UltiPrec(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(), textBoxButtonCodCli.Text.Trim()); if (ds1.Tables[0].Rows.Count >= 1) { dataGridView1.Rows[e.RowIndex].Cells[4].Value = ds1.Tables[0].Rows[0].ItemArray[0].ToString(); dataGridView1.Rows[e.RowIndex].Cells[3].Value = CalcPrecUni(ds1.Tables[0].Rows[0].ItemArray[0].ToString()).ToString("N4"); } else { dataGridView1.Rows[e.RowIndex].Cells[3].Value = 0.ToString("N4"); dataGridView1.Rows[e.RowIndex].Cells[4].Value = 0.ToString("N2"); } //total de las lineas dataGridView1.Rows[e.RowIndex].Cells[7].Value = TotLin(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); dataGridView1.Rows[e.RowIndex].Cells[8].Value = TotLin(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString()); dataGridView1.Rows[e.RowIndex].Cells[8].Value = TotImpLine(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString()); SumaTotales(); } else { MessageBox.Show("Codigo no existe"); } } break; case 1: if (dataGridView1.CurrentRow.Cells[1].Value != null) { DataSet ds = ds_ArtDes(dataGridView1.CurrentRow.Cells[1].Value.ToString()); if (ds.Tables[0].Rows.Count == 1) { dataGridView1.Rows[e.RowIndex].Cells[2].Value = 1.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[1].Value = ds.Tables[0].Rows[0].ItemArray[1].ToString(); dataGridView1.Rows[e.RowIndex].Cells[4].Value = ds.Tables[0].Rows[0].ItemArray[2].ToString(); dataGridView1.Rows[e.RowIndex].Cells[6].Value = ds.Tables[0].Rows[0].ItemArray[4].ToString(); // Consulta Ultimo presio atendido al mismo cliente DataSet ds1 = ds_UltiPrec(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(), textBoxButtonCodCli.Text.Trim()); if (ds1.Tables[0].Rows.Count >= 1) { dataGridView1.Rows[e.RowIndex].Cells[4].Value = ds1.Tables[0].Rows[0].ItemArray[0].ToString(); dataGridView1.Rows[e.RowIndex].Cells[3].Value = CalcPrecUni(ds1.Tables[0].Rows[0].ItemArray[0].ToString()).ToString("N4"); } else { dataGridView1.Rows[e.RowIndex].Cells[3].Value = 0.ToString("N4"); dataGridView1.Rows[e.RowIndex].Cells[4].Value = 0.ToString("N2"); } //total de las lineas dataGridView1.Rows[e.RowIndex].Cells[7].Value = TotLin(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); dataGridView1.Rows[e.RowIndex].Cells[8].Value = TotLin(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString()); dataGridView1.Rows[e.RowIndex].Cells[8].Value = TotImpLine(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString()); SumaTotales(); } } break; case 2: oCantid = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); oPreUni = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); if (oPreUni >= 0) { oImpu = (oCantid * oPreUni) * 0.18; oPreBru = oPreUni * 1.18; oTotal = oCantid * oPreUni; oTotBru = oCantid * oPreBru; // dataGridView1.Rows[e.RowIndex].Cells[4].Value = oPreBru.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[7].Value = oTotal.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[8].Value = oTotBru.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[9].Value = oImpu.ToString("N2"); // dataGridView1.Rows[e.RowIndex].Cells[2].Value = oCantid.ToString("N2"); // SumaTotales(); } else { MessageBox.Show("INGRESAR PRECIO DE ARTICULO"); } break; case 3: oCantid = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); oPreUni = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); if (oPreUni >= 0) { oImpu = (oCantid * oPreUni) * 0.18; oPreBru = oPreUni * 1.18; oTotal = oCantid * oPreUni; oTotBru = oCantid * oPreBru; // dataGridView1.Rows[e.RowIndex].Cells[4].Value = oPreBru.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[7].Value = oTotal.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[8].Value = oTotBru.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[9].Value = oImpu.ToString("N2"); // dataGridView1.Rows[e.RowIndex].Cells[3].Value = oPreUni.ToString("N2"); // SumaTotales(); } else { MessageBox.Show("INGRESAR PRECIO DE ARTICULO"); } break; case 4: //precio bruto oCantid = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); oPreBru = double.Parse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString()); oPreUni = oPreBru / 1.18; oTotal = oCantid * oPreUni; oTotBru = oCantid * oPreBru; oImpu = oTotBru - oTotal; // dataGridView1.Rows[e.RowIndex].Cells[3].Value = oPreUni.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[7].Value = oTotal.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[8].Value = oTotBru.ToString("N2"); dataGridView1.Rows[e.RowIndex].Cells[9].Value = oImpu.ToString("N2"); // dataGridView1.Rows[e.RowIndex].Cells[4].Value = oPreBru.ToString("N2"); // SumaTotales(); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); ElogFormBase.save(this, ex); } }