Exemple #1
0
        private void SaveInTransaction()
        {
            // Calismasi icin accountDataSet.cs ye bak!!!!!!!!!!!!!!!!!!!! Hierarcial Update False oldugunda calismasi icin

            bool workConnOpened = false;

            global::System.Data.IDbConnection workConnection = this.aodTableAdapter.Connection;
            if (((workConnection.State & global::System.Data.ConnectionState.Broken) == global::System.Data.ConnectionState.Broken))
            {
                workConnection.Close();
            }
            if ((workConnection.State == global::System.Data.ConnectionState.Closed))
            {
                workConnection.Open();
                workConnOpened = true;
            }
            //workConnection.Open();
            global::System.Data.IDbTransaction workTransaction = workConnection.BeginTransaction();
            try
            {
                this.aodTableAdapter.Transaction = ((global::FirebirdSql.Data.FirebirdClient.FbTransaction)(workTransaction));
                this.aodTableAdapter.Update(this.accountDataSet.AOD);
                workTransaction.Commit();
            }
            catch (Exception ex)
            {
                workTransaction.Rollback();
                //MessageBox.Show(ex.Message);
                MessageBox.Show("Kaydederken hata oluştu. Hiçbir değisiklik kaydedilmedi!");
            }
            finally
            {
                if (workConnOpened)
                {
                    workConnection.Close();
                }
            }
        }
Exemple #2
0
        public virtual int UpdateAll(School_SystemDataSet6 dataSet)
        {
            if ((dataSet == null))
            {
                throw new global::System.ArgumentNullException("dataSet");
            }
            if ((dataSet.HasChanges() == false))
            {
                return(0);
            }
            global::System.Data.IDbConnection workConnection = this.Connection;
            if ((workConnection == null))
            {
                throw new global::System.ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" +
                                                              "ger TableAdapter property to a valid TableAdapter instance.");
            }
            bool workConnOpened = false;

            if (((workConnection.State & global::System.Data.ConnectionState.Broken)
                 == global::System.Data.ConnectionState.Broken))
            {
                workConnection.Close();
            }
            if ((workConnection.State == global::System.Data.ConnectionState.Closed))
            {
                workConnection.Open();
                workConnOpened = true;
            }
            global::System.Data.IDbTransaction workTransaction = workConnection.BeginTransaction();
            if ((workTransaction == null))
            {
                throw new global::System.ApplicationException("The transaction cannot begin. The current data connection does not support transa" +
                                                              "ctions or the current state is not allowing the transaction to begin.");
            }
            global::System.Collections.Generic.List <global::System.Data.DataRow>                     allChangedRows = new global::System.Collections.Generic.List <global::System.Data.DataRow>();
            global::System.Collections.Generic.List <global::System.Data.DataRow>                     allAddedRows   = new global::System.Collections.Generic.List <global::System.Data.DataRow>();
            global::System.Collections.Generic.List <global::System.Data.Common.DataAdapter>          adaptersWithAcceptChangesDuringUpdate = new global::System.Collections.Generic.List <global::System.Data.Common.DataAdapter>();
            global::System.Collections.Generic.Dictionary <object, global::System.Data.IDbConnection> revertConnections = new global::System.Collections.Generic.Dictionary <object, global::System.Data.IDbConnection>();
            int result = 0;

            global::System.Data.DataSet backupDataSet = null;
            if (this.BackupDataSetBeforeUpdate)
            {
                backupDataSet = new global::System.Data.DataSet();
                backupDataSet.Merge(dataSet);
            }
            try {
                // ---- Prepare for update -----------
                //
                //
                //---- Perform updates -----------
                //
                if ((this.UpdateOrder == UpdateOrderOption.UpdateInsertDelete))
                {
                    result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                    result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                }
                else
                {
                    result = (result + this.UpdateInsertedRows(dataSet, allAddedRows));
                    result = (result + this.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows));
                }
                result = (result + this.UpdateDeletedRows(dataSet, allChangedRows));
                //
                //---- Commit updates -----------
                //
                workTransaction.Commit();
                if ((0 < allAddedRows.Count))
                {
                    global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                    allAddedRows.CopyTo(rows);
                    for (int i = 0; (i < rows.Length); i = (i + 1))
                    {
                        global::System.Data.DataRow row = rows[i];
                        row.AcceptChanges();
                    }
                }
                if ((0 < allChangedRows.Count))
                {
                    global::System.Data.DataRow[] rows = new System.Data.DataRow[allChangedRows.Count];
                    allChangedRows.CopyTo(rows);
                    for (int i = 0; (i < rows.Length); i = (i + 1))
                    {
                        global::System.Data.DataRow row = rows[i];
                        row.AcceptChanges();
                    }
                }
            }
            catch (global::System.Exception ex) {
                workTransaction.Rollback();
                // ---- Restore the dataset -----------
                if (this.BackupDataSetBeforeUpdate)
                {
                    global::System.Diagnostics.Debug.Assert((backupDataSet != null));
                    dataSet.Clear();
                    dataSet.Merge(backupDataSet);
                }
                else
                {
                    if ((0 < allAddedRows.Count))
                    {
                        global::System.Data.DataRow[] rows = new System.Data.DataRow[allAddedRows.Count];
                        allAddedRows.CopyTo(rows);
                        for (int i = 0; (i < rows.Length); i = (i + 1))
                        {
                            global::System.Data.DataRow row = rows[i];
                            row.AcceptChanges();
                            row.SetAdded();
                        }
                    }
                }
                throw ex;
            }
            finally {
                if (workConnOpened)
                {
                    workConnection.Close();
                }
                if ((0 < adaptersWithAcceptChangesDuringUpdate.Count))
                {
                    global::System.Data.Common.DataAdapter[] adapters = new System.Data.Common.DataAdapter[adaptersWithAcceptChangesDuringUpdate.Count];
                    adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters);
                    for (int i = 0; (i < adapters.Length); i = (i + 1))
                    {
                        global::System.Data.Common.DataAdapter adapter = adapters[i];
                        adapter.AcceptChangesDuringUpdate = true;
                    }
                }
            }
            return(result);
        }