void removeExpiredRows(DataTable table, string expiredColumnName) { string filter = string.Format(CultureInfo.InvariantCulture, "{0} < #{1}#", expiredColumnName, DateTime.Now); DataView view = new DataView(table, filter, null, DataViewRowState.CurrentRows); for (int i = view.Count - 1; i >= 0; i--) view.Delete(i); }
public void delImportCar(string sSimNum) { DataView view = new DataView(this.m_dtImportCar, string.Format("SimNum='{0}'", sSimNum), "", DataViewRowState.CurrentRows); if (view.Count > 0) { if (this.lbImportCar.SelectedValue.ToString() == sSimNum) ///ToString { this.setTrackingCar(); } view.Delete(0); } }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { int index; index = SndataGrid.CurrentCell.RowNumber; int rNumber = sRow.Number; using (FBirdTask t = new FBirdTask()) { t.CommandText = "DELETE FROM [SongNotes] WHERE [Number] = @NNumber"; t.AddParameter("@Number", rNumber); t.ExecuteNonQuery(); } SNdataView.Delete(index); }
protected void repMyInfoBind() { DataTable dtInfo = new DataTable(); dtInfo.Columns.Add("Title", typeof(string)); dtInfo.Columns.Add("Id", typeof(int)); dtInfo.Columns.Add("AddTime", typeof(DateTime)); // dtInfo.Columns.Add("RowIndex", typeof(int)); // int rowIndex = 0; dtInfo.Columns.Add("ModelType", typeof(int)); DataTable modelDt = InfoModelBll.GetList(); foreach (DataRow dr in modelDt.Rows) { string tableName = dr["TableName"].ToString(); int recordCount = 0; DataTable dt = InfoOperBll.GetUserInfoList(tableName, UserModel.UserID, "", "", 0, "0", "3", "", "", "", -1, 1, 10, ref recordCount); InfoNumber.Text = dt.Rows.Count.ToString(); for (int i = 0; i < dt.Rows.Count; i++) { DataRow tempDr = dtInfo.NewRow(); tempDr["Title"] = dt.Rows[i]["Title"]; tempDr["Id"] = dt.Rows[i]["id"]; tempDr["AddTime"] = dt.Rows[i]["AddTime"]; tempDr["ModelType"] = dt.Rows[i]["ModelType"]; //tempDr["RowIndex"] = rowIndex; // rowIndex++; dtInfo.Rows.Add(tempDr); } dt.Dispose(); } DataView dv = new DataView(dtInfo); dv.Sort = "AddTime desc"; if (dv.Count <= 0) { showMore1.Visible = false; Label1.Text = "暂无稿件!"; return; } while (dv.Count > 5) dv.Delete(dv.Count - 1); repMyInfo.DataSource = dv; repMyInfo.DataBind(); }
private void DeleteAllTrans(System.Object sender, EventArgs e) { if ((FPreviouslySelectedDetailRow == null) || !FIsUnposted) { return; } else if (!FFilterAndFindObject.IsActiveFilterEqualToBase) { MessageBox.Show(Catalog.GetString("Please remove the filter before attempting to delete all transactions in this journal."), Catalog.GetString("Delete All Transactions")); return; } if ((MessageBox.Show(String.Format(Catalog.GetString( "You have chosen to delete all transactions in this Journal ({0}).\n\nDo you really want to continue?"), FJournalNumber), Catalog.GetString("Confirm Deletion"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)) { //Backup the Dataset for reversion purposes GLBatchTDS FTempDS = (GLBatchTDS)FMainDS.Copy(); FTempDS.Merge(FMainDS); try { //Unbind any transactions currently being editied in the Transaction Tab ClearCurrentSelection(); //Delete transactions DataView TransDV = new DataView(FMainDS.ATransaction); DataView TransAttribDV = new DataView(FMainDS.ATransAnalAttrib); TransDV.AllowDelete = true; TransAttribDV.AllowDelete = true; TransDV.RowFilter = String.Format("{0}={1} AND {2}={3}", ATransactionTable.GetBatchNumberDBName(), FBatchNumber, ATransactionTable.GetJournalNumberDBName(), FJournalNumber); TransDV.Sort = String.Format("{0} ASC", ATransactionTable.GetTransactionNumberDBName()); TransAttribDV.RowFilter = String.Format("{0}={1} AND {2}={3}", ATransactionTable.GetBatchNumberDBName(), FBatchNumber, ATransactionTable.GetJournalNumberDBName(), FJournalNumber); TransAttribDV.Sort = String.Format("{0} ASC, {1} ASC", ATransAnalAttribTable.GetTransactionNumberDBName(), ATransAnalAttribTable.GetAnalysisTypeCodeDBName()); for (int i = TransAttribDV.Count - 1; i >= 0; i--) { TransAttribDV.Delete(i); } for (int i = TransDV.Count - 1; i >= 0; i--) { TransDV.Delete(i); } //Set last journal number GetJournalRow().LastTransactionNumber = 0; FPetraUtilsObject.SetChangedFlag(); //Need to call save if (((TFrmGLBatch)ParentForm).SaveChanges()) { MessageBox.Show(Catalog.GetString("The journal has been cleared successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateTransactionTotals(); ((TFrmGLBatch)ParentForm).SaveChanges(); } else { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString( "The journal has been cleared but there were problems during saving; ") + Environment.NewLine + Catalog.GetString("Please try and save immediately."), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); SelectRowInGrid(1); } } catch (Exception ex) { MessageBox.Show(ex.Message); FMainDS.Merge(FTempDS); } //If all rows have deleted successfully if (grdDetails.Rows.Count < 2) { UpdateChangeableStatus(); ClearControls(); } } }
public void TestDeleteClosed () { DataView TestView = new DataView (dataTable); TestView.Dispose (); // Close the table TestView.Delete (0); // cannot access to item at 0. }
public void TestDeleteOutOfBounds () { DataView TestView = new DataView (dataTable); TestView.Delete (100); }
public void RowStateFilter_2 () { DataSet dataset = new DataSet ("new"); DataTable dt = new DataTable ("table1"); dataset.Tables.Add (dt); dt.Columns.Add ("col1"); dt.Columns.Add ("col2"); dt.Rows.Add (new object [] {1,1}); dt.Rows.Add (new object [] {1,2}); dt.Rows.Add (new object [] {1,3}); dataset.AcceptChanges (); DataView dataView = new DataView (dataset.Tables [0]); // 'new' table in this sample contains 6 records dataView.AllowEdit = true; dataView.AllowDelete = true; string v; // Editing the row dataView [0] ["col1"] = -1; dataView.RowStateFilter = DataViewRowState.ModifiedOriginal; v = dataView [0] [0].ToString (); AssertEquals ("ModifiedOriginal.Count", 1, dataView.Count); AssertEquals ("ModifiedOriginal.Value", "1", v); // Deleting the row dataView.Delete (0); dataView.RowStateFilter = DataViewRowState.Deleted; v = dataView [0] [0].ToString (); AssertEquals ("Deleted.Count", 1, dataView.Count); AssertEquals ("Deleted.Value", "1", v); }
// delete all rows private void DeleteAllReallocations(Object Sender, EventArgs e) { if (FPreviouslySelectedDetailRow == null) { return; } if ((MessageBox.Show(String.Format(Catalog.GetString( "You have chosen to delete all Reallocations.\n\nDo you really want to continue?")), Catalog.GetString("Confirm Deletion"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)) { DataView dv = ((DevAge.ComponentModel.BoundDataView)grdDetails.DataSource).DataView; DataView TransAttribDV = new DataView(FMainDS.ATransAnalAttrib); for (int i = TransAttribDV.Count - 1; i >= 0; i--) { TransAttribDV.Delete(i); } for (int i = dv.Count - 1; i >= 0; i--) { dv[i].Delete(); } SelectRowInGrid(1); btnOK.Enabled = false; } }
public void Delete() { DataView.Delete(_index); }
public void TestDeleteClosed () { DataView TestView = new DataView (dataTable); TestView.Dispose (); // Close the table TestView.Delete (0); }
public DataView FillAdSet(DataSet dsAds, bool isBig) { //1. If less than or equal to 52, add the ads //in a second time. If less than 35, add the ads three times, //if less than 26 four times, less than 21 five times, less than //17 six times, less than 15 seven times, less than 13 eight times, // less than 11 nine times, less than 10 ten times, less than 9 eleven // times, less than 8 thirteen times, less than 7 fifteen times, // less than 6 seventeen times, less than 5 twenty one times, //less than 4 twenty six times, 3 thirty times. //2. Fill the rest with Hippo Happenings ad stating that there’s a discount, //meaning you will see your ad more frequently for the same price. DataView dvAds = new DataView(dsAds.Tables[0], "", "", DataViewRowState.CurrentRows); //If ad count is as desired, return the original dataset int adNumberToGet = numberTotalAds; if (isBig) adNumberToGet = numberTotalBigAds; if (dvAds.Count == adNumberToGet) { return dvAds; } //If ad count is bigger than desired, trim the dataset else if (dvAds.Count > adNumberToGet) { for (int i = adNumberToGet; i < dvAds.Count - adNumberToGet; i++) { dvAds.Delete(i); } return dvAds; } //If ad set is zero, fill all with hippo happenings ads else if (dvAds.Count == 0) { ArrayList a = new ArrayList(adNumberToGet); for (int i = 0; i < adNumberToGet; i++) { if (i % 2 == 0) { a.Insert(i, hippoHalfAvailableCategory); } else { a.Insert(i, hippoAdCategory); } } DataSet ab = GetAdsBasedOnArray(a); DataView dvAB = new DataView(ab.Tables[0], "", "", DataViewRowState.CurrentRows); return dvAB; } //If ad count is less than desired, add hippo ads and multiply the ads whever probable else { ArrayList a = new ArrayList(adNumberToGet); //Fill with ads that state half of the space is available so your ad will be seen //more than once for the same price. bool fillWithHalf = false; int toDivideBy = 4; if (isBig) toDivideBy = 2; int temp = adNumberToGet / toDivideBy; //subtract one of the ads for every four/two since these will be filled with hippo ads. int temp2 = adNumberToGet - temp; int temp3 = temp2 / 2; if (dvAds.Count <= temp3) { fillWithHalf = true; } if (fillWithHalf) { int repeatNum = temp2 / dvAds.Count; int repeatNumCount = 1; int threeOrOne = 3; if (isBig) threeOrOne = 1; int countAds = 0; for (int j = 0; j < adNumberToGet; j++) { //when there is less than or equal to a half minus hippo ads //fill the hippo add every fourt ad, //repeat the ads the number of times all of them can repeat in full //when reach the point where they can't all repeat, fill the rest with hippo ads if (j % toDivideBy == threeOrOne) { a.Insert(j,hippoHalfAvailableCategory); } else { if (repeatNumCount <= repeatNum) { a.Insert(j, dvAds[countAds]["Ad_ID"]); countAds++; if (countAds == dvAds.Count) { repeatNumCount++; countAds = 0; } } else { a.Insert(j, hippoHalfAvailableCategory); } } } } else { for (int j = 0; j < adNumberToGet; j++) { //when there is more than half - hippo ads, fill ads from the beginning //Hippo ads will go in the back if (j < dvAds.Count) { a.Insert(j, dvAds[j]["Ad_ID"]); } else { a.Insert(j, hippoAdCategory); } } } DataSet ab = GetAdsBasedOnArray(a); DataView dvAB = new DataView(ab.Tables[0], "", "", DataViewRowState.CurrentRows); return dvAB; } }
/// <summary> /// Receives a record number and DataView as parameters and deletes that /// record /// </summary> /// <param name="nPosition"></param> /// <param name="toView"></param> public static void Delete(int nRecNo, System.Data.DataView toView) { toView.Delete(nRecNo); }
//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 = dv[0]; BeginCase("Delete - DataView Row Count"); try { dv.Delete(0); Compare(CountView-1,dv.Count ); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } BeginCase("Delete - Table Row Count "); try { Compare(CountTable,dt.Rows.Count ); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } BeginCase("Delete - check table"); try { Compare(drv.Row.Table,dt); } catch (Exception ex) { exp = ex; } finally { EndCase(exp); exp = null; } }
[Test] public void Delete() { //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 = dv[0]; // Delete - DataView Row Count dv.Delete(0); Assert.AreEqual(dv.Count , CountView-1, "DV32"); // Delete - Table Row Count Assert.AreEqual(dt.Rows.Count , CountTable, "DV33"); // Delete - check table Assert.AreEqual(dt, drv.Row.Table, "DV34"); }
[Test] public void AllowDelete() { DataTable dt = DataProvider.CreateParentDataTable(); DataView dv = new DataView(dt); // AllowDelete - default value Assert.AreEqual(true , dv.AllowDelete , "DV6"); // AllowDelete - true dv.AllowDelete = true; Assert.AreEqual(true, dv.AllowDelete , "DV7"); // AllowDelete - false dv.AllowDelete = false; Assert.AreEqual(false, dv.AllowDelete , "DV8"); dv.AllowDelete = false; // AllowDelete false- Exception try { dv.Delete(0); Assert.Fail("DV9: Delete Failed to throw DataException"); } catch (DataException) {} catch (AssertionException exc) {throw exc;} catch (Exception exc) { Assert.Fail("DV10: Delete. Wrong exception type. Got:" + exc); } dv.AllowDelete = true; int RowsCount = dv.Count ; // AllowDelete true- Exception dv.Delete(0); Assert.AreEqual(RowsCount-1, dv.Count , "DV11"); }
_delayBeginEdit; // DataRowView.BegingEdit() was called, but not edited yet. public void Delete() => _dataView.Delete(Row);
//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("AllowDelete - default value"); Compare(dv.AllowDelete ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("AllowDelete - true"); dv.AllowDelete = true; Compare(dv.AllowDelete , true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("AllowDelete - false"); dv.AllowDelete = false; Compare(dv.AllowDelete , false); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dv.AllowDelete = false; try { BeginCase("AllowDelete false- Exception"); try { dv.Delete(0); } 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.AllowDelete = true; int RowsCount = dv.Count ; try { BeginCase("AllowDelete true- Exception"); dv.Delete(0); Compare(dv.Count , RowsCount-1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} }
public void Delete() { dataView.Delete(Row); }
public void TestDelete () { DataView TestView = new DataView (dataTable); TestView.Delete (0); DataRow r = TestView.Table.Rows [0]; Assertion.Assert ("Dv #1", !((string)r ["itemId"] == "item 1")); }
public static void DataTableDeleteAllEmptyRow(DataView aDView, DataTable aDTable) { for(int iRow = 0; iRow < aDView.Count-1; iRow++) { string rowVal = string.Empty; foreach (DataColumn dCol in aDTable.Columns) { object val=aDView[iRow][dCol.Ordinal]; if (!val.Equals(dCol.DefaultValue)) rowVal+= val.ToString(); } if (rowVal.Length == 0) aDView.Delete(iRow); else break; } }
public void TestDeleteNotAllowed () { DataView TestView = new DataView (dataTable); TestView.AllowDelete = false; TestView.Delete (0); }
public static void DataTableDeleteLastEmptyRow(DataView aDView, int aCurrentRowIndex, DataTable aDTable) { for(int iRow = aDView.Count-1; iRow > aCurrentRowIndex; iRow--) { string rowVal = string.Empty; foreach (DataColumn dCol in aDTable.Columns) rowVal += aDView[iRow][dCol.Ordinal].ToString().Equals("0")?string.Empty:aDView[iRow][dCol.Ordinal].ToString(); if (rowVal.Length == 0) aDView.Delete(iRow); else break; } }
[Test] // based on bug #74631 public void TestDeleteAndCount () { DataSet dataset = new DataSet ("new"); DataTable dt = new DataTable ("table1"); dataset.Tables.Add (dt); dt.Columns.Add ("col1"); dt.Columns.Add ("col2"); dt.Rows.Add (new object []{1,1}); dt.Rows.Add (new object []{1,2}); dt.Rows.Add (new object []{1,3}); DataView dataView = new DataView (dataset.Tables[0]); AssertEquals ("before delete", 3, dataView.Count); dataView.AllowDelete = true; // Deleting the first row dataView.Delete (0); AssertEquals ("before delete", 2, dataView.Count); }
/// <include file='doc\DataRowView.uex' path='docs/doc[@for="DataRowView.Delete"]/*' /> /// <devdoc> /// <para>Deletes a row.</para> /// </devdoc> public void Delete() { dataView.Delete(index); }