Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 30.65 KB | None | 0 0
  1.         private void MemberRetrieve(IOrganizationService service, EntityCollection results)
  2.        
  3.         {
  4.             canPlaceBBWInternetOrder = true;
  5.             canPlaceComputerOrder = true;
  6.             errorMessage = "";
  7.             try
  8.             {
  9.                 /*OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);
  10.                 EntityCollection results = (EntityCollection)response["EntityCollection"];*/
  11.  
  12.                 StringBuilder sb = new StringBuilder();
  13.                 if (results.Entities.Count != 0)
  14.                 {
  15.                     address1 = results.Entities[0].GetAttributeValue<string>("address1_line1");
  16.                     address2 = results.Entities[0].GetAttributeValue<string>("address1_line2");
  17.                     address3 = results.Entities[0].GetAttributeValue<string>("address1_line3");
  18.                     telephone1 = results.Entities[0].GetAttributeValue<string>("telephone1");
  19.                     this.Dispatcher.BeginInvoke(delegate()
  20.                     {
  21.                         //do something here.                      
  22.                         MemberID = TextBoxMembershipNumber.Text = results.Entities[0].GetAttributeValue<string>("new_memberid");
  23.                        
  24.                         //textBlockStudentName.Text = LookupContact.Items.First().Name;*/
  25.  
  26.                         if (
  27.                             (results.Entities[0].GetAttributeValue<bool>("new_istb") != null && results.Entities[0].GetAttributeValue<bool>("new_istb") == true)
  28.                             ||
  29.                             (results.Entities[0].GetAttributeValue<object>("account.new_istb") != null && (bool)((AliasedValue)results.Entities[0].GetAttributeValue<object>("account.new_istb")).Value == true))
  30.                         {
  31.                             IsTB = true;
  32.                         }
  33.                         else
  34.                         {
  35.                             IsTB = false;
  36.                         }
  37.  
  38.                         // Check Role Type (Computer)
  39.                         if (results.Entities[0].GetAttributeValue<OptionSetValue>("new_roletype") != null)
  40.                         {
  41.                             OptionSetValue roleType = results.Entities[0].GetAttributeValue<OptionSetValue>("new_roletype");
  42.  
  43.                             if (roleType.Value == 100000000 || roleType.Value == 100000001 || roleType.Value == 100000002)
  44.                             {
  45.                                 if (!errorMessage.Contains("- Father / Mother / Guardian cannot order computer items."))
  46.                                     errorMessage += "- Father / Mother / Guardian cannot order computer items.\n";
  47.                                 canPlaceComputerOrder = false;
  48.                             }
  49.                         }
  50.                         // Check Role Type (Computer) Finish
  51.  
  52.                         // Check Order within 3 years (Computer) & 1 year (Internet)
  53.                         foreach (Entity tmpEntity in results.Entities)
  54.                         {
  55.                             // Computer
  56.                             DateTime orderDate = new DateTime();
  57.                             if (tmpEntity.GetAttributeValue<AliasedValue>("orderitemcomputer.new_purchasedate") != null &&
  58.                                 tmpEntity.GetAttributeValue<AliasedValue>("product.productid") != null)
  59.                             {
  60.                                 orderDate = ((DateTime)(tmpEntity.GetAttributeValue<AliasedValue>("orderitemcomputer.new_purchasedate").Value)).ToLocalTime();
  61.                                 /* modified by Justina
  62.                                 DateTime threeYearsAgo = DateTime.Today.AddYears(-3); */
  63.                                 DateTime threeYearsAgo = DateTime.Now.ToUniversalTime().AddYears(-3);
  64.                                 if (orderDate > threeYearsAgo)
  65.                                 {
  66.                                     if (!errorMessage.Contains("- Cannot order computer items within 3 years."))
  67.                                        errorMessage += "- Cannot order computer items within 3 years.\n";
  68.                                     canPlaceComputerOrder = false;
  69.                                   //break;
  70.                                 }
  71.                             }
  72.  
  73.                             // Internet Service
  74.                             orderDate = new DateTime();
  75.                             if (tmpEntity.GetAttributeValue<AliasedValue>("allinternetorders.new_orderdate") != null
  76.                                 && tmpEntity.GetAttributeValue<AliasedValue>("allinternetorders.new_servicetype") != null
  77.                                 && tmpEntity.GetAttributeValue<AliasedValue>("allinternetorders_product.productid") != null)
  78.                             {
  79.                                 OptionSetValue serviceTypeOption = (OptionSetValue)(tmpEntity.GetAttributeValue<AliasedValue>("allinternetorders.new_servicetype").Value);
  80.                                 orderDate = ((DateTime)(tmpEntity.GetAttributeValue<AliasedValue>("allinternetorders.new_orderdate").Value)).ToLocalTime();
  81.                                 /* modified by justina
  82.                                 DateTime oneYearAgo = DateTime.Today.AddYears(-1);
  83.                                 DateTime threeYearsAgo = DateTime.Today.AddYears(-3); */
  84.                                 DateTime oneYearAgo = DateTime.Now.ToUniversalTime().AddYears(-1);
  85.                                 DateTime threeYearsAgo = DateTime.Now.ToUniversalTime().AddYears(-3);
  86.  
  87.                                 if (orderDate > threeYearsAgo)
  88.                                 {
  89.                                     if (!errorMessage.Contains("- Cannot order BBW/BBM items or other family members placed BBW/BBM items within 3 years."))
  90.                                         errorMessage += "- Cannot order BBW/BBM items or other family members placed BBW/BBM items within 3 years.\n";
  91.  
  92.                                     canPlaceBBWInternetOrder = false;
  93.                                     canPlaceBBMInternetOrder = false;
  94.                                 }
  95.                                 /*if (orderDate > oneYearAgo && serviceTypeOption.Value == 6)
  96.                                 {
  97.                                     if (!errorMessage.Contains("- Cannot order BBW internet items or other family members placed BBW internet items within 1 year"))
  98.                                         errorMessage += "- Cannot order BBW internet items or other family members placed BBW internet items within 1 year\n";
  99.                                    
  100.                                     canPlaceBBWInternetOrder = false;
  101.                                    
  102.                                     //break;
  103.                                 }
  104.                                 else if (serviceTypeOption.Value == 100000000)
  105.                                 {
  106.                                     PlacedBBMInternetOrder = true;
  107.                                 }*/
  108.                             }
  109.                         }
  110.                         // Check Order within 3 years (Computer) & 1 year (Internet) Finish
  111.  
  112.                         // Check isTB & Age<18 & Has Main Contact (Computer)
  113.                         if (IsTB && results.Entities[0].GetAttributeValue<Object>("new_age") != null && results.Entities[0].GetAttributeValue<AliasedValue>("account.primarycontactid") == null)
  114.                         {
  115.                             Decimal age = results.Entities[0].GetAttributeValue<Decimal>("new_age");
  116.                             if (age < 18)
  117.                             {
  118.                                 if (!errorMessage.Contains("- TB member with Age < 18 without Main Contact cannot order computer items."))
  119.                                     errorMessage += "- TB member with Age < 18 without Main Contact cannot order computer items.\n";
  120.                                 canPlaceComputerOrder = false;
  121.                             }
  122.                         }
  123.                         // Check isTB & Age<18 & Has Main Contact (Computer) Finish
  124.  
  125.                         // Check Age<18 & Has Main Contact (Internet)
  126.                         if (results.Entities[0].GetAttributeValue<Object>("new_age") != null && results.Entities[0].GetAttributeValue<AliasedValue>("account.primarycontactid") == null)
  127.                         {
  128.                             Decimal age = results.Entities[0].GetAttributeValue<Decimal>("new_age");
  129.                             if (age < 18)
  130.                             {
  131.                                 if (!errorMessage.Contains("- TB member with Age < 18 without Main Contact cannot order internet services."))
  132.                                     errorMessage += "- TB member with Age < 18 without Main Contact cannot order internet services.\n";
  133.                                 canPlaceBBWInternetOrder = false;
  134.                                 canPlaceBBMInternetOrder = false;
  135.                             }
  136.                         }
  137.                         // Check Age<18 & Has Main Contact (Internet) Finish
  138.  
  139.  
  140.                         if (errorMessage != null && errorMessage != "")
  141.                         {
  142.                             //this.Dispatcher.BeginInvoke(() =>
  143.                             //{
  144.                                 MessageBox.Show(errorMessage);
  145.                                 return;
  146.                             //});
  147.                         }
  148.  
  149.                         ProductList();                                                
  150.                     });
  151.                 }
  152.             }
  153.             catch (Exception ex)
  154.             {
  155.                 this.ReportError(ex);
  156.             }
  157.         }
  158.  
  159.         private void LookupContact_LookupControlOnUserChangeValue(object sender, RoutedEventArgs e)
  160.         {
  161.             try
  162.             {
  163.                 QueryExpression query = new QueryExpression()
  164.                 {
  165.                     EntityName = "contact",
  166.                     ColumnSet = new ColumnSet()
  167.                     {
  168.                         Columns = new System.Collections.ObjectModel.ObservableCollection<string>(
  169.                             new string[] {
  170.                                 "new_memberid", "new_istb", "address1_line1", "address1_line2", "address1_line3",
  171.                                 "new_roletype", "new_age", "telephone1", "telephone2"
  172.                             }
  173.                         )
  174.                     },
  175.                     Criteria = new FilterExpression()
  176.                     {
  177.                         Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>
  178.                         (new ConditionExpression[] {
  179.                             new ConditionExpression(){
  180.                                 AttributeName = "contactid",
  181.                                 Operator = ConditionOperator.Equal,
  182.                                 Values = new System.Collections.ObjectModel.ObservableCollection<object>(
  183.                                     new object[] {
  184.                                         LookupContact.Items.First().Id
  185.                                     }
  186.                                 )
  187.                             }
  188.                         })
  189.                     },
  190.                     Orders = new System.Collections.ObjectModel.ObservableCollection<OrderExpression>(new OrderExpression[]
  191.                     {
  192.                         new OrderExpression() { AttributeName = "new_memberid", OrderType = OrderType.Ascending }
  193.                     })
  194.                 };
  195.  
  196.                 //query.PageInfo = new PagingInfo { Count = MaxRecordsToReturn, PageNumber = 1, PagingCookie = null };
  197.                 LinkEntity le = new LinkEntity();
  198.                 le.LinkFromEntityName = "contact";
  199.                 le.LinkFromAttributeName = "parentcustomerid";
  200.                 le.LinkToEntityName = "account";
  201.                 le.LinkToAttributeName = "accountid";
  202.                 le.JoinOperator = JoinOperator.LeftOuter;
  203.                 le.EntityAlias = "account";
  204.  
  205.                 le.Columns = new ColumnSet()
  206.                 {
  207.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  208.                         "accountid", "new_istb", "primarycontactid"
  209.                     })
  210.                 };
  211.  
  212.                 // Get all contacts from same account and the corresponding orderiteminternetservice records
  213.                 LinkEntity le1a = new LinkEntity();
  214.                 le1a.LinkFromEntityName = "account";
  215.                 le1a.LinkFromAttributeName = "accountid";
  216.                 le1a.LinkToEntityName = "contact";
  217.                 le1a.LinkToAttributeName = "parentcustomerid";
  218.                 le1a.JoinOperator = JoinOperator.LeftOuter;
  219.                 le1a.EntityAlias = "allcontacts";
  220.  
  221.                 le1a.Columns = new ColumnSet()
  222.                 {
  223.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  224.                         "parentcustomerid"
  225.                     })
  226.                 };
  227.  
  228.                 LinkEntity le1b = new LinkEntity();
  229.                 le1b.LinkFromEntityName = "contact";
  230.                 le1b.LinkFromAttributeName = "contactid";
  231.                 le1b.LinkToEntityName = "salesorder";
  232.                 le1b.LinkToAttributeName = "customerid";
  233.                 le1b.JoinOperator = JoinOperator.LeftOuter;
  234.                 le1b.EntityAlias = "allorders";
  235.  
  236.                 le1b.Columns = new ColumnSet()
  237.                 {
  238.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  239.                         "customerid", "createdon"
  240.                     })
  241.                 };
  242.                 le1b.LinkCriteria = new FilterExpression()
  243.                 {
  244.                     Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>(
  245.                         new ConditionExpression[] {
  246.                             new ConditionExpression(){
  247.                                 AttributeName = "statecode",
  248.                                 Operator = ConditionOperator.Equal,
  249.                                 Values = new System.Collections.ObjectModel.ObservableCollection<object>(
  250.                                     new object[] { 0 }
  251.                                 )
  252.                             }
  253.                         }),                    
  254.                 };
  255.                 /*le1b.LinkCriteria.Filters.Add(
  256.                     new FilterExpression()
  257.                 {
  258.                     Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>(
  259.                         new ConditionExpression[] {
  260.                             new ConditionExpression(){
  261.                                 AttributeName = "new_advanceterminationdate",
  262.                                 Operator = ConditionOperator.Null                                
  263.                             }
  264.                         })
  265.                 });*/
  266.  
  267.                 le1a.LinkEntities.Add(le1b);
  268.  
  269.                 LinkEntity le1c = new LinkEntity();
  270.                 le1c.LinkFromEntityName = "salesorder";
  271.                 le1c.LinkFromAttributeName = "salesorderid";
  272.                 le1c.LinkToEntityName = "new_orderiteminternetservice";
  273.                 le1c.LinkToAttributeName = "new_orderidid";
  274.                 le1c.JoinOperator = JoinOperator.LeftOuter;
  275.                 le1c.EntityAlias = "allinternetorders";
  276.  
  277.                 le1c.Columns = new ColumnSet()
  278.                 {
  279.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  280.                         "createdon", "new_servicetype", "new_orderdate"
  281.                     })
  282.                 };
  283.                 le1c.LinkCriteria = new FilterExpression()
  284.                 {
  285.                     Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>(
  286.                         new ConditionExpression[] {
  287.                             new ConditionExpression(){
  288.                                 AttributeName = "statecode",
  289.                                 Operator = ConditionOperator.Equal,
  290.                                 Values = new System.Collections.ObjectModel.ObservableCollection<object>(
  291.                                     new object[] { 0 }
  292.                                 )
  293.                             },
  294.                             new ConditionExpression(){
  295.                                 AttributeName = "new_advanceterminationdate",
  296.                                 Operator = ConditionOperator.Null                                                                
  297.                             }
  298.                         }),
  299.                     FilterOperator = LogicalOperator.And
  300.                 };
  301.  
  302.                 LinkEntity le_AllInternetOrders_Product = new LinkEntity();
  303.                 le_AllInternetOrders_Product.LinkFromEntityName = "new_orderiteminternetservice";
  304.                 le_AllInternetOrders_Product.LinkFromAttributeName = "new_productidid";
  305.                 le_AllInternetOrders_Product.LinkToEntityName = "product";
  306.                 le_AllInternetOrders_Product.LinkToAttributeName = "productid";
  307.                 le_AllInternetOrders_Product.JoinOperator = JoinOperator.LeftOuter;
  308.                 le_AllInternetOrders_Product.EntityAlias = "allinternetorders_product";
  309.  
  310.                 le_AllInternetOrders_Product.Columns = new ColumnSet()
  311.                 {
  312.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  313.                         "productid", "new_type"
  314.                     })
  315.                 };
  316.  
  317.                 le_AllInternetOrders_Product.LinkCriteria = new FilterExpression()
  318.                 {
  319.                     Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>(
  320.                         new ConditionExpression[] {
  321.                             new ConditionExpression(){
  322.                                 AttributeName = "new_wifiservice",
  323.                                 Operator = ConditionOperator.Equal,
  324.                                 Values = new System.Collections.ObjectModel.ObservableCollection<object>(
  325.                                     new object[] {false}
  326.                                 )
  327.                             },
  328.                             new ConditionExpression(){
  329.                                 AttributeName = "new_wifiservice",
  330.                                 Operator = ConditionOperator.Null
  331.                             }
  332.                         })
  333.                     , FilterOperator = LogicalOperator.Or
  334.                 };
  335.  
  336.                 le1c.LinkEntities.Add(le_AllInternetOrders_Product);
  337.  
  338.                 le1b.LinkEntities.Add(le1c);
  339.                 // Get all contacts from same account and the corresponding orderiteminternetservice records Finish
  340.                 le.LinkEntities.Add(le1a);
  341.  
  342.                 LinkEntity le2 = new LinkEntity();
  343.                 le2.LinkFromEntityName = "contact";
  344.                 le2.LinkFromAttributeName = "contactid";
  345.                 le2.LinkToEntityName = "salesorder";
  346.                 le2.LinkToAttributeName = "customerid";
  347.                 le2.JoinOperator = JoinOperator.LeftOuter;
  348.                 le2.EntityAlias = "order";
  349.  
  350.                 le2.Columns = new ColumnSet()
  351.                 {
  352.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  353.                         "customerid", "createdon"
  354.                     })
  355.                 };
  356.                 le2.LinkCriteria = new FilterExpression()
  357.                 {
  358.                     Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>(
  359.                         new ConditionExpression[] {
  360.                             new ConditionExpression(){
  361.                                 AttributeName = "statecode",
  362.                                 Operator = ConditionOperator.Equal,
  363.                                 Values = new System.Collections.ObjectModel.ObservableCollection<object>(
  364.                                     new object[] { 0 }
  365.                                 )
  366.                             }
  367.                         })
  368.                 };
  369.  
  370.  
  371.                 LinkEntity le3 = new LinkEntity();
  372.                 le3.LinkFromEntityName = "salesorder";
  373.                 le3.LinkFromAttributeName = "salesorderid";
  374.                 le3.LinkToEntityName = "new_orderitemcomputer";
  375.                 le3.LinkToAttributeName = "new_orderidid";
  376.                 le3.JoinOperator = JoinOperator.LeftOuter;
  377.                 le3.EntityAlias = "orderitemcomputer";
  378.  
  379.                 le3.Columns = new ColumnSet()
  380.                 {
  381.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  382.                         "new_orderidid", "createdon", "new_purchasedate"
  383.                     })
  384.                 };
  385.  
  386.                 LinkEntity le_OrderItemComputer_Product = new LinkEntity();
  387.                 le_OrderItemComputer_Product.LinkFromEntityName = "new_orderitemcomputer";
  388.                 le_OrderItemComputer_Product.LinkFromAttributeName = "new_productidid";
  389.                 le_OrderItemComputer_Product.LinkToEntityName = "product";
  390.                 le_OrderItemComputer_Product.LinkToAttributeName = "productid";
  391.                 le_OrderItemComputer_Product.JoinOperator = JoinOperator.LeftOuter;
  392.                 le_OrderItemComputer_Product.EntityAlias = "product";
  393.  
  394.                 le_OrderItemComputer_Product.Columns = new ColumnSet()
  395.                 {
  396.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  397.                         "productid", "new_type"
  398.                     })
  399.                 };
  400.  
  401.                 le_OrderItemComputer_Product.LinkCriteria = new FilterExpression()
  402.                 {
  403.                     Conditions = new System.Collections.ObjectModel.ObservableCollection<ConditionExpression>(
  404.                         new ConditionExpression[] {
  405.                             new ConditionExpression(){
  406.                                 AttributeName = "new_type",
  407.                                 Operator = ConditionOperator.In,
  408.                                 Values = new System.Collections.ObjectModel.ObservableCollection<object>(
  409.                                     new object[] { 1, 2, 3, 5 }
  410.                                 )
  411.                             }
  412.                         })
  413.                 };
  414.  
  415.                 le3.LinkEntities.Add(le_OrderItemComputer_Product);
  416.  
  417.                 le2.LinkEntities.Add(le3);
  418.  
  419.                 LinkEntity le4 = new LinkEntity();
  420.                 le4.LinkFromEntityName = "salesorder";
  421.                 le4.LinkFromAttributeName = "salesorderid";
  422.                 le4.LinkToEntityName = "new_orderiteminternetservice";
  423.                 le4.LinkToAttributeName = "new_orderidid";
  424.                 le4.JoinOperator = JoinOperator.LeftOuter;
  425.                 le4.EntityAlias = "orderiteminternetservice";
  426.  
  427.                 le4.Columns = new ColumnSet()
  428.                 {
  429.                     Columns = new System.Collections.ObjectModel.ObservableCollection<string>(new string[] {
  430.                         "new_orderidid", "createdon", "new_servicetype"
  431.                     })
  432.                 };
  433.  
  434.                 le2.LinkEntities.Add(le4);
  435.  
  436.                 query.LinkEntities = new System.Collections.ObjectModel.ObservableCollection<LinkEntity>(
  437.                     new LinkEntity[] { le, le2 }
  438.                 );
  439.  
  440.                 OrganizationRequest request = new OrganizationRequest() { RequestName = "RetrieveMultiple" };
  441.                 request["Query"] = query;
  442.  
  443.                 IOrganizationService service = SilverlightUtility.GetSoapService();
  444.  
  445.                 Guid sysAdmin = SilverlightUtility.GetAdminUserGuid();
  446.                 OrganizationServiceClient serviceWithCRMAdminRight = (OrganizationServiceClient)SilverlightUtility.GetSoapService();
  447.  
  448.                 using (var scope = new OperationContextScope(serviceWithCRMAdminRight.InnerChannel))
  449.                 {
  450.                     var ns = "http://schemas.microsoft.com/xrm/2011/Contracts";
  451.                     var userHeader = MessageHeader.CreateHeader("CallerId", ns, sysAdmin);
  452.                     OperationContext.Current.OutgoingMessageHeaders.Add(userHeader);
  453.  
  454.                     //service.BeginExecute(request, new AsyncCallback(MembershipNo_ClickCallback), service);
  455.  
  456.                     var memberRetrieveTask = SilverlightUtility.CreateRetrieveMultipleTask(serviceWithCRMAdminRight, query);
  457.  
  458.                     Task.Factory.ContinueWhenAll(new Task[] { memberRetrieveTask },
  459.                         completedTasks =>
  460.                         {
  461.                            MemberRetrieve(serviceWithCRMAdminRight, memberRetrieveTask.Result);
  462.                         }
  463.                      );
  464.                 }
  465.             }
  466.             catch (Exception ex)
  467.             {
  468.                 this.ReportError(ex);
  469.             }
  470.         }
  471.  
  472.         private void ButtonSave_Click(object sender, RoutedEventArgs e)
  473.         {            
  474.             if (LookupContact.Items.Count == 0 || TextBoxMembershipNumber.Text == "")
  475.             {
  476.                 //MessageBox.Show("You must provide a value for Student Name");
  477.                 SilverlightMessageBoxLibrary.Message.ErrorMessage("You must provide a value for Student Name");
  478.                 return;
  479.             }
  480.  
  481.             SelectedMembershipNumber = TextBoxMembershipNumber.Text;
  482.  
  483.             bool isInternetService = false;
  484.             bool isComputer = false;
  485.             int selectedCount = 0;
  486.             foreach (Product product in OCProducts)
  487.             {
  488.                 if (product.IsSelect)
  489.                 {
  490.                     if (product.KitProducts.Count == 0) // Not Kit product
  491.                     {
  492.                         if (product.ProductType.Value == 1) isComputer = true;
  493.                         else if (product.ProductType.Value == 2) isInternetService = true;
  494.                     }
  495.                     else
  496.                     {
  497.                         foreach (Product kitProduct in product.KitProducts)
  498.                         {
  499.                             if (kitProduct.ProductType.Value == 1) isComputer = true;
  500.                             else if (kitProduct.ProductType.Value == 2) isInternetService = true;
  501.                         }
  502.                     }
  503.                     selectedCount++;
  504.                 }
  505.             }
  506.             if (selectedCount == 0)
  507.             {
  508.                 SilverlightMessageBoxLibrary.Message.ErrorMessage("You must at least select one Product/Kit Product");
  509.                 return;
  510.             }
  511.  
  512.             int deliveryMethodCount = 0;
  513.             if (CheckBoxDeliverToHome.IsChecked == true) deliveryMethodCount++;
  514.             if (CheckBoxCollectatSchool.IsChecked == true) deliveryMethodCount++;
  515.             if (CheckBoxCollectatCentres.IsChecked == true) deliveryMethodCount++;
  516.             if (isComputer == true && deliveryMethodCount == 0)
  517.             {
  518.                 SilverlightMessageBoxLibrary.Message.ErrorMessage("You must select the Delivery Method for Computer Product");
  519.                 return;
  520.             }
  521.             else if (isComputer == true && deliveryMethodCount > 1)
  522.             {
  523.                 SilverlightMessageBoxLibrary.Message.ErrorMessage("You cannot select more than one Delivery Method for Computer Product");
  524.                 return;
  525.             }
  526.             else if (isInternetService == true && isComputer == false && deliveryMethodCount >= 1)
  527.             {
  528.                 SilverlightMessageBoxLibrary.Message.ErrorMessage("Please unselect all Delivery Method for Internet Service Order");
  529.                 return;
  530.             }
  531.  
  532.             //installmentYear = 1;
  533.  
  534.             Entity newOrderRecord = new Entity();
  535.             newOrderRecord.LogicalName = "salesorder";
  536.  
  537.             //newOrderRecord["name"] = "Order";
  538.             ContactGUID = LookupContact.Items.First().Id;
  539.             string contactName = LookupContact.Items.First().Name;
  540.             newOrderRecord["customerid"] = new EntityReference() { Id = ContactGUID, LogicalName = "contact" };            
  541.             newOrderRecord["pricelevelid"] = new EntityReference() { Id = PriceListGuid, LogicalName = "pricelevel" };
  542.             IsOneOffPayment = CheckBoxOneoffPayment.IsChecked.Value;
  543.             newOrderRecord["new_oneoffpayment"] = IsOneOffPayment;
  544.             newOrderRecord["new_delivertohome"] = CheckBoxDeliverToHome.IsChecked;
  545.             newOrderRecord["new_collectatschool"] = CheckBoxCollectatSchool.IsChecked;
  546.             newOrderRecord["new_collectatcentres"] = CheckBoxCollectatCentres.IsChecked;
  547.  
  548.             if (CheckBoxDeliverToHome.IsChecked == true || isInternetService == true)
  549.             {
  550.                 newOrderRecord["billto_name"] = newOrderRecord["shipto_name"] = contactName;
  551.                 newOrderRecord["billto_line1"] = newOrderRecord["shipto_line1"] = address1;
  552.                 newOrderRecord["billto_line2"] = newOrderRecord["shipto_line2"] = address2;
  553.                 newOrderRecord["billto_line3"] = newOrderRecord["shipto_line3"] = address3;
  554.                 newOrderRecord["billto_telephone"] = newOrderRecord["shipto_telephone"] = telephone1;
  555.             }
  556.  
  557.             if (isInternetService == true)
  558.             {
  559.                 OptionSetValue timeSlot = new OptionSetValue();
  560.                 if (TimeSlot1.IsChecked == true) timeSlot.Value = 100000000;
  561.                 if (TimeSlot2.IsChecked == true) timeSlot.Value = 100000001;
  562.                 if (TimeSlot3.IsChecked == true) timeSlot.Value = 100000002;
  563.                 if (TimeSlot4.IsChecked == true) timeSlot.Value = 100000003;
  564.  
  565.                 newOrderRecord["new_preferredtimeslotforhomebroadbandinstalla"] = timeSlot;
  566.             }
  567.             Total = System.Convert.ToDecimal(TextBoxTotal.Text);
  568.             newOrderRecord["new_totalamount"] = new Money() { Value = Total };
  569.  
  570.             ButtonSave.IsEnabled = false;
  571.             LookupContact.IsEnabled = false;
  572.  
  573.             IOrganizationService service = SilverlightUtility.GetSoapService();
  574.  
  575.             //service.BeginCreate(newOrderRecord, new AsyncCallback(OrderAdd_Callback), service);
  576.             Task<Guid> addOrderTask = SilverlightUtility.CreateEntityRecordTask(service, newOrderRecord);
  577.  
  578.             Task.Factory.ContinueWhenAll(new Task[] { addOrderTask },
  579.                 completedTasks =>
  580.                 {
  581.                     OrderAdd(service, addOrderTask.Result);                    
  582.                 }
  583.              );                      
  584.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement