Esempio n. 1
0
        /* Update */
        public override void Update(Document doc, NorthwindConfig config, ref List <TransactionResult> result)
        {
            List <TransactionResult> transactionResult = new List <TransactionResult>();
            ProductDocument          productDoc        = doc as ProductDocument;

            #region check input values

            if (productDoc == 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(productDoc.Id));
                if (recordCount == 0)
                {
                    doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, "Product does not exists");
                    return;
                }
                row = (DataSets.Product.ProductsRow)productDataset.Products.Rows[0];

                try
                {
                    // active???

                    // code???

                    if (productDoc.name.IsNull)
                    {
                        row.SetProductNameNull();
                    }
                    else
                    {
                        row.ProductName = Convert.ToString(productDoc.name.Value);
                    }

                    if (productDoc.productfamilyid.IsNull)
                    {
                        row.SetCategoryIDNull();
                    }
                    else
                    {
                        row.CategoryID = Convert.ToInt32(productDoc.productfamilyid.Value);
                    }

                    // uom category ???

                    if (productDoc.instock.IsNull)
                    {
                        row.SetUnitsInStockNull();
                    }
                    else
                    {
                        row.UnitsInStock = Convert.ToInt16(productDoc.instock.Value);
                    }

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

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

                tableAdapter.Update(productDataset.Products);

                result.Add(doc.SetTransactionStatus(TransactionStatus.Success));
            }
        }
Esempio n. 2
0
        /* Add */
        public override void Add(Document doc, NorthwindConfig config, ref List <TransactionResult> result)
        {
            List <TransactionResult> transactionResult = new List <TransactionResult>();
            ProductDocument          productDoc        = doc as ProductDocument;

            #region check input values

            if (productDoc == 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???

                // code???

                if (productDoc.name.IsNull)
                {
                    row.SetProductNameNull();
                }
                else
                {
                    row.ProductName = Convert.ToString(productDoc.name.Value);
                }

                if (productDoc.productfamilyid.IsNull)
                {
                    row.SetCategoryIDNull();
                }
                else
                {
                    row.CategoryID = Convert.ToInt32(productDoc.productfamilyid.Value);
                }

                // uom category ???

                if (productDoc.instock.IsNull)
                {
                    row.SetUnitsInStockNull();
                }
                else
                {
                    row.UnitsInStock = Convert.ToInt16(productDoc.instock.Value);
                }


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

                row.ModifyID   = config.SequenceNumber;
                row.ModifyUser = config.CrmUser;
            }
            catch (Exception e)
            {
                productDoc.Id = "";
#warning Check error message
                result.Add(productDoc.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();

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

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