Exemple #1
0
        protected virtual DataTable SaveDataImplementation(ChangeList changeList, object parameters, string loadMethod)
        {
            if ((_adapter != null) && (_updateMethod != null))
            {
                DataTable dataTable = GetData(parameters, loadMethod);
                foreach (object rowToDelete in changeList.Deleted)
                {
                    FindRow(GetDictionary(rowToDelete, dataTable.Columns), dataTable).Delete();
                }
                foreach (object rowToUpdate in changeList.Updated)
                {
                    BaseTypedDictionary rowDict  = GetDictionary(rowToUpdate, dataTable.Columns);
                    DataRow             tableRow = FindRow(rowDict, dataTable);
                    CopyToRow(rowDict, tableRow);
                }
                foreach (object rowToInsert in changeList.Inserted)
                {
                    DataRow newRow = dataTable.NewRow();
                    dataTable.Rows.Add(newRow);
                    BaseTypedDictionary rowDict = GetDictionary(rowToInsert, dataTable.Columns);
                    CopyToRow(rowDict, newRow);
                }
                _updateMethod.Invoke(_adapter, new object[] { dataTable });
                return(dataTable);
            }
            else
            {
                MethodInfo deleteMethod = GetDataMethod(DataObjectMethodType.Delete);
                MethodInfo updateMethod = GetDataMethod(DataObjectMethodType.Update);
                MethodInfo insertMethod = GetDataMethod(DataObjectMethodType.Insert);

                if (deleteMethod != null)
                {
                    foreach (object rowToDelete in changeList.Deleted)
                    {
                        InvokeMethod(deleteMethod, this, rowToDelete);
                    }
                }
                else if (changeList.Deleted.Length != 0)
                {
                    throw new InvalidOperationException("The Data Service must implement one method marked with the DataObjectMethod(DataObjectMethodType.Delete) attribute to handle deleted rows.");
                }

                if (updateMethod != null)
                {
                    foreach (object rowToUpdate in changeList.Updated)
                    {
                        InvokeMethod(updateMethod, this, rowToUpdate);
                    }
                }
                else if (changeList.Updated.Length != 0)
                {
                    throw new InvalidOperationException("The Data Service must implement one method marked with the DataObjectMethod(DataObjectMethodType.Update) attribute to handle updated rows.");
                }

                if (insertMethod != null)
                {
                    foreach (object rowToInsert in changeList.Inserted)
                    {
                        InvokeMethod(insertMethod, this, rowToInsert);
                    }
                }
                else if (changeList.Inserted.Length != 0)
                {
                    throw new InvalidOperationException("The Data Service must implement one method marked with the DataObjectMethod(DataObjectMethodType.Insert) attribute to handle inserted rows.");
                }
                return(GetData(parameters, loadMethod));
            }
        }
        protected virtual DataTable SaveDataImplementation(ChangeList changeList, object parameters, string loadMethod) {
            if ((_adapter != null) && (_updateMethod != null)) {
                DataTable dataTable = GetData(parameters, loadMethod);
                foreach (object rowToDelete in changeList.Deleted) {
                    FindRow(GetDictionary(rowToDelete, dataTable.Columns), dataTable).Delete();
                }
                foreach (object rowToUpdate in changeList.Updated) {
                    BaseTypedDictionary rowDict = GetDictionary(rowToUpdate, dataTable.Columns);
                    DataRow tableRow = FindRow(rowDict, dataTable);
                    CopyToRow(rowDict, tableRow);
                }
                foreach (object rowToInsert in changeList.Inserted) {
                    DataRow newRow = dataTable.NewRow();
                    dataTable.Rows.Add(newRow);
                    BaseTypedDictionary rowDict = GetDictionary(rowToInsert, dataTable.Columns);
                    CopyToRow(rowDict, newRow);
                }
                _updateMethod.Invoke(_adapter, new object[] { dataTable });
                return dataTable;
            }
            else {
                MethodInfo deleteMethod = GetDataMethod(DataObjectMethodType.Delete);
                MethodInfo updateMethod = GetDataMethod(DataObjectMethodType.Update);
                MethodInfo insertMethod = GetDataMethod(DataObjectMethodType.Insert);

                if (deleteMethod != null) {
                    foreach (object rowToDelete in changeList.Deleted) {
                        InvokeMethod(deleteMethod, this, rowToDelete);
                    }
                }
                else if (changeList.Deleted.Length != 0) {
                    throw new InvalidOperationException("The Data Service must implement one method marked with the DataObjectMethod(DataObjectMethodType.Delete) attribute to handle deleted rows.");
                }

                if (updateMethod != null) {
                    foreach (object rowToUpdate in changeList.Updated) {
                        InvokeMethod(updateMethod, this, rowToUpdate);
                    }
                }
                else if (changeList.Updated.Length != 0) {
                    throw new InvalidOperationException("The Data Service must implement one method marked with the DataObjectMethod(DataObjectMethodType.Update) attribute to handle updated rows.");
                }

                if (insertMethod != null) {
                    foreach (object rowToInsert in changeList.Inserted) {
                        InvokeMethod(insertMethod, this, rowToInsert);
                    }
                }
                else if (changeList.Inserted.Length != 0) {
                    throw new InvalidOperationException("The Data Service must implement one method marked with the DataObjectMethod(DataObjectMethodType.Insert) attribute to handle inserted rows.");
                }
                return GetData(parameters, loadMethod);
            }
        }
Exemple #3
0
 public DataTable SaveData(ChangeList changeList, object parameters, string loadMethod)
 {
     return(SaveDataImplementation(changeList, parameters, loadMethod));
 }
 public DataTable SaveData(ChangeList changeList, object parameters, string loadMethod) {
     return SaveDataImplementation(changeList, parameters, loadMethod);
 }