示例#1
0
        log4net.ILog log = log4net.LogManager.GetLogger("fileLog");//获取一个日志记录器
        public UpdateProductQuantityResponse UpdateProductQuantity(String productId, String quantity)
        {
            log.Info("CMS-->Product Quantity:" + quantity);
            UpdateProductQuantityResponse response = new UpdateProductQuantityResponse();
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                //Update Account TradeRegistration
                Entity    product    = new Entity("product");
                ColumnSet attributes = new ColumnSet(new string[] { "quantityonhand" });

                product = organizationProxy.Retrieve(product.LogicalName, new Guid(productId), attributes);
                log.Info("Retrieved quantityonhand: " + product["quantityonhand"]);

                //OptionSetValue register = new OptionSetValue(1);

                //account.Attributes.Add("new_check",  register);
                product["quantityonhand"] = Decimal.Parse(quantity);;


                organizationProxy.Update(product);



                response.ErrCode = "0";
                return(response);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
示例#2
0
        public AppCrmAuthorization SupplierAuthorization(string email)
        {
            log.Info("Supplier Login-->:" + email);
            AppCrmAuthorization auth = new AppCrmAuthorization();

            auth.IsLoginSuccess = "false";
            try
            {
                CrmUtil cu = new CrmUtil();
                OrganizationServiceProxy organizationProxy = cu.getCrmService();
                Entity account = RetriveAccountByEmail(organizationProxy, email);
                if (account != null)
                {
                    if (account.Contains("new_signedsuppliers") && account.GetAttributeValue <bool>("new_signedsuppliers"))
                    {
                        auth.IsLoginSuccess = "true";
                    }
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(auth);
        }
示例#3
0
        public SupplierCrmProductResponse AppUpdateProduct(SupplierCrmProduct newProduct)
        {
            log.Info("CMS-->Product update:" + newProduct.ProductName);
            SupplierCrmProductResponse response = new SupplierCrmProductResponse();
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                Entity    oldProduct = new Entity("product");
                ColumnSet attributes = new ColumnSet(new string[] { "quantityonhand" });

                oldProduct = organizationProxy.Retrieve(oldProduct.LogicalName, new Guid(newProduct.ProductId), attributes);

                //oldProduct["productnumber"] = newProduct.ProductName;
                //oldProduct["name"] = newProduct.ProductSku;
                //oldProduct["description"] = newProduct.ProductDescription;
                oldProduct["quantityonhand"] = Decimal.Parse(newProduct.Quantity);


                organizationProxy.Update(oldProduct);

                response.result = "success";
                return(response);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
示例#4
0
        public void UpdateContactCompany(Guid contactId, Guid accountId)
        {
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                Entity    contact    = new Entity("contact");
                ColumnSet attributes = new ColumnSet(new string[] { "firstname", "ownerid" });

                contact = organizationProxy.Retrieve(contact.LogicalName, contactId, attributes);
                log.Info("Update contact  company: " + contact["firstname"]);//contact["firstname"]必须有值,否则报错:given key not in 。。

                contact["parentcustomerid"] = new EntityReference("account", accountId);

                organizationProxy.Update(contact);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "\r\n" + ex.ToString());
            }
        }
示例#5
0
        public AppCrmAccount AppGetAccountByEmail(string email)
        {
            log.Info("AppGetAccountByEmail-->:" + email);
            AppCrmAccount new_account = new AppCrmAccount();

            try
            {
                CrmUtil cu = new CrmUtil();
                OrganizationServiceProxy organizationProxy = cu.getCrmService();
                Entity account = RetriveAccountByEmail(organizationProxy, email);


                new_account.AccName          = account.GetAttributeValue <string>("name");
                new_account.AccPhone         = account.GetAttributeValue <string>("telephone1");
                new_account.AccFax           = account.GetAttributeValue <string>("fax");
                new_account.AccEmail         = account.GetAttributeValue <string>("emailaddress1");
                new_account.AccStreet1       = account.GetAttributeValue <string>("address1_line1");
                new_account.AccStreet2       = account.GetAttributeValue <string>("address1_line2");
                new_account.AccCity          = account.GetAttributeValue <string>("address1_city");
                new_account.AccStateProvince = account.GetAttributeValue <string>("address1_stateorprovince");
                new_account.AccCountryRegion = account.GetAttributeValue <string>("address1_country");
                new_account.AccZIPPostalCode = account.GetAttributeValue <string>("address1_postalcode");

                if (account.Contains("new_check") && account.GetAttributeValue <bool>("new_check"))
                {
                    new_account.AccTradeRegistration = "true";
                }
                else
                {
                    new_account.AccTradeRegistration = "false";
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(new_account);
        }
示例#6
0
        public UpdateTradeRegistrationResponse UpdateTradeRegistration(String accountId)
        {
            log.Info("CMS-->Approved:" + accountId);
            UpdateTradeRegistrationResponse response = new UpdateTradeRegistrationResponse();
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                //Update Account TradeRegistration
                //Entity account = new Entity("account");
                //ColumnSet attributes = new ColumnSet(new string[] { "new_check" });

                //account = organizationProxy.Retrieve(account.LogicalName, new Guid(accountId), attributes);
                //log.Info("Retrieved new_check: " + account["new_check"]);

                Entity account = RetriveAccountByEmail(organizationProxy, accountId);

                OptionSetValue register = new OptionSetValue(1);

                //account.Attributes.Add("new_check",  register);
                account["new_check"] = true;


                organizationProxy.Update(account);



                response.ErrCode = "0";
                return(response);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
        log4net.ILog log = log4net.LogManager.GetLogger("fileLog");//获取一个日志记录器
        public CrmOrderResponse CreateCrmOrder(CreateCrmOrder CreateCrmOrder)
        {
            log.Info("Call CreateCrmOrder Interface....");
            CrmOrderResponse         response          = new CrmOrderResponse();
            CrmUtil                  cu                = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                //1.Create order
                Entity salesorder = new Entity("salesorder");
                //if (CreateCrmOrder != null)
                //{
                //    log.Info("request is not null");
                //    log.Info(CreateCrmOrder);
                //    foreach (System.Reflection.PropertyInfo p in CreateCrmOrder.GetType().GetProperties())
                //    {
                //        log.Info("Name:" + p.Name + "--Value:" + p.GetValue(CreateCrmOrder));
                //    }
                //}


                salesorder["name"] = CreateCrmOrder.OrderName;

                Entity email_account = RetriveAccountByEmail(organizationProxy, CreateCrmOrder.CustomerId);
                salesorder["customerid"] = new EntityReference("account", email_account.Id);

                //salesorder["pricelevelid"] = new EntityReference("pricelevel", new Guid(CreateCrmOrder.PricelevelId));

                //salesorder["pricelevelid"] = new EntityReference("pricelevel", new Guid("52CFEDBC-FF7A-E411-80D6-AC162DB4BC5C"));
                salesorder["pricelevelid"] = new EntityReference("pricelevel", new Guid(cu.pricelevelid_value));

                string Po_Numbser = CreateCrmOrder.PoNumbser;
                if (Po_Numbser != null && Po_Numbser != "" && Po_Numbser.Length > 390)
                {
                    Po_Numbser = Po_Numbser.Substring(0, 390);
                }
                salesorder["new_ordernumber"] = Po_Numbser;
                OptionSetValue pv = new OptionSetValue(int.Parse(CreateCrmOrder.PaymenttermsCode));
                salesorder["paymenttermscode"]       = pv;
                salesorder["billto_name"]            = CreateCrmOrder.BilltoName;
                salesorder["billto_line1"]           = CreateCrmOrder.BilltoLine1;
                salesorder["billto_line2"]           = CreateCrmOrder.BilltoLine2;
                salesorder["billto_city"]            = CreateCrmOrder.BilltoCity;
                salesorder["billto_stateorprovince"] = CreateCrmOrder.BilltoStateOrProvince;
                salesorder["billto_country"]         = CreateCrmOrder.BilltoCountry;
                salesorder["billto_postalcode"]      = CreateCrmOrder.BilltoPostalcode;
                salesorder["shipto_name"]            = CreateCrmOrder.ShiptoName;
                salesorder["shipto_line1"]           = CreateCrmOrder.ShiptoLine1;
                salesorder["shipto_line2"]           = CreateCrmOrder.ShiptoLine2;
                salesorder["shipto_city"]            = CreateCrmOrder.ShiptoCity;
                salesorder["shipto_stateorprovince"] = CreateCrmOrder.ShiptoStateOrProvince;
                salesorder["shipto_country"]         = CreateCrmOrder.ShiptoCountry;
                salesorder["shipto_postalcode"]      = CreateCrmOrder.ShiptoPostalcode;

                List <CrmProduct> topProdcutList = CreateCrmOrder.CrmProductList;

                IEnumerable <IGrouping <string, CrmProduct> > query = topProdcutList.GroupBy(x => x.ManufacturerId);
                foreach (IGrouping <string, CrmProduct> info in query)
                {
                    List <CrmProduct> prodcutList = info.ToList <CrmProduct>();//分组后的集合

                    Entity vendor_account = RetriveAccountByManuFacturer(organizationProxy, prodcutList[0].ManufacturerId);
                    salesorder["new_vendor"] = new EntityReference("account", vendor_account.Id);

                    //Create Order
                    Guid orderId = organizationProxy.Create(salesorder);
                    log.Info("Create salesorder Success:" + orderId.ToString());


                    //2.Add prodcut to Order

                    log.Info("ProductList Count:" + prodcutList.Count);


                    #region Execute Multiple with Results
                    // Create an ExecuteMultipleRequest object.
                    ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
                    {
                        // Assign settings that define execution behavior: continue on error, return responses.
                        Settings = new ExecuteMultipleSettings()
                        {
                            ContinueOnError = false,
                            ReturnResponses = true
                        },
                        // Create an empty organization request collection.
                        Requests = new OrganizationRequestCollection()
                    };

                    // Create several (local, in memory) entities in a collection.
                    EntityCollection input = GetCollectionOfEntitiesToCreate(prodcutList, orderId, cu.uomid_value, organizationProxy);

                    // Add a CreateRequest for each entity to the request collection.
                    foreach (var entity in input.Entities)
                    {
                        CreateRequest createRequest = new CreateRequest {
                            Target = entity
                        };
                        requestWithResults.Requests.Add(createRequest);
                    }

                    // Execute all the requests in the request collection using a single web method call.
                    ExecuteMultipleResponse responseWithResults =
                        (ExecuteMultipleResponse)organizationProxy.Execute(requestWithResults);

                    // Display the results returned in the responses.
                    foreach (var responseItem in responseWithResults.Responses)
                    {
                        // A valid response.
                        if (responseItem.Response != null)
                        {
                            OrganizationRequest  orq = requestWithResults.Requests[responseItem.RequestIndex];
                            OrganizationResponse ors = responseItem.Response;
                        }

                        // An error has occurred.
                        else if (responseItem.Fault != null)
                        {
                            OrganizationRequest orq = requestWithResults.Requests[responseItem.RequestIndex];
                            int idx = responseItem.RequestIndex;
                            OrganizationServiceFault fa = responseItem.Fault;
                        }
                    }
                    #endregion Execute Multiple with Results

                    #region Execute Multiple with No Results

                    ExecuteMultipleRequest requestWithNoResults = new ExecuteMultipleRequest()
                    {
                        // Set the execution behavior to not continue after the first error is received
                        // and to not return responses.
                        Settings = new ExecuteMultipleSettings()
                        {
                            ContinueOnError = false,
                            ReturnResponses = false
                        },
                        Requests = new OrganizationRequestCollection()
                    };

                    // Update the entities that were previously created.
                    EntityCollection update = GetCollectionOfEntitiesToUpdate(prodcutList, organizationProxy);

                    foreach (var entity in update.Entities)
                    {
                        UpdateRequest updateRequest = new UpdateRequest {
                            Target = entity
                        };
                        requestWithNoResults.Requests.Add(updateRequest);
                    }

                    ExecuteMultipleResponse responseWithNoResults =
                        (ExecuteMultipleResponse)organizationProxy.Execute(requestWithNoResults);

                    // There should be no responses unless there was an error. Only the first error
                    // should be returned. That is the behavior defined in the settings.
                    if (responseWithNoResults.Responses.Count > 0)
                    {
                        foreach (var responseItem in responseWithNoResults.Responses)
                        {
                            if (responseItem.Fault != null)
                            {
                                OrganizationRequest orq = requestWithNoResults.Requests[responseItem.RequestIndex];
                                int ri = responseItem.RequestIndex;
                                OrganizationServiceFault fa = responseItem.Fault;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("All account records have been updated successfully.");
                    }

                    #endregion Execute Multiple with No Results



                    ////2.Add prodcut to Order
                    //log.Info("ProductList数量:"+CreateCrmOrder.CrmProductList.Count);
                    //List<CrmProduct> prodcutList = CreateCrmOrder.CrmProductList;
                    //foreach (CrmProduct prd in prodcutList)
                    //{
                    //    log.Info("Create salesorderdetail Begin:" + prd.ProductName);
                    //    Entity salesorderdetail = new Entity("salesorderdetail");
                    //    salesorderdetail["productid"] = new EntityReference("product", new Guid(prd.ProductName));
                    //    salesorderdetail["quantity"] = Decimal.Parse(prd.Quantity);
                    //    salesorderdetail["salesorderid"] = new EntityReference("salesorder", orderId);
                    //    //salesorderdetail["uomid"] = new EntityReference("uom", new Guid("CCFF5EBE-5407-4214-BD04-60461B7161AA"));
                    //    salesorderdetail["uomid"] = new EntityReference("uom", new Guid(cu.uomid_value));
                    //    //salesorderdetail["productid"] = prd.FreightAmount;
                    //    //salesorderdetail["productid"] = prd.AmountDiscount;
                    //    log.Info("Befor Create....");
                    //    Guid salesorderdetailId = organizationProxy.Create(salesorderdetail);
                    //    log.Info("创建salesorderdetail成功:" + salesorderdetailId.ToString());
                    //    //同时修改product的库存,用减法
                    //    Entity product = new Entity("product");
                    //    ColumnSet attributes = new ColumnSet(new string[] { "quantityonhand" });

                    //    product = organizationProxy.Retrieve(product.LogicalName, new Guid(prd.ProductName), attributes);
                    //    log.Info("Retrieved quantityonhand: " + product["quantityonhand"]);

                    //    decimal nowQuantity = (Decimal)product["quantityonhand"];
                    //    decimal newQuantity = nowQuantity - Decimal.Parse(prd.Quantity);
                    //    product["quantityonhand"] = newQuantity;
                    //    log.Info("newQuantity: " + newQuantity);

                    //    organizationProxy.Update(product);
                    //    log.Info("Update product quantity Success:" + prd.ProductName.ToString());
                    //}
                    //Add Free Shipping 4608DBBF-6E8F-E411-80DA-AC162DB4BC5C Flat Shipping Rate

                    //取消运费功能
                    //string isFreeShipping = CreateCrmOrder.IsFreeShipping;
                    //if(isFreeShipping.Equals("N"))//不免运费,加上运费的price list item
                    //{
                    //    Entity salesorderdetail = new Entity("salesorderdetail");
                    //    //salesorderdetail["productid"] = new EntityReference("product", new Guid("8698AE03-F994-E411-80E2-AC162DB41AC0"));
                    //    salesorderdetail["productid"] = new EntityReference("product", new Guid(cu.freeshipping_product_value));
                    //    salesorderdetail["quantity"] = Decimal.Parse("1");
                    //    salesorderdetail["salesorderid"] = new EntityReference("salesorder", orderId);
                    //    //salesorderdetail["uomid"] = new EntityReference("uom", new Guid("CCFF5EBE-5407-4214-BD04-60461B7161AA"));
                    //    salesorderdetail["uomid"] = new EntityReference("uom", new Guid(cu.uomid_value));
                    //    //salesorderdetail["productid"] = prd.FreightAmount;
                    //    //salesorderdetail["productid"] = prd.AmountDiscount;
                    //    Guid salesorderdetailId = organizationProxy.Create(salesorderdetail);
                    //    log.Info("创建运费成功:" + salesorderdetailId.ToString());
                    //}

                    Entity    isExistOrder     = new Entity("salesorder");
                    ColumnSet order_attributes = new ColumnSet(new string[] { "myce_taxratingid" });

                    isExistOrder = organizationProxy.Retrieve(isExistOrder.LogicalName, orderId, order_attributes);

                    isExistOrder["myce_taxratingid"] = new EntityReference("myce_taxrating", new Guid(cu.myce_taxratingid_value));
                    organizationProxy.Update(isExistOrder);

                    //fullfill salesorder
                    // FulfillSalesOrder(organizationProxy, orderId);

                    //create invoices
                    // CreateInvoice(organizationProxy, orderId);
                }



                response.ErrCode = "0";
                return(response);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
        public ExportCrmOrder getOrderInfoById(Guid orderId)
        {
            ExportCrmOrder crmOrder = new ExportCrmOrder();
            List <ExportCrmOrderProduct> crmOrderProduct = new List <ExportCrmOrderProduct>();
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                Entity    isExistOrder     = new Entity("salesorder");
                ColumnSet order_attributes = new ColumnSet(true);

                isExistOrder = organizationProxy.Retrieve(isExistOrder.LogicalName, orderId, order_attributes);

                crmOrder.OrderId    = orderId.ToString();
                crmOrder.BillToName = isExistOrder.GetAttributeValue <string>("shipto_name");
                crmOrder.Street1    = isExistOrder.GetAttributeValue <string>("shipto_line1");
                crmOrder.Street2    = isExistOrder.GetAttributeValue <string>("shipto_line2");
                crmOrder.City       = isExistOrder.GetAttributeValue <string>("shipto_city");
                crmOrder.PostCode   = isExistOrder.GetAttributeValue <string>("shipto_postalcode");
                crmOrder.OrderNo    = isExistOrder.GetAttributeValue <string>("name");
                crmOrder.RefNo      = isExistOrder.GetAttributeValue <string>("new_pickinglistnumber");
                crmOrder.ShipDate   = isExistOrder.GetAttributeValue <DateTime>("new_pickingdate").ToLocalTime().ToString("dd/MM/yyyy");
                if (isExistOrder.Contains("shippingmethodcode") && isExistOrder["shippingmethodcode"] != null)
                {
                    crmOrder.ShipVia = isExistOrder.FormattedValues["shippingmethodcode"];
                }
                crmOrder.Note = isExistOrder.GetAttributeValue <string>("new_packinglistnote");


                //Query Product by OrderId
                QueryExpression qe = new QueryExpression();
                qe.EntityName = "salesorderdetail";
                qe.ColumnSet  = new ColumnSet();
                qe.ColumnSet.Columns.Add("quantity");
                qe.ColumnSet.Columns.Add("productid");

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "salesorderid";
                condition1.Operator      = ConditionOperator.Equal;
                condition1.Values.Add(orderId);

                FilterExpression filter1 = new FilterExpression();
                filter1.Conditions.Add(condition1);

                qe.Criteria.AddFilter(filter1);

                qe.LinkEntities.Add(new LinkEntity("salesorderdetail", "product", "productid", "productid", JoinOperator.Inner));
                qe.LinkEntities[0].Columns.AddColumns("new_stocklocation", "name", "new_stockstatus", "new_suppliera1", "producttypecode", "currentcost");
                qe.LinkEntities[0].EntityAlias = "orderproduct";


                //  Query passed to service proxy.
                EntityCollection retrieved = organizationProxy.RetrieveMultiple(qe);
                foreach (Entity entity in retrieved.Entities)
                {
                    bool isProduct = true;

                    //Product Status is Service Rate 10
                    if (entity.GetAttributeValue <AliasedValue>("orderproduct.producttypecode") != null)
                    {
                        OptionSetValue op = (OptionSetValue)(entity.GetAttributeValue <AliasedValue>("orderproduct.producttypecode").Value);

                        int ov = op.Value;
                        if (ov.Equals(10))
                        {
                            isProduct = false;
                        }
                    }

                    if (isProduct)
                    {
                        ExportCrmOrderProduct product = new ExportCrmOrderProduct();
                        if (entity.Contains("orderproduct.new_stocklocation") && entity["orderproduct.new_stocklocation"] != null)
                        {
                            product.Location = entity.GetAttributeValue <AliasedValue>("orderproduct.new_stocklocation").Value.ToString();
                        }
                        if (entity.Contains("orderproduct.currentcost") && entity["orderproduct.currentcost"] != null)
                        {
                            Money cost = (Money)(entity.GetAttributeValue <AliasedValue>("orderproduct.currentcost").Value);
                            product.LandedCost = cost.Value.ToString("0.00");
                        }

                        //Non Stock-->1,Purchased Stock-->2,Third Party Stock-->3
                        if (entity.GetAttributeValue <AliasedValue>("orderproduct.new_stockstatus") != null)
                        {
                            OptionSetValue op = (OptionSetValue)(entity.GetAttributeValue <AliasedValue>("orderproduct.new_stockstatus").Value);

                            //string text = entity.FormattedValues.Where(a => a.Key == "orderproduct.new_stockstatus").FirstOrDefault().Value;
                            product.StockStatus = op.Value.ToString();
                        }
                        product.ProductName = entity.GetAttributeValue <AliasedValue>("orderproduct.name").Value.ToString();
                        product.QtyOrdered  = entity.GetAttributeValue <decimal>("quantity").ToString("#");
                        if (entity.Contains("orderproduct.new_suppliera1") && entity["orderproduct.new_suppliera1"] != null)
                        {
                            EntityReference supplier_a = (EntityReference)(entity.GetAttributeValue <AliasedValue>("orderproduct.new_suppliera1").Value);
                            product.SupplierA = supplier_a.Name;
                        }

                        crmOrderProduct.Add(product);
                    }
                }
                //排序
                List <ExportCrmOrderProduct> SortedList = crmOrderProduct.OrderBy(o => o.StockStatus).ThenBy(o => o.Location).ToList();
                crmOrder.products = SortedList;
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(crmOrder);
        }
示例#9
0
        log4net.ILog log = log4net.LogManager.GetLogger("fileLog");//获取一个日志记录器
        public AddAccountAndContactResponse AddAccountAndContact(AddAccountAndContact AddAccountAndContact)
        {
            log.Info("调用AddAccountAndContact接口。");
            AddAccountAndContactResponse response = new AddAccountAndContactResponse();
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                //1.Create Contact
                Entity contact = new Entity("contact");
                log.Info("request的值为:" + AddAccountAndContact.ToString());
                //if (AddAccountAndContact != null) {
                //    log.Info("request is not null");
                //    log.Info(AddAccountAndContact);
                //    foreach (System.Reflection.PropertyInfo p in AddAccountAndContact.GetType().GetProperties())
                //    {
                //        log.Info("Name:"+p.Name+"--Value:"+p.GetValue(AddAccountAndContact));
                //    }
                //}
                contact["firstname"]                = AddAccountAndContact.ContFirstName;
                contact["lastname"]                 = AddAccountAndContact.ContLastName;
                contact["emailaddress1"]            = AddAccountAndContact.ContEmail;
                contact["telephone1"]               = AddAccountAndContact.ContTelephone1;
                contact["address1_line1"]           = AddAccountAndContact.ContStreet1;
                contact["address1_line2"]           = AddAccountAndContact.ContStreet2;
                contact["address1_city"]            = AddAccountAndContact.ContCity;
                contact["address1_stateorprovince"] = AddAccountAndContact.ContStateProvince;
                contact["address1_country"]         = AddAccountAndContact.ContCountryRegion;
                contact["address1_postalcode"]      = AddAccountAndContact.ContZIPPostalCode;

                Guid contactId = organizationProxy.Create(contact);
                log.Info("创建contact成功:" + contactId.ToString());
                //2.Create Account
                Entity account = new Entity("account");
                account["name"]                     = AddAccountAndContact.AccAccountName;
                account["telephone1"]               = AddAccountAndContact.AccPhone;
                account["fax"]                      = AddAccountAndContact.AccFax;
                account["emailaddress1"]            = AddAccountAndContact.AccEmail;
                account["address1_line1"]           = AddAccountAndContact.AccStreet1;
                account["address1_line2"]           = AddAccountAndContact.AccStreet2;
                account["address1_city"]            = AddAccountAndContact.AccCity;
                account["address1_stateorprovince"] = AddAccountAndContact.AccStateProvince;
                account["address1_country"]         = AddAccountAndContact.AccCountryRegion;
                account["address1_postalcode"]      = AddAccountAndContact.AccZIPPostalCode;
                if (AddAccountAndContact.AccNewsletter == "0")
                {
                    account["new_newslettersubscribe"] = false;
                }
                else if (AddAccountAndContact.AccNewsletter == "1")
                {
                    account["new_newslettersubscribe"] = true;
                }

                account["primarycontactid"] = new EntityReference("contact", contactId);

                Guid accountId = organizationProxy.Create(account);
                log.Info("创建account成功:" + accountId.ToString());

                //update contact company..
                UpdateContactCompany(contactId, accountId);

                response.AccountId = accountId.ToString();
                response.ErrCode   = "0";
                return(response);
            }
            catch (Exception ex) {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
示例#10
0
        public AnalysisCrmProduct AnalysisGetProductById(String productId)
        {
            log.Info("AnalysisGetProductById==" + productId);
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();
            AnalysisCrmProduct       res_product       = new AnalysisCrmProduct();

            try
            {
                //Update Account TradeRegistration
                Entity    product    = new Entity("product");
                ColumnSet attributes = new ColumnSet(true);

                product = organizationProxy.Retrieve(product.LogicalName, new Guid(productId), attributes);

                res_product.ProductName = product.GetAttributeValue <string>("productnumber");
                res_product.ProductSku  = product.GetAttributeValue <string>("name");

                if (product.Contains("producttypecode") && product["producttypecode"] != null)
                {
                    res_product.ProductStatus = product.FormattedValues["producttypecode"];
                }
                if (product.Contains("defaultuomid") && product["defaultuomid"] != null)
                {
                    EntityReference unit = (EntityReference)product["defaultuomid"];
                    res_product.Unit = unit.Name;
                }

                res_product.DecimalsSupported = product.GetAttributeValue <int>("quantitydecimal").ToString();

                if (product.Contains("pricelevelid") && product["pricelevelid"] != null)
                {
                    EntityReference pricelist = (EntityReference)product["pricelevelid"];
                    res_product.PriceList = pricelist.Name;
                }
                if (product.Contains("new_suppliera1") && product["new_suppliera1"] != null)
                {
                    EntityReference supplier_a = (EntityReference)product["new_suppliera1"];
                    res_product.SupplierA = supplier_a.Name;
                }
                res_product.Brand = product.GetAttributeValue <string>("suppliername");

                res_product.Quantity = product.GetAttributeValue <decimal>("quantityonhand").ToString("#.##");

                res_product.BrandedPackage   = product.GetAttributeValue <bool>("new_brandedpackage").ToString();
                res_product.PetDreamHouseURL = product.GetAttributeValue <string>("producturl");

                if (product.Contains("price") && product["price"] != null)
                {
                    res_product.ListPrice = product.GetAttributeValue <Money>("price").Value.ToString("#.##");
                }

                if (product.Contains("new_rrp") && product["new_rrp"] != null)
                {
                    res_product.RRP = product.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                }

                res_product.ProductColor         = product.GetAttributeValue <string>("new_colour");
                res_product.ProductBarcode       = product.GetAttributeValue <string>("new_productbarcode");
                res_product.ProductDimensions    = product.GetAttributeValue <string>("new_size");
                res_product.ProductWeight        = product.GetAttributeValue <string>("new_productweight");
                res_product.IdenticalUnitPerCase = product.GetAttributeValue <string>("new_casequantity");
                res_product.CaseBarcode          = product.GetAttributeValue <string>("new_casebarcode");
                res_product.CaseDimensions       = product.GetAttributeValue <string>("new_casedimensions");
                res_product.CaseWeight           = product.GetAttributeValue <string>("new_caseweight");
                res_product.CTNDetails           = product.GetAttributeValue <string>("new_ctndetails");

                if (product.Contains("new_parentcatalog") && product["new_parentcatalog"] != null)
                {
                    res_product.ParentCatalog = product.FormattedValues["new_parentcatalog"];
                }
                if (product.Contains("new_subcatelog") && product["new_subcatelog"] != null)
                {
                    res_product.SubCatalog = product.FormattedValues["new_subcatelog"];
                }
                if (product.Contains("new_additionalcatelog") && product["new_additionalcatelog"] != null)
                {
                    res_product.AdditionalCatalog = product.FormattedValues["new_additionalcatelog"];
                }

                res_product.ProductDescription = product.GetAttributeValue <string>("description");
                res_product.UnitBarCode        = product.GetAttributeValue <string>("new_barcode");
                res_product.UnitWeight_KG      = product.GetAttributeValue <decimal>("new_grossunitweight").ToString("#.##");
                res_product.UnitDepthLength_CM = product.GetAttributeValue <decimal>("new_unitdepthcm").ToString("#.##");
                res_product.UnitWidthGirth_CM  = product.GetAttributeValue <decimal>("new_unitwidthcm").ToString("#.##");
                res_product.UnitHeightNeck_CM  = product.GetAttributeValue <decimal>("new_unitheight").ToString("#.##");
                res_product.CartonBarcode      = product.GetAttributeValue <string>("new_mastercartonbarcode");
                res_product.UnitsPerCarton     = product.GetAttributeValue <string>("new_packspermasterbox");
                res_product.CartonWeight_KG    = product.GetAttributeValue <decimal>("new_mastercartonweightkg").ToString("#.##");
                res_product.CartonDepth_CM     = product.GetAttributeValue <decimal>("new_mastercartondepthcm").ToString("#.##");
                res_product.CartonWidth_CM     = product.GetAttributeValue <decimal>("new_mastercartonwidthcm").ToString("#.##");
                res_product.CartonHeight_CM    = product.GetAttributeValue <decimal>("new_mastercartonheightcm").ToString("#.##");
                res_product.CreatedOn          = product.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");

                return(res_product);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
示例#11
0
        public List <AppCrmProduct> AppGetProductsByCategory(AppCrmProductCategoryRequest request)
        {
            log.Info("AppGetProductsByCategory:");
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();
            List <AppCrmProduct>     products          = new List <AppCrmProduct>();

            try
            {
                QueryExpression qe = new QueryExpression();
                qe.EntityName = "product";
                qe.ColumnSet  = new ColumnSet(true);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = request.categoryType;
                condition1.Operator      = ConditionOperator.Equal;
                condition1.Values.Add(request.categoryValue);

                FilterExpression filter1 = new FilterExpression();
                filter1.Conditions.Add(condition1);

                qe.Criteria.AddFilter(filter1);

                EntityCollection ec = organizationProxy.RetrieveMultiple(qe);

                foreach (Entity product in ec.Entities)
                {
                    AppCrmProduct res_product = new AppCrmProduct();
                    res_product.ProductId   = product.GetAttributeValue <Guid>("productid").ToString();
                    res_product.ProductName = product.GetAttributeValue <string>("productnumber");
                    res_product.ProductSku  = product.GetAttributeValue <string>("name");
                    res_product.Brand       = product.GetAttributeValue <string>("suppliername");
                    res_product.Quantity    = product.GetAttributeValue <decimal>("quantityonhand").ToString("#.##");
                    res_product.PictureList = product.GetAttributeValue <string>("new_picturelist");

                    if (product.Contains("price") && product["price"] != null)
                    {
                        res_product.ListPrice = product.GetAttributeValue <Money>("price").Value.ToString("#.##");
                    }

                    if (product.Contains("new_rrp") && product["new_rrp"] != null)
                    {
                        res_product.RRP = product.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                    }

                    res_product.ProductColor         = product.GetAttributeValue <string>("new_colour");
                    res_product.ProductBarcode       = product.GetAttributeValue <string>("new_productbarcode");
                    res_product.ProductDimensions    = product.GetAttributeValue <string>("new_size");
                    res_product.ProductWeight        = product.GetAttributeValue <string>("new_productweight");
                    res_product.IdenticalUnitPerCase = product.GetAttributeValue <string>("new_casequantity");
                    res_product.CaseBarcode          = product.GetAttributeValue <string>("new_casebarcode");
                    res_product.CaseDimensions       = product.GetAttributeValue <string>("new_casedimensions");
                    res_product.CaseWeight           = product.GetAttributeValue <string>("new_caseweight");
                    res_product.CTNDetails           = product.GetAttributeValue <string>("new_ctndetails");

                    if (product.Contains("new_parentcatalog") && product["new_parentcatalog"] != null)
                    {
                        res_product.ParentCatalog = product.FormattedValues["new_parentcatalog"];
                    }
                    if (product.Contains("new_subcatelog") && product["new_subcatelog"] != null)
                    {
                        res_product.SubCatalog = product.FormattedValues["new_subcatelog"];
                    }
                    if (product.Contains("new_additionalcatelog") && product["new_additionalcatelog"] != null)
                    {
                        res_product.AdditionalCatalog = product.FormattedValues["new_additionalcatelog"];
                    }
                    res_product.ProductDescription = product.GetAttributeValue <string>("description");
                    res_product.ProductCreatedon   = product.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");


                    products.Add(res_product);
                }
            }
            catch (Exception ex)
            {
                log.Info(ex + "--" + ex.Message + "--" + ex.ToString());
            }
            return(products);
        }
示例#12
0
        public AppCrmOrderResponse AppCreateOrder(AppCrmOrderRequest orderRequest)
        {
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();

            try
            {
                string email = orderRequest.email;
                log.Info("order-request:" + email);
                List <AppCrmOrderProduct> prodcutList = orderRequest.product;
                log.Info("order-request product:" + "----" + prodcutList.Count);

                string datetime_now = DateTime.Now.ToString("yyyyMMddHHmmss");

                Entity salesorder = new Entity("salesorder");


                Entity email_account = RetriveAccountByEmail(organizationProxy, email);
                salesorder["customerid"] = new EntityReference("account", email_account.Id);

                salesorder["pricelevelid"] = new EntityReference("pricelevel", new Guid(cu.pricelevelid_value));
                //salesorder["pricelevelid"] = new EntityReference("pricelevel", new Guid("780D3E7B-D6F9-E211-8ABD-984BE17C68D3"));

                //AN000001
                string new_orderno = this.readAppOrderNoFromXML();
                salesorder["name"]            = "AN" + new_orderno;
                salesorder["new_ordernumber"] = "PO" + new_orderno;
                Int32 exit_orderno = Int32.Parse(new_orderno);
                exit_orderno += 1;
                string new_exit_orderno = exit_orderno.ToString().PadLeft(6, '0');
                this.writeAppOrderNoToXML(new_exit_orderno);

                //From Mobile
                OptionSetValue orderfrom = new OptionSetValue(100000001);
                salesorder["new_orderfrom"] = orderfrom;

                //Payment
                OptionSetValue payment = new OptionSetValue(Int32.Parse(orderRequest.payment));
                salesorder["paymenttermscode"] = payment;

                //contact time
                salesorder["new_requestedringback"] = DateTime.Parse(orderRequest.contactTime);


                //OptionSetValue pv = new OptionSetValue(1);
                //salesorder["paymenttermscode"] = pv;
                //salesorder["billto_name"] = CreateCrmOrder.BilltoName;
                //salesorder["billto_line1"] = CreateCrmOrder.BilltoLine1;
                //salesorder["billto_line2"] = CreateCrmOrder.BilltoLine2;
                //salesorder["billto_city"] = CreateCrmOrder.BilltoCity;
                //salesorder["billto_stateorprovince"] = CreateCrmOrder.BilltoStateOrProvince;
                //salesorder["billto_country"] = CreateCrmOrder.BilltoCountry;
                //salesorder["billto_postalcode"] = CreateCrmOrder.BilltoPostalcode;
                //salesorder["shipto_line1"] = CreateCrmOrder.ShiptoLine1;
                //salesorder["shipto_line2"] = CreateCrmOrder.ShiptoLine2;
                //salesorder["shipto_city"] = CreateCrmOrder.ShiptoCity;
                //salesorder["shipto_stateorprovince"] = CreateCrmOrder.ShiptoStateOrProvince;
                //salesorder["shipto_country"] = CreateCrmOrder.ShiptoCountry;
                //salesorder["shipto_postalcode"] = CreateCrmOrder.ShiptoPostalcode;

                Guid orderId = organizationProxy.Create(salesorder);
                log.Info("创建salesorder成功:" + orderId.ToString());


                //2.Add prodcut to Order
                log.Info("ProductList数量:" + prodcutList.Count);
                #region Execute Multiple with Results
                // Create an ExecuteMultipleRequest object.
                ExecuteMultipleRequest requestWithResults = new ExecuteMultipleRequest()
                {
                    // Assign settings that define execution behavior: continue on error, return responses.
                    Settings = new ExecuteMultipleSettings()
                    {
                        ContinueOnError = false,
                        ReturnResponses = true
                    },
                    // Create an empty organization request collection.
                    Requests = new OrganizationRequestCollection()
                };

                // Create several (local, in memory) entities in a collection.
                EntityCollection input = GetCollectionOfEntitiesToCreate2(prodcutList, orderId, cu.uomid_value, organizationProxy);

                // Add a CreateRequest for each entity to the request collection.
                foreach (var entity in input.Entities)
                {
                    CreateRequest createRequest = new CreateRequest {
                        Target = entity
                    };
                    requestWithResults.Requests.Add(createRequest);
                }

                // Execute all the requests in the request collection using a single web method call.
                ExecuteMultipleResponse responseWithResults =
                    (ExecuteMultipleResponse)organizationProxy.Execute(requestWithResults);

                // Display the results returned in the responses.
                foreach (var responseItem in responseWithResults.Responses)
                {
                    // A valid response.
                    if (responseItem.Response != null)
                    {
                        OrganizationRequest  orq = requestWithResults.Requests[responseItem.RequestIndex];
                        OrganizationResponse ors = responseItem.Response;
                    }

                    // An error has occurred.
                    else if (responseItem.Fault != null)
                    {
                        OrganizationRequest orq = requestWithResults.Requests[responseItem.RequestIndex];
                        int idx = responseItem.RequestIndex;
                        OrganizationServiceFault fa = responseItem.Fault;
                    }
                }
                #endregion Execute Multiple with Results

                #region Execute Multiple with No Results

                ExecuteMultipleRequest requestWithNoResults = new ExecuteMultipleRequest()
                {
                    // Set the execution behavior to not continue after the first error is received
                    // and to not return responses.
                    Settings = new ExecuteMultipleSettings()
                    {
                        ContinueOnError = false,
                        ReturnResponses = false
                    },
                    Requests = new OrganizationRequestCollection()
                };

                // Update the entities that were previously created.
                EntityCollection update = GetCollectionOfEntitiesToUpdate2(prodcutList, organizationProxy);

                foreach (var entity in update.Entities)
                {
                    UpdateRequest updateRequest = new UpdateRequest {
                        Target = entity
                    };
                    requestWithNoResults.Requests.Add(updateRequest);
                }

                ExecuteMultipleResponse responseWithNoResults =
                    (ExecuteMultipleResponse)organizationProxy.Execute(requestWithNoResults);

                // There should be no responses unless there was an error. Only the first error
                // should be returned. That is the behavior defined in the settings.
                if (responseWithNoResults.Responses.Count > 0)
                {
                    foreach (var responseItem in responseWithNoResults.Responses)
                    {
                        if (responseItem.Fault != null)
                        {
                            OrganizationRequest orq = requestWithNoResults.Requests[responseItem.RequestIndex];
                            int ri = responseItem.RequestIndex;
                            OrganizationServiceFault fa = responseItem.Fault;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("All account records have been updated successfully.");
                }

                #endregion Execute Multiple with No Results


                //Add Free Shipping 4608DBBF-6E8F-E411-80DA-AC162DB4BC5C Flat Shipping Rate
                //string isFreeShipping = CreateCrmOrder.IsFreeShipping;
                //if(isFreeShipping.Equals("N"))//不免运费,加上运费的price list item
                //{
                //    Entity salesorderdetail = new Entity("salesorderdetail");
                //    //salesorderdetail["productid"] = new EntityReference("product", new Guid("8698AE03-F994-E411-80E2-AC162DB41AC0"));
                //    salesorderdetail["productid"] = new EntityReference("product", new Guid("85ACAB90-7248-E411-9212-D89D67639EF0"));
                //    salesorderdetail["quantity"] = Decimal.Parse("1");
                //    salesorderdetail["salesorderid"] = new EntityReference("salesorder", orderId);
                //    //salesorderdetail["uomid"] = new EntityReference("uom", new Guid("CCFF5EBE-5407-4214-BD04-60461B7161AA"));
                //    salesorderdetail["uomid"] = new EntityReference("uom", new Guid("3E055750-D6F9-E211-8ABD-984BE17C68D3"));
                //    //salesorderdetail["productid"] = prd.FreightAmount;
                //    //salesorderdetail["productid"] = prd.AmountDiscount;
                //    Guid salesorderdetailId = organizationProxy.Create(salesorderdetail);
                //    log.Info("创建运费成功:" + salesorderdetailId.ToString());
                //}

                //Entity isExistOrder = new Entity("salesorder");
                //ColumnSet order_attributes = new ColumnSet(new string[] { "myce_taxratingid" });

                //isExistOrder = organizationProxy.Retrieve(isExistOrder.LogicalName, orderId, order_attributes);

                //isExistOrder["myce_taxratingid"] = new EntityReference("myce_taxrating", new Guid("99596F96-054E-E411-9212-D89D67639EF0"));
                //organizationProxy.Update(isExistOrder);

                AppCrmOrderResponse rs = new AppCrmOrderResponse();
                rs.orderId = orderId.ToString();
                return(rs);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(null);
        }
示例#13
0
        public AppCrmProductCategory AppGetProdcutCategory()
        {
            //new_parentcatalog,new_subcatelog,new_featuredbrandscatalog,new_additionalcatelog
            log.Info("AppGetProdcutCategory:");
            AppCrmProductCategory                     category              = new AppCrmProductCategory();
            List <AppCrmProductParentCatalog>         parentCatalogs        = new List <AppCrmProductParentCatalog>();
            List <AppCrmProductSubCatalog>            subCatalogs           = new List <AppCrmProductSubCatalog>();
            List <AppCrmProductBrandCatalog>          brandCatalogs         = new List <AppCrmProductBrandCatalog>();
            List <AppCrmProductFeaturedBrandsCatalog> featuredBrandsCatalog = new List <AppCrmProductFeaturedBrandsCatalog>();

            try
            {
                CrmUtil cu = new CrmUtil();
                OrganizationServiceProxy organizationProxy = cu.getCrmService();

                OptionMetadataCollection optionSetMetaData = getOptionSetValueAndName("product", "new_parentcatalog", organizationProxy);
                foreach (OptionMetadata oc in optionSetMetaData)
                {
                    AppCrmProductParentCatalog parentCatalog = new AppCrmProductParentCatalog();
                    parentCatalog.ParentCatalogName  = oc.Label.UserLocalizedLabel.Label;
                    parentCatalog.ParentCatalogValue = oc.Value.ToString();

                    parentCatalogs.Add(parentCatalog);
                }
                OptionMetadataCollection optionSetMetaData1 = getOptionSetValueAndName("product", "new_subcatelog", organizationProxy);
                foreach (OptionMetadata oc in optionSetMetaData1)
                {
                    AppCrmProductSubCatalog subCatalog = new AppCrmProductSubCatalog();
                    subCatalog.SubCatalogName  = oc.Label.UserLocalizedLabel.Label;
                    subCatalog.SubCatalogValue = oc.Value.ToString();

                    subCatalogs.Add(subCatalog);
                }
                OptionMetadataCollection optionSetMetaData3 = getOptionSetValueAndName("product", "new_featuredbrandscatalog", organizationProxy);
                foreach (OptionMetadata oc in optionSetMetaData3)
                {
                    AppCrmProductFeaturedBrandsCatalog featuredCatalog = new AppCrmProductFeaturedBrandsCatalog();
                    featuredCatalog.FeaturedBrandsCatalogName  = oc.Label.UserLocalizedLabel.Label;
                    featuredCatalog.FeaturedBrandsCatalogValue = oc.Value.ToString();

                    featuredBrandsCatalog.Add(featuredCatalog);
                }
                OptionMetadataCollection optionSetMetaData2 = getOptionSetValueAndName("product", "new_additionalcatelog", organizationProxy);
                foreach (OptionMetadata oc in optionSetMetaData2)
                {
                    AppCrmProductBrandCatalog brandCatalog = new AppCrmProductBrandCatalog();
                    brandCatalog.BrandCatalogName  = oc.Label.UserLocalizedLabel.Label;
                    brandCatalog.BrandCatalogValue = oc.Value.ToString();

                    brandCatalogs.Add(brandCatalog);
                }


                category.ParentCatalog         = parentCatalogs;
                category.SubCatalog            = subCatalogs;
                category.BrandCatalog          = brandCatalogs;
                category.FeaturedBrandsCatalog = featuredBrandsCatalog;
            }
            catch (Exception ex)
            {
                log.Info(ex + "--" + ex.Message + "--" + ex.ToString());
            }
            return(category);
        }
示例#14
0
        public List <SupplierCrmProduct> AppGetProductBySupplier(String email)
        {
            log.Info("AppGetProductBySupplier:" + email);
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy  organizationProxy = cu.getCrmService();
            List <SupplierCrmProduct> res_products      = new List <SupplierCrmProduct>();

            try
            {
                QueryExpression qe = new QueryExpression();
                qe.EntityName = "product";
                qe.ColumnSet  = new ColumnSet(true);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "emailaddress1";
                condition1.Operator      = ConditionOperator.Equal;
                condition1.Values.Add(email);

                FilterExpression filter1 = new FilterExpression();
                filter1.Conditions.Add(condition1);

                //qe.Criteria.AddFilter(filter1);

                qe.LinkEntities.Add(new LinkEntity("product", "account", "new_suppliera1", "accountid", JoinOperator.Inner));
                qe.LinkEntities[0].Columns.AddColumns("accountid");
                qe.LinkEntities[0].EntityAlias = "supplier";
                qe.LinkEntities[0].LinkCriteria.AddFilter(filter1);



                //  Query passed to service proxy.
                EntityCollection retrieved = organizationProxy.RetrieveMultiple(qe);
                foreach (Entity product in retrieved.Entities)
                {
                    SupplierCrmProduct res_product = new SupplierCrmProduct();
                    res_product.ProductId   = product.GetAttributeValue <Guid>("productid").ToString();
                    res_product.ProductName = product.GetAttributeValue <string>("productnumber");
                    res_product.ProductSku  = product.GetAttributeValue <string>("name");
                    res_product.Brand       = product.GetAttributeValue <string>("suppliername");
                    res_product.Quantity    = product.GetAttributeValue <decimal>("quantityonhand").ToString("#.##");


                    res_product.CommissionRate = product.GetAttributeValue <decimal>("new_commisionrate").ToString("#.##");


                    if (product.Contains("price") && product["price"] != null)
                    {
                        res_product.TradePrice = product.GetAttributeValue <Money>("price").Value.ToString("#.##");
                    }
                    if (product.Contains("new_pdhprice") && product["new_pdhprice"] != null)
                    {
                        res_product.PdhPrice = product.GetAttributeValue <Money>("new_pdhprice").Value.ToString("#.##");
                    }

                    if (product.Contains("new_rrp") && product["new_rrp"] != null)
                    {
                        res_product.RRP = product.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                    }

                    //res_product.ProductColor = product.GetAttributeValue<string>("new_colour");
                    //res_product.ProductBarcode = product.GetAttributeValue<string>("new_productbarcode");
                    res_product.ProductDimensions    = product.GetAttributeValue <string>("new_size");
                    res_product.ProductWeight        = product.GetAttributeValue <string>("new_productweight");
                    res_product.IdenticalUnitPerCase = product.GetAttributeValue <string>("new_casequantity");
                    res_product.CaseBarcode          = product.GetAttributeValue <string>("new_casebarcode");
                    res_product.CaseDimensions       = product.GetAttributeValue <string>("new_casedimensions");
                    res_product.CaseWeight           = product.GetAttributeValue <string>("new_caseweight");
                    res_product.CTNDetails           = product.GetAttributeValue <string>("new_ctndetails");

                    if (product.Contains("new_parentcatalog") && product["new_parentcatalog"] != null)
                    {
                        res_product.ParentCatalog = product.FormattedValues["new_parentcatalog"];
                    }
                    if (product.Contains("new_subcatelog") && product["new_subcatelog"] != null)
                    {
                        res_product.SubCatalog = product.FormattedValues["new_subcatelog"];
                    }
                    if (product.Contains("new_additionalcatelog") && product["new_additionalcatelog"] != null)
                    {
                        res_product.AdditionalCatalog = product.FormattedValues["new_additionalcatelog"];
                    }
                    res_product.ProductDescription = product.GetAttributeValue <string>("description");
                    res_product.ProductCreatedon   = product.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");

                    res_products.Add(res_product);
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(res_products);
        }
示例#15
0
        public List <AppCrmProduct> AppGetAllProduct()
        {
            log.Info("GetAllProduct:");
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();
            List <AppCrmProduct>     products          = new List <AppCrmProduct>();

            try
            {
                //Update Account TradeRegistration
                QueryExpression qe = new QueryExpression();
                qe.EntityName = "product";
                qe.ColumnSet  = new ColumnSet(true);

                //qe.LinkEntities.Add(new LinkEntity("account", "contact", "primarycontactid", "contactid", JoinOperator.Inner));
                //qe.LinkEntities[0].Columns.AddColumns("firstname", "lastname");
                //qe.LinkEntities[0].EntityAlias = "primarycontact";

                EntityCollection ec = organizationProxy.RetrieveMultiple(qe);

                foreach (Entity product in ec.Entities)
                {
                    AppCrmProduct res_product = new AppCrmProduct();
                    res_product.ProductId   = product.GetAttributeValue <Guid>("productid").ToString();
                    res_product.ProductName = product.GetAttributeValue <string>("productnumber");
                    res_product.ProductSku  = product.GetAttributeValue <string>("name");
                    res_product.Brand       = product.GetAttributeValue <string>("suppliername");
                    res_product.Quantity    = product.GetAttributeValue <decimal>("quantityonhand").ToString("#.##");
                    res_product.PictureList = product.GetAttributeValue <string>("new_picturelist");

                    if (product.Contains("price") && product["price"] != null)
                    {
                        res_product.ListPrice = product.GetAttributeValue <Money>("price").Value.ToString("#.##");
                    }

                    if (product.Contains("new_rrp") && product["new_rrp"] != null)
                    {
                        res_product.RRP = product.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                    }

                    res_product.ProductColor         = product.GetAttributeValue <string>("new_colour");
                    res_product.ProductBarcode       = product.GetAttributeValue <string>("new_productbarcode");
                    res_product.ProductDimensions    = product.GetAttributeValue <string>("new_size");
                    res_product.ProductWeight        = product.GetAttributeValue <string>("new_productweight");
                    res_product.IdenticalUnitPerCase = product.GetAttributeValue <string>("new_casequantity");
                    res_product.CaseBarcode          = product.GetAttributeValue <string>("new_casebarcode");
                    res_product.CaseDimensions       = product.GetAttributeValue <string>("new_casedimensions");
                    res_product.CaseWeight           = product.GetAttributeValue <string>("new_caseweight");
                    res_product.CTNDetails           = product.GetAttributeValue <string>("new_ctndetails");

                    if (product.Contains("new_parentcatalog") && product["new_parentcatalog"] != null)
                    {
                        res_product.ParentCatalog = product.FormattedValues["new_parentcatalog"];
                    }
                    if (product.Contains("new_subcatelog") && product["new_subcatelog"] != null)
                    {
                        res_product.SubCatalog = product.FormattedValues["new_subcatelog"];
                    }
                    if (product.Contains("new_additionalcatelog") && product["new_additionalcatelog"] != null)
                    {
                        res_product.AdditionalCatalog = product.FormattedValues["new_additionalcatelog"];
                    }
                    res_product.ProductDescription = product.GetAttributeValue <string>("description");
                    res_product.ProductCreatedon   = product.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");


                    products.Add(res_product);
                }
            }
            catch (Exception ex)
            {
                log.Info(ex + "--" + ex.Message + "--" + ex.ToString());
            }
            return(products);
        }
示例#16
0
        public AppCrmProduct AppGetProductById(String productId)
        {
            log.Info("AppGetProductById:" + productId);
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy organizationProxy = cu.getCrmService();
            AppCrmProduct            res_product       = new AppCrmProduct();

            try
            {
                //Update Account TradeRegistration
                Entity    product    = new Entity("product");
                ColumnSet attributes = new ColumnSet(true);

                product = organizationProxy.Retrieve(product.LogicalName, new Guid(productId), attributes);

                res_product.ProductName = product.GetAttributeValue <string>("productnumber");
                res_product.ProductSku  = product.GetAttributeValue <string>("name");
                res_product.Brand       = product.GetAttributeValue <string>("suppliername");
                res_product.Quantity    = product.GetAttributeValue <decimal>("quantityonhand").ToString("#.##");
                res_product.PictureList = product.GetAttributeValue <string>("new_picturelist");

                if (product.Contains("price") && product["price"] != null)
                {
                    res_product.ListPrice = product.GetAttributeValue <Money>("price").Value.ToString("#.##");
                }

                if (product.Contains("new_rrp") && product["new_rrp"] != null)
                {
                    res_product.RRP = product.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                }

                res_product.ProductColor         = product.GetAttributeValue <string>("new_colour");
                res_product.ProductBarcode       = product.GetAttributeValue <string>("new_productbarcode");
                res_product.ProductDimensions    = product.GetAttributeValue <string>("new_size");
                res_product.ProductWeight        = product.GetAttributeValue <string>("new_productweight");
                res_product.IdenticalUnitPerCase = product.GetAttributeValue <string>("new_casequantity");
                res_product.CaseBarcode          = product.GetAttributeValue <string>("new_casebarcode");
                res_product.CaseDimensions       = product.GetAttributeValue <string>("new_casedimensions");
                res_product.CaseWeight           = product.GetAttributeValue <string>("new_caseweight");
                res_product.CTNDetails           = product.GetAttributeValue <string>("new_ctndetails");

                if (product.Contains("new_parentcatalog") && product["new_parentcatalog"] != null)
                {
                    res_product.ParentCatalog = product.FormattedValues["new_parentcatalog"];
                }
                if (product.Contains("new_subcatelog") && product["new_subcatelog"] != null)
                {
                    res_product.SubCatalog = product.FormattedValues["new_subcatelog"];
                }
                if (product.Contains("new_additionalcatelog") && product["new_additionalcatelog"] != null)
                {
                    res_product.AdditionalCatalog = product.FormattedValues["new_additionalcatelog"];
                }
                res_product.ProductDescription = product.GetAttributeValue <string>("description");
                res_product.ProductCreatedon   = product.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");


                //EntityReference subject = (EntityReference)product["subjectid"];
                //res_product.ProductCategory = subject.Name;
                //res_product.ProductPrice = ((Money)product["new_rrp"]).Value.ToString();
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(res_product);
        }
示例#17
0
        public List <AppCrmOrderHistoryResponse> AppGetOrderHistory(AppCrmOrderHistoryRequest orderHistoryRequest)
        {
            log.Info("AppGetOrderHistory:" + orderHistoryRequest.email);
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy          organizationProxy = cu.getCrmService();
            List <AppCrmOrderHistoryResponse> response_s        = new List <AppCrmOrderHistoryResponse>();

            try
            {
                //Entity account = RetriveAccountByEmail(organizationProxy, orderHistoryRequest.email);

                QueryExpression qe = new QueryExpression();
                qe.EntityName = "salesorder";
                qe.ColumnSet  = new ColumnSet(true);


                ConditionExpression condition11 = new ConditionExpression();
                condition11.AttributeName = "emailaddress1";
                condition11.Operator      = ConditionOperator.Equal;
                condition11.Values.Add(orderHistoryRequest.email);

                FilterExpression filter11 = new FilterExpression();
                filter11.Conditions.Add(condition11);

                string beginDate = orderHistoryRequest.beginDate;
                string endDate   = orderHistoryRequest.endDate;
                if ((beginDate != null && !beginDate.Equals("")) && (endDate != null && !endDate.Equals("")))
                {
                    ConditionExpression condition12 = new ConditionExpression("createdon", ConditionOperator.Between, beginDate, endDate);

                    FilterExpression filter12 = new FilterExpression();
                    filter12.Conditions.Add(condition12);

                    qe.Criteria.AddFilter(filter12);
                }

                //ConditionExpression condition12 = new ConditionExpression();
                //condition12.AttributeName = "createdon";
                //condition12.Operator = ConditionOperator.Between;
                //condition12.Values.Add(new string[] { orderHistoryRequest.beginDate, orderHistoryRequest.endDate });



                qe.LinkEntities.Add(new LinkEntity("salesorder", "account", "customerid", "accountid", JoinOperator.Inner));
                qe.LinkEntities[0].Columns.AddColumns("accountid");
                qe.LinkEntities[0].EntityAlias = "customer";
                qe.LinkEntities[0].LinkCriteria.AddFilter(filter11);



                //  Query passed to service proxy.
                EntityCollection retrieved = organizationProxy.RetrieveMultiple(qe);
                foreach (Entity salseorder in retrieved.Entities)
                {
                    AppCrmOrderHistoryResponse res = new AppCrmOrderHistoryResponse();
                    res.orderName = salseorder.GetAttributeValue <string>("name");
                    if (salseorder.Contains("totalamount") && salseorder["totalamount"] != null)
                    {
                        decimal totalRRP = 0;
                        res.totalAmount = salseorder.GetAttributeValue <Money>("totalamount").Value.ToString("0.00");

                        res.createdOn = salseorder.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");

                        List <AppCrmOrderHistoryProduct> res_products = new List <AppCrmOrderHistoryProduct>();
                        Guid orderId = salseorder.GetAttributeValue <Guid>("salesorderid");

                        QueryExpression qe2 = new QueryExpression();
                        qe2.EntityName = "salesorderdetail";
                        qe2.ColumnSet  = new ColumnSet(true);
                        //qe2.ColumnSet.Columns.Add("quantity");
                        //qe2.ColumnSet.Columns.Add("priceperunit");
                        //qe2.ColumnSet.Columns.Add("baseamount");
                        //qe2.ColumnSet.Columns.Add("extendedamount");
                        //qe2.ColumnSet.Columns.Add("productid");

                        ConditionExpression condition2 = new ConditionExpression();
                        condition2.AttributeName = "salesorderid";
                        condition2.Operator      = ConditionOperator.Equal;
                        condition2.Values.Add(orderId);

                        FilterExpression filter2 = new FilterExpression();
                        filter2.Conditions.Add(condition2);

                        qe2.Criteria.AddFilter(filter2);


                        //  Query passed to service proxy.
                        EntityCollection retrieved2 = organizationProxy.RetrieveMultiple(qe2);
                        foreach (Entity entity in retrieved2.Entities)
                        {
                            bool isProduct = true;

                            //Product Status is Service Rate 10
                            //if (entity.GetAttributeValue<AliasedValue>("orderproduct.producttypecode") != null)
                            //{
                            //    OptionSetValue op = (OptionSetValue)(entity.GetAttributeValue<AliasedValue>("orderproduct.producttypecode").Value);

                            //    int ov = op.Value;
                            //    if (ov.Equals(10))
                            //    {
                            //        isProduct = false;
                            //    }
                            //}

                            if (isProduct)
                            {
                                AppCrmOrderHistoryProduct product = new AppCrmOrderHistoryProduct();

                                if (entity.Contains("productid") && entity["productid"] != null)
                                {
                                    EntityReference pro = (EntityReference)entity["productid"];
                                    product.ProductId  = pro.Id.ToString();
                                    product.ProductSku = pro.Name;

                                    Entity    product_entity = new Entity("product");
                                    ColumnSet attributes     = new ColumnSet(new string[] { "price", "new_rrp" });

                                    product_entity = organizationProxy.Retrieve(product_entity.LogicalName, pro.Id, attributes);
                                    if (product_entity.Contains("price") && product_entity["price"] != null)
                                    {
                                        product.PriceList = product_entity.GetAttributeValue <Money>("price").Value.ToString("#.##");
                                    }
                                    if (product_entity.Contains("new_rrp") && product_entity["new_rrp"] != null)
                                    {
                                        product.RRP = product_entity.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                                        totalRRP   += (product_entity.GetAttributeValue <Money>("new_rrp").Value) * (entity.GetAttributeValue <decimal>("quantity"));
                                    }
                                }
                                product.Quantity = entity.GetAttributeValue <decimal>("quantity").ToString("#");

                                res_products.Add(product);
                            }
                        }
                        res.totalRRP = totalRRP.ToString("0.00");
                        res.product  = res_products;
                    }
                    response_s.Add(res);
                }
                return(response_s);
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }

            return(response_s);
        }
示例#18
0
        public List <AnalysisCrmProduct> AnalysisGetAllProduct()
        {
            log.Info("AnalysisGetAllProduct:");
            CrmUtil cu = new CrmUtil();
            OrganizationServiceProxy  organizationProxy = cu.getCrmService();
            List <AnalysisCrmProduct> products          = new List <AnalysisCrmProduct>();

            try
            {
                //Update Account TradeRegistration
                QueryExpression qe = new QueryExpression();
                qe.EntityName = "product";
                qe.ColumnSet  = new ColumnSet(true);
                //qe.ColumnSet.Columns.Add("name");
                //qe.ColumnSet.Columns.Add("quantityonhand");

                //qe.LinkEntities.Add(new LinkEntity("account", "contact", "primarycontactid", "contactid", JoinOperator.Inner));
                //qe.LinkEntities[0].Columns.AddColumns("firstname", "lastname");
                //qe.LinkEntities[0].EntityAlias = "primarycontact";

                EntityCollection ec = organizationProxy.RetrieveMultiple(qe);

                foreach (Entity product in ec.Entities)
                {
                    AnalysisCrmProduct res_product = new AnalysisCrmProduct();

                    res_product.ProductId   = product.GetAttributeValue <Guid>("productid").ToString();
                    res_product.ProductName = product.GetAttributeValue <string>("productnumber");
                    res_product.ProductSku  = product.GetAttributeValue <string>("name");

                    if (product.Contains("producttypecode") && product["producttypecode"] != null)
                    {
                        res_product.ProductStatus = product.FormattedValues["producttypecode"];
                    }
                    if (product.Contains("defaultuomid") && product["defaultuomid"] != null)
                    {
                        EntityReference unit = (EntityReference)product["defaultuomid"];
                        res_product.Unit = unit.Name;
                    }

                    res_product.DecimalsSupported = product.GetAttributeValue <int>("quantitydecimal").ToString();

                    if (product.Contains("pricelevelid") && product["pricelevelid"] != null)
                    {
                        EntityReference pricelist = (EntityReference)product["pricelevelid"];
                        res_product.PriceList = pricelist.Name;
                    }
                    if (product.Contains("new_suppliera1") && product["new_suppliera1"] != null)
                    {
                        EntityReference supplier_a = (EntityReference)product["new_suppliera1"];
                        res_product.SupplierA = supplier_a.Name;
                    }
                    res_product.Brand = product.GetAttributeValue <string>("suppliername");

                    res_product.Quantity = product.GetAttributeValue <decimal>("quantityonhand").ToString("#.##");

                    res_product.BrandedPackage   = product.GetAttributeValue <bool>("new_brandedpackage").ToString();
                    res_product.PetDreamHouseURL = product.GetAttributeValue <string>("producturl");

                    if (product.Contains("price") && product["price"] != null)
                    {
                        res_product.ListPrice = product.GetAttributeValue <Money>("price").Value.ToString("#.##");
                    }

                    if (product.Contains("new_rrp") && product["new_rrp"] != null)
                    {
                        res_product.RRP = product.GetAttributeValue <Money>("new_rrp").Value.ToString("#.##");
                    }

                    res_product.ProductColor         = product.GetAttributeValue <string>("new_colour");
                    res_product.ProductBarcode       = product.GetAttributeValue <string>("new_productbarcode");
                    res_product.ProductDimensions    = product.GetAttributeValue <string>("new_size");
                    res_product.ProductWeight        = product.GetAttributeValue <string>("new_productweight");
                    res_product.IdenticalUnitPerCase = product.GetAttributeValue <string>("new_casequantity");
                    res_product.CaseBarcode          = product.GetAttributeValue <string>("new_casebarcode");
                    res_product.CaseDimensions       = product.GetAttributeValue <string>("new_casedimensions");
                    res_product.CaseWeight           = product.GetAttributeValue <string>("new_caseweight");
                    res_product.CTNDetails           = product.GetAttributeValue <string>("new_ctndetails");

                    if (product.Contains("new_parentcatalog") && product["new_parentcatalog"] != null)
                    {
                        res_product.ParentCatalog = product.FormattedValues["new_parentcatalog"];
                    }
                    if (product.Contains("new_subcatelog") && product["new_subcatelog"] != null)
                    {
                        res_product.SubCatalog = product.FormattedValues["new_subcatelog"];
                    }
                    if (product.Contains("new_additionalcatelog") && product["new_additionalcatelog"] != null)
                    {
                        res_product.AdditionalCatalog = product.FormattedValues["new_additionalcatelog"];
                    }

                    res_product.ProductDescription = product.GetAttributeValue <string>("description");
                    res_product.UnitBarCode        = product.GetAttributeValue <string>("new_barcode");
                    res_product.UnitWeight_KG      = product.GetAttributeValue <decimal>("new_grossunitweight").ToString("#.##");
                    res_product.UnitDepthLength_CM = product.GetAttributeValue <decimal>("new_unitdepthcm").ToString("#.##");
                    res_product.UnitWidthGirth_CM  = product.GetAttributeValue <decimal>("new_unitwidthcm").ToString("#.##");
                    res_product.UnitHeightNeck_CM  = product.GetAttributeValue <decimal>("new_unitheight").ToString("#.##");
                    res_product.CartonBarcode      = product.GetAttributeValue <string>("new_mastercartonbarcode");
                    res_product.UnitsPerCarton     = product.GetAttributeValue <string>("new_packspermasterbox");
                    res_product.CartonWeight_KG    = product.GetAttributeValue <decimal>("new_mastercartonweightkg").ToString("#.##");
                    res_product.CartonDepth_CM     = product.GetAttributeValue <decimal>("new_mastercartondepthcm").ToString("#.##");
                    res_product.CartonWidth_CM     = product.GetAttributeValue <decimal>("new_mastercartonwidthcm").ToString("#.##");
                    res_product.CartonHeight_CM    = product.GetAttributeValue <decimal>("new_mastercartonheightcm").ToString("#.##");
                    res_product.CreatedOn          = product.GetAttributeValue <DateTime>("createdon").ToLocalTime().ToString("yyyyMMddHHmmss");

                    products.Add(res_product);
                    //Console.WriteLine("account name:" + act["name"]);
                    //Console.WriteLine("primary contact first name:" + act["primarycontact.firstname"]);
                    //Console.WriteLine("primary contact last name:" + act["primarycontact.lastname"]);
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message + "--" + ex.ToString());
            }
            return(products);
        }