/* 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 }
/// <summary> /// The Add verb inserts an account and all subentities in the underlying data-store. On success, the /// identity of the newly inserted instances will added to the document and all subdocuments. /// </summary> /// <param name="doc">Document (without ID) containing the data to be stored</param> /// <param name="config">The configuration object</param> /// <returns>The transactionResult contais status information of the single transaction an also the nesed transactions of the subentities</returns> public override void Add(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { #region Declarations AccountDocument accDoc; AccountDataset.AccountsRow row; #endregion // cast the given document to an account document accDoc = doc as AccountDocument; if (accDoc == null) { result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported)); return; } // get the account row from the given document row = GetRow(accDoc, config, true); // store as customer if the account type is set to customer if (CRMSelections.acc_type_Customer == (string)accDoc.customerSupplierFlag.Value) StoreCustomer(accDoc, row, config, ref result); // store as supplier if the account type is set to supplier else if (CRMSelections.acc_type_Supplier == (string)accDoc.customerSupplierFlag.Value) StoreSupplier(accDoc, row, config, ref result); // for any other account type, set the transactionstatus to not supported else { result.Add(accDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountTypeNotSupported)); } }
/// <summary> /// dispatch the transaction between Add, Update,Delete /// </summary> /// <param name="doc">the data document</param> /// <param name="config">the configuratio Object</param> /// <returns>returns a transaction result for the transaction and all nested ones</returns> private void ExecuteTransaction(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { if (doc.LogState == LogState.Created) Add(doc, config, ref result); else if (doc.LogState == LogState.Deleted) Delete(doc, config, ref result); else Update(doc, config, ref result); }
public override void Update(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { List<TransactionResult> transactionResult = new List<TransactionResult>(); ProductFamilyDocument productFamilyDoc = doc as ProductFamilyDocument; #region check input values if (productFamilyDoc == null) { result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported)); return; } // check id #endregion DataSets.CategoryTableAdapters.CategoriesTableAdapter tableAdapter; DataSets.Category category = new DataSets.Category(); DataSets.Category.CategoriesRow row; tableAdapter = new DataSets.CategoryTableAdapters.CategoriesTableAdapter(); using (OleDbConnection connection = new OleDbConnection(config.ConnectionString)) { connection.Open(); tableAdapter.Connection = connection; int recordCount = tableAdapter.FillBy(category.Categories, Convert.ToInt32(productFamilyDoc.Id)); if (recordCount == 0) { doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, "Category does not exists"); return; } row = (Category.CategoriesRow)category.Categories.Rows[0]; try { if(!productFamilyDoc.name.NotSet) if (productFamilyDoc.name.IsNull) row.SetCategoryNameNull(); else row.CategoryName = (string)productFamilyDoc.name.Value; if(!productFamilyDoc.description.NotSet) if (productFamilyDoc.description.IsNull) row.SetDescriptionNull(); else row.Description = (string)productFamilyDoc.description.Value; row.ModifyID = config.SequenceNumber; row.ModifyUser = config.CrmUser; } catch (Exception e) { productFamilyDoc.Id = ""; #warning Check error message result.Add(productFamilyDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString())); return; } tableAdapter = new DataSets.CategoryTableAdapters.CategoriesTableAdapter(); tableAdapter.Connection = connection; tableAdapter.Update(category.Categories); result.Add(doc.SetTransactionStatus(TransactionStatus.Success)); } }
/* 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)); } }
public override PayloadBase GetTransformedPayload(Document document, out List<SyncFeedEntryLink> links) { PayloadBase result = _transformation.GetTransformedPayload(document as ProductFamilyDocument, out links); links = Helper.ExtendPayloadPath(links, "commodityGroup"); return result; }
public override PayloadBase GetTransformedPayload(Document document, out List<SyncFeedEntryLink> links) { throw new NotImplementedException(); }
private void InitProperty(string propName, TypeCode propTypecode, Document propParent) { this.parent = propParent; this.name = propName; this.typeCode = propTypecode; this.NotSet = true; try { this.crmCaption = DocumentPropertyCaption.ResourceManager.GetString(parent.DocumentName + "." + this.Name); if ((this.crmCaption == null) || (this.crmCaption == "")) this.crmCaption = this.Name; } catch (Exception) { this.crmCaption = this.Name; } }
/* 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)); }
/* 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)); } }
/* 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); } }
public override PayloadBase GetTransformedPayload(Document document, out List<SyncFeedEntryLink> links) { PayloadBase result = _transformation.GetTransformedPayload(document as UnitOfMeasureFamilyDocument, out links); links = Helper.ExtendPayloadPath(links, "unitOfMeasureGroup"); return result; }
public abstract FeedEntry GetTransformedPayload(Document document);
public override void Add(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { List<TransactionResult> transactionResult = new List<TransactionResult>(); ProductFamilyDocument productFamilyDoc = doc as ProductFamilyDocument; #region check input values if (productFamilyDoc == null) { result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported)); return; } #endregion DataSets.CategoryTableAdapters.CategoriesTableAdapter tableAdapter; DataSets.Category category = new DataSets.Category(); DataSets.Category.CategoriesRow row = category.Categories.NewCategoriesRow(); #region fill dataset from document try { if (productFamilyDoc.name.IsNull) row.SetCategoryNameNull(); else row.CategoryName = (string)productFamilyDoc.name.Value; if (productFamilyDoc.description.IsNull) row.SetDescriptionNull(); else row.Description = (string)productFamilyDoc.description.Value; row.CreateID = config.SequenceNumber; row.CreateUser = config.CrmUser; row.ModifyID = config.SequenceNumber; row.ModifyUser = config.CrmUser; } catch (Exception e) { productFamilyDoc.Id = ""; #warning Check error message result.Add(productFamilyDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString())); return; } #endregion using (OleDbConnection connection = new OleDbConnection(config.ConnectionString)) { connection.Open(); tableAdapter = new DataSets.CategoryTableAdapters.CategoriesTableAdapter(); tableAdapter.Connection = connection; category.Categories.AddCategoriesRow(row); tableAdapter.Update(category.Categories); OleDbCommand Cmd = new OleDbCommand("SELECT @@IDENTITY", connection); object lastid = Cmd.ExecuteScalar(); productFamilyDoc.Id = ((int)lastid).ToString(); } result.Add(doc.SetTransactionStatus(TransactionStatus.Success)); }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="config"></param> /// <returns></returns> public virtual void Add(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { result.Add(doc.GetOperationNotImplementedTransactionResult()); }
public abstract PayloadBase GetTransformedPayload(Document document, out List<SyncFeedEntryLink> links);
public override void Add(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { TransactionResult tmpTransactionResult; List<TransactionResult> transactionResult = new List<TransactionResult>(); OrderDocument orderDoc = doc as OrderDocument; #region check input values if (orderDoc == null) { result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported)); return; } string customerID; if (orderDoc.accountid.IsNull) { result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountIDMadatory)); return; } customerID = (string)orderDoc.accountid.Value; if (!customerID.StartsWith(Constants.CustomerIdPrefix)) { result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AddOrdersForCustomersOnly)); return; } #endregion DataSets.OrderTableAdapters.OrdersTableAdapter tableAdapter; DataSets.OrderTableAdapters.Order_DetailsTableAdapter detailsTableAdapter; DataSets.Order order = new DataSets.Order(); DataSets.Order.OrdersRow newOrder = order.Orders.NewOrdersRow(); customerID = customerID.Substring(Constants.CustomerIdPrefix.Length); newOrder.CustomerID = customerID; #region get Company Name DataSet dataSet = new DataSet(); OleDbDataAdapter dataAdapter; string sqlQuery = "Select CompanyName from Customers where CustomerID = '" + customerID + "'"; try { using (OleDbConnection connection = new OleDbConnection(config.ConnectionString)) { dataAdapter = new OleDbDataAdapter(sqlQuery, connection); if (dataAdapter.Fill(dataSet, "Customers") == 0) { result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountNotFound)); return; } newOrder.ShipName = dataSet.Tables[0].Rows[0][0].ToString(); } } catch (Exception e) { orderDoc.Id = ""; throw; } #endregion #region get Sels rep if (orderDoc.salesrepr.IsNull) newOrder.SetEmployeeIDNull(); else { try { newOrder.EmployeeID = int.Parse((string)orderDoc.salesrepr.Value); } catch (Exception) { newOrder.SetEmployeeIDNull(); } if (newOrder.IsEmployeeIDNull()) { try { dataSet = new DataSet(); sqlQuery = "SELECT Employees.EmployeeID FROM Employees where Employees.FirstName + ' ' + Employees.LastName = ? "; using (OleDbConnection connection = new OleDbConnection(config.ConnectionString)) { dataAdapter = new OleDbDataAdapter(sqlQuery, connection); OleDbParameter parameter = new OleDbParameter("Name", (string)orderDoc.salesrepr.Value); dataAdapter.SelectCommand.Parameters.Add(parameter); if (dataAdapter.Fill(dataSet, "Employees") > 0) newOrder.EmployeeID = Convert.ToInt32(dataSet.Tables[0].Rows[0][0]); else newOrder.EmployeeID = 1; } } catch (Exception e) { orderDoc.Id = ""; throw; } } } #endregion #region fill dataset from document try { if (orderDoc.opened.IsNull) newOrder.SetOrderDateNull(); else newOrder.OrderDate = (DateTime)orderDoc.opened.Value; if (orderDoc.deliverydate.IsNull) newOrder.SetRequiredDateNull(); else newOrder.RequiredDate = (DateTime)orderDoc.deliverydate.Value; if (orderDoc.shippedvia.IsNull) newOrder.SetShipViaNull(); else newOrder.ShipVia = (int)orderDoc.shippedvia.Value; if (orderDoc.shipaddress.IsNull) { newOrder.SetShipAddressNull(); newOrder.SetShipCityNull(); newOrder.SetShipCountryNull(); newOrder.SetShipPostalCodeNull(); } else { OrderAddress orderAddress = new OrderAddress(); orderAddress.CrmOrderAddress = (string)orderDoc.shipaddress.Value; newOrder.ShipAddress = (string)orderAddress.NorthwindAddress; newOrder.ShipCity = (string)orderAddress.NorthwindCity; newOrder.ShipPostalCode = (string)orderAddress.NorthwindZipCode; newOrder.ShipCountry = (string)orderAddress.NorthwindCountry; } if (orderDoc.freight.IsNull) newOrder.Freight = (decimal)0; else newOrder.Freight = (decimal)orderDoc.freight.Value; newOrder.CreateUser = config.CrmUser; newOrder.ModifyUser = config.CrmUser; newOrder.CreateID = config.SequenceNumber; newOrder.ModifyID = config.SequenceNumber; } catch (Exception e) { orderDoc.Id = ""; #warning Check error message result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.ToString())); return; } #endregion using (OleDbConnection connection = new OleDbConnection(config.ConnectionString)) { OleDbTransaction transaction = null; try { connection.Open(); transaction = connection.BeginTransaction(); tableAdapter = new DataSets.OrderTableAdapters.OrdersTableAdapter(); tableAdapter.Connection = connection; detailsTableAdapter = new DataSets.OrderTableAdapters.Order_DetailsTableAdapter(); detailsTableAdapter.Connection = connection; tableAdapter.SetTransaction(transaction); detailsTableAdapter.SetTransaction(transaction); order.Orders.AddOrdersRow(newOrder); tableAdapter.Update(order.Orders); OleDbCommand Cmd = new OleDbCommand("SELECT @@IDENTITY", connection); Cmd.Transaction = transaction; object lastid = Cmd.ExecuteScalar(); orderDoc.Id = ((int)lastid).ToString(); // add line Items DataSets.Order.Order_DetailsRow detailRow; Hashtable addedProductsProducts; addedProductsProducts = new Hashtable(); int productID; foreach (LineItemDocument lineItemDoc in orderDoc.orderitems) { try { try { productID = (int)lineItemDoc.productid.Value; } catch (Exception) { #warning only to test unsupported products productID = 0; } if (addedProductsProducts.Contains(productID)) { transaction.Rollback(); orderDoc.Id = ""; result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_OrderContainsProductTwice)); return; } addedProductsProducts.Add(productID, productID); detailRow = order.Order_Details.NewOrder_DetailsRow(); lineItemDoc.Id = orderDoc.Id + "-" + productID.ToString(); detailRow.OrderID = Convert.ToInt32(orderDoc.Id); detailRow.ProductID = productID; detailRow.Quantity = Convert.ToInt16(lineItemDoc.quantity.Value); detailRow.UnitPrice = (Decimal)lineItemDoc.listprice.Value; if ((lineItemDoc.discountsum.IsNull) || (detailRow.Quantity == 0) || (detailRow.UnitPrice == 0)) { detailRow.Discount = (float)0; } else { // discountPC = discountsum / qunatity * listprice //detailRow.Discount = Convert.ToSingle((decimal)lineItemDoc.discountsum.Value / ((decimal)detailRow.Quantity * detailRow.UnitPrice)); float discount = Convert.ToSingle((decimal)lineItemDoc.discountsum.Value / (detailRow.UnitPrice)); if (discount > 1) discount = 0; detailRow.Discount = discount; } detailRow.CreateUser = config.CrmUser; detailRow.ModifyUser = config.CrmUser; detailRow.CreateID = config.SequenceNumber; detailRow.ModifyID = config.SequenceNumber; } // this error occours in case of invalid data types catch (Exception e) { transaction.Rollback(); orderDoc.Id = ""; result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.Message)); return; } order.Order_Details.AddOrder_DetailsRow(detailRow); lineItemDoc.SetTransactionStatus(TransactionStatus.Success); } // here could an error ouucour in case on broken database connection // or of same invalid constraints which are unhandled before try { detailsTableAdapter.Update(order.Order_Details); } catch (Exception e) { transaction.Rollback(); orderDoc.Id = ""; result.Add(orderDoc.SetTransactionStatus(TransactionStatus.UnRecoverableError, e.Message)); return; } transaction.Commit(); orderDoc.GetTransactionResult(ref result); } catch (Exception transactionException) { if (transaction != null) transaction.Rollback(); orderDoc.Id = ""; throw; } } }
public void Add(Document document) { documents.Add(document); }
/// <summary> /// Constructor. The method initializes the class. /// </summary> /// <param name="propName">the Name Of the Property</param> /// <param name="propTypecode">the typecode of the value</param> /// /// <param name="propParent">the parent document</param> public Property(string propName, TypeCode propTypecode, Document propParent) { InitProperty(propName, propTypecode, propParent); this.maxLength = 0; }
public override Sage.Integration.Northwind.Feeds.PayloadBase GetTransformedPayload(Document document, out List<SyncFeedEntryLink> links) { throw new NotImplementedException(); }
public override PayloadBase GetTransformedPayload(Document document, out List<SyncFeedEntryLink> links) { PayloadBase result = _transformation.GetTransformedPayload(document as PriceDocument, out links); links = Helper.ExtendPayloadPath(links, "price"); return result; }
/// <summary> /// The Delete verb deletes existing account and all subentities in the underlying data-store. /// /// Should no account instance be found in the data-store that matches the id of the document, /// the transaction result will set accordingly. /// </summary> /// <param name="doc">Document (incl. ID) containing the data to be stored</param> /// <param name="config">The configuration object</param> /// <returns>The transactionResult contais status information of the single transaction an also the nesed transactions of the subentities</returns> public override void Delete(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { #region Declarations CustomersTableAdapter customers; SuppliersTableAdapter suppliers; DeleteHistoryTableAdapter deleteHistory; int sequenceId; string accountId ; string customerId = ""; int supplierID = 0; #endregion // get the account Id from the given document accountId = doc.Id == null ? "" : doc.Id; // get the northwind Supplier or customer id if possible if (doc.Id.StartsWith(Constants.CustomerIdPrefix)) customerId = accountId.Substring(Constants.CustomerIdPrefix.Length); else if (doc.Id.StartsWith(Constants.SupplierIdPrefix)) supplierID = Identity.GetId(accountId.Substring(Constants.SupplierIdPrefix.Length)); else { result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountTypeNotSupported)); return; } // get the logging sequence number sequenceId = config.SequenceNumber; using (OleDbConnection connection = new OleDbConnection(config.ConnectionString)) { try { // get Table Adpater and set the connecion deleteHistory = new DeleteHistoryTableAdapter(); deleteHistory.Connection = connection; if (supplierID > 0) { // get Table Adpater and set the connecion suppliers = new SuppliersTableAdapter(); suppliers.Connection = connection; // delete the supplier suppliers.DeleteQuery(supplierID); // logg the deleted supplier in the delete history deleteHistory.LogSuppliers(supplierID.ToString(), sequenceId, config.CrmUser); // set transaction status to success result.Add(doc.SetTransactionStatus(TransactionStatus.Success)); } else if (customerId.Length > 0) { // get Table Adpater and set the connecion customers = new CustomersTableAdapter(); customers.Connection = connection; // delete The customer customers.DeleteQuery(customerId); // logg the deleted Customer in the delete history deleteHistory.LogCustomers(customerId, sequenceId, config.CrmUser); // set transaction status to success result.Add(doc.SetTransactionStatus(TransactionStatus.Success)); } else // set transaction status result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountTypeNotSupported)); } catch (Exception deleteException) { #warning Check the error status. this occours if the account is not deletable, because of having orders // set transaction status and logg the error message result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, deleteException.ToString())); } } }
public override FeedEntry GetTransformedPayload(Document document) { _transformer.TradingAccountId = ((AccountDocument)document).Id; if(((AccountDocument)document).people.documents.Count > 0) return _transformer.GetTransformedPayload((PersonDocument)((AccountDocument)document).people.documents[0]); return null; }
/// <summary> /// The Update verb ammends an existing account and all subentities (Person, Email, Address, Phone) in the underlying data-store. /// The data as it should be stored is found in the parameter document. /// /// Should no account instance be found in the data-store that matches the id of the document, /// the transaction result will set accordingly. /// </summary> /// <param name="doc">Document (incl. ID) containing the data to be stored</param> /// <param name="config">The configuration object</param> /// <returns>The transactionResult contais status information of the single transaction an also the nesed transactions of the subentities</returns> public override void Update(Document doc, NorthwindConfig config, ref List<TransactionResult> result) { #region declarations string accountID; AccountDocument sourceAccount; AccountDocument targetAccount; AccountDataset.AccountsRow row; #endregion // cast the given document to an account document sourceAccount = doc as AccountDocument; if (sourceAccount == null) { result.Add(doc.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_DocumentTypeNotSupported)); return; } // get the linked account id accountID = sourceAccount.Id; //try to get the original Document targetAccount = GetDocument(accountID, config) as AccountDocument; // return error if the account not found if ((targetAccount == null) || (targetAccount.LogState == LogState.Deleted)) { result.Add(sourceAccount.SetTransactionStatus(TransactionStatus.UnRecoverableError, Resources.ErrorMessages_AccountNotFound)); return; } // merge the source data into the original account targetAccount.Merge(sourceAccount); // convert the Acoount Doc into a Dataset row row = GetRow(targetAccount, config, false); // check if it is linked and the given id is a customer id if ((accountID != null) && (accountID.Length > 2) && accountID.StartsWith(Constants.CustomerIdPrefix)) { // Store the taget account document into the customer and customeremail table StoreCustomer(targetAccount, row, config, ref result); } // check if it is linked and the given id is a customer id else if ((accountID != null) && (accountID.Length > 2) && accountID.StartsWith(Constants.SupplierIdPrefix)) { // Store the taget account document into the suppliers table StoreSupplier(targetAccount, row, config, ref result); } // return the set transaction result //targetAccount.GetTransactionResult(true, ref result); }
/* 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 abstract XmlAttribute[] GetUnhandledAttributes(); /// <summary> /// merge a document into the current. /// </summary> /// <param name="sourceDocument">the source Document</param> public void Merge(Document sourceDocument) { #region Declarations Property sourceProperty; DocumentCollection sourceCollection; #endregion // set the CRM id from the source document this.crmId = sourceDocument.crmId; // set the log state from the source document this.logState = sourceDocument.logState; // go thru each property of the current document foreach (Property prop in Properties.Values) { // if the log state is deleted clear the property if (sourceDocument.LogState == LogState.Deleted) { prop.Value = null; continue; } // if the property not part of the source documet // continue with the next property if (!sourceDocument.Properties.ContainsKey(prop.Name)) continue; // get the source property sourceProperty = sourceDocument.Properties[prop.Name]; // continue if the property was not set. Not set is different from null if (sourceProperty.NotSet) continue; // set the property prop.Value = sourceProperty.Value; } // go thru each document collection foreach (DocumentCollection coll in Collections.Values) { // continue if the document collection is not part of the source document if (!sourceDocument.Collections.ContainsKey(coll.CollectionName)) continue; // get the source collection sourceCollection = sourceDocument.Collections[coll.CollectionName]; // continue if the collection was not set. Not set is different from null if (sourceCollection.NotSet) continue; //merge the collection coll.Merge(sourceCollection); } }