[Test] public void AddNew() { //create the source datatable DataTable dt = DataProvider.CreateChildDataTable(); //create the dataview for the table DataView dv = new DataView(dt); int CountView = dv.Count ; int CountTable= dt.Rows.Count ; DataRowView drv = null; // AddNew - DataView Row Count drv = dv.AddNew(); Assert.AreEqual(dv.Count , CountView+1, "DV1"); // AddNew - Table Row Count Assert.AreEqual(dt.Rows.Count , CountTable, "DV2"); // AddNew - new row in DataTable drv.EndEdit(); Assert.AreEqual(dt.Rows.Count , CountTable+1, "DV3"); // AddNew - new row != null Assert.AreEqual(true, drv!=null, "DV4"); // AddNew - check table Assert.AreEqual(dt, drv.Row.Table, "DV5"); }
private void DemonstrateDtaView() { DataTable table = new DataTable("table"); DataColumn colItem = new DataColumn("item", Type.GetType("System.String")); table.Columns.Add(colItem); DataRow NewRow; for (int i = 0; i < 5; ++i) { NewRow = table.NewRow(); NewRow["item"] = "Item" + i; table.Rows.Add(NewRow); } table.Rows[0]["item"] = "cat"; table.Rows[1][0] = "dog"; // Commits all the changes made to this table since the last time AcceptChanges was called. // The DataRowState also changes: all Added and Modified rows become Unchanged, // and Deleted rows are removed. table.AcceptChanges(); DataView firstView = new DataView(table); DataView secondView = new DataView(table); PrintTableOrView(table, "Current Value in Table"); firstView.RowStateFilter = DataViewRowState.ModifiedOriginal; PrintTableOrView(firstView, "First DataView: Modifiedoriginal"); DataRowView rowView; rowView = secondView.AddNew(); rowView["item"] = "fish"; secondView.RowStateFilter = DataViewRowState.ModifiedCurrent | DataViewRowState.Added; PrintTableOrView(secondView, "Second DataVies: ModifiedCurent | Added"); }
public Form_AccountList() { InitializeComponent(); dataSet1 = arxDs.ds; accountsBindingSource.DataSource = arxDs.ds; dataGridView1.DataSource = accountsBindingSource; using (var remainingColumn = new DataGridViewTextBoxColumn { Width = 100, HeaderText = "Текущее состояние", ReadOnly = true }) { dataGridView1.Columns.Add(remainingColumn); } var view1 = new DataView(arxDs.ds.Tables["Accounts"], "", "", DataViewRowState.CurrentRows); if (!view1.Cast<DataRowView>() .Any(rv => rv.Row.Field<string>("Account") == "Основной")) { DataRowView newRow = view1.AddNew(); newRow["Account"] = "Основной"; newRow["StartSum"] = 0; newRow.EndEdit(); } }
static public void AddNew(ModelBase model, DataView v, int remarkTypeId, string remarks = null, string title = null, bool alert = false) { DataRowView r = v.AddNew(); r["TableId"] = (model is SponsorModel) ? 9 : 10; r["FKRowGUID"] = model.GUID; r["RemarkTypeId"] = remarkTypeId; r["Remarks"] = remarks; r["Title"] = title; r["Alert"] = alert; r["CreateDate"] = r["LastUpdate"] = DateTime.Now; r["CreateAgentGUID"] = UserModel.Current.GUID; r["CreateTaxOfficeId"] = SettingsModel.TaxOfficeId; r.Row.Table.Rows.Add(r.Row); }
private void AgregarFondoCaja() { string fecha = DateTime.Today.ToString("yyyy-MM-dd"); DataSet dsFondoCaja = BL.FondoCajaBLL.CrearDataset(fecha, 1); DataTable tblFondoCaja = dsFondoCaja.Tables[1]; DataView viewFondoCaja = new DataView(tblFondoCaja); if (viewFondoCaja.Count == 0) { viewFondoCaja.RowStateFilter = DataViewRowState.Added; Random rand = new Random(); int clave = rand.Next(1, 2000000000); DataRowView rowView = viewFondoCaja.AddNew(); rowView["IdFondoFONP"] = clave; rowView["FechaFONP"] = DateTime.Today; rowView["IdPcFONP"] = 1; // Jesus Maria rowView["ImporteFONP"] = 0; rowView.EndEdit(); } if (tblFondoCaja.GetChanges() != null) { BL.FondoCajaBLL.GrabarDB(dsFondoCaja, ref codigoError, false); } }
private void fillComboBoxes() { var view1 = new DataView(arxDs.ds.Tables["Accounts"], "", "", DataViewRowState.CurrentRows); var view2 = new DataView(arxDs.ds.Tables["Accounts"], "", "", DataViewRowState.CurrentRows); if (!view1.Cast<DataRowView>() .Any(rv => rv.Row.Field<string>("Account") == "Основной")) { DataRowView newRow = view1.AddNew(); newRow["Account"] = "Основной"; newRow["StartSum"] = 0; newRow.EndEdit(); } comboBox1.DataSource = view1; comboBox1.DisplayMember = "Account"; comboBox2.DataSource = view2; comboBox2.DisplayMember = "Account"; }
private void frmTesoreriaMov_Load(object sender, EventArgs e) { System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; this.ControlBox = true; this.MaximizeBox = false; tblLocales = BL.LocalesBLL.CrearDataset(); viewLocal = new DataView(tblLocales); viewLocal.RowFilter = "IdLocalLOC = '13'"; // Local 13 es Jesus Maria lstLocales.ValueMember = "IdLocalLOC"; lstLocales.DisplayMember = "NombreLOC"; lstLocales.DataSource = viewLocal; tblPcs = BL.PcsBLL.CrearDataset(); string local = lstLocales.SelectedValue.ToString(); viewPc = new DataView(tblPcs); viewPc.RowFilter = "IdPC = '1'"; // Pc 1 es caja1 de Jesus Maria viewPc.Sort = "Detalle ASC"; lstPc.ValueMember = "IdPC"; lstPc.DisplayMember = "Detalle"; lstPc.DataSource = viewPc; this.lstLocales.SelectedValueChanged += new System.EventHandler(this.lstLocales_SelectedValueChanged); dsTesoreriaMov = BL.TesoreriaMovimientosBLL.CrearDataset(); tblTesoreriaMov = dsTesoreriaMov.Tables[0]; viewTesoreria = new DataView(tblTesoreriaMov); if (PK == "") { Random rand = new Random(); int clave = rand.Next(1, 2000000000); lblClave.Text = clave.ToString(); lblClave.ForeColor = System.Drawing.Color.DarkRed; viewTesoreria.RowStateFilter = DataViewRowState.Added; rowView = viewTesoreria.AddNew(); rowView["IdMovTESM"] = clave.ToString(); rowView["FechaTESM"] = DateTime.Today; rowView["IdPcTESM"] = 1; rowView.EndEdit(); } else { lstLocales.SelectedValue = idLocal; lstPc.SelectedValue = idPc; lblClave.Text = PK; lblClave.ForeColor = System.Drawing.Color.DarkRed; viewTesoreria.RowFilter = "IdMovTESM = '" + PK + "'"; rowView = viewTesoreria[0]; txtDetalle.Focus(); } dateTimePicker1.DataBindings.Add("Text", rowView, "FechaTESM", false, DataSourceUpdateMode.OnPropertyChanged); lstPc.DataBindings.Add("SelectedValue", rowView, "IdPcTESM", false, DataSourceUpdateMode.OnPropertyChanged); txtDetalle.DataBindings.Add("Text", rowView, "DetalleTESM", false, DataSourceUpdateMode.OnPropertyChanged); txtImporte.DataBindings.Add("Text", rowView, "ImporteTESM", false, DataSourceUpdateMode.OnPropertyChanged); txtImporte.KeyPress += new KeyPressEventHandler(BL.Utilitarios.SoloNumerosConComa); }
public void run() { Exception exp = null; DataTable dt = GHTUtils.DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); //add event handler dv.ListChanged +=new System.ComponentModel.ListChangedEventHandler(dv_ListChanged); // ----- Change Value --------- evProp = null; try { BeginCase("change value - Event raised"); dv[1]["String1"] = "something"; Compare(evProp!=null ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("change value - ListChangedType"); Compare(evProp.lstType ,System.ComponentModel.ListChangedType.ItemChanged); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("change value - NewIndex"); Compare(evProp.NewIndex,1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("change value - OldIndex"); Compare(evProp.OldIndex ,-1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} // ----- Add New --------- evProp = null; try { BeginCase("Add New - Event raised"); dv.AddNew(); Compare(evProp!=null ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("Add New - ListChangedType"); Compare(evProp.lstType ,System.ComponentModel.ListChangedType.ItemAdded ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("Add New - NewIndex"); Compare(evProp.NewIndex,6); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("Add New - OldIndex"); Compare(evProp.OldIndex ,-1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} // ----- Sort --------- evProp = null; try { BeginCase("sort - Event raised"); dv.Sort = "ParentId Desc"; Compare(evProp!=null ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("sort - ListChangedType"); Compare(evProp.lstType ,System.ComponentModel.ListChangedType.Reset ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("sort - NewIndex"); Compare(evProp.NewIndex,-1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("sort - OldIndex"); Compare(evProp.OldIndex ,-1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //ListChangedType - this was not checked //Move //PropertyDescriptorAdded - A PropertyDescriptor was added, which changed the schema. //PropertyDescriptorChanged - A PropertyDescriptor was changed, which changed the schema. //PropertyDescriptorDeleted }
[Test] public void AllowNew() { DataTable dt = DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); // AllowNew - default value Assert.AreEqual(true , dv.AllowNew , "DV18"); // AllowNew - true dv.AllowNew = true; Assert.AreEqual(true, dv.AllowNew , "DV19"); // AllowNew - false dv.AllowNew = false; Assert.AreEqual(false, dv.AllowNew , "DV20"); // AllowNew - exception try { dv.AddNew(); Assert.Fail("DV21: AddNew Failed to throw DataException"); } catch (DataException) {} catch (AssertionException exc) {throw exc;} catch (Exception exc) { Assert.Fail("DV22: AddNew. Wrong exception type. Got:" + exc); } dv.AllowNew=true; int RowsCount = dv.Count ; // AllowNew - exception dv.AddNew(); Assert.AreEqual(RowsCount+1, dv.Count , "DV23"); }
private void frmStockMov_Load(object sender, EventArgs e) { this.CenterToScreen(); this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange; instanciaStockComp = this; grabacionCorrecta = true; System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; this.ControlBox = true; this.MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.CausesValidation = true; dgvDatos.ShowCellErrors = true; cargarCombos(); tblArticulos = BL.GetDataBLL.Articulos(); tblArticulos.TableName = "Articulos"; if (PK == "") //registro nuevo { tblStockMov = BL.StockMovBLL.GetTablaMov(); tblStockMovDetalle = BL.StockMovBLL.GetTablaDetalle(); tblStockMovDetalle.PrimaryKey = new DataColumn[] { tblStockMovDetalle.Columns["IdMSTKD"] }; dsStockMov = new DataSet(); dsStockMov.DataSetName = "dsStockMov"; dsStockMov.Tables.Add(tblStockMov); dsStockMov.Tables.Add(tblStockMovDetalle); viewStockMov = new DataView(tblStockMov); viewStockMovDetalle = new DataView(tblStockMovDetalle); lblNro.ForeColor = System.Drawing.Color.DarkRed; Random rand = new Random(); int clave = rand.Next(-2000000000, 2000000000); lblNro.Text = clave.ToString(); rowView = viewStockMov.AddNew(); rowView["IdMovMSTK"] = clave.ToString(); rowView["FechaMSTK"] = DateTime.Today; rowView["OrigenMSTK"] = 1; rowView["CompensaMSTK"] = 1; rowView.EndEdit(); } else // editar registros { tblStockMov = dsStockMov.Tables[0]; tblStockMovDetalle = dsStockMov.Tables[1]; tblStockMovDetalle.PrimaryKey = new DataColumn[] { tblStockMovDetalle.Columns["IdMSTKD"] }; viewStockMov = new DataView(tblStockMov); viewStockMovDetalle = new DataView(tblStockMovDetalle); viewStockMov.RowFilter = "IdMovMSTK = '" + PK + "'"; rowView = viewStockMov[0]; viewStockMovDetalle.RowFilter = "IdMovMSTKD = '" + PK + "'"; lblNro.Text = viewStockMov[0]["IdMovMSTK"].ToString(); cmbOrigen.Enabled = false; cmbDestino.Enabled = false; dgvDatos.Enabled = true; cmbDestino.SelectedIndexChanged -= new EventHandler(this.validarMaestro); } dateTimePicker1.DataBindings.Add("Text", rowView, "FechaMSTK", false, DataSourceUpdateMode.OnPropertyChanged); cmbOrigen.DataBindings.Add("SelectedValue", rowView, "OrigenMSTK", false, DataSourceUpdateMode.OnPropertyChanged); cmbDestino.DataBindings.Add("SelectedValue", rowView, "DestinoMSTK", false, DataSourceUpdateMode.OnPropertyChanged); rowView.CancelEdit(); bindingSource1.DataSource = viewStockMovDetalle; bindingNavigator1.BindingSource = bindingSource1; dgvDatos.AutoGenerateColumns = false; AddColumns(); dgvDatos.DataSource = bindingSource1; dgvDatos.AllowUserToOrderColumns = false; dgvDatos.EditMode = DataGridViewEditMode.EditOnKeystroke; dgvDatos.Enabled = false; cmbOrigen.Visible = false; btnArticulos.Enabled = false; this.dgvDatos.RowValidating += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.ValidarFila); }
public void RowVersion1 () { // I guess we could write better tests. DataTable dt = new DataTable ("table"); dt.Columns.Add ("col"); dt.Rows.Add (new object [] {1}); DataView dv = new DataView (dt); DataRowView drv = dv.AddNew (); AssertEquals (DataRowVersion.Current, drv.RowVersion); AssertEquals (DataRowVersion.Current, dv [0].RowVersion); drv ["col"] = "mod"; AssertEquals (DataRowVersion.Current, drv.RowVersion); AssertEquals (DataRowVersion.Current, dv [0].RowVersion); dt.AcceptChanges (); AssertEquals (DataRowVersion.Current, drv.RowVersion); AssertEquals (DataRowVersion.Current, dv [0].RowVersion); drv.EndEdit (); dv [0].EndEdit (); AssertEquals (DataRowVersion.Current, drv.RowVersion); AssertEquals (DataRowVersion.Current, dv [0].RowVersion); }
public void IsEdit () { DataTable dt = new DataTable ("table"); dt.Columns.Add ("col"); dt.Rows.Add ((new object [] {"val"})); DataView dv = new DataView (dt); DataRowView drv = dv [0]; dt.Rows [0].BeginEdit (); AssertEquals ("DataView.Item", true, drv.IsEdit); drv = dv.AddNew (); drv.Row ["col"] = "test"; drv.Row.CancelEdit (); AssertEquals ("AddNew", false, drv.IsEdit); }
//Activate This Construntor to log All To Standard output //public TestClass():base(true){} //Activate this constructor to log Failures to a log file //public TestClass(System.IO.TextWriter tw):base(tw, false){} //Activate this constructor to log All to a log file //public TestClass(System.IO.TextWriter tw):base(tw, true){} //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES public void run() { Exception exp = null; DataTable dt = GHTUtils.DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); DataRowView drv = dv[0]; try { BeginCase("existing row"); Compare(drv.IsNew ,false); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("add new row"); drv = dv.AddNew(); Compare(drv.IsNew ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} }
private void frmVentas_Load(object sender, EventArgs e) { System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = ","; System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator = ","; this.CenterToScreen(); instanciaVentas = this; this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange; System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; this.ControlBox = true; this.MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; CargarComboLocales(); grpABM.Enabled = false; tblArticulos = BL.GetDataBLL.Articulos(); tblArticulos.TableName = "Articulos"; var source = new AutoCompleteStringCollection(); String[] stringArray = Array.ConvertAll<DataRow, String>(tblArticulos.Select(), delegate(DataRow row) { return (String)row["IdArticuloART"]; }); source.AddRange(stringArray); txtArticulo.AutoCompleteMode = AutoCompleteMode.SuggestAppend; txtArticulo.AutoCompleteCustomSource = source; txtArticulo.AutoCompleteSource = AutoCompleteSource.CustomSource; txtArticulo.BackColor = Color.White; txtDescripcion.BackColor = Color.White; txtDescripcion.TabStop = false; txtDescripcion.ReadOnly = true; txtCantidad.BackColor = Color.White; txtPrecio.BackColor = Color.White; tblFormasPago = BL.GetDataBLL.FormasPago(); cmbForma.ValueMember = "IdFormaPagoFOR"; cmbForma.DisplayMember = "DescripcionFOR"; cmbForma.DropDownStyle = ComboBoxStyle.DropDown; cmbForma.DataSource = tblFormasPago; cmbForma.SelectedValue = -1; cmbForma.BackColor = Color.White; AutoCompleteStringCollection formasPagoColection = new AutoCompleteStringCollection(); foreach (DataRow row in tblFormasPago.Rows) { formasPagoColection.Add(Convert.ToString(row["DescripcionFOR"])); } cmbForma.AutoCompleteCustomSource = formasPagoColection; cmbForma.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cmbForma.AutoCompleteSource = AutoCompleteSource.CustomSource; cmbForma.Validating += new System.ComponentModel.CancelEventHandler(BL.Utilitarios.ValidarComboBox); lblCosto.Visible = false; txtCosto.Visible = false; grpVentas.CausesValidation = false; dateTimePicker1.CausesValidation = false; cmbLocal.CausesValidation = false; cmbCliente.CausesValidation = false; btnClientes.CausesValidation = false; btnEditar.CausesValidation = false; btnBorrar.CausesValidation = false; btnArticulos.CausesValidation = false; dsVentas = new DataSet(); dsVentas.DataSetName = "dsVentas"; if (tblVentas.DataSet == null) { dsVentas.Tables.Add(tblVentas); dsVentas.Tables.Add(tblVentasDetalle); } tblVentasDetalle.PrimaryKey = new DataColumn[] { tblVentasDetalle.Columns["IdDVEN"] }; viewVentas = new DataView(tblVentas); viewDetalle = new DataView(tblVentasDetalle); viewDetalle.Sort = "OrdenarDVEN ASC"; bindingSource1.DataSource = viewDetalle; bindingNavigator1.BindingSource = bindingSource1; dgvDatos.ReadOnly = true; dgvDatos.AllowUserToAddRows = false; dgvDatos.AllowUserToOrderColumns = false; dgvDatos.DataSource = bindingSource1; dgvDatos.Columns["IdDVEN"].Visible = false; dgvDatos.Columns["IdVentaDVEN"].Visible = false; dgvDatos.Columns["IdLocalDVEN"].Visible = false; dgvDatos.Columns["PrecioCostoDVEN"].Visible = false; dgvDatos.Columns["PrecioMayorDVEN"].Visible = false; dgvDatos.Columns["IdFormaPagoDVEN"].Visible = false; dgvDatos.Columns["NroCuponDVEN"].Visible = false; dgvDatos.Columns["IdEmpleadoDVEN"].Visible = false; dgvDatos.Columns["LiquidadoDVEN"].Visible = false; dgvDatos.Columns["EsperaDVEN"].Visible = false; dgvDatos.Columns["OrdenarDVEN"].Visible = false; dgvDatos.Columns["CantidadDVEN"].Width = 55; dgvDatos.Columns["CantidadDVEN"].HeaderText = "Cantidad"; dgvDatos.Columns["IdArticuloDVEN"].HeaderText = "Artículo"; dgvDatos.Columns["DescripcionDVEN"].HeaderText = "Descripción"; dgvDatos.Columns["PrecioPublicoDVEN"].Width = 100; dgvDatos.Columns["PrecioPublicoDVEN"].HeaderText = "Precio"; dgvDatos.Columns["PrecioPublicoDVEN"].DefaultCellStyle.Format = "C2"; dgvDatos.Columns["NroFacturaDVEN"].Width = 100; dgvDatos.Columns["NroFacturaDVEN"].HeaderText = "Nº fact."; dgvDatos.Columns.Remove("DevolucionDVEN"); dgvDatos.Columns.Remove("IdFormaPagoDVEN"); DataGridViewComboBoxColumn cmbFormaPago = new DataGridViewComboBoxColumn(); cmbFormaPago.Name = "FormaPago"; cmbFormaPago.HeaderText = "Forma de pago"; cmbFormaPago.DataSource = tblFormasPago; cmbFormaPago.ValueMember = "IdFormaPagoFOR"; cmbFormaPago.DisplayMember = "DescripcionFOR"; cmbFormaPago.DataPropertyName = "IdFormaPagoDVEN"; dgvDatos.Columns.Insert(7, cmbFormaPago); DataGridViewCheckBoxColumn chkDevolucion = new DataGridViewCheckBoxColumn(); chkDevolucion.Name = "DevolucionDVEN"; chkDevolucion.Width = 40; chkDevolucion.HeaderText = "Dev."; chkDevolucion.DataPropertyName = "DevolucionDVEN"; chkDevolucion.TrueValue = 1; chkDevolucion.FalseValue = 0; dgvDatos.Columns.Insert(12, chkDevolucion); dgvDatos.SelectionMode = DataGridViewSelectionMode.FullRowSelect; lblTotal.Text = "$ 0"; if (PK == "") //registro nuevo { lblNro.ForeColor = System.Drawing.Color.DarkRed; Random rand = new Random(); int clave = rand.Next(-2000000000, 2000000000); lblNro.Text = clave.ToString(); rowView = viewVentas.AddNew(); rowView["IdVentaVEN"] = clave.ToString(); rowView["FechaVEN"] = dateTimePicker1.Value; rowView.EndEdit(); // SetStateForm(FormState.inicial); } else // editar registros { viewVentas.RowFilter = "IdVentaVEN = '" + PK + "'"; rowView = viewVentas[0]; rowView.BeginEdit(); viewDetalle.RowFilter = "IdVentaDVEN = '" + PK + "'"; lblNro.Text = viewVentas[0][0].ToString(); cmbLocal.Enabled = false; lblTotal.Text = "$ " + CalcularTotal(); dateTimePicker1.TabStop = false; cmbLocal.TabStop = false; cmbCliente.Focus(); SetStateForm(FormState.inicial); } dateTimePicker1.DataBindings.Add("Text", rowView, "FechaVEN", false, DataSourceUpdateMode.OnPropertyChanged); cmbLocal.DataBindings.Add("SelectedValue", rowView, "IdPCVEN", false, DataSourceUpdateMode.OnPropertyChanged); cmbCliente.DataBindings.Add("SelectedValue", rowView, "IdClienteVEN", false, DataSourceUpdateMode.OnPropertyChanged); rowView.CancelEdit(); ToolTip tooltip = new ToolTip(); tooltip.SetToolTip(btnClientes, "Agregar nuevo cliente"); cmbLocal.SelectedIndexChanged += new EventHandler(this.ValidarMaestro); cmbCliente.Validating += new System.ComponentModel.CancelEventHandler(BL.Utilitarios.ValidarComboBox); txtPrecio.KeyPress += new KeyPressEventHandler(BL.Utilitarios.SoloNumerosConComa); txtCantidad.KeyPress += new KeyPressEventHandler(BL.Utilitarios.SoloNumeros); txtArticulo.Enter += new System.EventHandler(BL.Utilitarios.SelTextoTextBox); txtCantidad.Enter += new System.EventHandler(BL.Utilitarios.SelTextoTextBox); txtPrecio.Enter += new System.EventHandler(BL.Utilitarios.SelTextoTextBox); cmbForma.Enter += new System.EventHandler(BL.Utilitarios.SelTextoTextBox); txtArticulo.KeyDown += new System.Windows.Forms.KeyEventHandler(BL.Utilitarios.EnterTab); txtCantidad.KeyDown += new System.Windows.Forms.KeyEventHandler(BL.Utilitarios.EnterTab); txtPrecio.KeyDown += new System.Windows.Forms.KeyEventHandler(BL.Utilitarios.EnterTab); cmbForma.KeyDown += new System.Windows.Forms.KeyEventHandler(BL.Utilitarios.EnterTab); chkDev.KeyDown += new System.Windows.Forms.KeyEventHandler(BL.Utilitarios.EnterTab); }
// End of Week Process private void doWeeklyUpdate() { //-- Truncate All Summary Records try { sqLiteConnection1.Open(); sqLiteCommand1.ExecuteNonQuery(); //drop the debtors summary table sqLiteConnection1.Close(); } catch { ; } Vectra.DataSet2TableAdapters.customerTableAdapter cda = new customerTableAdapter(); //-- Iteate all customer Transactions DataView dv = new DataView(dataSet2.customer_trans); DataView debtorView = new DataView(dataSet2.debtors_summary); DataRowView debtorsSummary; // = debtorView.AddNew(); dv.Sort = "t_cust_id"; int custId = 0; Decimal currentAmt = 0; Decimal days7 = 0; Decimal days14 = 0; Decimal days21 = 0; DateTime lastPayment = DateTime.MinValue; DateTime today = processDateTime.Value; Decimal amount; Decimal owing; Decimal openBal; foreach (DataRowView dr in dv) { if (custId.ToString() != dr["t_cust_id"].ToString()) { if (custId > 0) { // Add a new row openBal = (Decimal)cda.GetCustomerOpenBal(custId)* -1; owing = Decimal.Add(days7, currentAmt); owing = Decimal.Add(owing, days14); owing = Decimal.Add(owing, days21); owing = Decimal.Add(owing, openBal); debtorsSummary = debtorView.AddNew(); debtorsSummary["cust_id"] = custId; debtorsSummary["curAmt"] = currentAmt; debtorsSummary["days7"] = days7; debtorsSummary["days14"] = days14; debtorsSummary["days21"] = days21; debtorsSummary["Owing"] = owing; debtorsSummary["date_last_payment"] = lastPayment.ToString(); debtorsSummary["open_bal"] = openBal * -1; debtorsSummary.EndEdit(); } custId = int.Parse(dr["t_cust_id"].ToString()); currentAmt = 0; days7 = 0; days14 = 0; days21 = 0; lastPayment = DateTime.MinValue; } DateTime dt = (DateTime)new DateTimeConverter().ConvertFromString(dr["t_date"].ToString()); // Payments to subtracted, other type as is. /* if (dr["t_type"].ToString() == "Payment") { amount = Decimal.Multiply(Decimal.Parse(dr["t_amount"].ToString()), -1); if (dt > lastPayment) lastPayment = dt; } else amount = Decimal.Parse(dr["t_amount"].ToString()); */ amount = Decimal.Parse(dr["t_unpaid"].ToString()); //owing is sum of unpaid amounts if (dt >= today.AddDays(-7)) currentAmt = Decimal.Add(currentAmt,amount); else if (dt < today.AddDays(-7) && dt >= today.AddDays(-14)) days7 = Decimal.Add(days7, amount); else if (dt < today.AddDays(-14) && dt >= today.AddDays(-21)) days14 = Decimal.Add(days14, amount); else days21 = Decimal.Add(days21, amount); } //Decimal owing; if (custId > 0) { openBal = (Decimal)cda.GetCustomerOpenBal(custId) * -1; } else { openBal = 0; } owing = Decimal.Add(days7, currentAmt); owing = Decimal.Add(owing, days14); owing = Decimal.Add(owing, days21); owing = Decimal.Add(owing, openBal); // Add new row debtorsSummary = debtorView.AddNew(); debtorsSummary["cust_id"] = custId; debtorsSummary["curAmt"] = currentAmt; debtorsSummary["days7"] = days7; debtorsSummary["days14"] = days14; debtorsSummary["days21"] = days21; debtorsSummary["date_last_payment"] = lastPayment.ToString(); debtorsSummary["Owing"] = owing; debtorsSummary["open_bal"] = openBal * -1; debtorsSummary.EndEdit(); this.debtors_summaryBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.dataSet2); }
/// <summary> /// Receives a DataView as a parameter and inserts an empty new record at the end /// </summary> /// <example> /// vfpData.AppendBlank(oView); /// </example> /// <param name="toView"></param> public static DataRow AppendBlank(System.Data.DataView toView) { DataRowView drv = toView.AddNew(); return(drv.Row); }
public void UnsignedTypes() { execSQL("CREATE TABLE Test (b TINYINT UNSIGNED PRIMARY KEY)"); MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); DataTable dt = new DataTable(); da.Fill(dt); DataView dv = new DataView(dt); DataRowView row; row = dv.AddNew(); row["b"] = 120; row.EndEdit(); da.Update(dv.Table); row = dv.AddNew(); row["b"] = 135; row.EndEdit(); da.Update(dv.Table); cb.Dispose(); execSQL("DROP TABLE IF EXISTS Test"); execSQL("CREATE TABLE Test (b MEDIUMINT UNSIGNED PRIMARY KEY)"); execSQL("INSERT INTO Test VALUES(20)"); MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test WHERE (b > ?id)", conn); cmd.Parameters.Add("?id", MySqlDbType.UInt16).Value = 10; using (MySqlDataReader dr = cmd.ExecuteReader()) { dr.Read(); Assert.AreEqual(20, dr.GetUInt16(0)); } }
private void btnAgrupar_Click(object sender, EventArgs e) { if (dgvDatosOrigen.Rows.Count == 0) { MessageBox.Show("Debe indicar un artículo de origen", "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); txtParametrosOrigen.Focus(); return; } if (dgvDatosDestino.Rows.Count == 0) { MessageBox.Show("Debe indicar un artículo de destino", "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); txtParametrosDestino.Focus(); return; } if (!BL.UtilDB.ValidarServicioMysql()) { MessageBox.Show("NO SE ACTUALIZARON LOS DATOS." + '\r' + "No se pudo conectar con el servidor de base de datos." + '\r' + "Consulte al administrador del sistema.", "Trend Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Error); tblArticulos.RejectChanges(); return; } if (MessageBox.Show("La agrupación de artículos eliminará los artículos de origen. ¿Desea continuar?", "Trend", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return; Cursor.Current = Cursors.WaitCursor; DataView viewStock = new DataView(tblStock); DataView viewArticulos = new DataView(tblArticulos); DataTable tblLocales = BL.GetDataBLL.Locales(); DataView viewLocales = new DataView(tblLocales); viewLocales.RowFilter = "IdLocalLOC <> 1 AND IdLocalLOC <> 2"; string articuloDestino = dgvDatosDestino.CurrentRow.Cells["IdArticuloART"].Value.ToString(); int cantidadArticulos = 0; int cantidadDestino = 0; ArrayList articulosBorrar = new ArrayList(); foreach (DataGridViewRow rowOrigen in dgvDatosOrigen.Rows) { if (rowOrigen.Cells["Agrupar"].Value != null) { if (rowOrigen.Cells["Agrupar"].Value.ToString() == "1") { string articuloOrigen = rowOrigen.Cells["IdArticuloART"].Value.ToString(); foreach (DataRowView rowLocales in viewLocales) { string local = rowLocales["IdLocalLOC"].ToString(); if (local != "1" && local != "2") { viewStock.RowFilter = "IdLocalSTK = '" + local + "' AND IdArticuloSTK = '" + articuloOrigen + "'"; int cantidadOrigen = Convert.ToInt32(viewStock[0]["CantidadSTK"].ToString()); viewStock.RowFilter = "IdLocalSTK = '" + local + "' AND IdArticuloSTK = '" + articuloDestino + "'"; if (viewStock.Count > 0) { cantidadDestino = Convert.ToInt32(viewStock[0]["CantidadSTK"].ToString()); viewStock[0]["CantidadSTK"] = cantidadOrigen + cantidadDestino; } else // no existe el registro en la tabla stock. Lo agrego { DataRowView rowView = viewStock.AddNew(); rowView["IdArticuloSTK"] = articuloDestino; rowView["IdLocalSTK"] = local; rowView["CantidadSTK"] = cantidadOrigen; rowView.EndEdit(); } } } articulosBorrar.Add(articuloOrigen); // agrego los articulos agrupados para luego borrarlos } cantidadArticulos++; } } if (cantidadArticulos == 0) { MessageBox.Show("Debe seleccionar un artículo de origen", "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // borro los articulos agrupados foreach (string borrado in articulosBorrar) { DataRow[] found = tblArticulos.Select("IdArticuloART = '" + borrado + "'"); found[0].Delete(); } //Actualizo el viewOrigen para reflejar los cambios en pantalla foreach (string borrado in articulosBorrar) { DataRow[] found = tblArticulosStock.Select("IdArticuloART = '" + borrado + "'"); found[0].Delete(); } Cursor.Current = Cursors.Arrow; if(tblArticulos.GetChanges() != null) { frmProgress frm = new frmProgress(tblArticulos, tblStock, "frmArticulosAgrupar", "grabar", instanciaArticulosAgrupar); frm.FormClosed += frmProgress_FormClosed; frm.ShowDialog(); } }
private void frmFondoCaja_Load(object sender, EventArgs e) { this.Location = new Point(50, 50); System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; this.ControlBox = true; this.MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; tblLocales = BL.GetDataBLL.Locales(); viewLocal = new DataView(tblLocales); viewLocal.RowFilter = "IdLocalLOC <>'1' AND IdLocalLOC <>'2' AND IdLocalLOC <>'11' AND IdLocalLOC <>'12'"; lstLocales.ValueMember = "IdLocalLOC"; lstLocales.DisplayMember = "NombreLOC"; lstLocales.DataSource = viewLocal; tblPcs = BL.GetDataBLL.Pc(); string local = lstLocales.SelectedValue.ToString(); viewPc = new DataView(tblPcs); viewPc.RowFilter = "IdLocalPC = '" + local + "'"; viewPc.Sort = "Detalle ASC"; lstPc.ValueMember = "IdPC"; lstPc.DisplayMember = "Detalle"; lstPc.DataSource = viewPc; viewFondoCaja = new DataView(tblFondoCaja); if (tblFondoCaja.Rows.Count == 0) { rowView = viewFondoCaja.AddNew(); Random rand = new Random(); int clave = rand.Next(-2000000000, 2000000000); rowView["IdFondoFONP"] = clave; rowView["FechaFONP"] = DateTime.Today; rowView.EndEdit(); } else { viewFondoCaja.RowFilter = "IdFondoFONP = '" + PK + "'"; rowView = viewFondoCaja[0]; lstLocales.SelectedValue = rowView["IdLocalLOC"]; lstPc.SelectedValue = rowView["IdPcFONP"]; } dateTimePicker1.DataBindings.Add("Text", rowView, "FechaFONP", false, DataSourceUpdateMode.OnPropertyChanged); lstPc.DataBindings.Add("SelectedValue", rowView, "IdPcFONP", false, DataSourceUpdateMode.OnPropertyChanged); txtImporte.DataBindings.Add("Text", rowView, "ImporteFONP", false, DataSourceUpdateMode.OnPropertyChanged); if (lstPc.Items.Count > 0) lstPc.SetSelected(0, true); this.lstLocales.SelectedValueChanged += new System.EventHandler(this.lstLocales_SelectedValueChanged); this.AcceptButton = btnAceptar; txtImporte.Focus(); }
// [NUnit.Framework.Category ("NotWorking")] public void ItemException () { DataTable dt = new DataTable ("table"); dt.Columns.Add ("col"); dt.Rows.Add ((new object [] {"val"})); DataView dv = new DataView (dt); DataRowView drv = dv.AddNew (); drv.Row ["col"] = "test"; drv.Row.CancelEdit (); object o = drv ["col"]; }
//Activate This Construntor to log All To Standard output //public TestClass():base(true){} //Activate this constructor to log Failures to a log file //public TestClass(System.IO.TextWriter tw):base(tw, false){} //Activate this constructor to log All to a log file //public TestClass(System.IO.TextWriter tw):base(tw, true){} //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES public void run() { Exception exp = null; //create the source datatable DataTable dt = GHTUtils.DataProvider.CreateChildDataTable(); //create the dataview for the table DataView dv = new DataView(dt); int CountView = dv.Count ; int CountTable= dt.Rows.Count ; DataRowView drv = null; BeginCase("AddNew - DataView Row Count"); try { drv = dv.AddNew(); Compare(CountView+1,dv.Count ); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } BeginCase("AddNew - Table Row Count "); try { Compare(CountTable,dt.Rows.Count ); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } BeginCase("AddNew - new row in DataTable"); try { drv.EndEdit(); Compare(CountTable+1,dt.Rows.Count ); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } BeginCase("AddNew - new row != null"); try { Compare(drv!=null,true); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } BeginCase("AddNew - check table"); try { Compare(drv.Row.Table,dt); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } }
private void frmFondoCaja_Load(object sender, EventArgs e) { System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; #region comboLocal tblLocales = new DataTable(); DataColumn IdPc = new DataColumn(); IdPc.ColumnName = "IdPc"; tblLocales.Columns.Add(IdPc); DataColumn NombreLOC = new DataColumn(); NombreLOC.ColumnName = "NombreLOC"; tblLocales.Columns.Add(NombreLOC); DataRow row = tblLocales.NewRow(); row["IdPc"] = 1; row["NombreLOC"] = "JESUS MARIA"; tblLocales.Rows.Add(row); cmbLocal.ValueMember = "IdPC"; cmbLocal.DisplayMember = "NombreLOC"; cmbLocal.DropDownStyle = ComboBoxStyle.DropDownList; cmbLocal.DataSource = tblLocales; cmbLocal.SelectedValue = 1; #endregion fecha = dateTimePicker1.Value.ToString("yyyy-MM-dd"); dsFondoCaja = BL.FondoCajaBLL.CrearDataset(fecha, 1); tblFondoCaja = dsFondoCaja.Tables[1]; viewFondoCaja = new DataView(tblFondoCaja); if (viewFondoCaja.Count == 0) { viewFondoCaja.RowStateFilter = DataViewRowState.Added; Random rand = new Random(); int clave = rand.Next(1, 2000000000); lblClave.Text = clave.ToString(); lblClave.ForeColor = System.Drawing.Color.DarkRed; rowView = viewFondoCaja.AddNew(); rowView["IdFondoFONP"] = clave; rowView["FechaFONP"] = DateTime.Today; rowView["IdPcFONP"] = 1; // Jesus Maria rowView["ImporteFONP"] = 0; rowView.EndEdit(); } else { rowView = viewFondoCaja[0]; } lblClave.DataBindings.Add("Text", rowView, "IdFondoFONP", false, DataSourceUpdateMode.OnPropertyChanged); dateTimePicker1.DataBindings.Add("Text", rowView, "FechaFONP", false, DataSourceUpdateMode.OnPropertyChanged); cmbLocal.DataBindings.Add("SelectedValue", rowView, "IdPcFONP", false, DataSourceUpdateMode.OnPropertyChanged); txtImporte.DataBindings.Add("Text", rowView, "ImporteFONP", false, DataSourceUpdateMode.OnPropertyChanged); txtImporte.Focus(); txtImporte.KeyPress += new KeyPressEventHandler(BL.Utilitarios.SoloNumerosConComa); }
[Test] public void ListChanged() { DataTable dt = DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); //add event handler dv.ListChanged +=new ListChangedEventHandler(dv_ListChanged); // ----- Change Value --------- evProp = null; // change value - Event raised dv[1]["String1"] = "something"; Assert.AreEqual(true , evProp!=null , "DV58"); // change value - ListChangedType Assert.AreEqual(ListChangedType.ItemChanged, evProp.lstType , "DV59"); // change value - NewIndex Assert.AreEqual(1, evProp.NewIndex, "DV60"); // change value - OldIndex Assert.AreEqual(-1, evProp.OldIndex , "DV61"); // ----- Add New --------- evProp = null; // Add New - Event raised dv.AddNew(); Assert.AreEqual(true , evProp!=null , "DV62"); // Add New - ListChangedType Assert.AreEqual(ListChangedType.ItemAdded , evProp.lstType , "DV63"); // Add New - NewIndex Assert.AreEqual(6, evProp.NewIndex, "DV64"); // Add New - OldIndex Assert.AreEqual(-1, evProp.OldIndex , "DV65"); // ----- Sort --------- evProp = null; // sort - Event raised dv.Sort = "ParentId Desc"; Assert.AreEqual(true , evProp!=null , "DV66"); // sort - ListChangedType Assert.AreEqual(ListChangedType.Reset , evProp.lstType , "DV67"); // sort - NewIndex Assert.AreEqual(-1, evProp.NewIndex, "DV68"); // sort - OldIndex Assert.AreEqual(-1, evProp.OldIndex , "DV69"); //ListChangedType - this was not checked //Move //PropertyDescriptorAdded - A PropertyDescriptor was added, which changed the schema. //PropertyDescriptorChanged - A PropertyDescriptor was changed, which changed the schema. //PropertyDescriptorDeleted }
//Activate This Construntor to log All To Standard output //public TestClass():base(true){} //Activate this constructor to log Failures to a log file //public TestClass(System.IO.TextWriter tw):base(tw, false){} //Activate this constructor to log All to a log file //public TestClass(System.IO.TextWriter tw):base(tw, true){} //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES public void run() { Exception exp = null; DataTable dt = GHTUtils.DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); try { BeginCase("AllowNew - default value"); Compare(dv.AllowNew ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("AllowNew - true"); dv.AllowNew = true; Compare(dv.AllowNew , true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("AllowNew - false"); dv.AllowNew = false; Compare(dv.AllowNew , false); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("AllowNew - exception"); try { dv.AddNew(); } catch(DataException ex) { exp=ex; } Compare(exp.GetType().FullName , typeof(DataException).FullName ); exp=null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dv.AllowNew=true; int RowsCount = dv.Count ; try { BeginCase("AllowNew - exception"); dv.AddNew(); Compare(dv.Count , RowsCount+1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} }
public void Bug18898 () { var table = new DataTable(); table.Columns.Add("col1"); table.Columns.Add("col2"); table.Rows.Add("1", "2"); table.Rows.Add("4", "3"); table.AcceptChanges(); table.Rows.Add("5", "6"); DataView dv = new DataView(table, string.Empty, string.Empty, DataViewRowState.Added); dv.AllowNew = true; var new_row = dv.AddNew(); new_row[0] = "7"; new_row[1] = "8"; var another_new_row = dv.AddNew(); another_new_row[0] = "9"; another_new_row[1] = "10"; AssertEquals ("#1", dv[2][0], "9"); //This should not throw a System.Data.VersionNotFoundException: "There is no Proposed data to accces" AssertEquals ("#1", dv[1][0], "7"); }
/// <summary> /// Constructs the dialog /// </summary> private void Construct() { const string SELECTION = "Selection"; selectionList = new DataTable(SELECTION); selectionList.Columns.Add(new DataColumn(SELECTION)); DataView dgListView = new DataView( selectionList ); dgListView.ListChanged += new System.ComponentModel.ListChangedEventHandler(dgListView_ListChanged); this.dgList.DataSource = dgListView; this.dgList.DataMember = ""; DataGridTableStyle ts = new DataGridTableStyle(); ts.MappingName = SELECTION; dgList.TableStyles.Clear(); dgList.TableStyles.Add(ts); dgList.TableStyles[SELECTION].GridColumnStyles[SELECTION].Width = dgList.Width - dgList.RowHeaderWidth; dgListView.AddNew(); }
private void frmStockMov_Load(object sender, EventArgs e) { this.CenterToScreen(); System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; this.ControlBox = true; this.MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; tblStockMov = BL.StockMovBLL.GetTablaMov(); tblStockMovDetalle = BL.StockMovBLL.GetTablaDetalle(); DataColumn col = new DataColumn(); col.ColumnName = "Precio"; tblStockMovDetalle.Columns.Add(col); dsStockMov = new DataSet(); dsStockMov.DataSetName = "dsStockMov"; dsStockMov.Tables.Add(tblStockMov); dsStockMov.Tables.Add(tblStockMovDetalle); tblStockEntradas = tblStockMov.Clone(); tblEntradasDetalle = tblStockMovDetalle.Clone(); viewStockMov = new DataView(tblStockEntradas); viewStockMovDetalle = new DataView(tblEntradasDetalle); lblNro.ForeColor = System.Drawing.Color.DarkRed; Random rand = new Random(); idMov = rand.Next(-2000000000, 2000000000); lblNro.Text = idMov.ToString(); viewStockMov.RowStateFilter = DataViewRowState.Added; rowView = viewStockMov.AddNew(); rowView["IdMovMSTK"] = idMov.ToString(); rowView["OrigenMSTK"] = 1; rowView["FechaMSTK"] = DateTime.Today; rowView["CompensaMSTK"] = 0; rowView.EndEdit(); dgvDatos.Enabled = false; dateTimePicker1.DataBindings.Add("Text", rowView, "FechaMSTK", false, DataSourceUpdateMode.OnPropertyChanged); cmbOrigen.DataBindings.Add("SelectedValue", rowView, "OrigenMSTK", false, DataSourceUpdateMode.OnPropertyChanged); cmbDestino.DataBindings.Add("SelectedValue", rowView, "DestinoMSTK", false, DataSourceUpdateMode.OnPropertyChanged); rowView.CancelEdit(); bindingSource1.DataSource = viewStockMovDetalle; bindingNavigator1.BindingSource = bindingSource1; dgvDatos.DataSource = bindingSource1; dgvDatos.AllowUserToOrderColumns = false; dgvDatos.EditMode = DataGridViewEditMode.EditOnKeystroke; dgvDatos.Columns["IdArticuloMSTKD"].HeaderText = "Código"; dgvDatos.Columns["IdArticuloMSTKD"].SortMode = DataGridViewColumnSortMode.NotSortable; dgvDatos.Columns["DescripcionART"].HeaderText = "Descripción"; dgvDatos.Columns["DescripcionART"].SortMode = DataGridViewColumnSortMode.NotSortable; dgvDatos.Columns["IdMovMSTKD"].Visible = false; dgvDatos.Columns["IdMSTKD"].Visible = false; dgvDatos.Columns["CompensaMSTKD"].Visible = false; dgvDatos.Columns["OrigenMSTKD"].Visible = false; dgvDatos.Columns["DestinoMSTKD"].Visible = false; dgvDatos.Columns["Precio"].Visible = false; dgvDatos.Columns["CantidadMSTKD"].Width = 100; dgvDatos.Columns["CantidadMSTKD"].HeaderText = "Cantidad"; dgvDatos.Columns["CantidadMSTKD"].SortMode = DataGridViewColumnSortMode.NotSortable; tblArticulos = BL.GetDataBLL.Articulos(); tblArticulos.TableName = "Articulos"; dgvDatos.Columns[3].Width = 500; dgvDatos.Columns[3].ReadOnly = true; dgvDatos.Enabled = false; btnArticulos.Enabled = false; cmbDestino.Focus(); }
[Test] public void IsNew() { DataTable dt = DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); DataRowView drv = dv[0]; // existing row Assert.AreEqual(false, drv.IsNew , "DRV35"); // add new row drv = dv.AddNew(); Assert.AreEqual(true, drv.IsNew , "DRV36"); }
private void frmVentas_Load(object sender, EventArgs e) { this.StartPosition = FormStartPosition.CenterScreen; System.Drawing.Icon ico = Properties.Resources.icono_app; this.Icon = ico; this.ControlBox = true; this.MaximizeBox = false; instanciaVentas = this; this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange; this.ControlBox = true; this.MaximizeBox = false; this.CancelButton = btnSalir; btnSalir.Visible = false; dateTimePicker1.Visible = false; lblFecha.Text = DateTime.Today.ToLongDateString(); lblTotal.ForeColor = System.Drawing.Color.DarkRed; ToolTip tooltipClientes = new ToolTip(); tooltipClientes.SetToolTip(btnClientes, "Agregar nuevo cliente"); ToolTip tooltipCupones = new ToolTip(); tooltipCupones.SetToolTip(btnCupon, "Ingresar cupón de descuento"); dsForaneos = BL.VentasBLL.CrearDatasetForaneos(); tblLocales = dsForaneos.Tables[3]; tblPcs = dsForaneos.Tables[4]; CargarComboLocales(); tblArticulos = dsForaneos.Tables[0]; tblArticulos.TableName = "Articulos"; var source = new AutoCompleteStringCollection(); String[] stringArray = Array.ConvertAll<DataRow, String>(tblArticulos.Select(), delegate(DataRow row) { return (String)row["IdArticuloART"]; }); source.AddRange(stringArray); txtArticulo.AutoCompleteMode = AutoCompleteMode.SuggestAppend; txtArticulo.AutoCompleteCustomSource = source; txtArticulo.AutoCompleteSource = AutoCompleteSource.CustomSource; txtArticulo.BackColor = Color.White; txtDescripcion.BackColor = Color.White; txtDescripcion.TabStop = false; txtDescripcion.ReadOnly = true; txtCantidad.BackColor = Color.White; txtPrecio.BackColor = Color.White; tblFormasPago = dsForaneos.Tables[2]; tblFormasPago.TableName = "FormasPago"; cmbForma.ValueMember = "IdFormaPagoFOR"; cmbForma.DisplayMember = "DescripcionFOR"; cmbForma.DropDownStyle = ComboBoxStyle.DropDown; cmbForma.DataSource = tblFormasPago; cmbForma.SelectedValue = -1; cmbForma.BackColor = Color.White; AutoCompleteStringCollection formasColection = new AutoCompleteStringCollection(); foreach (DataRow row in tblFormasPago.Rows) { formasColection.Add(Convert.ToString(row["DescripcionFOR"])); } cmbForma.AutoCompleteCustomSource = formasColection; cmbForma.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cmbForma.AutoCompleteSource = AutoCompleteSource.CustomSource; txtCosto.Visible = false; grpInicial.CausesValidation = false; grpBotonera.CausesValidation = false; btnClientes.CausesValidation = false; btnCupon.CausesValidation = false; btnEditar.CausesValidation = false; btnBorrar.CausesValidation = false; btnArticulos.CausesValidation = false; lblNro.ForeColor = System.Drawing.Color.DarkRed; dsVentas = new DataSet(); dsVentas.DataSetName = "dsVentas"; if (tblVentas.DataSet == null) { dsVentas.Tables.Add(tblVentas); dsVentas.Tables.Add(tblVentasDetalle); } tblVentasDetalle.PrimaryKey = new DataColumn[] { tblVentasDetalle.Columns["IdDVEN"] }; viewVentas = new DataView(tblVentas); viewDetalle = new DataView(tblVentasDetalle); bindingSource1.DataSource = viewDetalle; bindingNavigator1.BindingSource = bindingSource1; dgvDatos.ReadOnly = true; dgvDatos.AllowUserToAddRows = false; dgvDatos.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgvDatos.DataSource = viewDetalle; dgvDatos.AllowUserToOrderColumns = false; dgvDatos.Columns["IdDVEN"].Visible = false; dgvDatos.Columns["IdVentaDVEN"].Visible = false; dgvDatos.Columns["IdLocalDVEN"].Visible = false; dgvDatos.Columns["PrecioCostoDVEN"].Visible = false; dgvDatos.Columns["PrecioMayorDVEN"].Visible = false; dgvDatos.Columns["IdFormaPagoDVEN"].Visible = false; dgvDatos.Columns["NroCuponDVEN"].Visible = false; dgvDatos.Columns["NroFacturaDVEN"].Visible = false; dgvDatos.Columns["IdEmpleadoDVEN"].Visible = false; dgvDatos.Columns["LiquidadoDVEN"].Visible = false; dgvDatos.Columns["EsperaDVEN"].Visible = false; dgvDatos.Columns["DescripcionDVEN"].HeaderText = "Descripción"; dgvDatos.Columns["CantidadDVEN"].Width = 55; dgvDatos.Columns["CantidadDVEN"].HeaderText = "Cantidad"; dgvDatos.Columns["IdArticuloDVEN"].HeaderText = "Artículo"; dgvDatos.Columns["PrecioPublicoDVEN"].Width = 100; dgvDatos.Columns["PrecioPublicoDVEN"].HeaderText = "Precio"; dgvDatos.Columns["NroFacturaDVEN"].Width = 100; dgvDatos.Columns["NroFacturaDVEN"].HeaderText = "Nº fact."; dgvDatos.Columns.Remove("DevolucionDVEN"); dgvDatos.Columns.Remove("IdFormaPagoDVEN"); cmbFormaPago = new DataGridViewComboBoxColumn(); cmbFormaPago.Name = "FormaPago"; cmbFormaPago.HeaderText = "Forma de pago"; cmbFormaPago.DataSource = tblFormasPago; cmbFormaPago.ValueMember = "IdFormaPagoFOR"; cmbFormaPago.DisplayMember = "DescripcionFOR"; cmbFormaPago.DataPropertyName = "IdFormaPagoDVEN"; dgvDatos.Columns.Insert(7, cmbFormaPago); chkDevolucion = new DataGridViewCheckBoxColumn(); chkDevolucion.Name = "DevolucionDVEN"; chkDevolucion.Width = 40; chkDevolucion.HeaderText = "Dev."; chkDevolucion.DataPropertyName = "DevolucionDVEN"; chkDevolucion.TrueValue = 1; chkDevolucion.FalseValue = 0; dgvDatos.Columns.Insert(12, chkDevolucion); if (PK == "") //registro nuevo { tblVentas.PrimaryKey = new DataColumn[] { tblVentas.Columns["IdVentaVEN"] }; tblDetalleOriginal = tblVentasDetalle.Copy(); //tblDetalleOriginal se usa para controlar errores de guardado remoto por falta de internet Random rand = new Random(); int clave = rand.Next(1, 2000000000); bool existe = true; while (existe == true) { DataRow foundRow = dsVentas.Tables["Ventas"].Rows.Find(clave); if (foundRow == null) { existe = false; } else { clave = rand.Next(1, 2000000000); } } lblNro.Text = clave.ToString(); viewVentas.RowStateFilter = DataViewRowState.Added; viewDetalle.RowStateFilter = DataViewRowState.Added; rowView = viewVentas.AddNew(); rowView["IdVentaVEN"] = clave.ToString(); rowView["FechaVEN"] = DateTime.Now; rowView["IdPCVEN"] = 1; rowView["NroCuponVEN"] = "00000000000"; rowView.EndEdit(); } else // editar registros { tblDetalleOriginal = tblVentasDetalle.Copy(); //tblDetalleOriginal se usa para controlar errores de guardado remoto por falta de internet viewVentas.RowFilter = "IdVentaVEN = '" + PK + "'"; rowView = viewVentas[0]; viewDetalle.RowFilter = "IdVentaDVEN = '" + PK + "'"; lblNro.Text = viewVentas[0][0].ToString(); cmbLocal.Enabled = false; // viewDetalleOriginal se usa para registrar en tabla fallidas errores de guardado remoto por falta de internet viewDetalleOriginal = new DataView(tblDetalleOriginal); viewDetalleOriginal.RowFilter = "IdVentaDVEN = '" + PK + "'"; lblTotal.Text = "$" + CalcularTotalOk().ToString(); } dateTimePicker1.DataBindings.Add("Text", rowView, "FechaVEN", false, DataSourceUpdateMode.OnPropertyChanged); cmbLocal.DataBindings.Add("SelectedValue", rowView, "IdPCVEN", false, DataSourceUpdateMode.OnPropertyChanged); cmbCliente.DataBindings.Add("SelectedValue", rowView, "IdClienteVEN", false, DataSourceUpdateMode.OnPropertyChanged); txtCupon.DataBindings.Add("Text", rowView, "NroCuponVEN", false, DataSourceUpdateMode.OnPropertyChanged); rowView.CancelEdit(); cmbCliente.Validating += new System.ComponentModel.CancelEventHandler(BL.Utilitarios.ValidarComboBox); txtPrecio.KeyPress += new KeyPressEventHandler(BL.Utilitarios.SoloNumerosConComa); txtCantidad.KeyPress += new KeyPressEventHandler(BL.Utilitarios.SoloNumeros); txtArticulo.Enter += new System.EventHandler(Utilitarios.SelTextoTextBox); txtCantidad.Enter += new System.EventHandler(Utilitarios.SelTextoTextBox); txtPrecio.Enter += new System.EventHandler(Utilitarios.SelTextoTextBox); txtArticulo.KeyDown += new System.Windows.Forms.KeyEventHandler(Utilitarios.EnterTab); txtCantidad.KeyDown += new System.Windows.Forms.KeyEventHandler(Utilitarios.EnterTab); txtPrecio.KeyDown += new System.Windows.Forms.KeyEventHandler(Utilitarios.EnterTab); cmbForma.KeyDown += new System.Windows.Forms.KeyEventHandler(Utilitarios.EnterTab); cmbForma.Validating += new System.ComponentModel.CancelEventHandler(BL.Utilitarios.ValidarComboBox); chkDev.KeyDown += new System.Windows.Forms.KeyEventHandler(Utilitarios.EnterTab); if (!string.IsNullOrEmpty(PK)) //registro nuevo { tblVentas.AcceptChanges(); tblVentasDetalle.AcceptChanges(); } SetStateForm(FormState.insercion); }
public void CancelEditAndEvents () { string reference = " =====ItemAdded:3 ------4 =====ItemAdded:3 =====ItemAdded:4 ------5 =====ItemAdded:4 =====ItemAdded:5 ------6 =====ItemDeleted:5 ------5 =====ItemAdded:5"; eventWriter = new StringWriter (); DataTable dt = new DataTable (); dt.Columns.Add ("col1"); dt.Columns.Add ("col2"); dt.Columns.Add ("col3"); dt.Rows.Add (new object [] {1,2,3}); dt.Rows.Add (new object [] {1,2,3}); dt.Rows.Add (new object [] {1,2,3}); DataView dv = new DataView (dt); dv.ListChanged += new ListChangedEventHandler (ListChanged); DataRowView a1 = dv.AddNew (); eventWriter.Write (" ------" + dv.Count); // I wonder why but MS fires another event here. a1 = dv.AddNew (); eventWriter.Write (" ------" + dv.Count); // I wonder why but MS fires another event here. DataRowView a2 = dv.AddNew (); eventWriter.Write (" ------" + dv.Count); a2.CancelEdit (); eventWriter.Write (" ------" + dv.Count); DataRowView a3 = dv.AddNew (); AssertEquals (reference, eventWriter.ToString ()); }
private void CreateAction(DataView actions, String id, String action, int weight) { DataRowView row = actions.AddNew(); row[Strings.ACTION_ID] = id; row[Strings.ACTION] = action; row[Strings.WEIGHT] = weight; row.EndEdit(); }