FillByCustomerId() private method

private FillByCustomerId ( Emails dataTable, string CustomerID ) : int
dataTable Emails
CustomerID string
return int
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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();
                }

            }
        }