本文整理汇总了C#中System.Data.DataView.AddNew方法的典型用法代码示例。如果您正苦于以下问题:C# DataView.AddNew方法的具体用法?C# DataView.AddNew怎么用?C# DataView.AddNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataView
的用法示例。
在下文中一共展示了DataView.AddNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddNew
[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");
}
示例2: DemonstrateDtaView
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");
}
示例3: Form_AccountList
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();
}
}
示例4: AddNew
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);
}
示例5: fillComboBoxes
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";
}
示例6: AgregarFondoCaja
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);
}
}
示例7: btnAgrupar_Click
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();
}
}
示例8: UnsignedTypes
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));
}
}
示例9: run
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");
//.........这里部分代码省略.........
示例10: AllowNew
[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");
}
示例11: frmStockMov_Load
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);
}
示例12: RowVersion1
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);
}
示例13: frmFondoCaja_Load
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();
}
示例14: run
//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;}
}
示例15: frmVentas_Load
//.........这里部分代码省略.........
{
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);
}