Inheritance: global::System.Data.DataSet
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(Emails emails, DeleteHistoryDataset history, Token lastToken, string crmUser)
        {
            EmailsDocumentCollection emailCollection = new EmailsDocumentCollection();
            EmailDocument email;

            foreach (DeleteHistoryDataset.DeleteHistoryRow dr in history.DeleteHistory)
            {
                if (dr.DeleteUser == crmUser)
                    continue;
                if (dr.DeleteID <= lastToken.SequenceNumber)
                    continue;
                email = new EmailDocument();
                email.Id = dr.Identity;
                email.LogState = LogState.Deleted;
                emailCollection.Add(email);

            }

            int index = 0;
            foreach (Emails.CustomerEmailsRow er in emails.CustomerEmails)
            {
                email = new EmailDocument();
                if ((er.CreateUser != crmUser) && (er.CreateID > lastToken.SequenceNumber))
                    email.LogState = LogState.Created;
                else if ((er.ModifyUser != crmUser) && (er.ModifyID > lastToken.SequenceNumber))
                    email.LogState = LogState.Updated;

                email.Id = er.ID.ToString();
                try
                {

                    email.emailaddress.Value = er.Email;

                    if (index == 0)
                        email.type.Value = "Business";
                    if (index == 1)
                        email.type.Value = "Private";
                    index++;
                }
                catch (StrongTypingException)
                {
                    email.emailaddress.Value = null;
                }

                emailCollection.Add(email);

            }
            return emailCollection;
        }
Beispiel #3
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 #4
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 #5
0
        /* ChangeLog */
        public override int FillChangeLog(out System.Data.DataTable table, NorthwindConfig config, Token lastToken)
        {
            Emails emails;
            int lastId;
            int recordCount;

            emails = new Emails();

            lastId = Token.GetId(lastToken);

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                CustomerEmailsChangeLogsTableAdapter tableAdapter;
                tableAdapter = new CustomerEmailsChangeLogsTableAdapter();
                tableAdapter.Connection = connection;
                // fill the Changelog dataset
                if (lastToken.InitRequest)
                    recordCount = tableAdapter.Fill(emails.CustomerEmailsChangeLogs, lastId, lastToken.SequenceNumber, lastToken.SequenceNumber, "");
                else
                    recordCount = tableAdapter.Fill(emails.CustomerEmailsChangeLogs, lastId, lastToken.SequenceNumber, lastToken.SequenceNumber, config.CrmUser);

            }

            table = emails.CustomerEmailsChangeLogs;
            return recordCount;
        }
Beispiel #6
0
        private Document GetDocument(Emails.CustomerEmailsRow row, Token lastToken, NorthwindConfig config)
        {
            EmailDocument doc;
            string id;

            id = row.ID.ToString();

            doc = new EmailDocument();
            doc.Id = id;

            if (lastToken.InitRequest)
                doc.LogState = LogState.Created;

            else if (row.IsCreateIDNull() || row.IsModifyIDNull()
                || row.IsCreateUserNull() || row.IsModifyUserNull())
                doc.LogState = LogState.Created;

            else if ((row.CreateID > lastToken.SequenceNumber)
                   && (row.CreateUser != config.CrmUser))
                doc.LogState = LogState.Created;

            else if ((row.CreateID == lastToken.SequenceNumber)
                && (row.CreateUser != config.CrmUser)
                && (id.CompareTo(lastToken.Id.Id) > 0))
                doc.LogState = LogState.Created;
            else if ((row.ModifyID >= lastToken.SequenceNumber) && (row.ModifyUser != config.CrmUser))
                doc.LogState = LogState.Updated;

            doc.emailaddress.Value = row.IsEmailNull() ? null : row.Email;

            doc.type.Value = Constants.DefaultValues.Email.Type;

            return doc;
        }
Beispiel #7
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 #8
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 #9
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;
        }