Beispiel #1
0
        /* Add */
        public override void Add(Document doc, NorthwindConfig config, ref List<TransactionResult> result)
        {
            List<TransactionResult> transactionResult = new List<TransactionResult>();

            // cast the given document to an email document
            // return if fails
            EmailDocument emailDocument = doc as EmailDocument;
            if (emailDocument == null)
            {
                result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported));
                return;
            }

            CustomerEmailsTableAdapter tableAdapter;
            Emails emailsDataset = new Emails();
            Emails.CustomerEmailsRow emailRow = emailsDataset.CustomerEmails.NewCustomerEmailsRow();

            #region fill dataset from document

            try
            {
                if (emailDocument.emailaddress.IsNull)
                    emailRow.SetEmailNull();
                else
                    emailRow.Email = (string)emailDocument.emailaddress.Value;

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

                emailRow.ModifyID = config.SequenceNumber;
                emailRow.ModifyUser = config.CrmUser;
            }
            catch (Exception e)
            {
                emailDocument.Id = "";
            #warning Check error message
                result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString()));
                return;
            }

            #endregion

            #region Get the ID of the new row and set it to the document

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                connection.Open();

                tableAdapter = new CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;

                emailsDataset.CustomerEmails.AddCustomerEmailsRow(emailRow);
                tableAdapter.Update(emailsDataset.CustomerEmails);
                OleDbCommand Cmd = new OleDbCommand("SELECT @@IDENTITY", connection);
                object lastid = Cmd.ExecuteScalar();
                emailDocument.Id = ((int)lastid).ToString();
            }

            #endregion
        }
Beispiel #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);
        }
Beispiel #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();
                }

            }
        }
Beispiel #4
0
        /* Update */
        public override void Update(Document doc, NorthwindConfig config, ref List<TransactionResult> result)
        {
            List<TransactionResult> transactionResult = new List<TransactionResult>();
            EmailDocument emailDocument = doc as EmailDocument;

            #region check input values

            if (emailDocument == null)
            {
                result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported));
                return;
            }

            // check id
            #endregion

            CustomerEmailsTableAdapter tableAdapter;

            Emails emailsDataset = new Emails();
            Emails.CustomerEmailsRow emailsRow;
            tableAdapter = new CustomerEmailsTableAdapter();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                connection.Open();
                tableAdapter.Connection = connection;
                int recordCount = tableAdapter.FillBy(emailsDataset.CustomerEmails, Convert.ToInt32(emailDocument.Id));
                if (recordCount == 0)
                {
                    doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, "Category does not exists");
                    return;
                }
                emailsRow = (Emails.CustomerEmailsRow)emailsDataset.CustomerEmails.Rows[0];

                try
                {
                    if (emailDocument.emailaddress.IsNull)
                        emailsRow.SetEmailNull();
                    else
                        emailsRow.Email = (string)emailDocument.emailaddress.Value;

                    emailsRow.ModifyID = config.SequenceNumber;
                    emailsRow.ModifyUser = config.CrmUser;
                }
                catch (Exception e)
                {
                    emailDocument.Id = "";
            #warning Check error message
                    result.Add(emailDocument.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString()));
                    return;
                }

                tableAdapter = new CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;

                tableAdapter.Update(emailsDataset.CustomerEmails);
            }
        }
Beispiel #5
0
        /* Get */
        public override Document GetDocument(Identity identity, Token lastToken, NorthwindConfig config)
        {
            int recordCount;
            Emails emails = new Emails();

            int id = Identity.GetId(identity);
            //string strId = Convert.ToString(id);

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                CustomerEmailsTableAdapter tableAdapter;
                tableAdapter = new CustomerEmailsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillBy(emails.CustomerEmails, id);
            }

            if (recordCount == 0)
                return GetDeletedDocument(identity);

            return GetDocument((Emails.CustomerEmailsRow)emails.CustomerEmails[0], lastToken, config);
        }
Beispiel #6
0
        public override List<Identity> GetAll(NorthwindConfig config, string whereExpression, OleDbParameter[] oleDbParameters)
        {
            List<Identity> result = new List<Identity>();
            int recordCount = 0;
            Emails emailsDataset = new Emails();

            // get the first 11 rows of the changelog
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                CustomerEmailsTableAdapter tableAdapter;

                tableAdapter = new CustomerEmailsTableAdapter();

                tableAdapter.Connection = connection;

                if (string.IsNullOrEmpty(whereExpression))
                    recordCount = tableAdapter.Fill(emailsDataset.CustomerEmails);
                else
                    recordCount = tableAdapter.FillByWhereClause(emailsDataset.CustomerEmails, whereExpression, oleDbParameters);
            }

            foreach (Emails.CustomerEmailsRow row in emailsDataset.CustomerEmails.Rows)
            {
                // use where expression !!
                result.Add(new Identity(this.EntityName, row.ID.ToString()));
            }

            return result;
        }