Advertisement
Guest User

Untitled

a guest
Sep 27th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 40.00 KB | None | 0 0
  1. namespace edited.DatabaseDataSetTableAdapters {
  2.    
  3.    
  4.     /// <summary>
  5.     ///Represents the connection and commands used to retrieve and save data.
  6.     ///</summary>
  7.     [global::System.ComponentModel.DesignerCategoryAttribute("code")]
  8.     [global::System.ComponentModel.ToolboxItem(true)]
  9.     [global::System.ComponentModel.DataObjectAttribute(true)]
  10.     [global::System.ComponentModel.DesignerAttribute("Microsoft.VSDesigner.DataSource.Design.TableAdapterDesigner, Microsoft.VSDesigner" +
  11.         ", Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  12.     [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  13.     public partial class CompaniesTableAdapter : global::System.ComponentModel.Component {
  14.        
  15.         private global::System.Data.SqlClient.SqlDataAdapter _adapter;
  16.        
  17.         private global::System.Data.SqlClient.SqlConnection _connection;
  18.        
  19.         private global::System.Data.SqlClient.SqlTransaction _transaction;
  20.        
  21.         private global::System.Data.SqlClient.SqlCommand[] _commandCollection;
  22.        
  23.         private bool _clearBeforeFill;
  24.        
  25.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  26.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  27.         public CompaniesTableAdapter() {
  28.             this.ClearBeforeFill = true;
  29.         }
  30.        
  31.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  32.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  33.         protected internal global::System.Data.SqlClient.SqlDataAdapter Adapter {
  34.             get {
  35.                 if ((this._adapter == null)) {
  36.                     this.InitAdapter();
  37.                 }
  38.                 return this._adapter;
  39.             }
  40.         }
  41.        
  42.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  43.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  44.         internal global::System.Data.SqlClient.SqlConnection Connection {
  45.             get {
  46.                 if ((this._connection == null)) {
  47.                     this.InitConnection();
  48.                 }
  49.                 return this._connection;
  50.             }
  51.             set {
  52.                 this._connection = value;
  53.                 if ((this.Adapter.InsertCommand != null)) {
  54.                     this.Adapter.InsertCommand.Connection = value;
  55.                 }
  56.                 if ((this.Adapter.DeleteCommand != null)) {
  57.                     this.Adapter.DeleteCommand.Connection = value;
  58.                 }
  59.                 if ((this.Adapter.UpdateCommand != null)) {
  60.                     this.Adapter.UpdateCommand.Connection = value;
  61.                 }
  62.                 for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1)) {
  63.                     if ((this.CommandCollection[i] != null)) {
  64.                         ((global::System.Data.SqlClient.SqlCommand)(this.CommandCollection[i])).Connection = value;
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.        
  70.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  71.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  72.         internal global::System.Data.SqlClient.SqlTransaction Transaction {
  73.             get {
  74.                 return this._transaction;
  75.             }
  76.             set {
  77.                 this._transaction = value;
  78.                 for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1)) {
  79.                     this.CommandCollection[i].Transaction = this._transaction;
  80.                 }
  81.                 if (((this.Adapter != null)
  82.                             && (this.Adapter.DeleteCommand != null))) {
  83.                     this.Adapter.DeleteCommand.Transaction = this._transaction;
  84.                 }
  85.                 if (((this.Adapter != null)
  86.                             && (this.Adapter.InsertCommand != null))) {
  87.                     this.Adapter.InsertCommand.Transaction = this._transaction;
  88.                 }
  89.                 if (((this.Adapter != null)
  90.                             && (this.Adapter.UpdateCommand != null))) {
  91.                     this.Adapter.UpdateCommand.Transaction = this._transaction;
  92.                 }
  93.             }
  94.         }
  95.        
  96.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  97.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  98.         protected global::System.Data.SqlClient.SqlCommand[] CommandCollection {
  99.             get {
  100.                 if ((this._commandCollection == null)) {
  101.                     this.InitCommandCollection();
  102.                 }
  103.                 return this._commandCollection;
  104.             }
  105.         }
  106.        
  107.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  108.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  109.         public bool ClearBeforeFill {
  110.             get {
  111.                 return this._clearBeforeFill;
  112.             }
  113.             set {
  114.                 this._clearBeforeFill = value;
  115.             }
  116.         }
  117.        
  118.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  119.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  120.         private void InitAdapter() {
  121.             this._adapter = new global::System.Data.SqlClient.SqlDataAdapter();
  122.             global::System.Data.Common.DataTableMapping tableMapping = new global::System.Data.Common.DataTableMapping();
  123.             tableMapping.SourceTable = "Table";
  124.             tableMapping.DataSetTable = "Companies";
  125.             tableMapping.ColumnMappings.Add("Name", "Name");
  126.             this._adapter.TableMappings.Add(tableMapping);
  127.             this._adapter.DeleteCommand = new global::System.Data.SqlClient.SqlCommand();
  128.             this._adapter.DeleteCommand.Connection = this.Connection;
  129.             this._adapter.DeleteCommand.CommandText = "DELETE FROM [Companies] WHERE (([Name] = @Original_Name))";
  130.             this._adapter.DeleteCommand.CommandType = global::System.Data.CommandType.Text;
  131.             this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Original_Name", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "Name", global::System.Data.DataRowVersion.Original, false, null, "", "", ""));
  132.             this._adapter.InsertCommand = new global::System.Data.SqlClient.SqlCommand();
  133.             this._adapter.InsertCommand.Connection = this.Connection;
  134.             this._adapter.InsertCommand.CommandText = "INSERT INTO [Companies] ([Name]) VALUES (@Name);\r\nSELECT Name FROM Companies WHER" +
  135.                 "E (Name = @Name)";
  136.             this._adapter.InsertCommand.CommandType = global::System.Data.CommandType.Text;
  137.             this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Name", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "Name", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
  138.             this._adapter.UpdateCommand = new global::System.Data.SqlClient.SqlCommand();
  139.             this._adapter.UpdateCommand.Connection = this.Connection;
  140.             this._adapter.UpdateCommand.CommandText = "UPDATE [Companies] SET [Name] = @Name WHERE (([Name] = @Original_Name));\r\nSELECT " +
  141.                 "Name FROM Companies WHERE (Name = @Name)";
  142.             this._adapter.UpdateCommand.CommandType = global::System.Data.CommandType.Text;
  143.             this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Name", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "Name", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
  144.             this._adapter.UpdateCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Original_Name", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "Name", global::System.Data.DataRowVersion.Original, false, null, "", "", ""));
  145.         }
  146.        
  147.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  148.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  149.         private void InitConnection() {
  150.             this._connection = new global::System.Data.SqlClient.SqlConnection();
  151.             this._connection.ConnectionString = global::edited.Properties.Settings.Default.DatabaseConnectionString;
  152.         }
  153.        
  154.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  155.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  156.         private void InitCommandCollection() {
  157.             this._commandCollection = new global::System.Data.SqlClient.SqlCommand[1];
  158.             this._commandCollection[0] = new global::System.Data.SqlClient.SqlCommand();
  159.             this._commandCollection[0].Connection = this.Connection;
  160.             this._commandCollection[0].CommandText = "SELECT Name FROM Companies";
  161.             this._commandCollection[0].CommandType = global::System.Data.CommandType.Text;
  162.         }
  163.        
  164.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  165.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  166.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  167.         [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Fill, true)]
  168.         public virtual int Fill(DatabaseDataSet.CompaniesDataTable dataTable) {
  169.             this.Adapter.SelectCommand = this.CommandCollection[0];
  170.             if ((this.ClearBeforeFill == true)) {
  171.                 dataTable.Clear();
  172.             }
  173.             int returnValue = this.Adapter.Fill(dataTable);
  174.             return returnValue;
  175.         }
  176.        
  177.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  178.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  179.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  180.         [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Select, true)]
  181.         public virtual DatabaseDataSet.CompaniesDataTable GetData() {
  182.             this.Adapter.SelectCommand = this.CommandCollection[0];
  183.             DatabaseDataSet.CompaniesDataTable dataTable = new DatabaseDataSet.CompaniesDataTable();
  184.             this.Adapter.Fill(dataTable);
  185.             return dataTable;
  186.         }
  187.        
  188.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  189.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  190.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  191.         public virtual int Update(DatabaseDataSet.CompaniesDataTable dataTable) {
  192.             return this.Adapter.Update(dataTable);
  193.         }
  194.        
  195.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  196.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  197.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  198.         public virtual int Update(DatabaseDataSet dataSet) {
  199.             return this.Adapter.Update(dataSet, "Companies");
  200.         }
  201.        
  202.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  203.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  204.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  205.         public virtual int Update(global::System.Data.DataRow dataRow) {
  206.             return this.Adapter.Update(new global::System.Data.DataRow[] {
  207.                         dataRow});
  208.         }
  209.        
  210.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  211.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  212.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  213.         public virtual int Update(global::System.Data.DataRow[] dataRows) {
  214.             return this.Adapter.Update(dataRows);
  215.         }
  216.        
  217.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  218.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  219.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  220.         [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Delete, true)]
  221.         public virtual int Delete(string Original_Name) {
  222.             if ((Original_Name == null)) {
  223.                 throw new global::System.ArgumentNullException("Original_Name");
  224.             }
  225.             else {
  226.                 this.Adapter.DeleteCommand.Parameters[0].Value = ((string)(Original_Name));
  227.             }
  228.             global::System.Data.ConnectionState previousConnectionState = this.Adapter.DeleteCommand.Connection.State;
  229.             if (((this.Adapter.DeleteCommand.Connection.State & global::System.Data.ConnectionState.Open)
  230.                         != global::System.Data.ConnectionState.Open)) {
  231.                 this.Adapter.DeleteCommand.Connection.Open();
  232.             }
  233.             try {
  234.                 int returnValue = this.Adapter.DeleteCommand.ExecuteNonQuery();
  235.                 return returnValue;
  236.             }
  237.             finally {
  238.                 if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) {
  239.                     this.Adapter.DeleteCommand.Connection.Close();
  240.                 }
  241.             }
  242.         }
  243.        
  244.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  245.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  246.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  247.         [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Insert, true)]
  248.         public virtual int Insert(string Name) {
  249.             if ((Name == null)) {
  250.                 throw new global::System.ArgumentNullException("Name");
  251.             }
  252.             else {
  253.                 this.Adapter.InsertCommand.Parameters[0].Value = ((string)(Name));
  254.             }
  255.             global::System.Data.ConnectionState previousConnectionState = this.Adapter.InsertCommand.Connection.State;
  256.             if (((this.Adapter.InsertCommand.Connection.State & global::System.Data.ConnectionState.Open)
  257.                         != global::System.Data.ConnectionState.Open)) {
  258.                 this.Adapter.InsertCommand.Connection.Open();
  259.             }
  260.             try {
  261.                 int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
  262.                 return returnValue;
  263.             }
  264.             finally {
  265.                 if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) {
  266.                     this.Adapter.InsertCommand.Connection.Close();
  267.                 }
  268.             }
  269.         }
  270.        
  271.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  272.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  273.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  274.         [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Update, true)]
  275.         public virtual int Update(string Name, string Original_Name) {
  276.             if ((Name == null)) {
  277.                 throw new global::System.ArgumentNullException("Name");
  278.             }
  279.             else {
  280.                 this.Adapter.UpdateCommand.Parameters[0].Value = ((string)(Name));
  281.             }
  282.             if ((Original_Name == null)) {
  283.                 throw new global::System.ArgumentNullException("Original_Name");
  284.             }
  285.             else {
  286.                 this.Adapter.UpdateCommand.Parameters[1].Value = ((string)(Original_Name));
  287.             }
  288.             global::System.Data.ConnectionState previousConnectionState = this.Adapter.UpdateCommand.Connection.State;
  289.             if (((this.Adapter.UpdateCommand.Connection.State & global::System.Data.ConnectionState.Open)
  290.                         != global::System.Data.ConnectionState.Open)) {
  291.                 this.Adapter.UpdateCommand.Connection.Open();
  292.             }
  293.             try {
  294.                 int returnValue = this.Adapter.UpdateCommand.ExecuteNonQuery();
  295.                 return returnValue;
  296.             }
  297.             finally {
  298.                 if ((previousConnectionState == global::System.Data.ConnectionState.Closed)) {
  299.                     this.Adapter.UpdateCommand.Connection.Close();
  300.                 }
  301.             }
  302.         }
  303.        
  304.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  305.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  306.         [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
  307.         [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Update, true)]
  308.         public virtual int Update(string Original_Name) {
  309.             return this.Update(Original_Name, Original_Name);
  310.         }
  311.     }
  312.    
  313.     /// <summary>
  314.     ///TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios
  315.     ///</summary>
  316.     [global::System.ComponentModel.DesignerCategoryAttribute("code")]
  317.     [global::System.ComponentModel.ToolboxItem(true)]
  318.     [global::System.ComponentModel.DesignerAttribute("Microsoft.VSDesigner.DataSource.Design.TableAdapterManagerDesigner, Microsoft.VSD" +
  319.         "esigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  320.     [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapterManager")]
  321.     public partial class TableAdapterManager : global::System.ComponentModel.Component {
  322.        
  323.         private UpdateOrderOption _updateOrder;
  324.        
  325.         private CompaniesTableAdapter _companiesTableAdapter;
  326.        
  327.         private bool _backupDataSetBeforeUpdate;
  328.        
  329.         private global::System.Data.IDbConnection _connection;
  330.        
  331.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  332.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  333.         public UpdateOrderOption UpdateOrder {
  334.             get {
  335.                 return this._updateOrder;
  336.             }
  337.             set {
  338.                 this._updateOrder = value;
  339.             }
  340.         }
  341.        
  342.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  343.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  344.         [global::System.ComponentModel.EditorAttribute("Microsoft.VSDesigner.DataSource.Design.TableAdapterManagerPropertyEditor, Microso" +
  345.             "ft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3" +
  346.             "a", "System.Drawing.Design.UITypeEditor")]
  347.         public CompaniesTableAdapter CompaniesTableAdapter {
  348.             get {
  349.                 return this._companiesTableAdapter;
  350.             }
  351.             set {
  352.                 this._companiesTableAdapter = value;
  353.             }
  354.         }
  355.        
  356.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  357.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  358.         public bool BackupDataSetBeforeUpdate {
  359.             get {
  360.                 return this._backupDataSetBeforeUpdate;
  361.             }
  362.             set {
  363.                 this._backupDataSetBeforeUpdate = value;
  364.             }
  365.         }
  366.        
  367.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  368.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  369.         [global::System.ComponentModel.Browsable(false)]
  370.         public global::System.Data.IDbConnection Connection {
  371.             get {
  372.                 if ((this._connection != null)) {
  373.                     return this._connection;
  374.                 }
  375.                 if (((this._companiesTableAdapter != null)
  376.                             && (this._companiesTableAdapter.Connection != null))) {
  377.                     return this._companiesTableAdapter.Connection;
  378.                 }
  379.                 return null;
  380.             }
  381.             set {
  382.                 this._connection = value;
  383.             }
  384.         }
  385.        
  386.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  387.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  388.         [global::System.ComponentModel.Browsable(false)]
  389.         public int TableAdapterInstanceCount {
  390.             get {
  391.                 int count = 0;
  392.                 if ((this._companiesTableAdapter != null)) {
  393.                     count = (count + 1);
  394.                 }
  395.                 return count;
  396.             }
  397.         }
  398.        
  399.         /// <summary>
  400.         ///Update rows in top-down order.
  401.         ///</summary>
  402.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  403.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  404.         private int UpdateUpdatedRows(DatabaseDataSet dataSet, global::System.Collections.Generic.List<global::System.Data.DataRow> allChangedRows, global::System.Collections.Generic.List<global::System.Data.DataRow> allAddedRows) {
  405.             int result = 0;
  406.             if ((this._companiesTableAdapter != null)) {
  407.                 global::System.Data.DataRow[] updatedRows = dataSet.Companies.Select(null, null, global::System.Data.DataViewRowState.ModifiedCurrent);
  408.                 updatedRows = this.GetRealUpdatedRows(updatedRows, allAddedRows);
  409.                 if (((updatedRows != null)
  410.                             && (0 < updatedRows.Length))) {
  411.                     result = (result + this._companiesTableAdapter.Update(updatedRows));
  412.                     allChangedRows.AddRange(updatedRows);
  413.                 }
  414.             }
  415.             return result;
  416.         }
  417.        
  418.         /// <summary>
  419.         ///Insert rows in top-down order.
  420.         ///</summary>
  421.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  422.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  423.         private int UpdateInsertedRows(DatabaseDataSet dataSet, global::System.Collections.Generic.List<global::System.Data.DataRow> allAddedRows) {
  424.             int result = 0;
  425.             if ((this._companiesTableAdapter != null)) {
  426.                 global::System.Data.DataRow[] addedRows = dataSet.Companies.Select(null, null, global::System.Data.DataViewRowState.Added);
  427.                 if (((addedRows != null)
  428.                             && (0 < addedRows.Length))) {
  429.                     result = (result + this._companiesTableAdapter.Update(addedRows));
  430.                     allAddedRows.AddRange(addedRows);
  431.                 }
  432.             }
  433.             return result;
  434.         }
  435.        
  436.         /// <summary>
  437.         ///Delete rows in bottom-up order.
  438.         ///</summary>
  439.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  440.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  441.         private int UpdateDeletedRows(DatabaseDataSet dataSet, global::System.Collections.Generic.List<global::System.Data.DataRow> allChangedRows) {
  442.             int result = 0;
  443.             if ((this._companiesTableAdapter != null)) {
  444.                 global::System.Data.DataRow[] deletedRows = dataSet.Companies.Select(null, null, global::System.Data.DataViewRowState.Deleted);
  445.                 if (((deletedRows != null)
  446.                             && (0 < deletedRows.Length))) {
  447.                     result = (result + this._companiesTableAdapter.Update(deletedRows));
  448.                     allChangedRows.AddRange(deletedRows);
  449.                 }
  450.             }
  451.             return result;
  452.         }
  453.        
  454.         /// <summary>
  455.         ///Remove inserted rows that become updated rows after calling TableAdapter.Update(inserted rows) first
  456.         ///</summary>
  457.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  458.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  459.         private global::System.Data.DataRow[] GetRealUpdatedRows(global::System.Data.DataRow[] updatedRows, global::System.Collections.Generic.List<global::System.Data.DataRow> allAddedRows) {
  460.             if (((updatedRows == null)
  461.                         || (updatedRows.Length < 1))) {
  462.                 return updatedRows;
  463.             }
  464.             if (((allAddedRows == null)
  465.                         || (allAddedRows.Count < 1))) {
  466.                 return updatedRows;
  467.             }
  468.             global::System.Collections.Generic.List<global::System.Data.DataRow> realUpdatedRows = new global::System.Collections.Generic.List<global::System.Data.DataRow>();
  469.             for (int i = 0; (i < updatedRows.Length); i = (i + 1)) {
  470.                 global::System.Data.DataRow row = updatedRows[i];
  471.                 if ((allAddedRows.Contains(row) == false)) {
  472.                     realUpdatedRows.Add(row);
  473.                 }
  474.             }
  475.             return realUpdatedRows.ToArray();
  476.         }
  477.        
  478.         /// <summary>
  479.         ///Update all changes to the dataset.
  480.         ///</summary>
  481.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  482.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  483.         public virtual int UpdateAll(DatabaseDataSet dataSet) {
  484.             if ((dataSet == null)) {
  485.                 throw new global::System.ArgumentNullException("dataSet");
  486.             }
  487.             if ((dataSet.HasChanges() == false)) {
  488.                 return 0;
  489.             }
  490.             if (((this._companiesTableAdapter != null)
  491.                         && (this.MatchTableAdapterConnection(this._companiesTableAdapter.Connection) == false))) {
  492.                 throw new global::System.ArgumentException("All TableAdapters managed by a TableAdapterManager must use the same connection s" +
  493.                         "tring.");
  494.             }
  495.             global::System.Data.IDbConnection workConnection = this.Connection;
  496.             if ((workConnection == null)) {
  497.                 throw new global::System.ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" +
  498.                         "ger TableAdapter property to a valid TableAdapter instance.");
  499.             }
  500.             bool workConnOpened = false;
  501.             if (((workConnection.State & global::System.Data.ConnectionState.Broken)
  502.                         == global::System.Data.ConnectionState.Broken)) {
  503.                 workConnection.Close();
  504.             }
  505.             if ((workConnection.State == global::System.Data.ConnectionState.Closed)) {
  506.                 workConnection.Open();
  507.                 workConnOpened = true;
  508.             }
  509.             global::System.Data.IDbTransaction workTransaction = workConnection.BeginTransaction();
  510.             if ((workTransaction == null)) {
  511.                 throw new global::System.ApplicationException("The transaction cannot begin. The current data connection does not support transa" +
  512.                         "ctions or the current state is not allowing the transaction to begin.");
  513.             }
  514.             global::System.Collections.Generic.List<global::System.Data.DataRow> allChangedRows = new global::System.Collections.Generic.List<global::System.Data.DataRow>();
  515.             global::System.Collections.Generic.List<global::System.Data.DataRow> allAddedRows = new global::System.Collections.Generic.List<global::System.Data.DataRow>();
  516.             global::System.Collections.Generic.List<global::System.Data.Common.DataAdapter> adaptersWithAcceptChangesDuringUpdate = new global::System.Collections.Generic.List<global::System.Data.Common.DataAdapter>();
  517.             global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection> revertConnections = new global::System.Collections.Generic.Dictionary<object, global::System.Data.IDbConnection>();
  518.             int result = 0;
  519.             global::System.Data.DataSet backupDataSet = null;
  520.             if (this.BackupDataSetBeforeUpdate) {
  521.                 backupDataSet = new global::System.Data.DataSet();
  522.                 backupDataSet.Merge(dataSet);
  523.             }
  524.             try {
  525.                 // ---- Prepare for update -----------
  526.                 //
  527.                 if ((this._companiesTableAdapter != null)) {
  528.                     revertConnections.Add(this._companiesTableAdapter, this._companiesTableAdapter.Connection);
  529.                     this._companiesTableAdapter.Connection = ((global::System.Data.SqlClient.SqlConnection)(workConnection));
  530.                     this._companiesTableAdapter.Transaction = ((global::System.Data.SqlClient.SqlTransaction)(workTransaction));
  531.                     if (this._companiesTableAdapter.Adapter.AcceptChangesDuringUpdate) {
  532.                         this._companiesTableAdapter.Adapter.AcceptChangesDuringUpdate = false;
  533.                         adaptersWithAcceptChangesDuringUpdate.Add(this._companiesTableAdapter.Adapter);
  534.                     }
  535.                 }
  536.                 //
  537.                 //---- Perform updates -----------
  538.                 //
  539.                 if ((this.UpdateOrder == UpdateOrderOption.UpdateInsertDelete)) {
  540.                     result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
  541.                     result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
  542.                 }
  543.                 else {
  544.                     result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
  545.                     result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
  546.                 }
  547.                 result = (result + this.UpdateDeletedRows(dataSet, allChangedRows));
  548.                 //
  549.                 //---- Commit updates -----------
  550.                 //
  551.                 workTransaction.Commit();
  552.                 if ((0 < allAddedRows.Count)) {
  553.                     global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
  554.                     allAddedRows.CopyTo(rows);
  555.                     for (int i = 0; (i < rows.Length); i = (i + 1)) {
  556.                         global::System.Data.DataRow row = rows[i];
  557.                         row.AcceptChanges();
  558.                     }
  559.                 }
  560.                 if ((0 < allChangedRows.Count)) {
  561.                     global::System.Data.DataRow[] rows = new System.Data.DataRow[allChangedRows.Count];
  562.                     allChangedRows.CopyTo(rows);
  563.                     for (int i = 0; (i < rows.Length); i = (i + 1)) {
  564.                         global::System.Data.DataRow row = rows[i];
  565.                         row.AcceptChanges();
  566.                     }
  567.                 }
  568.             }
  569.             catch (global::System.Exception ex) {
  570.                 workTransaction.Rollback();
  571.                 // ---- Restore the dataset -----------
  572.                 if (this.BackupDataSetBeforeUpdate) {
  573.                     global::System.Diagnostics.Debug.Assert((backupDataSet != null));
  574.                     dataSet.Clear();
  575.                     dataSet.Merge(backupDataSet);
  576.                 }
  577.                 else {
  578.                     if ((0 < allAddedRows.Count)) {
  579.                         global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
  580.                         allAddedRows.CopyTo(rows);
  581.                         for (int i = 0; (i < rows.Length); i = (i + 1)) {
  582.                             global::System.Data.DataRow row = rows[i];
  583.                             row.AcceptChanges();
  584.                             row.SetAdded();
  585.                         }
  586.                     }
  587.                 }
  588.                 throw ex;
  589.             }
  590.             finally {
  591.                 if (workConnOpened) {
  592.                     workConnection.Close();
  593.                 }
  594.                 if ((this._companiesTableAdapter != null)) {
  595.                     this._companiesTableAdapter.Connection = ((global::System.Data.SqlClient.SqlConnection)(revertConnections[this._companiesTableAdapter]));
  596.                     this._companiesTableAdapter.Transaction = null;
  597.                 }
  598.                 if ((0 < adaptersWithAcceptChangesDuringUpdate.Count)) {
  599.                     global::System.Data.Common.DataAdapter[] adapters = new System.Data.Common.DataAdapter[adaptersWithAcceptChangesDuringUpdate.Count];
  600.                     adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters);
  601.                     for (int i = 0; (i < adapters.Length); i = (i + 1)) {
  602.                         global::System.Data.Common.DataAdapter adapter = adapters[i];
  603.                         adapter.AcceptChangesDuringUpdate = true;
  604.                     }
  605.                 }
  606.             }
  607.             return result;
  608.         }
  609.        
  610.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  611.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  612.         protected virtual void SortSelfReferenceRows(global::System.Data.DataRow[] rows, global::System.Data.DataRelation relation, bool childFirst) {
  613.             global::System.Array.Sort<global::System.Data.DataRow>(rows, new SelfReferenceComparer(relation, childFirst));
  614.         }
  615.        
  616.         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  617.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  618.         protected virtual bool MatchTableAdapterConnection(global::System.Data.IDbConnection inputConnection) {
  619.             if ((this._connection != null)) {
  620.                 return true;
  621.             }
  622.             if (((this.Connection == null)
  623.                         || (inputConnection == null))) {
  624.                 return true;
  625.             }
  626.             if (string.Equals(this.Connection.ConnectionString, inputConnection.ConnectionString, global::System.StringComparison.Ordinal)) {
  627.                 return true;
  628.             }
  629.             return false;
  630.         }
  631.        
  632.         /// <summary>
  633.         ///Update Order Option
  634.         ///</summary>
  635.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  636.         public enum UpdateOrderOption {
  637.            
  638.             InsertUpdateDelete = 0,
  639.            
  640.             UpdateInsertDelete = 1,
  641.         }
  642.        
  643.         /// <summary>
  644.         ///Used to sort self-referenced table's rows
  645.         ///</summary>
  646.         [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  647.         private class SelfReferenceComparer : object, global::System.Collections.Generic.IComparer<global::System.Data.DataRow> {
  648.            
  649.             private global::System.Data.DataRelation _relation;
  650.            
  651.             private int _childFirst;
  652.            
  653.             [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  654.             [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  655.             internal SelfReferenceComparer(global::System.Data.DataRelation relation, bool childFirst) {
  656.                 this._relation = relation;
  657.                 if (childFirst) {
  658.                     this._childFirst = -1;
  659.                 }
  660.                 else {
  661.                     this._childFirst = 1;
  662.                 }
  663.             }
  664.            
  665.             [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  666.             [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  667.             private global::System.Data.DataRow GetRoot(global::System.Data.DataRow row, out int distance) {
  668.                 global::System.Diagnostics.Debug.Assert((row != null));
  669.                 global::System.Data.DataRow root = row;
  670.                 distance = 0;
  671.  
  672.                 global::System.Collections.Generic.IDictionary<global::System.Data.DataRow, global::System.Data.DataRow> traversedRows = new global::System.Collections.Generic.Dictionary<global::System.Data.DataRow, global::System.Data.DataRow>();
  673.                 traversedRows[row] = row;
  674.  
  675.                 global::System.Data.DataRow parent = row.GetParentRow(this._relation, global::System.Data.DataRowVersion.Default);
  676.                 for (
  677.                 ; ((parent != null)
  678.                             && (traversedRows.ContainsKey(parent) == false));
  679.                 ) {
  680.                     distance = (distance + 1);
  681.                     root = parent;
  682.                     traversedRows[parent] = parent;
  683.                     parent = parent.GetParentRow(this._relation, global::System.Data.DataRowVersion.Default);
  684.                 }
  685.  
  686.                 if ((distance == 0)) {
  687.                     traversedRows.Clear();
  688.                     traversedRows[row] = row;
  689.                     parent = row.GetParentRow(this._relation, global::System.Data.DataRowVersion.Original);
  690.                     for (
  691.                     ; ((parent != null)
  692.                                 && (traversedRows.ContainsKey(parent) == false));
  693.                     ) {
  694.                         distance = (distance + 1);
  695.                         root = parent;
  696.                         traversedRows[parent] = parent;
  697.                         parent = parent.GetParentRow(this._relation, global::System.Data.DataRowVersion.Original);
  698.                     }
  699.                 }
  700.  
  701.                 return root;
  702.             }
  703.            
  704.             [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
  705.             [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
  706.             public int Compare(global::System.Data.DataRow row1, global::System.Data.DataRow row2) {
  707.                 if (object.ReferenceEquals(row1, row2)) {
  708.                     return 0;
  709.                 }
  710.                 if ((row1 == null)) {
  711.                     return -1;
  712.                 }
  713.                 if ((row2 == null)) {
  714.                     return 1;
  715.                 }
  716.  
  717.                 int distance1 = 0;
  718.                 global::System.Data.DataRow root1 = this.GetRoot(row1, out distance1);
  719.  
  720.                 int distance2 = 0;
  721.                 global::System.Data.DataRow root2 = this.GetRoot(row2, out distance2);
  722.  
  723.                 if (object.ReferenceEquals(root1, root2)) {
  724.                     return (this._childFirst * distance1.CompareTo(distance2));
  725.                 }
  726.                 else {
  727.                     global::System.Diagnostics.Debug.Assert(((root1.Table != null)
  728.                                     && (root2.Table != null)));
  729.                     if ((root1.Table.Rows.IndexOf(root1) < root2.Table.Rows.IndexOf(root2))) {
  730.                         return -1;
  731.                     }
  732.                     else {
  733.                         return 1;
  734.                     }
  735.                 }
  736.             }
  737.         }
  738.     }
  739. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement