Inheritance: System.ComponentModel.Component
Example #1
0
        /// <summary> 
        /// The Delete verb deletes existing account and all subentities in the underlying data-store.
        /// 
        /// Should no account instance be found in the data-store that matches the id of the document, 
        /// the transaction result will set accordingly.
        /// </summary>
        /// <param name="doc">Document (incl. ID) containing the data to be stored</param>
        /// <param name="config">The configuration object</param>
        /// <returns>The transactionResult contais status information of the single transaction an also the nesed transactions of the subentities</returns>
        public override void Delete(Document doc, NorthwindConfig config, ref List<TransactionResult> result)
        {
            #region Declarations
            CustomersTableAdapter customers;
            SuppliersTableAdapter suppliers;
            DeleteHistoryTableAdapter deleteHistory;
            int sequenceId;
            string accountId ;
            string customerId = "";
            int supplierID = 0;
            #endregion

            // get the account Id from the given document
            accountId = doc.Id == null ? "" : doc.Id;

            // get the northwind Supplier or customer id if possible
            if (doc.Id.StartsWith(Constants.CustomerIdPrefix))
                customerId = accountId.Substring(Constants.CustomerIdPrefix.Length);

            else if (doc.Id.StartsWith(Constants.SupplierIdPrefix))
                supplierID = Identity.GetId(accountId.Substring(Constants.SupplierIdPrefix.Length));

            else
            {
                result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountTypeNotSupported));
                return;
            }

            // get the logging sequence number
            sequenceId = config.SequenceNumber;

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                try
                {
                    // get Table  Adpater and set the connecion
                    deleteHistory = new DeleteHistoryTableAdapter();
                    deleteHistory.Connection = connection;

                    if (supplierID > 0)
                    {
                        // get Table  Adpater and set the connecion
                        suppliers = new SuppliersTableAdapter();
                        suppliers.Connection = connection;

                        // delete the supplier
                        suppliers.DeleteQuery(supplierID);

                        // logg the deleted supplier in the delete history
                        deleteHistory.LogSuppliers(supplierID.ToString(), sequenceId, config.CrmUser);

                        // set transaction status to success
                        result.Add(doc.SetTransactionStatus(TransactionStatus.Success));
                    }

                    else if (customerId.Length > 0)
                    {
                        // get Table  Adpater and set the connecion
                        customers = new CustomersTableAdapter();
                        customers.Connection = connection;

                        // delete The customer
                        customers.DeleteQuery(customerId);

                        // logg the deleted Customer in the delete history
                        deleteHistory.LogCustomers(customerId, sequenceId, config.CrmUser);

                        // set transaction status to success
                        result.Add(doc.SetTransactionStatus(TransactionStatus.Success));
                    }

                    else
                        // set transaction status
                        result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountTypeNotSupported));
                }
                catch (Exception deleteException)
                {
            #warning Check the error status. this occours if the account is not deletable, because of having orders
                    // set transaction status and logg the error message
                    result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, deleteException.ToString()));
                }
            }
        }
Example #2
0
        private EmailsDocumentCollection GetEmailsCollectionFromCustomer(string customerId, Token lastToken, NorthwindConfig config)
        {
            int recordCount;
            Emails emails = new Emails();
            DeleteHistoryDataset history = new DeleteHistoryDataset();

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                Sage.Integration.Northwind.Application.Entities.Account.DataSets.EmailsTableAdapters.CustomerEmailsTableAdapter tableAdapter;
                tableAdapter = new Sage.Integration.Northwind.Application.Entities.Account.DataSets.EmailsTableAdapters.CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillByCustomerId(emails.CustomerEmails, customerId);

                DeleteHistoryTableAdapter tableAdapterDeleted;
                tableAdapterDeleted = new DeleteHistoryTableAdapter();
                tableAdapterDeleted.Connection = connection;
                recordCount += tableAdapterDeleted.FillCustomerEmailsBy(history.DeleteHistory, customerId.ToString());
            }

            if (recordCount == 0)
                return new EmailsDocumentCollection();

            return GetEmailsCollectionFromCustomer(emails, history, lastToken, config.CrmUser);
        }
Example #3
0
        private void UpdateEmailsCollectionFromCustomer(string customerId, EmailsDocumentCollection emailCollection, NorthwindConfig config, ref List<TransactionResult> result)
        {
            #region declarations
            int recordCount;
            Emails emails = new Emails();
            CustomerEmailsTableAdapter tableAdapter;
            DeleteHistoryTableAdapter history = new DeleteHistoryTableAdapter();
            Emails.CustomerEmailsRow row;
            OleDbCommand Cmd;
            object lastid;
            int newEmailID;
            #endregion

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                connection.Open();
                tableAdapter = new CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillByCustomerId(emails.CustomerEmails, customerId);
                foreach (EmailDocument emailDocument in emailCollection)
                {
                    if (emailDocument.HasNoLogStatus)
                        continue;

                    #region process deleted
                    if (emailDocument.LogState == LogState.Deleted)
                    {
                        try
                        {
                            if (tableAdapter.Delete(Identity.GetId(emailDocument.Id)) > 0)
                            {
                                history.Connection = connection;
                                history.LogCustomerEmails(emailDocument.Id, config.SequenceNumber, config.CrmUser, customerId);
                            }
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.Success));
                        }
                        catch (Exception deleteException)
                        {
            #warning todo: check this
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, deleteException.Message));

                        }
                        continue;
                    }
                    #endregion

                    if (emailDocument.emailaddress.IsNull)
                    {
                        emailDocument.ClearTransactionStatus();
                        continue;
                    }

                    #region process created
                    if (emailDocument.LogState == LogState.Created)
                    {
                        if ((emailDocument.Id != null) && (emailDocument.Id.Length > 0))
                            continue;

                        row = emails.CustomerEmails.NewCustomerEmailsRow();
                        row.CustomerID = customerId;
                        row.Email = (string)emailDocument.emailaddress.Value;

                        row.CreateID = config.SequenceNumber;
                        row.CreateUser = config.CrmUser;

                        row.ModifyID = config.SequenceNumber;
                        row.ModifyUser = config.CrmUser;

                        emails.CustomerEmails.AddCustomerEmailsRow(row);
                        try
                        {
                            tableAdapter.Update(emails.CustomerEmails);

                            Cmd = new OleDbCommand("SELECT @@IDENTITY", connection);

                            lastid = Cmd.ExecuteScalar();
                            newEmailID = (int)lastid;
                            emailDocument.Id = newEmailID.ToString();
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.Success));
                        }
                        catch (Exception addException)
                        {
            #warning todo: check this
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, addException.Message));

                        }

                        continue;
                    }
                    #endregion

                    #region process changed
                    if (emailDocument.LogState == LogState.Updated)
                    {

                        row = emails.CustomerEmails.FindByID(Identity.GetId(emailDocument.Id));
                        if (row == null)
                        {
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_EmailNotFound));
                            continue;
                        }
                        row.Email = (string)emailDocument.emailaddress.Value;
                        row.ModifyID = config.SequenceNumber;
                        row.ModifyUser = config.CrmUser;

                        try
                        {
                            tableAdapter.Update(emails.CustomerEmails);
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.Success));
                        }
                        catch (Exception updateException)
                        {
            #warning todo: check this
                            result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, updateException.Message));
                        }

                        continue;
                    }
                    #endregion

                    emailDocument.ClearTransactionStatus();
                }

            }
        }