Inheritance: System.Data.DataSet
        /* Add */
        public override void Add(Document doc, NorthwindConfig config, ref List<TransactionResult> result)
        {
            List<TransactionResult> transactionResult = new List<TransactionResult>();
            UnitOfMeasureFamilyDocument uomFamilyDoc = doc as UnitOfMeasureFamilyDocument;

            #region check input values

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

            #endregion

            DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;

            DataSets.Product productDataset = new DataSets.Product();
            DataSets.Product.ProductsRow row = productDataset.Products.NewProductsRow();

            #region fill dataset from document

            try
            {
                // active ???

                // defaultvalue ???

                if (uomFamilyDoc.name.IsNull)
                    row.SetQuantityPerUnitNull();
                else
                    row.QuantityPerUnit = (string)uomFamilyDoc.name.Value;

                if (uomFamilyDoc.description.IsNull)
                    row.SetProductNameNull();
                else
                    row.ProductName = (string)uomFamilyDoc.description.Value;

                // CreateID and ModifyID
                row.CreateID = config.SequenceNumber;
                row.CreateUser = config.CrmUser;

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

            #endregion

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

                connection.Open();

                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;

                productDataset.Products.AddProductsRow(row);
                tableAdapter.Update(productDataset.Products);
                OleDbCommand Cmd = new OleDbCommand("SELECT @@IDENTITY", connection);
                object lastid = Cmd.ExecuteScalar();
                uomFamilyDoc.Id = ((int)lastid).ToString();

            }
            result.Add(doc.SetTransactionStatus(TransactionStatus.Success));
        }
        public override Document GetDocument(Identity identity, Token lastToken, NorthwindConfig config)
        {
            int recordCount;
            DataSets.Product product = new DataSets.Product();
            int uomFamilyId;

            uomFamilyId = Identity.GetId(identity);

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                Sage.Integration.Northwind.Application.Entities.Product.DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;
                tableAdapter = new Sage.Integration.Northwind.Application.Entities.Product.DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillBy(product.Products, uomFamilyId);
            }

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

            return GetUOMFamilyDocument((DataSets.Product.ProductsRow)product.Products[0], lastToken, config);
        }
        /* Update */
        public override void Update(Document doc, NorthwindConfig config, ref List<TransactionResult> result)
        {
            List<TransactionResult> transactionResult = new List<TransactionResult>();
            UnitOfMeasureFamilyDocument uomFamilyDoc = doc as UnitOfMeasureFamilyDocument;

            #region check input values
            if (uomFamilyDoc == null)
            {
                result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported));
                return;
            }

            // check id
            #endregion

            DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;

            DataSets.Product productDataset = new DataSets.Product();
            DataSets.Product.ProductsRow row;
            tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {

                connection.Open();
                tableAdapter.Connection = connection;
                int recordCount = tableAdapter.FillBy(productDataset.Products, Convert.ToInt32(uomFamilyDoc.Id));
                if (recordCount == 0)
                {
                    doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, "Product does not exists");
                    return;
                }
                row = (DataSets.Product.ProductsRow)productDataset.Products.Rows[0];

                try
                {
                    // active ???

                    // defaultvalue ???

                    if(!uomFamilyDoc.name.NotSet)
                        if (uomFamilyDoc.name.IsNull)
                            row.SetQuantityPerUnitNull();
                        else
                            row.QuantityPerUnit = (string)uomFamilyDoc.name.Value;

                    if(!uomFamilyDoc.description.NotSet)
                        if (uomFamilyDoc.description.IsNull)
                            row.SetProductNameNull();
                        else
                            row.ProductName = (string)uomFamilyDoc.description.Value;

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

                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;

                tableAdapter.Update(productDataset.Products);

                result.Add(doc.SetTransactionStatus(TransactionStatus.Success));

            }
        }
        /* ChangeLog */
        public override int FillChangeLog(out System.Data.DataTable table, NorthwindConfig config, Token lastToken)
        {
            #region Declarations
            int recordCount = 0;
            DataSets.Product changelog = new DataSets.Product();
            int lastUomID = 0;
            #endregion

            lastUomID = Token.GetId(lastToken);

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

                tableAdapter = new ChangeLogsTableAdapter();

                tableAdapter.Connection = connection;

                // fill the Changelog dataset
                if (lastToken.InitRequest)
                    recordCount = tableAdapter.Fill(changelog.ChangeLogs, lastUomID, lastToken.SequenceNumber, lastToken.SequenceNumber, "");
                else
                    recordCount = tableAdapter.Fill(changelog.ChangeLogs, lastUomID, lastToken.SequenceNumber, lastToken.SequenceNumber, config.CrmUser);

            }

            table = changelog.ChangeLogs;
            return recordCount;
        }
        /* Get */
        public override List<Identity> GetAll(NorthwindConfig config, string whereExpression, OleDbParameter[] oleDbParameters)
        {
            List<Identity> result = new List<Identity>();
            int recordCount = 0;
            DataSets.Product productsDataset = new DataSets.Product();

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

                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();

                tableAdapter.Connection = connection;

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

            foreach (DataSets.Product.ProductsRow row in productsDataset.Products.Rows)
            {
                // use where expression !!
                result.Add(new Identity(this.EntityName, row.ProductID.ToString()));
            }

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

            #region check input values

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

            // check id

            #endregion

            DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;

            DataSets.Product productDataset = new DataSets.Product();
            DataSets.Product.ProductsRow row;
            tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                connection.Open();

                tableAdapter.Connection = connection;
                int recordCount = tableAdapter.FillBy(productDataset.Products, Convert.ToInt32(priceDoc.Id));
                if (recordCount == 0)
                {
                    doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, "Product does not exists");
                    return;
                }
                row = (DataSets.Product.ProductsRow)productDataset.Products.Rows[0];

                try
                {

                    // active???

                    // price_cid???

                    // pricinglistid ???

                    // productid ???

                    // uomid ???

                    if (priceDoc.price.IsNull)
                        row.SetUnitPriceNull();
                    else
                        row.UnitPrice = (decimal)priceDoc.price.Value;

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

                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;

                tableAdapter.Update(productDataset.Products);

                result.Add(doc.SetTransactionStatus(TransactionStatus.Success));

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

            #region check input values

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

            DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;

            DataSets.Product productDataset = new DataSets.Product();
            DataSets.Product.ProductsRow row = productDataset.Products.NewProductsRow();

            #region fill dataset from document

            try
            {

                // active???

                // price_cid???

                // pricinglistid ???

                // productid ???

                // uomid ???

                if (priceDoc.price.IsNull)
                    row.SetUnitPriceNull();
                else
                    row.UnitPrice = (decimal)priceDoc.price.Value;

                /* CreateID and ModifyID */
                row.CreateID = config.SequenceNumber;
                row.CreateUser = config.CrmUser;

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

            }
            catch (Exception e)
            {
                priceDoc.Id = "";
            #warning Check error message
                result.Add(priceDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString()));
                return;
            }

            #endregion

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

                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;

                productDataset.Products.AddProductsRow(row);

                tableAdapter.Update(productDataset.Products);

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

                object lastid = Cmd.ExecuteScalar();

                priceDoc.Id = ((int)lastid).ToString();
            }

            result.Add(doc.SetTransactionStatus(TransactionStatus.Success));
        }
Beispiel #8
0
        public override Document GetDocument(Identity identity, Token lastToken, NorthwindConfig config)
        {
            int recordCount;
            DataSets.Product product = new DataSets.Product();
            int priceID;

            priceID = Identity.GetId(identity);

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;
                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillBy(product.Products, priceID);
            }

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

            return GetDocument((DataSets.Product.ProductsRow)product.Products[0], lastToken, config);
        }
Beispiel #9
0
        public PricingDetail GetPricingDetails(OrderDetailInformation OrderDetails, NorthwindConfig config)
        {
            PricingDetail result = new PricingDetail();
            string customerID;
            int productId;
            List<int> productIds = new List<int>();

            int recordCount;

            if (!OrderDetails.Currency.Equals(config.CurrencyCode, StringComparison.InvariantCultureIgnoreCase))
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_CurrencyNotSupported;
                return result;
            }

            if (!OrderDetails.PricingListId.Equals(Constants.DefaultValues.PriceList.ID, StringComparison.InvariantCultureIgnoreCase))
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_PriceListNotSupported;
                return result;
            }

            if (OrderDetails.AccountId == null)
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_AccountNotFound;
                return result;
            }

            customerID = OrderDetails.AccountId;
            if (!(customerID.StartsWith(Constants.CustomerIdPrefix, StringComparison.InvariantCultureIgnoreCase)))
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_OnlyCustomersSupported;
                return result;
            }

            customerID = customerID.Substring(Constants.CustomerIdPrefix.Length);
            DataSet dataSet = new DataSet();
            OleDbDataAdapter dataAdapter;
            string sqlQuery = "Select * from Customers where CustomerID = '" + customerID + "'";

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                dataAdapter = new OleDbDataAdapter(sqlQuery, connection);
                if (dataAdapter.Fill(dataSet, "Customers") == 0)
                {
                    result.Result = false;
                    result.ErrorMessage = Resources.ErrorMessages_AccountNotFound;
                    return result;
                }
            }

            result.Result = true;
            result.ErrorMessage = "";

            result.PricingListId = Constants.DefaultValues.PriceList.ID;

            DataSets.Product product = new DataSets.Product();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;
                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.Fill(product.Products);
            }

            result.PricingDetailLineItems = new PricingDetailLineItem[OrderDetails.LineItemDetails.Length];
            DataSets.Product.ProductsRow row;
            decimal totalPrice = 0;
            decimal totalLineItemDiscount = 0;
            result.ErrorMessage = "";
            for (int index = 0; index < OrderDetails.LineItemDetails.Length; index++)
            {
                result.PricingDetailLineItems[index] = new PricingDetailLineItem();
                result.PricingDetailLineItems[index].Description = OrderDetails.LineItemDetails[index].Description;
                result.PricingDetailLineItems[index].LineItemId = OrderDetails.LineItemDetails[index].LineItemId;
                result.PricingDetailLineItems[index].LineType = OrderDetails.LineItemDetails[index].LineType;
                result.PricingDetailLineItems[index].SynchMessage = "";

                try
                {
                    productId = Convert.ToInt32(OrderDetails.LineItemDetails[index].ProductId);
                }
                catch (Exception)
                {
                    result.PricingDetailLineItems[index].SynchMessage = String.Format(Resources.ErrorMessages_ProductIdWrongFormat, OrderDetails.LineItemDetails[index].ProductId.ToString());
                    result.ErrorMessage += result.PricingDetailLineItems[index].SynchMessage + "\r\n";
                    result.Result = false;
                    continue;
                }
                if (productIds.Contains(productId))
                {
                    result.PricingDetailLineItems[index].SynchMessage = String.Format(Resources.ErrorMessages_OrderWithProductTwice, productId);
                    //result.ErrorMessage += result.PricingDetailLineItems[index].SynchMessage + "\r\n";
                    //result.Result = false;
                    //continue;
                }

                productIds.Add(productId);

                row = product.Products.FindByProductID(productId);
                if (row == null)
                {
                    result.PricingDetailLineItems[index].SynchMessage = String.Format(Resources.ErrorMessages_ProductIdNotFound, productId);
                    result.ErrorMessage += result.PricingDetailLineItems[index].SynchMessage + "\r\n";
                    result.Result = false;
                    continue;
                }

                //result.PricingDetailLineItems[index].RepricingStatus = ??;

                //result.PricingDetailLineItems[index].StockQuantity = row.IsUnitsInStockNull() ? 0 : (int)row.UnitsInStock;

                result.PricingDetailLineItems[index].ListPrice = row.IsUnitPriceNull() ? (decimal)0 : row.UnitPrice;

                result.PricingDetailLineItems[index].Tax = 0;
                //result.PricingDetailLineItems[index].TaxRate = "no Tax";
                result.PricingDetailLineItems[index].TaxRate = "0";

                result.PricingDetailLineItems[index].DiscountRate = 0;
                result.PricingDetailLineItems[index].Discount = 0;
                if (OrderDetails.LineItemDetails[index].Quantity >= 10)
                {
                    result.PricingDetailLineItems[index].DiscountRate = 10;
                    result.PricingDetailLineItems[index].Discount = 10;
                }

                result.PricingDetailLineItems[index].DiscountSum = ((result.PricingDetailLineItems[index].DiscountRate / 100)) * result.PricingDetailLineItems[index].ListPrice;

                result.PricingDetailLineItems[index].QuotedPrice = result.PricingDetailLineItems[index].ListPrice * (1 - (result.PricingDetailLineItems[index].DiscountRate / 100));
                result.PricingDetailLineItems[index].QuotedPriceTotal = OrderDetails.LineItemDetails[index].Quantity * result.PricingDetailLineItems[index].QuotedPrice;
                totalPrice += result.PricingDetailLineItems[index].QuotedPriceTotal;
                totalLineItemDiscount += OrderDetails.LineItemDetails[index].Quantity * result.PricingDetailLineItems[index].DiscountSum;
            }

            result.DiscountAmt = 0;
            result.DiscountPC = 0;
            result.DiscountType = "";
            result.GrossAmt = totalPrice;
            result.LineItemDisc = totalLineItemDiscount;
            result.NetAmt = totalPrice;
            //result.NoDiscAmt = 0; //????
            result.PricingListId = OrderDetails.PricingListId;
            result.OrderQuoteId = OrderDetails.OrderQuoteId;
            //result.Reference = "";
            result.Tax = 0;

            return result;
        }
Beispiel #10
0
        public Pricing CheckPrice(Pricing PricingInformation, NorthwindConfig config)
        {
            int productId = 0;
            int recordCount;

            //TODO: did we need to check if Account exists?
            try
            {
                productId = int.Parse(PricingInformation.ProductId);
                if (productId == 0)
                    throw new ArgumentException();
            }
            catch (Exception)
            {
                PricingInformation.SynchMessage = Resources.ErrorMessages_ProductNotFound;
                return PricingInformation;
            }

            DataSets.Product product = new DataSets.Product();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;
                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.FillBy(product.Products, productId);
            }
            if (recordCount == 0)
            {
                PricingInformation.SynchMessage = Resources.ErrorMessages_ProductNotFound;
                return PricingInformation;
            }

            DataSets.Product.ProductsRow row = product.Products[0];

            decimal listprice = row.IsUnitPriceNull() ? (decimal)0 : row.UnitPrice;

            PricingInformation.ListPrice = XmlConvert.ToString(listprice);

            PricingInformation.DiscountRate = 0;
            PricingInformation.Discount = 0;
            PricingInformation.DiscountSum = 0;

            if (PricingInformation.Quantity >= 10)
            {
                PricingInformation.DiscountRate = new decimal(10);
                PricingInformation.Discount = new decimal(10);
                PricingInformation.DiscountSum = listprice * new decimal(0.1);
            }

            decimal quotedPrice = listprice - PricingInformation.DiscountSum;

            PricingInformation.QuotedPrice = XmlConvert.ToString(quotedPrice);
            PricingInformation.QuotedPriceTotal = XmlConvert.ToString(PricingInformation.Quantity * quotedPrice);
            PricingInformation.Tax = 0;
            PricingInformation.TaxRate = 0;

            return PricingInformation;
        }
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs) {
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     Product ds = new Product();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "ChangeLogsDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     return type;
 }
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     Product ds = new Product();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     return type;
 }