200. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2/1/2017 2:56:24 PM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

200.1 Files compared

# Location File Last Modified
1 C:\Araxis_Merge_Comprasion\Pub_un\BTSSS_CIF_122016.zip\BTSSS_CIF_12_20_16\clean\CRM\trunk\SDK\SampleCode\CS\BusinessDataModel\BusinessManagement ProcessingQuotesAndSalesOrders.cs Tue Dec 20 19:51:44 2016 UTC
2 Wed Feb 1 19:56:24 2017 UTC

200.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 0 0
Removed 1 789

200.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

200.4 Active regular expressions

No regular expressions were active.

200.5 Comparison detail

1   // ======= ========== ========== ========== ========== ========== ========== ==        
2   //  This f ile is par t of the M icrosoft D ynamics CR M SDK code  samples.        
3   //        
4   //  Copyri ght (C) Mi crosoft Co rporation.   All righ ts reserve d.        
5   //        
6   //  This s ource code  is intend ed only as  a supplem ent to Mic rosoft        
7   //  Develo pment Tool s and/or o n-line doc umentation .  See the se other        
8   //  materi als for de tailed inf ormation r egarding M icrosoft c ode sample s.        
9   //        
10   //  THIS C ODE AND IN FORMATION  ARE PROVID ED "AS IS"  WITHOUT W ARRANTY OF  ANY        
11   //  KIND,  EITHER EXP RESSED OR  IMPLIED, I NCLUDING B UT NOT LIM ITED TO TH E        
12   //  IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND/OR F ITNESS FOR  A        
13   //  PARTIC ULAR PURPO SE.        
14   // ======= ========== ========== ========== ========== ========== ========== ==        
15          
16   //<snippet Processing QuotesAndS alesOrders >        
17   using Syst em;        
18   using Syst em.Service Model;        
19          
20   // This na mespace is  found in  Microsoft. Crm.Sdk.Pr oxy.dll as sembly        
21   // found i n the SDK\ bin folder .        
22   using Micr osoft.Crm. Sdk.Messag es;        
23          
24   // These n amespaces  are found  in the Mic rosoft.Xrm .Sdk.dll a ssembly        
25   // located  in the SD K\bin fold er of the  SDK downlo ad.        
26   using Micr osoft.Xrm. Sdk;        
27   using Micr osoft.Xrm. Sdk.Client ;        
28   using Micr osoft.Xrm. Sdk.Messag es;        
29   using Micr osoft.Xrm. Sdk.Query;        
30          
31   namespace  Microsoft. Crm.Sdk.Sa mples        
32   {        
33       /// <s ummary>        
34       /// De monstrates  how to co nvert a "w on" opport unity to a  quote and  then conv ert a quot e        
35       /// to  a sales o rder, and  a sales or der to an  invoice. A lso demons trates         
36       /// lo cking/unlo cking pric es on both  sales ord ers and in voices.</s ummary>        
37       /// <r emarks>        
38       /// At  run-time,  you will  be given t he option  to delete  all the        
39       /// da tabase rec ords creat ed by this  program.< /remarks>        
40       public  class Pro cessingQuo tesAndSale sOrders        
41       {        
42           #r egion Clas s Level Me mbers        
43          
44           pr ivate Guid  _opportun ityId;        
45           pr ivate Guid  _loseOppo rtunityId;        
46           pr ivate Guid  _unitGrou pId;        
47           pr ivate Guid  _defaultU nitId;        
48           pr ivate Guid  _productI d;        
49           pr ivate Guid  _priceLis tId;        
50           pr ivate Guid  _priceLis tItemId;        
51           pr ivate Guid  _accountI d;        
52           pr ivate Guid  _quoteId;        
53           pr ivate Guid  _closeQuo teId;        
54           pr ivate Guid  _quoteDet ailId;        
55           pr ivate Guid  _salesOrd erId;        
56           pr ivate Guid  _closeSal esOrderId;        
57           pr ivate Guid  _invoiceI d;        
58          
59           pr ivate Orga nizationSe rviceProxy  _serviceP roxy;        
60          
61           #e ndregion C lass Level  Members        
62          
63           #r egion How  To Sample  Code        
64           // / <summary >        
65           // / This met hod first  connects t o the Orga nization s ervice. Af terwards,         
66           // / quote is  created.  This quote  is then c onverted t o an order , and the  pricing        
67           // / is unloc ked and re locked. Th is is foll owed by th e order be ing conver ted        
68           // / to an in voice, and  the prici ng is lock ed then un locked.        
69           // / </summar y>        
70           // / <param n ame="serve rConfig">C ontains se rver conne ction info rmation.</ param>        
71           // / <param n ame="promp tforDelete ">When Tru e, the use r will be  prompted t o delete a ll        
72           // / created  entities.< /param>        
73           pu blic void  Run(Server Connection .Configura tion serve rConfig, b ool prompt forDelete)        
74           {        
75                try        
76                {        
77                    //<s nippetProc essingQuot esAndSales Orders1>        
78                    // C onnect to  the Organi zation ser vice.         
79                    // T he using s tatement a ssures tha t the serv ice proxy  will be pr operly dis posed.        
80                    usin g (_servic eProxy = n ew Organiz ationServi ceProxy(se rverConfig .Organizat ionUri, se rverConfig .HomeRealm Uri,server Config.Cre dentials,  serverConf ig.DeviceC redentials ))        
81                    {        
82                         // This st atement is  required  to enable  early-boun d type sup port.        
83                         _servicePr oxy.Enable ProxyTypes ();        
84          
85                         CreateRequ iredRecord s();        
86          
87                         #region Cr eate Oppor tunities        
88          
89                         // Create  an opportu nity        
90                         var crmOpp ortunity =  new Oppor tunity        
91                         {        
92                             Custom erId = new  EntityRef erence(Acc ount.Entit yLogicalNa me, _accou ntId),        
93                             Name =  "Sample",        
94                             PriceL evelId = n ew EntityR eference(P riceLevel. EntityLogi calName,        
95                                 _p riceListId )        
96                         };        
97                         _opportuni tyId = _se rviceProxy .Create(cr mOpportuni ty);        
98          
99                         crmOpportu nity = new  Opportuni ty        
100                         {        
101                             Custom erId = new  EntityRef erence(Acc ount.Entit yLogicalNa me, _accou ntId),        
102                             Name =  "Another  Sample",        
103                             PriceL evelId = n ew EntityR eference(P riceLevel. EntityLogi calName,        
104                                 _p riceListId )        
105                         };        
106                         _loseOppor tunityId =  _serviceP roxy.Creat e(crmOppor tunity);        
107          
108                         Console.Wr iteLine("O pportuniti es created .");        
109          
110                         #endregion        
111          
112                         #region Wi n Opportun ity        
113          
114                         //<snippet WinOpportu nity>        
115                         // Close t he opportu nity as wo n        
116                         var winOpp Request =  new WinOpp ortunityRe quest        
117                         {        
118                             Opport unityClose  = new Opp ortunityCl ose        
119                             {        
120                                 Op portunityI d = new En tityRefere nce        
121                                      (Opportu nity.Entit yLogicalNa me, _oppor tunityId)        
122                             },        
123                             Status  = new Opt ionSetValu e((int)opp ortunity_s tatuscode. Won)        
124                         };        
125          
126                         _servicePr oxy.Execut e(winOppRe quest);        
127          
128                         Console.Wr iteLine("O pportunity  closed as  Won.");        
129                         //</snippe tWinOpport unity>        
130          
131                         #endregion        
132          
133                         #region Lo se Opportu nity        
134                         //<snippet LoseOpport unity>        
135                         var loseOp pRequest =  new LoseO pportunity Request        
136                         {        
137                             Opport unityClose  = new Opp ortunityCl ose        
138                             {        
139                                 Op portunityI d = new En tityRefere nce        
140                                      (Opportu nity.Entit yLogicalNa me, _loseO pportunity Id)        
141                             },        
142                             Status  = new Opt ionSetValu e((int)opp ortunity_s tatuscode. Canceled)        
143                         };        
144          
145                         _servicePr oxy.Execut e(loseOppR equest);        
146          
147                         Console.Wr iteLine("O pportunity  closed as  Lost.");        
148                         //</snippe tLoseOppor tunity>        
149          
150                         #endregion        
151          
152                         #region Co nvert Oppo rtunity to  a Quote        
153          
154                         //<snippet GenerateQu oteFromOpp ortunity>        
155                         // Convert  the oppor tunity to  a quote        
156                         var genQuo teFromOppR equest = n ew Generat eQuoteFrom Opportunit yRequest        
157                         {        
158                             Opport unityId =  _opportuni tyId,        
159                             Column Set = new  ColumnSet( "quoteid",  "name")        
160                         };        
161          
162                         var genQuo teFromOppR esponse =  (GenerateQ uoteFromOp portunityR esponse)        
163                             _servi ceProxy.Ex ecute(genQ uoteFromOp pRequest);        
164          
165                         Quote quot e = genQuo teFromOppR esponse.En tity.ToEnt ity<Quote> ();        
166                         _quoteId =  quote.Id;        
167          
168                         Console.Wr iteLine("Q uote gener ated from  the Opport unity.");        
169                         //</snippe tGenerateQ uoteFromOp portunity>        
170          
171                         #endregion        
172          
173                         #region Cl ose Quote        
174          
175                         //<snippet CloseQuote >        
176                         // convert  the oppor tunity to  a quote        
177                         genQuoteFr omOppReque st = new G enerateQuo teFromOppo rtunityReq uest        
178                         {        
179                             Opport unityId =  _opportuni tyId,        
180                             Column Set = new  ColumnSet( "quoteid",  "name")        
181                         };        
182                         genQuoteFr omOppRespo nse = (Gen erateQuote FromOpport unityRespo nse)        
183                             _servi ceProxy.Ex ecute(genQ uoteFromOp pRequest);        
184          
185                         Quote clos eQuote = g enQuoteFro mOppRespon se.Entity. ToEntity<Q uote>();        
186                         _closeQuot eId = clos eQuote.Id;        
187          
188                         // Activat e the quot e        
189                         SetStateRe quest acti vateQuote  = new SetS tateReques t()        
190                         {        
191                             Entity Moniker =  closeQuote .ToEntityR eference() ,        
192                             State  = new Opti onSetValue ((int)Quot eState.Act ive),        
193                             Status  = new Opt ionSetValu e((int)quo te_statusc ode.InProg ress)        
194                         };        
195                         _servicePr oxy.Execut e(activate Quote);        
196          
197                         // Close t he quote        
198                         CloseQuote Request cl oseQuoteRe quest = ne w CloseQuo teRequest( )        
199                         {        
200                             QuoteC lose = new  QuoteClos e()        
201                             {        
202                                 Qu oteId = cl oseQuote.T oEntityRef erence(),        
203                                 Su bject = "Q uote Close  " + DateT ime.Now.To String()        
204                             },        
205                             Status  = new Opt ionSetValu e(-1)        
206                         };        
207                         _servicePr oxy.Execut e(closeQuo teRequest) ;        
208          
209                         Console.Wr iteLine("Q uote Close d");        
210                         //</snippe tCloseQuot e>        
211          
212                         #endregion        
213          
214                         #region Cr eate Quote 's Product        
215          
216                         // Set the  quote's p roduct        
217                         QuoteDetai l quoteDet ail = new  QuoteDetai l()        
218                         {        
219                             Produc tId = new  EntityRefe rence(Prod uct.Entity LogicalNam e,        
220                                 _p roductId),        
221                             Quanti ty = 1,        
222                             QuoteI d = quote. ToEntityRe ference(),        
223                             UoMId  = new Enti tyReferenc e(UoM.Enti tyLogicalN ame,        
224                                 _d efaultUnit Id)        
225                         };        
226                         _quoteDeta ilId = _se rviceProxy .Create(qu oteDetail) ;        
227          
228                         Console.Wr iteLine("Q uote Produ ct created .");        
229          
230                         // Activat e the quot e        
231                         activateQu ote = new  SetStateRe quest()        
232                         {        
233                             Entity Moniker =  quote.ToEn tityRefere nce(),        
234                             State  = new Opti onSetValue ((int)Quot eState.Act ive),        
235                             Status  = new Opt ionSetValu e((int)quo te_statusc ode.InProg ress)        
236                         };        
237                         _servicePr oxy.Execut e(activate Quote);        
238          
239                         Console.Wr iteLine("Q uote activ ated.");        
240          
241                         //<snippet WinQuote>        
242          
243                         // Mark th e quote as  won        
244                         // Note: t his is nec essary in  order to c onvert a q uote into         
245                         // SalesOr der.        
246                         WinQuoteRe quest winQ uoteReques t = new Wi nQuoteRequ est()        
247                         {        
248                             QuoteC lose = new  QuoteClos e()        
249                             {        
250                                 Su bject = "Q uote Close " + DateTi me.Now.ToS tring(),        
251                                 Qu oteId = qu ote.ToEnti tyReferenc e()        
252                             },        
253                             Status  = new Opt ionSetValu e(-1)        
254                         };        
255                         _servicePr oxy.Execut e(winQuote Request);        
256          
257                         Console.Wr iteLine("Q uote won." );        
258                         //</snippe tWinQuote>        
259          
260                         #endregion        
261          
262                         #region Co nvert Quot e to Sales Order        
263          
264          
265                         //<snippet ConvertQuo teToSalesO rder>        
266                         // Define  columns to  be retrie ved after  creating t he order        
267                         ColumnSet  salesOrder Columns =        
268                             new Co lumnSet("s alesorderi d", "total amount");        
269          
270                         // Convert  the quote  to a sale s order        
271                         ConvertQuo teToSalesO rderReques t convertQ uoteReques t =        
272                             new Co nvertQuote ToSalesOrd erRequest( )        
273                             {        
274                                 Qu oteId = _q uoteId,        
275                                 Co lumnSet =  salesOrder Columns        
276                             };        
277                         ConvertQuo teToSalesO rderRespon se convert QuoteRespo nse =        
278                             (Conve rtQuoteToS alesOrderR esponse)_s erviceProx y.Execute( convertQuo teRequest) ;        
279                         SalesOrder  salesOrde r = (Sales Order)conv ertQuoteRe sponse.Ent ity;        
280                         _salesOrde rId = sale sOrder.Id;        
281          
282                         //</snippe tConvertQu oteToSales Order>        
283                         Console.Wr iteLine("C onverted Q uote to Sa lesOrder." );        
284          
285                         #endregion        
286          
287                         #region Ca ncel Sales  Order        
288          
289                         //<snippet CancelSale sOrder>        
290          
291                         // Define  columns to  be retrie ved after  creating t he order        
292                         salesOrder Columns =  new Column Set("sales orderid",  "totalamou nt");        
293          
294                         // Convert  the quote  to a sale s order        
295                         convertQuo teRequest  =        
296                             new Co nvertQuote ToSalesOrd erRequest( )        
297                             {        
298                                 Qu oteId = _q uoteId,        
299                                 Co lumnSet =  salesOrder Columns        
300                             };        
301                         convertQuo teResponse  =        
302                             (Conve rtQuoteToS alesOrderR esponse)_s erviceProx y.Execute( convertQuo teRequest) ;        
303                         SalesOrder  closeSale sOrder = ( SalesOrder )convertQu oteRespons e.Entity;        
304                         _closeSale sOrderId =  closeSale sOrder.Id;        
305          
306                         CancelSale sOrderRequ est cancel Request =  new Cancel SalesOrder Request()        
307                         {        
308                             OrderC lose = new  OrderClos e()        
309                             {        
310                                 Sa lesOrderId  = closeSa lesOrder.T oEntityRef erence(),        
311                                 Su bject = "C lose Sales  Order " +  DateTime. Now        
312                             },        
313                             Status  = new Opt ionSetValu e(-1)        
314                         };        
315                         _servicePr oxy.Execut e(cancelRe quest);        
316          
317                         Console.Wr iteLine("C anceled sa les order" );        
318                         //</snippe tCancelSal esOrder>        
319          
320                         #endregion        
321          
322                         #region Lo ck pricing  on SalesO rder        
323          
324                         // Note: a fter conve rting a wo n quote to  an order,  the prici ng of         
325                         // the ord er is lock ed by defa ult.        
326          
327                         //<snippet UpdateRequ est>        
328          
329                         // Retriev e current  price list        
330                         ProductPri ceLevel pr iceListIte m =        
331                             (Produ ctPriceLev el)_servic eProxy.Ret rieve(        
332                                 Pr oductPrice Level.Enti tyLogicalN ame,        
333                                 _p riceListIt emId,        
334                                 ne w ColumnSe t("product pricelevel id", "amou nt")        
335                             );        
336          
337                         Console.Wr iteLine("C urrent pri ce list re trieved.") ;        
338                         Console.Wr iteLine();        
339          
340                         Console.Wr iteLine("D etails bef ore update :");        
341                         Console.Wr iteLine("- ---------- -----");        
342                         Console.Wr iteLine("C urrent ord er total:  {0}",        
343                             salesO rder.Total Amount.Val ue);        
344                         Console.Wr iteLine("C urrent pri ce per ite m: {0}",        
345                             priceL istItem.Am ount.Value );        
346                         Console.Wr iteLine("< /End of Li sting>");        
347                         Console.Wr iteLine();        
348          
349                         // Update  the price  list        
350                         priceListI tem.Amount  = new Mon ey(30.0M);        
351          
352                         UpdateRequ est update PriceListI tem = new  UpdateRequ est()        
353                         {        
354                             Target  = priceLi stItem,        
355                         };        
356                         _servicePr oxy.Execut e(updatePr iceListIte m);        
357          
358                         Console.Wr iteLine("P rice list  updated.") ;        
359                         //</snippe tUpdateReq uest>        
360          
361                         // Retriev e the orde r        
362                         SalesOrder  updatedSa lesOrder =  (SalesOrd er)_servic eProxy.Ret rieve(        
363                                 Sa lesOrder.E ntityLogic alName,        
364                                 _s alesOrderI d,        
365                                 ne w ColumnSe t("salesor derid", "t otalamount ")        
366                             );        
367          
368                         Console.Wr iteLine("U pdated ord er retriev ed.");        
369                         Console.Wr iteLine();        
370          
371                         Console.Wr iteLine("D etails aft er update: ");        
372                         Console.Wr iteLine("- ---------- -----");        
373                         Console.Wr iteLine("C urrent ord er total:  {0}",        
374                             update dSalesOrde r.TotalAmo unt.Value) ;        
375                         Console.Wr iteLine("C urrent pri ce per ite m: {0}",        
376                             priceL istItem.Am ount.Value );        
377                         Console.Wr iteLine("< /End of Li sting>");        
378                         Console.Wr iteLine();        
379          
380                         //<snippet UnlockSale sOrderPric ing>        
381                         // Unlock  the order  pricing        
382                         UnlockSale sOrderPric ingRequest  unlockOrd erRequest  =        
383                             new Un lockSalesO rderPricin gRequest()        
384                             {        
385                                 Sa lesOrderId  = _salesO rderId        
386                             };        
387                         _servicePr oxy.Execut e(unlockOr derRequest );        
388                         //</snippe tUnlockSal esOrderPri cing>        
389          
390                         Console.Wr iteLine("O rder prici ng unlocke d.");        
391          
392                         // Retriev e the orde r        
393                         updatedSal esOrder =  (SalesOrde r)_service Proxy.Retr ieve(        
394                                 Sa lesOrder.E ntityLogic alName,        
395                                 _s alesOrderI d,        
396                                 ne w ColumnSe t("salesor derid", "t otalamount ")        
397                             );        
398          
399                         Console.Wr iteLine("U pdated ord er retriev ed.");        
400                         Console.Wr iteLine();        
401          
402                         Console.Wr iteLine("D etails aft er update  and unlock :");        
403                         Console.Wr iteLine("- ---------- -----");        
404                         Console.Wr iteLine("C urrent ord er total:  {0}",        
405                             update dSalesOrde r.TotalAmo unt.Value) ;        
406                         Console.Wr iteLine("C urrent pri ce per ite m: {0}",        
407                             priceL istItem.Am ount.Value );        
408                         Console.Wr iteLine("< /End of Li sting>");        
409                         Console.Wr iteLine();        
410          
411                         //<snippet LockSalesO rderPricin g>        
412                         // Relock  the order  pricing        
413                         LockSalesO rderPricin gRequest l ockOrderRe quest =        
414                             new Lo ckSalesOrd erPricingR equest()        
415                             {        
416                                 Sa lesOrderId  = _salesO rderId        
417                             };        
418                         _servicePr oxy.Execut e(lockOrde rRequest);        
419          
420                         //</snippe tLockSales OrderPrici ng>        
421          
422                         Console.Wr iteLine("O rder prici ng relocke d.");        
423          
424                         #endregion        
425          
426                         //<snippet ConvertSal esOrderToI nvoice>         
427                         #region Co nvert Sale sOrder to  Invoice        
428          
429                         // Define  columns to  be retrie ved after  creating t he invoice        
430                         ColumnSet  invoiceCol umns =        
431                             new Co lumnSet("i nvoiceid",  "totalamo unt");        
432          
433                         // Convert  the order  to an inv oice        
434                         ConvertSal esOrderToI nvoiceRequ est conver tOrderRequ est =        
435                             new Co nvertSales OrderToInv oiceReques t()        
436                             {        
437                                 Sa lesOrderId  = _salesO rderId,        
438                                 Co lumnSet =  invoiceCol umns        
439                             };        
440                         ConvertSal esOrderToI nvoiceResp onse conve rtOrderRes ponse =        
441                             (Conve rtSalesOrd erToInvoic eResponse) _servicePr oxy.Execut e(convertO rderReques t);        
442                         Invoice in voice = (I nvoice)con vertOrderR esponse.En tity;        
443                         _invoiceId  = invoice .Id;        
444          
445                         //</snippe tConvertSa lesOrderTo Invoice>        
446                         Console.Wr iteLine("C onverted S alesOrder  to Invoice .");        
447          
448                         #endregion        
449          
450                         #region Lo ck pricing  on Invoic e        
451          
452                         // Note: a fter conve rting a Sa lesOrder t o Invoice,  the prici ng of         
453                         // the Inv oice is lo cked by de fault.        
454          
455                         // Retriev e current  price list        
456                         priceListI tem = (Pro ductPriceL evel)_serv iceProxy.R etrieve(        
457                                 Pr oductPrice Level.Enti tyLogicalN ame,        
458                                 _p riceListIt emId,        
459                                 ne w ColumnSe t("product pricelevel id", "amou nt")        
460                             );        
461          
462                         Console.Wr iteLine("C urrent pri ce list re trieved.") ;        
463                         Console.Wr iteLine();        
464          
465                         Console.Wr iteLine("D etails bef ore lock a nd update: ");        
466                         Console.Wr iteLine("- ---------- -----");        
467                         Console.Wr iteLine("C urrent inv oice total : {0}",        
468                             invoic e.TotalAmo unt.Value) ;        
469                         Console.Wr iteLine("C urrent pri ce per ite m: {0}",        
470                             priceL istItem.Am ount.Value );        
471                         Console.Wr iteLine("< /End of Li sting>");        
472                         Console.Wr iteLine();        
473          
474                         //<snippet UpdatePric eList>        
475                         // Update  the price  list        
476                         priceListI tem.Amount  = new Mon ey(40.0M);        
477          
478                         updatePric eListItem  = new Upda teRequest( )        
479                         {        
480                             Target  = priceLi stItem        
481                         };        
482                         _servicePr oxy.Execut e(updatePr iceListIte m);        
483          
484                         Console.Wr iteLine("P rice list  updated.") ;        
485                         //</snippe tUpdatePri ceList>        
486          
487                         //<snippet UnlockInvo icePricing >        
488          
489                         // Retriev e the invo ice        
490                         Invoice up datedInvoi ce = (Invo ice)_servi ceProxy.Re trieve(        
491                                 In voice.Enti tyLogicalN ame,        
492                                 _i nvoiceId,        
493                                 ne w ColumnSe t("invoice id", "tota lamount")        
494                             );        
495          
496                         Console.Wr iteLine("U pdated inv oice retri eved.");        
497                         Console.Wr iteLine();        
498          
499                         Console.Wr iteLine("D etails aft er lock an d update:" );        
500                         Console.Wr iteLine("- ---------- -----");        
501                         Console.Wr iteLine("C urrent inv oice total : {0}",        
502                             update dInvoice.T otalAmount .Value);        
503                         Console.Wr iteLine("C urrent pri ce per ite m: {0}",        
504                             priceL istItem.Am ount.Value );        
505                         Console.Wr iteLine("< /End of Li sting>");        
506                         Console.Wr iteLine();        
507          
508                         // Unlock  the invoic e pricing        
509                         UnlockInvo icePricing Request un lockInvoic eRequest =        
510                             new Un lockInvoic ePricingRe quest()        
511                             {        
512                                 In voiceId =  _invoiceId        
513                             };        
514                         _servicePr oxy.Execut e(unlockIn voiceReque st);        
515          
516                         Console.Wr iteLine("I nvoice pri cing unloc ked.");        
517                         //</snippe tUnlockInv oicePricin g>        
518          
519                         // Retriev e the invo ice        
520                         updatedInv oice = (In voice)_ser viceProxy. Retrieve(        
521                                 In voice.Enti tyLogicalN ame,        
522                                 _i nvoiceId,        
523                                 ne w ColumnSe t("invoice id", "tota lamount")        
524                             );        
525          
526                         Console.Wr iteLine("U pdated inv oice retri eved.");        
527                         Console.Wr iteLine();        
528          
529                         Console.Wr iteLine("D etails aft er update  and unlock :");        
530                         Console.Wr iteLine("- ---------- -----");        
531                         Console.Wr iteLine("C urrent inv oice total : {0}",        
532                             update dInvoice.T otalAmount .Value);        
533                         Console.Wr iteLine("C urrent pri ce per ite m: {0}",        
534                             priceL istItem.Am ount.Value );        
535                         Console.Wr iteLine("< /End of Li sting>");        
536                         Console.Wr iteLine();        
537          
538                         //<snippet LockInvoic ePricing>        
539                         // Relock  the invoic e pricing        
540                         LockInvoic ePricingRe quest lock InvoiceReq uest =        
541                             new Lo ckInvoiceP ricingRequ est()        
542                             {        
543                                 In voiceId =  _invoiceId        
544                             };        
545                         _servicePr oxy.Execut e(lockInvo iceRequest );        
546          
547                         Console.Wr iteLine("I nvoice pri cing reloc ked.");        
548                         //</snippe tLockInvoi cePricing>        
549          
550                         #endregion        
551          
552                         DeleteRequ iredRecord s(promptfo rDelete);        
553                    }        
554                    //</ snippetPro cessingQuo tesAndSale sOrders1>        
555                }        
556          
557                // Catch  any servi ce fault e xceptions  that Micro soft Dynam ics CRM th rows.        
558                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault>)        
559                {        
560                    // Y ou can han dle an exc eption her e or pass  it back to  the calli ng method.        
561                    thro w;        
562                }        
563           }        
564          
565           // / <summary >        
566           // / Creates  any entity  records t hat this s ample requ ires.        
567           // / </summar y>        
568           pu blic void  CreateRequ iredRecord s()        
569           {        
570                // Creat e a unit g roup        
571                UoMSched ule newUni tGroup = n ew UoMSche dule        
572                {        
573                    Name  = "Exampl e Unit Gro up",        
574                    Base UoMName =  "Example P rimary Uni t"        
575                };        
576                _unitGro upId = _se rviceProxy .Create(ne wUnitGroup );        
577                Console. WriteLine( "Create {0 }", newUni tGroup.Nam e);        
578          
579                // Retri eve the de fault unit  id that w as automat ically cre ated        
580                // when  we created  the Unit  Group        
581                QueryExp ression un itQuery =  new QueryE xpression        
582                {        
583                    Enti tyName = U oM.EntityL ogicalName ,        
584                    Colu mnSet = ne w ColumnSe t("uomid",  "name"),        
585                    Crit eria = new  FilterExp ression        
586                    {        
587                         Conditions  =         
588                             {        
589                                 ne w Conditio nExpressio        
590                                 {        
591                                      Attribut eName = "u omschedule id",        
592                                      Operator  = Conditi onOperator .Equal,        
593                                      Values =  { _unitGr oupId }        
594                                 }        
595                             }        
596                    },        
597                    Page Info = new  PagingInf o        
598                    {        
599                         PageNumber  = 1,        
600                         Count = 1        
601                    }        
602                };        
603          
604                // Retri eve the un it.        
605                UoM unit  = (UoM)_s erviceProx y.Retrieve Multiple(u nitQuery). Entities[0 ];        
606                _default UnitId = u nit.UoMId. Value;        
607          
608                // Creat e a few pr oducts        
609                Product  newProduct  = new Pro duct        
610                {        
611                    Prod uctNumber  = "1",        
612                    Name  = "Exampl e Product" ,        
613                    Prod uctStructu re = new O ptionSetVa lue(1),        
614                    Quan tityDecima l = 1,        
615                    Defa ultUoMSche duleId =        
616                         new Entity Reference( UoMSchedul e.EntityLo gicalName,  _unitGrou pId),        
617                    Defa ultUoMId =        
618                         new Entity Reference( UoM.Entity LogicalNam e, _defaul tUnitId)        
619                };        
620                _product Id = _serv iceProxy.C reate(newP roduct);        
621                newProdu ct.Id = _p roductId;        
622                Console. WriteLine( "Create {0 }", newPro duct.Name) ;        
623          
624                // Creat e a price  list        
625                PriceLev el newPric eList = ne w PriceLev el        
626                {        
627                    Name  = "Exampl e Price Li st"        
628                };        
629                _priceLi stId = _se rviceProxy .Create(ne wPriceList );        
630          
631                // Creat e a price  list item  for the pr oduct and  apply volu me discoun t        
632                ProductP riceLevel  newPriceLi stItem = n ew Product PriceLevel        
633                {        
634                    Pric eLevelId =        
635                         new Entity Reference( PriceLevel .EntityLog icalName,  _priceList Id),        
636                    Prod uctId =        
637                         new Entity Reference( Product.En tityLogica lName, _pr oductId),        
638                    UoMI d =        
639                         new Entity Reference( UoM.Entity LogicalNam e, _defaul tUnitId),        
640                    Amou nt = new M oney(20.0M ),        
641                };        
642                _priceLi stItemId =  _serviceP roxy.Creat e(newPrice ListItem);        
643          
644                // Publi sh the pro duct        
645                SetState Request pu blishReque st = new S etStateReq uest        
646                {        
647                    Enti tyMoniker  = new Enti tyReferenc e(Product. EntityLogi calName, _ productId) ,        
648                    Stat e = new Op tionSetVal ue((int)Pr oductState .Active),        
649                    Stat us = new O ptionSetVa lue(1)        
650                };        
651                _service Proxy.Exec ute(publis hRequest);        
652                Console. WriteLine( "Published  {0}", new Product.Na me);        
653          
654                // Creat e an accou nt record  for the op portunity' s potentia l customer id         
655                Account  newAccount  = new Acc ount        
656                {        
657                    Name  = "Litwar e, Inc.",        
658                    Addr ess1_Posta lCode = "6 0661"        
659                };        
660                _account Id = _serv iceProxy.C reate(newA ccount);        
661                newAccou nt.Id = _a ccountId;        
662          
663           }        
664          
665           // / <summary >        
666           // / Deletes  any entity  records t hat were c reated for  this samp le.        
667           // / <param n ame="promp t">Indicat es whether  to prompt  the user         
668           // / to delet e the reco rds create d in this  sample.</p aram>        
669           // / </summar y>        
670           pu blic void  DeleteRequ iredRecord s(bool pro mpt)        
671           {        
672                // The t hree syste m users th at were cr eated by t his sample  will cont inue to         
673                // exist  on your s ystem beca use system  users can not be del eted in Mi crosoft        
674                // Dynam ics CRM.   They can o nly be ena bled or di sabled.        
675          
676                bool toB eDeleted =  true;        
677          
678                if (prom pt)        
679                {        
680                    // A sk the use r if the c reated ent ities shou ld be dele ted.        
681                    Cons ole.Write( "\nDo you  want these  entity re cords dele ted? (y/n)  [y]: ");        
682                    Stri ng answer  = Console. ReadLine() ;        
683                    if ( answer.Sta rtsWith("y ") ||        
684                         answer.Sta rtsWith("Y ") ||        
685                         answer ==  String.Emp ty)        
686                    {        
687                         toBeDelete d = true;        
688                    }        
689                    else        
690                    {        
691                         toBeDelete d = false;        
692                    }        
693                }        
694          
695                if (toBe Deleted)        
696                {        
697                    // D elete all  records cr eated in t his sample .        
698                    _ser viceProxy. Delete("in voice", _i nvoiceId);        
699                    _ser viceProxy. Delete("sa lesorder",  _salesOrd erId);        
700                    _ser viceProxy. Delete("sa lesorder",  _closeSal esOrderId) ;        
701                    _ser viceProxy. Delete("qu otedetail" , _quoteDe tailId);        
702                    _ser viceProxy. Delete("qu ote", _quo teId);        
703                    _ser viceProxy. Delete("qu ote", _clo seQuoteId) ;        
704                    _ser viceProxy. Delete("op portunity" , _opportu nityId);        
705                    _ser viceProxy. Delete("op portunity" , _loseOpp ortunityId );        
706                    _ser viceProxy. Delete("ac count", _a ccountId);        
707                    _ser viceProxy. Delete("pr oductprice level", _p riceListIt emId);        
708                    _ser viceProxy. Delete("pr icelevel",  _priceLis tId);        
709                    _ser viceProxy. Delete("pr oduct", _p roductId);        
710                    _ser viceProxy. Delete("uo mschedule" , _unitGro upId);        
711          
712                    Cons ole.WriteL ine("Entit y record(s ) have bee n deleted. ");        
713                }        
714           }        
715          
716           #e ndregion H ow To Samp le Code        
717          
718           #r egion Main  method        
719          
720           // / <summary >        
721           // / Standard  Main() me thod used  by most SD K samples.        
722           // / </summar y>        
723           // / <param n ame="args" ></param>        
724           st atic publi c void Mai n(string[]  args)        
725           {        
726                try        
727                {        
728                    // O btain the  target org anization' s Web addr ess and cl ient logon          
729                    // c redentials  from the  user.        
730                    Serv erConnecti on serverC onnect = n ew ServerC onnection( );        
731                    Serv erConnecti on.Configu ration con fig = serv erConnect. GetServerC onfigurati on();        
732          
733                    Proc essingQuot esAndSales Orders app  = new Pro cessingQuo tesAndSale sOrders();        
734                    app. Run(config , true);        
735                }        
736                catch (F aultExcept ion<Micros oft.Xrm.Sd k.Organiza tionServic eFault> ex )        
737                {        
738                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
739                    Cons ole.WriteL ine("Times tamp: {0}" , ex.Detai l.Timestam p);        
740                    Cons ole.WriteL ine("Code:  {0}", ex. Detail.Err orCode);        
741                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Detail. Message);        
742                    Cons ole.WriteL ine("Plugi n Trace: { 0}", ex.De tail.Trace Text);        
743                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
744                         null == ex .Detail.In nerFault ?  "No Inner  Fault" :  "Has Inner  Fault");        
745                }        
746                catch (S ystem.Time outExcepti on ex)        
747                {        
748                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
749                    Cons ole.WriteL ine("Messa ge: {0}",  ex.Message );        
750                    Cons ole.WriteL ine("Stack  Trace: {0 }", ex.Sta ckTrace);        
751                    Cons ole.WriteL ine("Inner  Fault: {0 }",        
752                         null == ex .InnerExce ption.Mess age ? "No  Inner Faul t" : ex.In nerExcepti on.Message );        
753                }        
754                catch (S ystem.Exce ption ex)        
755                {        
756                    Cons ole.WriteL ine("The a pplication  terminate d with an  error.");        
757                    Cons ole.WriteL ine(ex.Mes sage);        
758          
759                    // D isplay the  details o f the inne r exceptio n.        
760                    if ( ex.InnerEx ception !=  null)        
761                    {        
762                         Console.Wr iteLine(ex .InnerExce ption.Mess age);        
763          
764                         FaultExcep tion<Micro soft.Xrm.S dk.Organiz ationServi ceFault> f e = ex.Inn erExceptio n        
765                             as Fau ltExceptio n<Microsof t.Xrm.Sdk. Organizati onServiceF ault>;        
766                         if (fe !=  null)        
767                         {        
768                             Consol e.WriteLin e("Timesta mp: {0}",  fe.Detail. Timestamp) ;        
769                             Consol e.WriteLin e("Code: { 0}", fe.De tail.Error Code);        
770                             Consol e.WriteLin e("Message : {0}", fe .Detail.Me ssage);        
771                             Consol e.WriteLin e("Plugin  Trace: {0} ", fe.Deta il.TraceTe xt);        
772                             Consol e.WriteLin e("Inner F ault: {0}" ,        
773                                 nu ll == fe.D etail.Inne rFault ? " No Inner F ault" : "H as Inner F ault");        
774                         }        
775                    }        
776                }        
777                // Addit ional exce ptions to  catch: Sec urityToken Validation Exception,  ExpiredSe curityToke nException ,        
778                // Secur ityAccessD eniedExcep tion, Mess ageSecurit yException , and Secu rityNegoti ationExcep tion.        
779          
780                finally        
781                {        
782                    Cons ole.WriteL ine("Press  <Enter> t o exit.");        
783                    Cons ole.ReadLi ne();        
784                }        
785           }        
786           #e ndregion M ain method        
787       }        
788   }        
789   //</snippe tProcessin gQuotesAnd SalesOrder s>