private int method_1(library_dataDataSet library_dataDataSet_0, List <DataRow> allAddedRows) { DataRow[] rowArray; int num = 0; if (this.tblGoodsTableAdapter_0 != null) { rowArray = library_dataDataSet_0.tblGoods.Select(null, null, DataViewRowState.Added); if ((rowArray != null) && (0 < rowArray.Length)) { num += this.tblGoodsTableAdapter_0.Update(rowArray); allAddedRows.AddRange(rowArray); } } if (this.tblBookAttrTableAdapter_0 != null) { rowArray = library_dataDataSet_0.tblBookAttr.Select(null, null, DataViewRowState.Added); if ((rowArray != null) && (0 < rowArray.Length)) { num += this.tblBookAttrTableAdapter_0.Update(rowArray); allAddedRows.AddRange(rowArray); } } if (this.tblCustomerTableAdapter_0 != null) { rowArray = library_dataDataSet_0.tblCustomer.Select(null, null, DataViewRowState.Added); if ((rowArray != null) && (0 < rowArray.Length)) { num += this.tblCustomerTableAdapter_0.Update(rowArray); allAddedRows.AddRange(rowArray); } } return(num); }
public virtual int Update(library_dataDataSet dataSet) { return(this.Adapter.Update(dataSet, "tblBookAttr")); }
public virtual int UpdateAll(library_dataDataSet dataSet) { DataRow[] rowArray; int num2; DataRow row; if (dataSet == null) { throw new ArgumentNullException("dataSet"); } if (!dataSet.HasChanges()) { return(0); } if (!((this.tblBookAttrTableAdapter_0 == null) || this.MatchTableAdapterConnection(this.tblBookAttrTableAdapter_0.SqlConnection_0))) { throw new ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection string."); } if (!((this.tblCustomerTableAdapter_0 == null) || this.MatchTableAdapterConnection(this.tblCustomerTableAdapter_0.SqlConnection_0))) { throw new ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection string."); } if (!((this.tblGoodsTableAdapter_0 == null) || this.MatchTableAdapterConnection(this.tblGoodsTableAdapter_0.SqlConnection_0))) { throw new ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection string."); } IDbConnection connection = this.Connection; if (connection == null) { throw new ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterManager TableAdapter property to a valid TableAdapter instance."); } bool flag = false; if ((connection.State & ConnectionState.Broken) == ConnectionState.Broken) { connection.Close(); } if (connection.State == ConnectionState.Closed) { connection.Open(); flag = true; } IDbTransaction transaction = connection.BeginTransaction(); if (transaction == null) { throw new ApplicationException("The transaction cannot begin. The current data connection does not support transactions or the current state is not allowing the transaction to begin."); } List <DataRow> allChangedRows = new List <DataRow>(); List <DataRow> allAddedRows = new List <DataRow>(); List <DataAdapter> list3 = new List <DataAdapter>(); Dictionary <object, IDbConnection> dictionary = new Dictionary <object, IDbConnection>(); int num = 0; DataSet set = null; if (this.BackupDataSetBeforeUpdate) { set = new DataSet(); set.Merge(dataSet); } try { if (this.tblBookAttrTableAdapter_0 != null) { dictionary.Add(this.tblBookAttrTableAdapter_0, this.tblBookAttrTableAdapter_0.SqlConnection_0); this.tblBookAttrTableAdapter_0.SqlConnection_0 = (SqlConnection)connection; this.tblBookAttrTableAdapter_0.SqlTransaction_0 = (SqlTransaction)transaction; if (this.tblBookAttrTableAdapter_0.Adapter.AcceptChangesDuringUpdate) { this.tblBookAttrTableAdapter_0.Adapter.AcceptChangesDuringUpdate = false; list3.Add(this.tblBookAttrTableAdapter_0.Adapter); } } if (this.tblCustomerTableAdapter_0 != null) { dictionary.Add(this.tblCustomerTableAdapter_0, this.tblCustomerTableAdapter_0.SqlConnection_0); this.tblCustomerTableAdapter_0.SqlConnection_0 = (SqlConnection)connection; this.tblCustomerTableAdapter_0.SqlTransaction_0 = (SqlTransaction)transaction; if (this.tblCustomerTableAdapter_0.Adapter.AcceptChangesDuringUpdate) { this.tblCustomerTableAdapter_0.Adapter.AcceptChangesDuringUpdate = false; list3.Add(this.tblCustomerTableAdapter_0.Adapter); } } if (this.tblGoodsTableAdapter_0 != null) { dictionary.Add(this.tblGoodsTableAdapter_0, this.tblGoodsTableAdapter_0.SqlConnection_0); this.tblGoodsTableAdapter_0.SqlConnection_0 = (SqlConnection)connection; this.tblGoodsTableAdapter_0.SqlTransaction_0 = (SqlTransaction)transaction; if (this.tblGoodsTableAdapter_0.Adapter.AcceptChangesDuringUpdate) { this.tblGoodsTableAdapter_0.Adapter.AcceptChangesDuringUpdate = false; list3.Add(this.tblGoodsTableAdapter_0.Adapter); } } if (this.UpdateOrder == UpdateOrderOption.UpdateInsertDelete) { num += this.method_0(dataSet, allChangedRows, allAddedRows); num += this.method_1(dataSet, allAddedRows); } else { num += this.method_1(dataSet, allAddedRows); num += this.method_0(dataSet, allChangedRows, allAddedRows); } num += this.method_2(dataSet, allChangedRows); transaction.Commit(); if (0 < allAddedRows.Count) { rowArray = new DataRow[allAddedRows.Count]; allAddedRows.CopyTo(rowArray); for (num2 = 0; num2 < rowArray.Length; num2++) { row = rowArray[num2]; row.AcceptChanges(); } } if (0 < allChangedRows.Count) { rowArray = new DataRow[allChangedRows.Count]; allChangedRows.CopyTo(rowArray); num2 = 0; while (num2 < rowArray.Length) { row = rowArray[num2]; row.AcceptChanges(); num2++; } } } catch (Exception exception) { transaction.Rollback(); if (this.BackupDataSetBeforeUpdate) { Debug.Assert(set != null); dataSet.Clear(); dataSet.Merge(set); } else if (0 < allAddedRows.Count) { rowArray = new DataRow[allAddedRows.Count]; allAddedRows.CopyTo(rowArray); num2 = 0; while (num2 < rowArray.Length) { row = rowArray[num2]; row.AcceptChanges(); row.SetAdded(); num2++; } } throw exception; } finally { if (flag) { connection.Close(); } if (this.tblBookAttrTableAdapter_0 != null) { this.tblBookAttrTableAdapter_0.SqlConnection_0 = (SqlConnection)dictionary[this.tblBookAttrTableAdapter_0]; this.tblBookAttrTableAdapter_0.SqlTransaction_0 = null; } if (this.tblCustomerTableAdapter_0 != null) { this.tblCustomerTableAdapter_0.SqlConnection_0 = (SqlConnection)dictionary[this.tblCustomerTableAdapter_0]; this.tblCustomerTableAdapter_0.SqlTransaction_0 = null; } if (this.tblGoodsTableAdapter_0 != null) { this.tblGoodsTableAdapter_0.SqlConnection_0 = (SqlConnection)dictionary[this.tblGoodsTableAdapter_0]; this.tblGoodsTableAdapter_0.SqlTransaction_0 = null; } if (0 < list3.Count) { DataAdapter[] array = new DataAdapter[list3.Count]; list3.CopyTo(array); for (num2 = 0; num2 < array.Length; num2++) { DataAdapter adapter = array[num2]; adapter.AcceptChangesDuringUpdate = true; } } } return(num); }