Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 145.77 KB | None | 0 0
  1. /*Update message to incident entity in Pre stage with Pre and Post image 'img'
  2.  * Oracle Reference - E:\oracle\product\10.2.0\db_1\ODP.NET\bin\2.x\Oracle.DataAccess.dll*/
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Microsoft.Crm.Sdk;
  8. using Microsoft.Crm.SdkTypeProxy;
  9. using Microsoft.Crm.SdkTypeProxy.Metadata;
  10. using System.Collections;
  11. using Microsoft.Crm.Sdk.Query;
  12. using Oracle.DataAccess.Client;
  13. using Oracle.DataAccess.Types;
  14. using System.ComponentModel;
  15. using System.Data;
  16.  
  17. namespace Plugin_Case
  18. {
  19.     public class plugin
  20.     {
  21.         public class plugin_testHandler : IPlugin
  22.         {
  23.             public void Execute(IPluginExecutionContext context)
  24.             {
  25.                 //try
  26.                 //{
  27.                 DynamicEntity entity = new DynamicEntity();
  28.                 if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
  29.                 {
  30.                     entity = (DynamicEntity)context.InputParameters["Target"];
  31.  
  32.                     //Do some
  33.                     //if (!entity.Properties.Contains("new_1") && entity.Properties.Contains("new_name"))
  34.                     //{
  35.                     //Get PreEntity Image
  36.                     DynamicEntity old_entity = (DynamicEntity)context.PreEntityImages["img"];
  37.  
  38.                     //incident
  39.                     string taip = "incident";
  40.                     Guid keisID = new Guid();
  41.                     string neim = "";
  42.                     Key keiskey = new Key();
  43.                     if (entity.Properties.Contains("incidentid"))
  44.                         keiskey = (Key)entity.Properties["incidentid"];
  45.                     keisID = keiskey.Value;
  46.                     //title
  47.                     if (entity.Properties.Contains("title"))
  48.                         neim = (string)entity.Properties["title"];
  49.                     if (old_entity.Properties.Contains("title"))
  50.                         neim = (string)old_entity.Properties["title"];
  51.  
  52.                     Lookup case_lookup = new Lookup();
  53.                     case_lookup.type = taip;
  54.                     case_lookup.Value = keisID;
  55.                     case_lookup.name = neim;
  56.  
  57.                     bool flagform = false;
  58.                     CrmBoolean flag2 = new CrmBoolean();
  59.                     if (entity.Properties.Contains("new_flag"))
  60.                         flag2 = (CrmBoolean)entity.Properties["new_flag"];
  61.                     flagform = flag2.Value;
  62.                     if (flagform == true)
  63.                     {
  64.                     try
  65.                     {
  66.                         int action = 0;
  67.                         Picklist picklist = new Picklist();
  68.                         if (entity.Properties.Contains("new_action"))
  69.                             picklist = (Picklist)entity.Properties["new_action"];
  70.                         action = picklist.Value;
  71.                         if (action == 2)
  72.                         {
  73.                             //delete
  74.                             Property attrflag2 = new CrmBooleanProperty();
  75.                             ((CrmBooleanProperty)attrflag2).Name = "new_flag3";
  76.                             ((CrmBooleanProperty)attrflag2).Value = new CrmBoolean();
  77.                             ((CrmBooleanProperty)attrflag2).Value.Value = true;
  78.  
  79.                             Property attrflag = new CrmBooleanProperty();
  80.                             ((CrmBooleanProperty)attrflag).Name = "new_flag";
  81.                             ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  82.                             ((CrmBooleanProperty)attrflag).Value.Value = false;
  83.  
  84.                             entity.Properties.Add(attrflag);
  85.                             entity.Properties.Add(attrflag2);
  86.  
  87.  
  88.                             context.InputParameters.Properties["Target"] = entity;
  89.                         }
  90.                         else if (action == 3)
  91.                         {
  92.                             //confirm
  93.                             owner own3r = new owner();
  94.                             string mpsid = "";
  95.                             string subject = "";
  96.                             string dkn = "";
  97.                             string chasssis = "";
  98.  
  99.                             if (entity.Properties.Contains("new_mpsid"))
  100.                                 mpsid = (string)entity.Properties["new_mpsid"];
  101.                             if (old_entity.Properties.Contains("new_mpsid"))
  102.                                 mpsid = (string)old_entity.Properties["new_mpsid"];
  103.  
  104.                             if (entity.Properties.Contains("new_chassis"))
  105.                                 chasssis = (string)entity.Properties["new_chassis"];
  106.                             if (old_entity.Properties.Contains("new_chassis"))
  107.                                 chasssis = (string)old_entity.Properties["new_chassis"];
  108.  
  109.                             if (entity.Properties.Contains("new_regnumber"))
  110.                                 dkn = (string)entity.Properties["new_regnumber"];
  111.                             if (old_entity.Properties.Contains("new_regnumber"))
  112.                                 dkn = (string)old_entity.Properties["new_regnumber"];
  113.  
  114.  
  115.                             Lookup lkp = new Lookup();
  116.                             if (entity.Properties.Contains("subjectid"))
  117.                             {
  118.                                 lkp = (Lookup)old_entity.Properties["subjectid"];
  119.                                 subject = lkp.name;
  120.                             }
  121.                             if (old_entity.Properties.Contains("subjectid"))
  122.                             {
  123.                                 lkp = (Lookup)old_entity.Properties["subjectid"];
  124.                                 subject = lkp.name;
  125.                                 //subject = (string)old_entity.Properties["subjectid"];
  126.                             }
  127.  
  128.                             //!!!check
  129.                             DynamicEntity praznoentity = new DynamicEntity();
  130.                             own3r = getowner(mpsid);
  131.                             Lookup obj_lkp = new Lookup();
  132.                             DynamicEntity existing_object = check_existing_object(dkn, context);
  133.                             if (existing_object.Name != null)
  134.                             {
  135.                                 if (existing_object.Properties.Contains("new_subjectofinsuranceid"))
  136.                                 {
  137.                                     Key accountid_guid = (Key)existing_object.Properties["new_subjectofinsuranceid"];
  138.                                     //accountid = accountid_guid.Value.ToString();
  139.                                     obj_lkp.Value = accountid_guid.Value;
  140.                                 }
  141.                                 if (existing_object.Properties.Contains("new_name"))
  142.                                 {
  143.                                     obj_lkp.name = (string)existing_object.Properties["new_name"];
  144.                                 }
  145.                                 obj_lkp.type = "new_subjectofinsurance";
  146.                             }
  147.                             else
  148.                                 obj_lkp = obj_of_ins(dkn, chasssis, mpsid, subject, context);
  149.  
  150.                             Lookup acc_lkp = new Lookup();
  151.                             DynamicEntity existing_customer = existing_auto_owner(own3r, context);
  152.                             if (existing_customer.Name != null)
  153.                             {
  154.                                 if (own3r.account == true)
  155.                                 {
  156.  
  157.                                     //string accountid = "";
  158.                                     //string accountname = "";
  159.                                     acc_lkp.type = "account";
  160.                                     if (existing_customer.Properties.Contains("accountid"))
  161.                                     {
  162.                                         Key accountid_guid = (Key)existing_customer.Properties["accountid"];
  163.                                         //accountid = accountid_guid.Value.ToString();
  164.                                         acc_lkp.Value = accountid_guid.Value;
  165.                                     }
  166.                                     if (existing_customer.Properties.Contains("name"))
  167.                                     {
  168.                                         acc_lkp.name = (string)existing_customer.Properties["name"];
  169.                                     }
  170.                                 }
  171.                                 else
  172.                                 {
  173.                                     acc_lkp.type = "contact";
  174.                                     if (existing_customer.Properties.Contains("contactid"))
  175.                                     {
  176.                                         Key accountid_guid = (Key)existing_customer.Properties["contactid"];
  177.                                         //accountid = accountid_guid.Value.ToString();
  178.                                         acc_lkp.Value = accountid_guid.Value;
  179.                                     }
  180.                                     if (existing_customer.Properties.Contains("lastname"))
  181.                                     {
  182.                                         acc_lkp.name = (string)existing_customer.Properties["lastname"];
  183.                                     }
  184.                                 }
  185.                             }
  186.  
  187.                             else
  188.                             {
  189.                                 acc_lkp = customer(own3r, context);
  190.                                 create_object_owner(acc_lkp, obj_lkp, own3r, context);
  191.                             }
  192.                             create_postradal(obj_lkp, case_lookup, lkp, context);
  193.                             //createobjectsSsSs
  194.                             //flag
  195.                             Property attrflag = new CrmBooleanProperty();
  196.                             ((CrmBooleanProperty)attrflag).Name = "new_flag2";
  197.                             ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  198.                             ((CrmBooleanProperty)attrflag).Value.Value = true;
  199.  
  200.                             entity.Properties.Add(attrflag);
  201.                             context.InputParameters["Target"] = entity;
  202.  
  203.                         }
  204.                         else if (action == 1)
  205.                         {
  206.                             bool flag = false;
  207.  
  208.                             string regnomer = string.Empty;
  209.                             string shasi = string.Empty;
  210.                             string pnomer = string.Empty;
  211.                             string subject = string.Empty;
  212.                             if (entity.Properties.Contains("new_regnumber"))
  213.                                 regnomer = (string)entity.Properties["new_regnumber"];
  214.                             //if (old_entity.Properties.Contains("new_regnumber"))
  215.                             //     regnomer = (string)old_entity.Properties["new_regnumber"];
  216.                             if (entity.Properties.Contains("new_chassis"))
  217.                                 shasi = (string)entity.Properties["new_chassis"];
  218.                             // if (old_entity.Properties.Contains("new_chassis"))
  219.                             //     shasi = (string)old_entity.Properties["new_chassis"];
  220.                             if (entity.Properties.Contains("new_policynumber"))
  221.                                 pnomer = (string)entity.Properties["new_policynumber"];
  222.                             // if (old_entity.Properties.Contains("new_policynumber"))
  223.                             //     pnomer = (string)old_entity.Properties["new_policynumber"];
  224.                             if (entity.Properties.Contains("subjectid"))
  225.                             {
  226.                                 Lookup lkp = (Lookup)old_entity.Properties["subjectid"];
  227.                                 subject = lkp.name;
  228.                             }
  229.                             if (old_entity.Properties.Contains("subjectid"))
  230.                             {
  231.                                 Lookup lkp = (Lookup)old_entity.Properties["subjectid"];
  232.                                 subject = lkp.name;
  233.                                 //subject = (string)old_entity.Properties["subjectid"];
  234.                             }
  235.                             if ((subject == "ГО на МПС") || (subject == "ГО на МПС 2007"))
  236.                             {
  237.                                 if (regnomer.Length > 0 && flag == false)
  238.                                 {
  239.                                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  240.                                     //string query = "select name from user$ where name is not null";
  241.                                     string query = @"select m.F3000090004, p.NOMER, p.DATEIZDAVANE, p.BEGINDATE, p.ENDDATE, p.PREMIADUE_AMOUNT, p.ID_POLICY, m.F3000090001
  242.                                                     from ORAHDI_INSPOLICY.policies p,
  243.                                                     ORAHDI_INSPOLICY.policy_links l,
  244.                                                     ORAHDI_DOCSYS.R3000090 m,
  245.                                                     ORAHDI_DOCSYS.R3000202 o
  246.                                                     where   p.ID_POLICY = l.ID_POLICY and
  247.                                                             l.ID_OBJECT = o.F3000202001 and
  248.                                                             o.F3000202002 = m.F3000090001 and
  249.                                                         m.F3000090003 = '";
  250.                                     query += regnomer;
  251.                                     query += @"'
  252.                                 order by p.DATEIZDAVANE desc";
  253.                                     OracleConnection con = new OracleConnection(conection);
  254.                                  
  255.                                     con.Open();
  256.  
  257.                                     //try
  258.                                     //{
  259.                                     OracleCommand command = new OracleCommand(query);
  260.                                     command.Connection = con;
  261.                                     command.CommandType = CommandType.Text;
  262.  
  263.                                     OracleDataReader reader = command.ExecuteReader();
  264.  
  265.                                     //OracleDataReader reader = command.ExecuteReader();
  266.                                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  267.                                     adapter.SelectCommand = command;
  268.  
  269.                                     DataSet ds = new DataSet();
  270.                                     adapter.Fill(ds);
  271.                                     string nomer = "";
  272.                                     string rama = "";
  273.                                     string dataizd = "";
  274.                                     string startdata = "";
  275.                                     string enddata = "";
  276.                                     string price = "";
  277.                                     string policyid = "";
  278.  
  279.                                     int countpayed = 0;
  280.                                     int countall = 0;
  281.                                     decimal sum = 0;
  282.                                     string mpsid = "";
  283.                                     danni danni = new danni();
  284.                                     for (int ij = 0; ij < ds.Tables.Count; ij++)
  285.                                     {
  286.                                         //for (int i = 0; i < ds.Tables[ij].Rows.Count; i++)
  287.                                         //{
  288.                                         //Application.DoEvents();
  289.                                         DataRow theRow = ds.Tables[ij].Rows[0];
  290.                                         //label1.Text = theRow["BLANKA"].ToString();
  291.                                         for (int j = 0; j < theRow.Table.Columns.Count; j++)
  292.                                         {
  293.                                             string tmp = theRow[j].ToString();
  294.                                             if (theRow.Table.Columns[j].ToString() == "ID_POLICY" && tmp != null)
  295.                                             {
  296.                                                 policyid = tmp;
  297.                                                 countall = getcount(policyid);
  298.                                                 int x = countall;
  299.                                                 danni = getsumncount(policyid);
  300.                                                 countpayed = (int)danni.count;
  301.                                                 sum = danni.sum;
  302.                                             }
  303.                                             if (theRow.Table.Columns[j].ToString() == "F3000090001" && tmp != null)
  304.                                             {
  305.                                                 mpsid = tmp;
  306.                                                 // int asdasd = 0;
  307.                                             }
  308.                                             if (theRow.Table.Columns[j].ToString() == "NOMER" && tmp != null)
  309.                                             {
  310.                                                 nomer = tmp;
  311.                                                 // int asdasd = 0;
  312.                                             }
  313.                                             if (theRow.Table.Columns[j].ToString() == "F3000090004" && tmp != null)
  314.                                             {
  315.                                                 rama = tmp;
  316.                                                 //int asdasd2 = 0;
  317.                                             }
  318.                                             if (theRow.Table.Columns[j].ToString() == "DATEIZDAVANE" && tmp != null)
  319.                                             {
  320.                                                 dataizd = tmp;
  321.                                                 //int asdasd2 = 0;
  322.                                             }
  323.                                             if (theRow.Table.Columns[j].ToString() == "BEGINDATE" && tmp != null)
  324.                                             {
  325.                                                 startdata = tmp;
  326.                                                 //int asdasd2 = 0;
  327.                                             }
  328.                                             if (theRow.Table.Columns[j].ToString() == "ENDDATE" && tmp != null)
  329.                                             {
  330.                                                 enddata = tmp;
  331.                                                 //int asdasd2 = 0;
  332.                                             }
  333.                                             if (theRow.Table.Columns[j].ToString() == "PREMIADUE_AMOUNT" && tmp != null)
  334.                                             {
  335.                                                 price = tmp;
  336.                                                 //int asdasd2 = 0;
  337.                                             }
  338.                                         }
  339.                                         //}
  340.                                     }
  341.  
  342.                                     con.Close();
  343.                                     CrmNumber number = new CrmNumber(countall - countpayed);
  344.                                     Property attr11 = new CrmNumberProperty();
  345.                                     ((CrmNumberProperty)attr11).Name = "new_countunpayeddefers";
  346.                                     ((CrmNumberProperty)attr11).Value = number;
  347.                                     //new_policypayed
  348.  
  349.                                     Property attr66 = new CrmMoneyProperty();
  350.                                     ((CrmMoneyProperty)attr66).Name = "new_policypayed";
  351.                                     ((CrmMoneyProperty)attr66).Value = new CrmMoney();
  352.                                     ((CrmMoneyProperty)attr66).Value.Value = sum;
  353.                                     //
  354.                                     Property attr667 = new CrmMoneyProperty();
  355.                                     ((CrmMoneyProperty)attr667).Name = "new_policynotpayed";
  356.                                     ((CrmMoneyProperty)attr667).Value = new CrmMoney();
  357.                                     ((CrmMoneyProperty)attr667).Value.Value = Convert.ToDecimal(price) - sum;
  358.  
  359.  
  360.                                     Property attr = new StringProperty();
  361.                                     ((StringProperty)attr).Name = "new_chassis";
  362.                                     ((StringProperty)attr).Value = rama;
  363.  
  364.                                     Property attr2 = new StringProperty();
  365.                                     ((StringProperty)attr2).Name = "new_policynumber";
  366.                                     ((StringProperty)attr2).Value = nomer;
  367.                                     //convert
  368.                                     //try
  369.                                     //{
  370.                                     DateTime date_izd = DateTime.Parse(dataizd);
  371.                                     DateTime date_start = DateTime.Parse(startdata);
  372.                                     DateTime date_end = DateTime.Parse(enddata);
  373.                                     //int x = 0;
  374.                                     dataizd = "";
  375.                                     startdata = "";
  376.                                     enddata = "";
  377.                                     dataizd += date_izd.Month.ToString() + "/" + date_izd.Day.ToString() + "/" + date_izd.Year.ToString();
  378.                                     startdata += date_start.Month.ToString() + "/" + date_start.Day.ToString() + "/" + date_start.Year.ToString();
  379.                                     enddata += date_end.Month.ToString() + "/" + date_end.Day.ToString() + "/" + date_end.Year.ToString();
  380.                                     /*}
  381.                                     catch
  382.                                     {
  383.                                         //
  384.                                     }*/
  385.                                     Property attr3 = new CrmDateTimeProperty();
  386.                                     ((CrmDateTimeProperty)attr3).Name = "new_policyvalidfrom";
  387.                                     ((CrmDateTimeProperty)attr3).Value = new CrmDateTime();
  388.                                     ((CrmDateTimeProperty)attr3).Value.Value = startdata;
  389.  
  390.  
  391.                                     Property attr4 = new CrmDateTimeProperty();
  392.                                     ((CrmDateTimeProperty)attr4).Name = "new_policyvalidto";
  393.                                     ((CrmDateTimeProperty)attr4).Value = new CrmDateTime();
  394.                                     ((CrmDateTimeProperty)attr4).Value.Value = enddata;
  395.  
  396.                                     Property attr5 = new CrmDateTimeProperty();
  397.                                     ((CrmDateTimeProperty)attr5).Name = "new_policyreleaseddate";
  398.                                     ((CrmDateTimeProperty)attr5).Value = new CrmDateTime();
  399.                                     ((CrmDateTimeProperty)attr5).Value.Value = dataizd;
  400.  
  401.                                     Property attr6 = new CrmMoneyProperty();
  402.                                     ((CrmMoneyProperty)attr6).Name = "new_policyprice";
  403.                                     ((CrmMoneyProperty)attr6).Value = new CrmMoney();
  404.                                     ((CrmMoneyProperty)attr6).Value.Value = Convert.ToDecimal(price);
  405.  
  406.                                     DynamicEntity entityaccount = GetOffice(nomer, context);
  407.                                     string accountid = "";
  408.                                     string accountname = "";
  409.                                     if (entityaccount.Properties.Contains("accountid"))
  410.                                     {
  411.                                         Key accountid_guid = (Key)entityaccount.Properties["accountid"];
  412.                                         accountid = accountid_guid.Value.ToString();
  413.                                     }
  414.                                     if (entityaccount.Properties.Contains("name"))
  415.                                     {
  416.                                         accountname = (string)entityaccount.Properties["name"];
  417.                                     }
  418.                                     Guid accid = new Guid(accountid);
  419.                                     Property attr7 = new LookupProperty();
  420.                                     ((LookupProperty)attr7).Name = "new_releasedinofficeid";
  421.                                     ((LookupProperty)attr7).Value = new Lookup();
  422.                                     ((LookupProperty)attr7).Value.Value = accid;
  423.                                     ((LookupProperty)attr7).Value.name = accountname;
  424.                                     ((LookupProperty)attr7).Value.type = "account";
  425.  
  426.                                     Property attr123 = new StringProperty();
  427.                                     ((StringProperty)attr123).Name = "new_mpsid";
  428.                                     ((StringProperty)attr123).Value = mpsid;
  429.  
  430.                                     Property attrflag = new CrmBooleanProperty();
  431.                                     ((CrmBooleanProperty)attrflag).Name = "new_flag";
  432.                                     ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  433.                                     ((CrmBooleanProperty)attrflag).Value.Value = false;
  434.  
  435.                                     entity.Properties.Add(attrflag);
  436.                                     entity.Properties.Add(attr123);
  437.                                     entity.Properties.Add(attr);
  438.                                     entity.Properties.Add(attr2);
  439.                                     entity.Properties.Add(attr3);
  440.                                     entity.Properties.Add(attr4);
  441.                                     entity.Properties.Add(attr5);
  442.                                     entity.Properties.Add(attr6);
  443.                                     entity.Properties.Add(attr7);
  444.                                     entity.Properties.Add(attr11);
  445.                                     entity.Properties.Add(attr66);
  446.                                     entity.Properties.Add(attr667);
  447.  
  448.                                     context.InputParameters["Target"] = entity;
  449.                                     flag = true;
  450.  
  451.                                 }
  452.                                 if (shasi.Length > 0 && flag == false)
  453.                                 {
  454.                                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  455.                                     //string query = "select name from user$ where name is not null";
  456.                                     string query = @"select m.F3000090003, p.NOMER, p.DATEIZDAVANE, p.BEGINDATE, p.ENDDATE, p.PREMIADUE_AMOUNT, p.ID_POLICY, m.F3000090001
  457.                                                     from ORAHDI_INSPOLICY.policies p,
  458.                                                     ORAHDI_INSPOLICY.policy_links l,
  459.                                                     ORAHDI_DOCSYS.R3000090 m,
  460.                                                     ORAHDI_DOCSYS.R3000202 o
  461.                                                     where   p.ID_POLICY = l.ID_POLICY and
  462.                                                             l.ID_OBJECT = o.F3000202001 and
  463.                                                             o.F3000202002 = m.F3000090001 and
  464.                                                         m.F3000090004 = '";
  465.                                     query += shasi;
  466.                                     query += @"'
  467.                                 order by p.DATEIZDAVANE desc";
  468.                                     OracleConnection con = new OracleConnection(conection);
  469.                                     con.Open();
  470.  
  471.                                     //try
  472.                                     //{
  473.                                     OracleCommand command = new OracleCommand(query);
  474.                                     command.Connection = con;
  475.                                     command.CommandType = CommandType.Text;
  476.  
  477.                                     OracleDataReader reader = command.ExecuteReader();
  478.  
  479.                                     //OracleDataReader reader = command.ExecuteReader();
  480.                                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  481.                                     adapter.SelectCommand = command;
  482.  
  483.                                     DataSet ds = new DataSet();
  484.                                     adapter.Fill(ds);
  485.                                     string mpsid = "";
  486.                                     string nomer = "";
  487.                                     string mps_no = "";
  488.                                     string dataizd = "";
  489.                                     string startdata = "";
  490.                                     string enddata = "";
  491.                                     string price = "";
  492.                                     string policyid = "";
  493.                                     int countpayed = 0;
  494.                                     int countall = 0;
  495.                                     decimal sum = 0;
  496.                                     danni danni = new danni();
  497.                                     for (int ij = 0; ij < ds.Tables.Count; ij++)
  498.                                     {
  499.                                         //for (int i = 0; i < ds.Tables[ij].Rows.Count; i++)
  500.                                         //{
  501.                                         //Application.DoEvents();
  502.                                         DataRow theRow = ds.Tables[ij].Rows[0];
  503.                                         //label1.Text = theRow["BLANKA"].ToString();
  504.                                         for (int j = 0; j < theRow.Table.Columns.Count; j++)
  505.                                         {
  506.                                             string tmp = theRow[j].ToString();
  507.                                             if (theRow.Table.Columns[j].ToString() == "ID_POLICY" && tmp != null)
  508.                                             {
  509.                                                 policyid = tmp;
  510.                                                 countall = getcount(policyid);
  511.                                                 int x = countall;
  512.                                                 danni = getsumncount(policyid);
  513.                                                 countpayed = (int)danni.count;
  514.                                                 sum = danni.sum;
  515.                                             }
  516.                                             //string tmp = theRow[j].ToString();
  517.                                             if (theRow.Table.Columns[j].ToString() == "NOMER" && tmp != null)
  518.                                             {
  519.                                                 nomer = tmp;
  520.                                                 // int asdasd = 0;
  521.                                             }
  522.                                             if (theRow.Table.Columns[j].ToString() == "F3000090001" && tmp != null)
  523.                                             {
  524.                                                 mpsid = tmp;
  525.                                                 // int asdasd = 0;
  526.                                             }
  527.                                             if (theRow.Table.Columns[j].ToString() == "F3000090003" && tmp != null)
  528.                                             {
  529.                                                 mps_no = tmp;
  530.                                                 //int asdasd2 = 0;
  531.                                             }
  532.                                             if (theRow.Table.Columns[j].ToString() == "DATEIZDAVANE" && tmp != null)
  533.                                             {
  534.                                                 dataizd = tmp;
  535.                                                 //int asdasd2 = 0;
  536.                                             }
  537.                                             if (theRow.Table.Columns[j].ToString() == "BEGINDATE" && tmp != null)
  538.                                             {
  539.                                                 startdata = tmp;
  540.                                                 //int asdasd2 = 0;
  541.                                             }
  542.                                             if (theRow.Table.Columns[j].ToString() == "ENDDATE" && tmp != null)
  543.                                             {
  544.                                                 enddata = tmp;
  545.                                                 //int asdasd2 = 0;
  546.                                             }
  547.                                             if (theRow.Table.Columns[j].ToString() == "PREMIADUE_AMOUNT" && tmp != null)
  548.                                             {
  549.                                                 price = tmp;
  550.                                                 //int asdasd2 = 0;
  551.                                             }
  552.                                         }
  553.                                         //}
  554.                                     }
  555.  
  556.                                     con.Close();
  557.                                     CrmNumber number = new CrmNumber(countall - countpayed);
  558.                                     Property attr11 = new CrmNumberProperty();
  559.                                     ((CrmNumberProperty)attr11).Name = "new_countunpayeddefers";
  560.                                     ((CrmNumberProperty)attr11).Value = number;
  561.                                     //new_policypayed
  562.  
  563.                                     Property attr66 = new CrmMoneyProperty();
  564.                                     ((CrmMoneyProperty)attr66).Name = "new_policypayed";
  565.                                     ((CrmMoneyProperty)attr66).Value = new CrmMoney();
  566.                                     ((CrmMoneyProperty)attr66).Value.Value = sum;
  567.                                     //
  568.                                     Property attr667 = new CrmMoneyProperty();
  569.                                     ((CrmMoneyProperty)attr667).Name = "new_policynotpayed";
  570.                                     ((CrmMoneyProperty)attr667).Value = new CrmMoney();
  571.                                     ((CrmMoneyProperty)attr667).Value.Value = Convert.ToDecimal(price) - sum;
  572.  
  573.                                     Property attr = new StringProperty();
  574.                                     ((StringProperty)attr).Name = "new_regnumber";
  575.                                     ((StringProperty)attr).Value = mps_no;
  576.  
  577.                                     Property attr2 = new StringProperty();
  578.                                     ((StringProperty)attr2).Name = "new_policynumber";
  579.                                     ((StringProperty)attr2).Value = nomer;
  580.                                     //convert
  581.                                     //try
  582.                                     //{
  583.                                     DateTime date_izd = DateTime.Parse(dataizd);
  584.                                     DateTime date_start = DateTime.Parse(startdata);
  585.                                     DateTime date_end = DateTime.Parse(enddata);
  586.                                     //int x = 0;
  587.                                     dataizd = "";
  588.                                     startdata = "";
  589.                                     enddata = "";
  590.                                     dataizd += date_izd.Month.ToString() + "/" + date_izd.Day.ToString() + "/" + date_izd.Year.ToString();
  591.                                     startdata += date_start.Month.ToString() + "/" + date_start.Day.ToString() + "/" + date_start.Year.ToString();
  592.                                     enddata += date_end.Month.ToString() + "/" + date_end.Day.ToString() + "/" + date_end.Year.ToString();
  593.                                     /*}
  594.                                     catch
  595.                                     {
  596.                                         //
  597.                                     }*/
  598.                                     Property attr3 = new CrmDateTimeProperty();
  599.                                     ((CrmDateTimeProperty)attr3).Name = "new_policyvalidfrom";
  600.                                     ((CrmDateTimeProperty)attr3).Value = new CrmDateTime();
  601.                                     ((CrmDateTimeProperty)attr3).Value.Value = startdata;
  602.  
  603.  
  604.                                     Property attr4 = new CrmDateTimeProperty();
  605.                                     ((CrmDateTimeProperty)attr4).Name = "new_policyvalidto";
  606.                                     ((CrmDateTimeProperty)attr4).Value = new CrmDateTime();
  607.                                     ((CrmDateTimeProperty)attr4).Value.Value = enddata;
  608.  
  609.                                     Property attr5 = new CrmDateTimeProperty();
  610.                                     ((CrmDateTimeProperty)attr5).Name = "new_policyreleaseddate";
  611.                                     ((CrmDateTimeProperty)attr5).Value = new CrmDateTime();
  612.                                     ((CrmDateTimeProperty)attr5).Value.Value = dataizd;
  613.  
  614.                                     Property attr6 = new CrmMoneyProperty();
  615.                                     ((CrmMoneyProperty)attr6).Name = "new_policyprice";
  616.                                     ((CrmMoneyProperty)attr6).Value = new CrmMoney();
  617.                                     ((CrmMoneyProperty)attr6).Value.Value = Convert.ToDecimal(price);
  618.  
  619.                                     DynamicEntity entityaccount = GetOffice(nomer, context);
  620.                                     string accountid = "";
  621.                                     string accountname = "";
  622.                                     if (entityaccount.Properties.Contains("accountid"))
  623.                                     {
  624.                                         Key accountid_guid = (Key)entityaccount.Properties["accountid"];
  625.                                         accountid = accountid_guid.Value.ToString();
  626.                                     }
  627.                                     if (entityaccount.Properties.Contains("name"))
  628.                                     {
  629.                                         accountname = (string)entityaccount.Properties["name"];
  630.                                     }
  631.                                     Guid accid = new Guid(accountid);
  632.                                     Property attr7 = new LookupProperty();
  633.                                     ((LookupProperty)attr7).Name = "new_releasedinofficeid";
  634.                                     ((LookupProperty)attr7).Value = new Lookup();
  635.                                     ((LookupProperty)attr7).Value.Value = accid;
  636.                                     ((LookupProperty)attr7).Value.name = accountname;
  637.                                     ((LookupProperty)attr7).Value.type = "account";
  638.  
  639.                                     Property attr123 = new StringProperty();
  640.                                     ((StringProperty)attr123).Name = "new_mpsid";
  641.                                     ((StringProperty)attr123).Value = mpsid;
  642.  
  643.                                     Property attrflag = new CrmBooleanProperty();
  644.                                     ((CrmBooleanProperty)attrflag).Name = "new_flag";
  645.                                     ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  646.                                     ((CrmBooleanProperty)attrflag).Value.Value = false;
  647.  
  648.                                     entity.Properties.Add(attrflag);
  649.                                     entity.Properties.Add(attr123);
  650.                                     entity.Properties.Add(attr);
  651.                                     entity.Properties.Add(attr2);
  652.                                     entity.Properties.Add(attr3);
  653.                                     entity.Properties.Add(attr4);
  654.                                     entity.Properties.Add(attr5);
  655.                                     entity.Properties.Add(attr6);
  656.                                     entity.Properties.Add(attr7);
  657.                                     entity.Properties.Add(attr11);
  658.                                     entity.Properties.Add(attr66);
  659.                                     entity.Properties.Add(attr667);
  660.  
  661.  
  662.                                     context.InputParameters["Target"] = entity;
  663.                                     flag = true;
  664.  
  665.                                 }
  666.                                 if (pnomer.Length > 0 && flag == false)
  667.                                 {
  668.                                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  669.                                     //string query = "select name from user$ where name is not null";
  670.                                     string query = @"select m.F3000090004, m.F3000090003, p.NOMER, p.DATEIZDAVANE, p.BEGINDATE, p.ENDDATE, p.PREMIADUE_AMOUNT, p.ID_POLICY, m.F3000090001
  671.                                                     from ORAHDI_INSPOLICY.policies p,
  672.                                                     ORAHDI_INSPOLICY.policy_links l,
  673.                                                     ORAHDI_DOCSYS.R3000090 m,
  674.                                                     ORAHDI_DOCSYS.R3000202 o
  675.                                                     where   p.ID_POLICY = l.ID_POLICY and
  676.                                                             l.ID_OBJECT = o.F3000202001 and
  677.                                                             o.F3000202002 = m.F3000090001 and
  678.                                                             p.BLANKA = '";
  679.                                     query += pnomer;
  680.                                     query += @"'
  681.                                 order by p.DATEIZDAVANE desc";
  682.                                     OracleConnection con = new OracleConnection(conection);
  683.                                     con.Open();
  684.  
  685.                                     //try
  686.                                     //{
  687.                                     OracleCommand command = new OracleCommand(query);
  688.                                     command.Connection = con;
  689.                                     command.CommandType = CommandType.Text;
  690.  
  691.                                     OracleDataReader reader = command.ExecuteReader();
  692.  
  693.                                     //OracleDataReader reader = command.ExecuteReader();
  694.                                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  695.                                     adapter.SelectCommand = command;
  696.  
  697.                                     DataSet ds = new DataSet();
  698.                                     adapter.Fill(ds);
  699.                                     string rama = "";
  700.                                     string nomer = "";
  701.                                     string mps_no = "";
  702.                                     string dataizd = "";
  703.                                     string startdata = "";
  704.                                     string enddata = "";
  705.                                     string price = "";
  706.                                     string policyid = "";
  707.                                     int countpayed = 0;
  708.                                     int countall = 0;
  709.                                     decimal sum = 0;
  710.                                     string mpsid = "";
  711.                                     danni danni = new danni();
  712.                                     for (int ij = 0; ij < ds.Tables.Count; ij++)
  713.                                     {
  714.                                         //for (int i = 0; i < ds.Tables[ij].Rows.Count; i++)
  715.                                         //{
  716.                                         //Application.DoEvents();
  717.                                         DataRow theRow = ds.Tables[ij].Rows[0];
  718.                                         //label1.Text = theRow["BLANKA"].ToString();
  719.                                         for (int j = 0; j < theRow.Table.Columns.Count; j++)
  720.                                         {
  721.                                             string tmp = theRow[j].ToString();
  722.                                             if (theRow.Table.Columns[j].ToString() == "ID_POLICY" && tmp != null)
  723.                                             {
  724.                                                 policyid = tmp;
  725.                                                 countall = getcount(policyid);
  726.                                                 int x = countall;
  727.                                                 danni = getsumncount(policyid);
  728.                                                 countpayed = (int)danni.count;
  729.                                                 sum = danni.sum;
  730.                                             }
  731.                                             if (theRow.Table.Columns[j].ToString() == "NOMER" && tmp != null)
  732.                                             {
  733.                                                 nomer = tmp;
  734.                                                 //int asdasd = 0;
  735.                                             }
  736.                                             if (theRow.Table.Columns[j].ToString() == "F3000090001" && tmp != null)
  737.                                             {
  738.                                                 mpsid = tmp;
  739.                                                 // int asdasd = 0;
  740.                                             }
  741.                                             if (theRow.Table.Columns[j].ToString() == "F3000090003" && tmp != null)
  742.                                             {
  743.                                                 mps_no = tmp;
  744.                                                 //int asdasd2 = 0;
  745.                                             }
  746.                                             if (theRow.Table.Columns[j].ToString() == "F3000090004" && tmp != null)
  747.                                             {
  748.                                                 rama = tmp;
  749.                                                 //int asdasd2 = 0;
  750.                                             }
  751.                                             if (theRow.Table.Columns[j].ToString() == "DATEIZDAVANE" && tmp != null)
  752.                                             {
  753.                                                 dataizd = tmp;
  754.                                                 //int asdasd2 = 0;
  755.                                             }
  756.                                             if (theRow.Table.Columns[j].ToString() == "BEGINDATE" && tmp != null)
  757.                                             {
  758.                                                 startdata = tmp;
  759.                                                 //int asdasd2 = 0;
  760.                                             }
  761.                                             if (theRow.Table.Columns[j].ToString() == "ENDDATE" && tmp != null)
  762.                                             {
  763.                                                 enddata = tmp;
  764.                                                 //int asdasd2 = 0;
  765.                                             }
  766.                                             if (theRow.Table.Columns[j].ToString() == "PREMIADUE_AMOUNT" && tmp != null)
  767.                                             {
  768.                                                 price = tmp;
  769.                                                 //int asdasd2 = 0;
  770.                                             }
  771.                                         }
  772.                                         //}
  773.                                     }
  774.  
  775.                                     con.Close();
  776.  
  777.                                     CrmNumber number = new CrmNumber(countall - countpayed);
  778.                                     Property attr11 = new CrmNumberProperty();
  779.                                     ((CrmNumberProperty)attr11).Name = "new_countunpayeddefers";
  780.                                     ((CrmNumberProperty)attr11).Value = number;
  781.                                     //new_policypayed
  782.  
  783.                                     Property attr66 = new CrmMoneyProperty();
  784.                                     ((CrmMoneyProperty)attr66).Name = "new_policypayed";
  785.                                     ((CrmMoneyProperty)attr66).Value = new CrmMoney();
  786.                                     ((CrmMoneyProperty)attr66).Value.Value = sum;
  787.                                     //
  788.                                     Property attr667 = new CrmMoneyProperty();
  789.                                     ((CrmMoneyProperty)attr667).Name = "new_policynotpayed";
  790.                                     ((CrmMoneyProperty)attr667).Value = new CrmMoney();
  791.                                     ((CrmMoneyProperty)attr667).Value.Value = Convert.ToDecimal(price) - sum;
  792.  
  793.                                     Property attr = new StringProperty();
  794.                                     ((StringProperty)attr).Name = "new_regnumber";
  795.                                     ((StringProperty)attr).Value = mps_no;
  796.  
  797.                                     Property attr8 = new StringProperty();
  798.                                     ((StringProperty)attr8).Name = "new_chassis";
  799.                                     ((StringProperty)attr8).Value = rama;
  800.  
  801.                                     Property attr2 = new StringProperty();
  802.                                     ((StringProperty)attr2).Name = "new_policynumber";
  803.                                     ((StringProperty)attr2).Value = nomer;
  804.                                     //convert
  805.                                     //try
  806.                                     //{
  807.                                     DateTime date_izd = DateTime.Parse(dataizd);
  808.                                     DateTime date_start = DateTime.Parse(startdata);
  809.                                     DateTime date_end = DateTime.Parse(enddata);
  810.                                     //int x = 0;
  811.                                     dataizd = "";
  812.                                     startdata = "";
  813.                                     enddata = "";
  814.                                     dataizd += date_izd.Month.ToString() + "/" + date_izd.Day.ToString() + "/" + date_izd.Year.ToString();
  815.                                     startdata += date_start.Month.ToString() + "/" + date_start.Day.ToString() + "/" + date_start.Year.ToString();
  816.                                     enddata += date_end.Month.ToString() + "/" + date_end.Day.ToString() + "/" + date_end.Year.ToString();
  817.                                     /*}
  818.                                     catch
  819.                                     {
  820.                                         //
  821.                                     }*/
  822.                                     Property attr3 = new CrmDateTimeProperty();
  823.                                     ((CrmDateTimeProperty)attr3).Name = "new_policyvalidfrom";
  824.                                     ((CrmDateTimeProperty)attr3).Value = new CrmDateTime();
  825.                                     ((CrmDateTimeProperty)attr3).Value.Value = startdata;
  826.  
  827.  
  828.                                     Property attr4 = new CrmDateTimeProperty();
  829.                                     ((CrmDateTimeProperty)attr4).Name = "new_policyvalidto";
  830.                                     ((CrmDateTimeProperty)attr4).Value = new CrmDateTime();
  831.                                     ((CrmDateTimeProperty)attr4).Value.Value = enddata;
  832.  
  833.                                     Property attr5 = new CrmDateTimeProperty();
  834.                                     ((CrmDateTimeProperty)attr5).Name = "new_policyreleaseddate";
  835.                                     ((CrmDateTimeProperty)attr5).Value = new CrmDateTime();
  836.                                     ((CrmDateTimeProperty)attr5).Value.Value = dataizd;
  837.  
  838.                                     Property attr6 = new CrmMoneyProperty();
  839.                                     ((CrmMoneyProperty)attr6).Name = "new_policyprice";
  840.                                     ((CrmMoneyProperty)attr6).Value = new CrmMoney();
  841.                                     ((CrmMoneyProperty)attr6).Value.Value = Convert.ToDecimal(price);
  842.  
  843.                                     DynamicEntity entityaccount = GetOffice(nomer, context);
  844.                                     string accountid = "";
  845.                                     string accountname = "";
  846.                                     if (entityaccount.Properties.Contains("accountid"))
  847.                                     {
  848.                                         Key accountid_guid = (Key)entityaccount.Properties["accountid"];
  849.                                         accountid = accountid_guid.Value.ToString();
  850.                                     }
  851.                                     if (entityaccount.Properties.Contains("name"))
  852.                                     {
  853.                                         accountname = (string)entityaccount.Properties["name"];
  854.                                     }
  855.                                     Guid accid = new Guid(accountid);
  856.                                     Property attr7 = new LookupProperty();
  857.                                     ((LookupProperty)attr7).Name = "new_releasedinofficeid";
  858.                                     ((LookupProperty)attr7).Value = new Lookup();
  859.                                     ((LookupProperty)attr7).Value.Value = accid;
  860.                                     ((LookupProperty)attr7).Value.name = accountname;
  861.                                     ((LookupProperty)attr7).Value.type = "account";
  862.  
  863.                                     Property attr123 = new StringProperty();
  864.                                     ((StringProperty)attr123).Name = "new_mpsid";
  865.                                     ((StringProperty)attr123).Value = mpsid;
  866.  
  867.                                     Property attrflag = new CrmBooleanProperty();
  868.                                     ((CrmBooleanProperty)attrflag).Name = "new_flag";
  869.                                     ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  870.                                     ((CrmBooleanProperty)attrflag).Value.Value = false;
  871.  
  872.                                     entity.Properties.Add(attrflag);
  873.                                     entity.Properties.Add(attr123);
  874.                                     entity.Properties.Add(attr);
  875.                                     entity.Properties.Add(attr2);
  876.                                     entity.Properties.Add(attr3);
  877.                                     entity.Properties.Add(attr4);
  878.                                     entity.Properties.Add(attr5);
  879.                                     entity.Properties.Add(attr6);
  880.                                     entity.Properties.Add(attr7);
  881.                                     entity.Properties.Add(attr8);
  882.                                     entity.Properties.Add(attr11);
  883.                                     entity.Properties.Add(attr66);
  884.                                     entity.Properties.Add(attr667);
  885.  
  886.                                     context.InputParameters["Target"] = entity;
  887.                                     flag = true;
  888.  
  889.                                 }
  890.                             }
  891.                             else if (subject == "Каско на МПС")
  892.                             {
  893.                                 if (regnomer.Length > 0 && flag == false)
  894.                                 {
  895.                                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  896.                                     //string query = "select name from user$ where name is not null";
  897.                                     string query = @"select m.F3000090004, p.NOMER, p.DATEIZDAVANE, p.BEGINDATE, p.ENDDATE, p.PREMIADUE_AMOUNT, p.ID_POLICY, m.F3000090001, o.FA3000102013
  898.                                                     from ORAHDI_INSPOLICY.policies p,
  899.                                                     ORAHDI_INSPOLICY.policy_links l,
  900.                                                     ORAHDI_DOCSYS.R3000090 m,
  901.                                                     ORAHDI_DOCSYS.R3000102 o
  902.                                                     where   p.ID_POLICY = l.ID_POLICY and
  903.                                                             l.ID_OBJECT = o.F3000102001 and
  904.                                                             o.F3000102002 = m.F3000090001 and
  905.                                                         m.F3000090003 = '";
  906.                                     query += regnomer;
  907.                                     query += @"'
  908.                                 order by p.DATEIZDAVANE desc";
  909.                                     OracleConnection con = new OracleConnection(conection);
  910.                                     con.Open();
  911.  
  912.                                     //try
  913.                                     //{
  914.                                     OracleCommand command = new OracleCommand(query);
  915.                                     command.Connection = con;
  916.                                     command.CommandType = CommandType.Text;
  917.  
  918.                                     OracleDataReader reader = command.ExecuteReader();
  919.  
  920.                                     //OracleDataReader reader = command.ExecuteReader();
  921.                                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  922.                                     adapter.SelectCommand = command;
  923.  
  924.                                     DataSet ds = new DataSet();
  925.                                     adapter.Fill(ds);
  926.                                     string nomer = "";
  927.                                     string rama = "";
  928.                                     string dataizd = "";
  929.                                     string startdata = "";
  930.                                     string enddata = "";
  931.                                     string price = "";
  932.                                     string policyid = "";
  933.                                     int countpayed = 0;
  934.                                     int countall = 0;
  935.                                     decimal sum = 0;
  936.                                     string inssum = "";
  937.                                     string mpsid = "";
  938.                                     danni danni = new danni();
  939.                                     for (int ij = 0; ij < ds.Tables.Count; ij++)
  940.                                     {
  941.                                         //for (int i = 0; i < ds.Tables[ij].Rows.Count; i++)
  942.                                         //{
  943.                                         //Application.DoEvents();
  944.                                         DataRow theRow = ds.Tables[ij].Rows[0];
  945.                                         //label1.Text = theRow["BLANKA"].ToString();
  946.                                         for (int j = 0; j < theRow.Table.Columns.Count; j++)
  947.                                         {
  948.                                             string tmp = theRow[j].ToString();
  949.                                             if (theRow.Table.Columns[j].ToString() == "ID_POLICY" && tmp != null)
  950.                                             {
  951.                                                 policyid = tmp;
  952.                                                 countall = getcount(policyid);
  953.                                                 int x = countall;
  954.                                                 danni = getsumncount(policyid);
  955.                                                 countpayed = (int)danni.count;
  956.                                                 sum = danni.sum;
  957.                                             }
  958.                                             if (theRow.Table.Columns[j].ToString() == "NOMER" && tmp != null)
  959.                                             {
  960.                                                 nomer = tmp;
  961.                                                 // int asdasd = 0;
  962.                                             }
  963.                                             if (theRow.Table.Columns[j].ToString() == "F3000090001" && tmp != null)
  964.                                             {
  965.                                                 mpsid = tmp;
  966.                                                 // int asdasd = 0;
  967.                                             }
  968.                                             if (theRow.Table.Columns[j].ToString() == "F3000090004" && tmp != null)
  969.                                             {
  970.                                                 rama = tmp;
  971.                                                 //int asdasd2 = 0;
  972.                                             }
  973.                                             if (theRow.Table.Columns[j].ToString() == "DATEIZDAVANE" && tmp != null)
  974.                                             {
  975.                                                 dataizd = tmp;
  976.                                                 //int asdasd2 = 0;
  977.                                             }
  978.                                             if (theRow.Table.Columns[j].ToString() == "BEGINDATE" && tmp != null)
  979.                                             {
  980.                                                 startdata = tmp;
  981.                                                 //int asdasd2 = 0;
  982.                                             }
  983.                                             if (theRow.Table.Columns[j].ToString() == "ENDDATE" && tmp != null)
  984.                                             {
  985.                                                 enddata = tmp;
  986.                                                 //int asdasd2 = 0;
  987.                                             }
  988.                                             if (theRow.Table.Columns[j].ToString() == "PREMIADUE_AMOUNT" && tmp != null)
  989.                                             {
  990.                                                 price = tmp;
  991.                                                 //int asdasd2 = 0;
  992.                                             }
  993.                                             if (theRow.Table.Columns[j].ToString() == "FA3000102013" && tmp != null)
  994.                                             {
  995.                                                 inssum = tmp;
  996.                                                 //int asdasd2 = 0;
  997.                                             }
  998.                                         }
  999.                                         //}
  1000.                                     }
  1001.                                     //
  1002.                                     con.Close();
  1003.  
  1004.                                     Property attr166 = new CrmMoneyProperty();
  1005.                                     ((CrmMoneyProperty)attr166).Name = "new_policyinsurancesum";
  1006.                                     ((CrmMoneyProperty)attr166).Value = new CrmMoney();
  1007.                                     ((CrmMoneyProperty)attr166).Value.Value = Convert.ToDecimal(inssum);
  1008.  
  1009.                                     CrmNumber number = new CrmNumber(countall - countpayed);
  1010.                                     Property attr11 = new CrmNumberProperty();
  1011.                                     ((CrmNumberProperty)attr11).Name = "new_countunpayeddefers";
  1012.                                     ((CrmNumberProperty)attr11).Value = number;
  1013.                                     //new_policypayed
  1014.  
  1015.                                     Property attr66 = new CrmMoneyProperty();
  1016.                                     ((CrmMoneyProperty)attr66).Name = "new_policypayed";
  1017.                                     ((CrmMoneyProperty)attr66).Value = new CrmMoney();
  1018.                                     ((CrmMoneyProperty)attr66).Value.Value = sum;
  1019.                                     //
  1020.                                     Property attr667 = new CrmMoneyProperty();
  1021.                                     ((CrmMoneyProperty)attr667).Name = "new_policynotpayed";
  1022.                                     ((CrmMoneyProperty)attr667).Value = new CrmMoney();
  1023.                                     ((CrmMoneyProperty)attr667).Value.Value = Convert.ToDecimal(price) - sum;
  1024.  
  1025.  
  1026.                                     Property attr = new StringProperty();
  1027.                                     ((StringProperty)attr).Name = "new_chassis";
  1028.                                     ((StringProperty)attr).Value = rama;
  1029.  
  1030.                                     Property attr2 = new StringProperty();
  1031.                                     ((StringProperty)attr2).Name = "new_policynumber";
  1032.                                     ((StringProperty)attr2).Value = nomer;
  1033.                                     //convert
  1034.                                     //try
  1035.                                     //{
  1036.                                     DateTime date_izd = DateTime.Parse(dataizd);
  1037.                                     DateTime date_start = DateTime.Parse(startdata);
  1038.                                     DateTime date_end = DateTime.Parse(enddata);
  1039.                                     //int x = 0;
  1040.                                     dataizd = "";
  1041.                                     startdata = "";
  1042.                                     enddata = "";
  1043.                                     dataizd += date_izd.Month.ToString() + "/" + date_izd.Day.ToString() + "/" + date_izd.Year.ToString();
  1044.                                     startdata += date_start.Month.ToString() + "/" + date_start.Day.ToString() + "/" + date_start.Year.ToString();
  1045.                                     enddata += date_end.Month.ToString() + "/" + date_end.Day.ToString() + "/" + date_end.Year.ToString();
  1046.                                     /*}
  1047.                                     catch
  1048.                                     {
  1049.                                         //
  1050.                                     }*/
  1051.                                     Property attr3 = new CrmDateTimeProperty();
  1052.                                     ((CrmDateTimeProperty)attr3).Name = "new_policyvalidfrom";
  1053.                                     ((CrmDateTimeProperty)attr3).Value = new CrmDateTime();
  1054.                                     ((CrmDateTimeProperty)attr3).Value.Value = startdata;
  1055.  
  1056.  
  1057.                                     Property attr4 = new CrmDateTimeProperty();
  1058.                                     ((CrmDateTimeProperty)attr4).Name = "new_policyvalidto";
  1059.                                     ((CrmDateTimeProperty)attr4).Value = new CrmDateTime();
  1060.                                     ((CrmDateTimeProperty)attr4).Value.Value = enddata;
  1061.  
  1062.                                     Property attr5 = new CrmDateTimeProperty();
  1063.                                     ((CrmDateTimeProperty)attr5).Name = "new_policyreleaseddate";
  1064.                                     ((CrmDateTimeProperty)attr5).Value = new CrmDateTime();
  1065.                                     ((CrmDateTimeProperty)attr5).Value.Value = dataizd;
  1066.  
  1067.                                     Property attr6 = new CrmMoneyProperty();
  1068.                                     ((CrmMoneyProperty)attr6).Name = "new_policyprice";
  1069.                                     ((CrmMoneyProperty)attr6).Value = new CrmMoney();
  1070.                                     ((CrmMoneyProperty)attr6).Value.Value = Convert.ToDecimal(price);
  1071.  
  1072.                                     DynamicEntity entityaccount = GetOffice(nomer, context);
  1073.                                     string accountid = "";
  1074.                                     string accountname = "";
  1075.                                     if (entityaccount.Properties.Contains("accountid"))
  1076.                                     {
  1077.                                         Key accountid_guid = (Key)entityaccount.Properties["accountid"];
  1078.                                         accountid = accountid_guid.Value.ToString();
  1079.                                     }
  1080.                                     if (entityaccount.Properties.Contains("name"))
  1081.                                     {
  1082.                                         accountname = (string)entityaccount.Properties["name"];
  1083.                                     }
  1084.                                     Guid accid = new Guid(accountid);
  1085.                                     Property attr7 = new LookupProperty();
  1086.                                     ((LookupProperty)attr7).Name = "new_releasedinofficeid";
  1087.                                     ((LookupProperty)attr7).Value = new Lookup();
  1088.                                     ((LookupProperty)attr7).Value.Value = accid;
  1089.                                     ((LookupProperty)attr7).Value.name = accountname;
  1090.                                     ((LookupProperty)attr7).Value.type = "account";
  1091.  
  1092.                                     Property attr123 = new StringProperty();
  1093.                                     ((StringProperty)attr123).Name = "new_mpsid";
  1094.                                     ((StringProperty)attr123).Value = mpsid;
  1095.  
  1096.                                     Property attrflag = new CrmBooleanProperty();
  1097.                                     ((CrmBooleanProperty)attrflag).Name = "new_flag";
  1098.                                     ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  1099.                                     ((CrmBooleanProperty)attrflag).Value.Value = false;
  1100.  
  1101.                                     entity.Properties.Add(attrflag);
  1102.                                     entity.Properties.Add(attr123);
  1103.                                     entity.Properties.Add(attr);
  1104.                                     entity.Properties.Add(attr2);
  1105.                                     entity.Properties.Add(attr3);
  1106.                                     entity.Properties.Add(attr4);
  1107.                                     entity.Properties.Add(attr5);
  1108.                                     entity.Properties.Add(attr6);
  1109.                                     entity.Properties.Add(attr7);
  1110.                                     entity.Properties.Add(attr11);
  1111.                                     entity.Properties.Add(attr66);
  1112.                                     entity.Properties.Add(attr667);
  1113.                                     entity.Properties.Add(attr166);
  1114.  
  1115.                                     context.InputParameters["Target"] = entity;
  1116.                                     flag = true;
  1117.  
  1118.                                 }
  1119.                                 if (shasi.Length > 0 && flag == false)
  1120.                                 {
  1121.                                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  1122.                                     //string query = "select name from user$ where name is not null";
  1123.                                     string query = @"select m.F3000090003, p.NOMER, p.DATEIZDAVANE, p.BEGINDATE, p.ENDDATE, p.PREMIADUE_AMOUNT, p.ID_POLICY, m.F3000090001, o.FA3000102013
  1124.                                                     from ORAHDI_INSPOLICY.policies p,
  1125.                                                     ORAHDI_INSPOLICY.policy_links l,
  1126.                                                     ORAHDI_DOCSYS.R3000090 m,
  1127.                                                     ORAHDI_DOCSYS.R3000102 o
  1128.                                                     where   p.ID_POLICY = l.ID_POLICY and
  1129.                                                             l.ID_OBJECT = o.F3000102001 and
  1130.                                                             o.F3000102002 = m.F3000090001 and
  1131.                                                         m.F3000090004 = '";
  1132.                                     query += shasi;
  1133.                                     query += @"'
  1134.                                 order by p.DATEIZDAVANE desc";
  1135.                                     OracleConnection con = new OracleConnection(conection);
  1136.                                     con.Open();
  1137.  
  1138.                                     //try
  1139.                                     //{
  1140.                                     OracleCommand command = new OracleCommand(query);
  1141.                                     command.Connection = con;
  1142.                                     command.CommandType = CommandType.Text;
  1143.  
  1144.                                     OracleDataReader reader = command.ExecuteReader();
  1145.  
  1146.                                     //OracleDataReader reader = command.ExecuteReader();
  1147.                                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  1148.                                     adapter.SelectCommand = command;
  1149.  
  1150.                                     DataSet ds = new DataSet();
  1151.                                     adapter.Fill(ds);
  1152.  
  1153.                                     string nomer = "";
  1154.                                     string mps_no = "";
  1155.                                     string dataizd = "";
  1156.                                     string startdata = "";
  1157.                                     string enddata = "";
  1158.                                     string price = "";
  1159.                                     string policyid = "";
  1160.                                     int countpayed = 0;
  1161.                                     int countall = 0;
  1162.                                     decimal sum = 0;
  1163.                                     string inssum = "";
  1164.                                     string mpsid = "";
  1165.                                     danni danni = new danni();
  1166.                                     for (int ij = 0; ij < ds.Tables.Count; ij++)
  1167.                                     {
  1168.                                         //for (int i = 0; i < ds.Tables[ij].Rows.Count; i++)
  1169.                                         //{
  1170.                                         //Application.DoEvents();
  1171.                                         DataRow theRow = ds.Tables[ij].Rows[0];
  1172.                                         //label1.Text = theRow["BLANKA"].ToString();
  1173.                                         for (int j = 0; j < theRow.Table.Columns.Count; j++)
  1174.                                         {
  1175.                                             string tmp = theRow[j].ToString();
  1176.                                             if (theRow.Table.Columns[j].ToString() == "ID_POLICY" && tmp != null)
  1177.                                             {
  1178.                                                 policyid = tmp;
  1179.                                                 countall = getcount(policyid);
  1180.                                                 int x = countall;
  1181.                                                 danni = getsumncount(policyid);
  1182.                                                 countpayed = (int)danni.count;
  1183.                                                 sum = danni.sum;
  1184.                                             }
  1185.                                             //string tmp = theRow[j].ToString();
  1186.                                             if (theRow.Table.Columns[j].ToString() == "NOMER" && tmp != null)
  1187.                                             {
  1188.                                                 nomer = tmp;
  1189.                                                 // int asdasd = 0;
  1190.                                             }
  1191.                                             if (theRow.Table.Columns[j].ToString() == "F3000090001" && tmp != null)
  1192.                                             {
  1193.                                                 mpsid = tmp;
  1194.                                                 // int asdasd = 0;
  1195.                                             }
  1196.                                             if (theRow.Table.Columns[j].ToString() == "F3000090003" && tmp != null)
  1197.                                             {
  1198.                                                 mps_no = tmp;
  1199.                                                 //int asdasd2 = 0;
  1200.                                             }
  1201.                                             if (theRow.Table.Columns[j].ToString() == "DATEIZDAVANE" && tmp != null)
  1202.                                             {
  1203.                                                 dataizd = tmp;
  1204.                                                 //int asdasd2 = 0;
  1205.                                             }
  1206.                                             if (theRow.Table.Columns[j].ToString() == "BEGINDATE" && tmp != null)
  1207.                                             {
  1208.                                                 startdata = tmp;
  1209.                                                 //int asdasd2 = 0;
  1210.                                             }
  1211.                                             if (theRow.Table.Columns[j].ToString() == "ENDDATE" && tmp != null)
  1212.                                             {
  1213.                                                 enddata = tmp;
  1214.                                                 //int asdasd2 = 0;
  1215.                                             }
  1216.                                             if (theRow.Table.Columns[j].ToString() == "PREMIADUE_AMOUNT" && tmp != null)
  1217.                                             {
  1218.                                                 price = tmp;
  1219.                                                 //int asdasd2 = 0;
  1220.                                             }
  1221.                                             if (theRow.Table.Columns[j].ToString() == "FA3000102013" && tmp != null)
  1222.                                             {
  1223.                                                 inssum = tmp;
  1224.                                                 //int asdasd2 = 0;
  1225.                                             }
  1226.                                         }
  1227.                                         //}
  1228.                                     }
  1229.  
  1230.                                     con.Close();
  1231.  
  1232.                                     Property attr166 = new CrmMoneyProperty();
  1233.                                     ((CrmMoneyProperty)attr166).Name = "new_policyinsurancesum";
  1234.                                     ((CrmMoneyProperty)attr166).Value = new CrmMoney();
  1235.                                     ((CrmMoneyProperty)attr166).Value.Value = Convert.ToDecimal(inssum);
  1236.  
  1237.                                     CrmNumber number = new CrmNumber(countall - countpayed);
  1238.                                     Property attr11 = new CrmNumberProperty();
  1239.                                     ((CrmNumberProperty)attr11).Name = "new_countunpayeddefers";
  1240.                                     ((CrmNumberProperty)attr11).Value = number;
  1241.                                     //new_policypayed
  1242.  
  1243.                                     Property attr66 = new CrmMoneyProperty();
  1244.                                     ((CrmMoneyProperty)attr66).Name = "new_policypayed";
  1245.                                     ((CrmMoneyProperty)attr66).Value = new CrmMoney();
  1246.                                     ((CrmMoneyProperty)attr66).Value.Value = sum;
  1247.                                     //
  1248.                                     Property attr667 = new CrmMoneyProperty();
  1249.                                     ((CrmMoneyProperty)attr667).Name = "new_policynotpayed";
  1250.                                     ((CrmMoneyProperty)attr667).Value = new CrmMoney();
  1251.                                     ((CrmMoneyProperty)attr667).Value.Value = Convert.ToDecimal(price) - sum;
  1252.  
  1253.                                     Property attr = new StringProperty();
  1254.                                     ((StringProperty)attr).Name = "new_regnumber";
  1255.                                     ((StringProperty)attr).Value = mps_no;
  1256.  
  1257.                                     Property attr2 = new StringProperty();
  1258.                                     ((StringProperty)attr2).Name = "new_policynumber";
  1259.                                     ((StringProperty)attr2).Value = nomer;
  1260.                                     //convert
  1261.                                     //try
  1262.                                     //{
  1263.                                     DateTime date_izd = DateTime.Parse(dataizd);
  1264.                                     DateTime date_start = DateTime.Parse(startdata);
  1265.                                     DateTime date_end = DateTime.Parse(enddata);
  1266.                                     //int x = 0;
  1267.                                     dataizd = "";
  1268.                                     startdata = "";
  1269.                                     enddata = "";
  1270.                                     dataizd += date_izd.Month.ToString() + "/" + date_izd.Day.ToString() + "/" + date_izd.Year.ToString();
  1271.                                     startdata += date_start.Month.ToString() + "/" + date_start.Day.ToString() + "/" + date_start.Year.ToString();
  1272.                                     enddata += date_end.Month.ToString() + "/" + date_end.Day.ToString() + "/" + date_end.Year.ToString();
  1273.                                     /*}
  1274.                                     catch
  1275.                                     {
  1276.                                         //
  1277.                                     }*/
  1278.                                     Property attr3 = new CrmDateTimeProperty();
  1279.                                     ((CrmDateTimeProperty)attr3).Name = "new_policyvalidfrom";
  1280.                                     ((CrmDateTimeProperty)attr3).Value = new CrmDateTime();
  1281.                                     ((CrmDateTimeProperty)attr3).Value.Value = startdata;
  1282.  
  1283.  
  1284.                                     Property attr4 = new CrmDateTimeProperty();
  1285.                                     ((CrmDateTimeProperty)attr4).Name = "new_policyvalidto";
  1286.                                     ((CrmDateTimeProperty)attr4).Value = new CrmDateTime();
  1287.                                     ((CrmDateTimeProperty)attr4).Value.Value = enddata;
  1288.  
  1289.                                     Property attr5 = new CrmDateTimeProperty();
  1290.                                     ((CrmDateTimeProperty)attr5).Name = "new_policyreleaseddate";
  1291.                                     ((CrmDateTimeProperty)attr5).Value = new CrmDateTime();
  1292.                                     ((CrmDateTimeProperty)attr5).Value.Value = dataizd;
  1293.  
  1294.                                     Property attr6 = new CrmMoneyProperty();
  1295.                                     ((CrmMoneyProperty)attr6).Name = "new_policyprice";
  1296.                                     ((CrmMoneyProperty)attr6).Value = new CrmMoney();
  1297.                                     ((CrmMoneyProperty)attr6).Value.Value = Convert.ToDecimal(price);
  1298.  
  1299.                                     DynamicEntity entityaccount = GetOffice(nomer, context);
  1300.                                     string accountid = "";
  1301.                                     string accountname = "";
  1302.                                     if (entityaccount.Properties.Contains("accountid"))
  1303.                                     {
  1304.                                         Key accountid_guid = (Key)entityaccount.Properties["accountid"];
  1305.                                         accountid = accountid_guid.Value.ToString();
  1306.                                     }
  1307.                                     if (entityaccount.Properties.Contains("name"))
  1308.                                     {
  1309.                                         accountname = (string)entityaccount.Properties["name"];
  1310.                                     }
  1311.                                     Guid accid = new Guid(accountid);
  1312.                                     Property attr7 = new LookupProperty();
  1313.                                     ((LookupProperty)attr7).Name = "new_releasedinofficeid";
  1314.                                     ((LookupProperty)attr7).Value = new Lookup();
  1315.                                     ((LookupProperty)attr7).Value.Value = accid;
  1316.                                     ((LookupProperty)attr7).Value.name = accountname;
  1317.                                     ((LookupProperty)attr7).Value.type = "account";
  1318.  
  1319.                                     Property attr123 = new StringProperty();
  1320.                                     ((StringProperty)attr123).Name = "new_mpsid";
  1321.                                     ((StringProperty)attr123).Value = mpsid;
  1322.  
  1323.                                     Property attrflag = new CrmBooleanProperty();
  1324.                                     ((CrmBooleanProperty)attrflag).Name = "new_flag";
  1325.                                     ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  1326.                                     ((CrmBooleanProperty)attrflag).Value.Value = false;
  1327.  
  1328.                                     entity.Properties.Add(attrflag);
  1329.                                     entity.Properties.Add(attr123);
  1330.                                     entity.Properties.Add(attr);
  1331.                                     entity.Properties.Add(attr2);
  1332.                                     entity.Properties.Add(attr3);
  1333.                                     entity.Properties.Add(attr4);
  1334.                                     entity.Properties.Add(attr5);
  1335.                                     entity.Properties.Add(attr6);
  1336.                                     entity.Properties.Add(attr7);
  1337.                                     entity.Properties.Add(attr11);
  1338.                                     entity.Properties.Add(attr66);
  1339.                                     entity.Properties.Add(attr667);
  1340.                                     entity.Properties.Add(attr166);
  1341.  
  1342.  
  1343.                                     context.InputParameters["Target"] = entity;
  1344.                                     flag = true;
  1345.  
  1346.                                 }
  1347.                                 if (pnomer.Length > 0 && flag == false)
  1348.                                 {
  1349.                                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  1350.                                     //string query = "select name from user$ where name is not null";
  1351.                                     string query = @"select m.F3000090004, m.F3000090003, p.NOMER, p.DATEIZDAVANE, p.BEGINDATE, p.ENDDATE, p.PREMIADUE_AMOUNT, p.ID_POLICY, m.F3000090001, o.FA3000102013
  1352.                                                     from ORAHDI_INSPOLICY.policies p,
  1353.                                                     ORAHDI_INSPOLICY.policy_links l,
  1354.                                                     ORAHDI_DOCSYS.R3000090 m,
  1355.                                                     ORAHDI_DOCSYS.R3000102 o
  1356.                                                     where   p.ID_POLICY = l.ID_POLICY and
  1357.                                                             l.ID_OBJECT = o.F3000102001 and
  1358.                                                             o.F3000102002 = m.F3000090001 and
  1359.                                                             p.BLANKA = '";
  1360.                                     query += pnomer;
  1361.                                     query += @"'
  1362.                                 order by p.DATEIZDAVANE desc";
  1363.                                     OracleConnection con = new OracleConnection(conection);
  1364.                                     con.Open();
  1365.  
  1366.                                     //try
  1367.                                     //{
  1368.                                     OracleCommand command = new OracleCommand(query);
  1369.                                     command.Connection = con;
  1370.                                     command.CommandType = CommandType.Text;
  1371.  
  1372.                                     OracleDataReader reader = command.ExecuteReader();
  1373.  
  1374.                                     //OracleDataReader reader = command.ExecuteReader();
  1375.                                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  1376.                                     adapter.SelectCommand = command;
  1377.  
  1378.                                     DataSet ds = new DataSet();
  1379.                                     adapter.Fill(ds);
  1380.                                     string rama = "";
  1381.                                     string nomer = "";
  1382.                                     string mps_no = "";
  1383.                                     string dataizd = "";
  1384.                                     string startdata = "";
  1385.                                     string enddata = "";
  1386.                                     string price = "";
  1387.                                     string policyid = "";
  1388.                                     int countpayed = 0;
  1389.                                     int countall = 0;
  1390.                                     decimal sum = 0;
  1391.                                     string inssum = "";
  1392.                                     string mpsid = "";
  1393.                                     danni danni = new danni();
  1394.                                     for (int ij = 0; ij < ds.Tables.Count; ij++)
  1395.                                     {
  1396.                                         //for (int i = 0; i < ds.Tables[ij].Rows.Count; i++)
  1397.                                         //{
  1398.                                         //Application.DoEvents();
  1399.                                         DataRow theRow = ds.Tables[ij].Rows[0];
  1400.                                         //label1.Text = theRow["BLANKA"].ToString();
  1401.                                         for (int j = 0; j < theRow.Table.Columns.Count; j++)
  1402.                                         {
  1403.                                             string tmp = theRow[j].ToString();
  1404.                                             if (theRow.Table.Columns[j].ToString() == "ID_POLICY" && tmp != null)
  1405.                                             {
  1406.                                                 policyid = tmp;
  1407.                                                 countall = getcount(policyid);
  1408.                                                 int x = countall;
  1409.                                                 danni = getsumncount(policyid);
  1410.                                                 countpayed = (int)danni.count;
  1411.                                                 sum = danni.sum;
  1412.                                             }
  1413.                                             if (theRow.Table.Columns[j].ToString() == "NOMER" && tmp != null)
  1414.                                             {
  1415.                                                 nomer = tmp;
  1416.                                                 // int asdasd = 0;
  1417.                                             }
  1418.                                             if (theRow.Table.Columns[j].ToString() == "F3000090003" && tmp != null)
  1419.                                             {
  1420.                                                 mps_no = tmp;
  1421.                                                 //int asdasd2 = 0;
  1422.                                             }
  1423.                                             if (theRow.Table.Columns[j].ToString() == "F3000090004" && tmp != null)
  1424.                                             {
  1425.                                                 rama = tmp;
  1426.                                                 //int asdasd2 = 0;
  1427.                                             }
  1428.                                             if (theRow.Table.Columns[j].ToString() == "DATEIZDAVANE" && tmp != null)
  1429.                                             {
  1430.                                                 dataizd = tmp;
  1431.                                                 //int asdasd2 = 0;
  1432.                                             }
  1433.                                             if (theRow.Table.Columns[j].ToString() == "BEGINDATE" && tmp != null)
  1434.                                             {
  1435.                                                 startdata = tmp;
  1436.                                                 //int asdasd2 = 0;
  1437.                                             }
  1438.                                             if (theRow.Table.Columns[j].ToString() == "ENDDATE" && tmp != null)
  1439.                                             {
  1440.                                                 enddata = tmp;
  1441.                                                 //int asdasd2 = 0;
  1442.                                             }
  1443.                                             if (theRow.Table.Columns[j].ToString() == "PREMIADUE_AMOUNT" && tmp != null)
  1444.                                             {
  1445.                                                 price = tmp;
  1446.                                                 //int asdasd2 = 0;
  1447.                                             }
  1448.                                             if (theRow.Table.Columns[j].ToString() == "FA3000102013" && tmp != null)
  1449.                                             {
  1450.                                                 inssum = tmp;
  1451.                                                 //int asdasd2 = 0;
  1452.                                             }
  1453.                                             if (theRow.Table.Columns[j].ToString() == "F3000090001" && tmp != null)
  1454.                                             {
  1455.                                                 mpsid = tmp;
  1456.                                                 // int asdasd = 0;
  1457.                                             }
  1458.                                         }
  1459.                                         //}
  1460.                                     }
  1461.  
  1462.                                     con.Close();
  1463.  
  1464.                                     Property attr166 = new CrmMoneyProperty();
  1465.                                     ((CrmMoneyProperty)attr166).Name = "new_policyinsurancesum";
  1466.                                     ((CrmMoneyProperty)attr166).Value = new CrmMoney();
  1467.                                     ((CrmMoneyProperty)attr166).Value.Value = Convert.ToDecimal(inssum);
  1468.  
  1469.                                     CrmNumber number = new CrmNumber(countall - countpayed);
  1470.                                     Property attr11 = new CrmNumberProperty();
  1471.                                     ((CrmNumberProperty)attr11).Name = "new_countunpayeddefers";
  1472.                                     ((CrmNumberProperty)attr11).Value = number;
  1473.                                     //new_policypayed
  1474.  
  1475.                                     Property attr66 = new CrmMoneyProperty();
  1476.                                     ((CrmMoneyProperty)attr66).Name = "new_policypayed";
  1477.                                     ((CrmMoneyProperty)attr66).Value = new CrmMoney();
  1478.                                     ((CrmMoneyProperty)attr66).Value.Value = sum;
  1479.                                     //
  1480.                                     Property attr667 = new CrmMoneyProperty();
  1481.                                     ((CrmMoneyProperty)attr667).Name = "new_policynotpayed";
  1482.                                     ((CrmMoneyProperty)attr667).Value = new CrmMoney();
  1483.                                     ((CrmMoneyProperty)attr667).Value.Value = Convert.ToDecimal(price) - sum;
  1484.  
  1485.                                     Property attr = new StringProperty();
  1486.                                     ((StringProperty)attr).Name = "new_regnumber";
  1487.                                     ((StringProperty)attr).Value = mps_no;
  1488.  
  1489.                                     Property attr8 = new StringProperty();
  1490.                                     ((StringProperty)attr8).Name = "new_chassis";
  1491.                                     ((StringProperty)attr8).Value = rama;
  1492.  
  1493.                                     Property attr2 = new StringProperty();
  1494.                                     ((StringProperty)attr2).Name = "new_policynumber";
  1495.                                     ((StringProperty)attr2).Value = nomer;
  1496.                                     //convert
  1497.                                     //try
  1498.                                     //{
  1499.                                     DateTime date_izd = DateTime.Parse(dataizd);
  1500.                                     DateTime date_start = DateTime.Parse(startdata);
  1501.                                     DateTime date_end = DateTime.Parse(enddata);
  1502.                                     //int x = 0;
  1503.                                     dataizd = "";
  1504.                                     startdata = "";
  1505.                                     enddata = "";
  1506.                                     dataizd += date_izd.Month.ToString() + "/" + date_izd.Day.ToString() + "/" + date_izd.Year.ToString();
  1507.                                     startdata += date_start.Month.ToString() + "/" + date_start.Day.ToString() + "/" + date_start.Year.ToString();
  1508.                                     enddata += date_end.Month.ToString() + "/" + date_end.Day.ToString() + "/" + date_end.Year.ToString();
  1509.                                     /*}
  1510.                                     catch
  1511.                                     {
  1512.                                         //
  1513.                                     }*/
  1514.                                     Property attr3 = new CrmDateTimeProperty();
  1515.                                     ((CrmDateTimeProperty)attr3).Name = "new_policyvalidfrom";
  1516.                                     ((CrmDateTimeProperty)attr3).Value = new CrmDateTime();
  1517.                                     ((CrmDateTimeProperty)attr3).Value.Value = startdata;
  1518.  
  1519.  
  1520.                                     Property attr4 = new CrmDateTimeProperty();
  1521.                                     ((CrmDateTimeProperty)attr4).Name = "new_policyvalidto";
  1522.                                     ((CrmDateTimeProperty)attr4).Value = new CrmDateTime();
  1523.                                     ((CrmDateTimeProperty)attr4).Value.Value = enddata;
  1524.  
  1525.                                     Property attr5 = new CrmDateTimeProperty();
  1526.                                     ((CrmDateTimeProperty)attr5).Name = "new_policyreleaseddate";
  1527.                                     ((CrmDateTimeProperty)attr5).Value = new CrmDateTime();
  1528.                                     ((CrmDateTimeProperty)attr5).Value.Value = dataizd;
  1529.  
  1530.                                     Property attr6 = new CrmMoneyProperty();
  1531.                                     ((CrmMoneyProperty)attr6).Name = "new_policyprice";
  1532.                                     ((CrmMoneyProperty)attr6).Value = new CrmMoney();
  1533.                                     ((CrmMoneyProperty)attr6).Value.Value = Convert.ToDecimal(price);
  1534.  
  1535.                                     DynamicEntity entityaccount = GetOffice(nomer, context);
  1536.                                     string accountid = "";
  1537.                                     string accountname = "";
  1538.                                     if (entityaccount.Properties.Contains("accountid"))
  1539.                                     {
  1540.                                         Key accountid_guid = (Key)entityaccount.Properties["accountid"];
  1541.                                         accountid = accountid_guid.Value.ToString();
  1542.                                     }
  1543.                                     if (entityaccount.Properties.Contains("name"))
  1544.                                     {
  1545.                                         accountname = (string)entityaccount.Properties["name"];
  1546.                                     }
  1547.                                     Guid accid = new Guid(accountid);
  1548.                                     Property attr7 = new LookupProperty();
  1549.                                     ((LookupProperty)attr7).Name = "new_releasedinofficeid";
  1550.                                     ((LookupProperty)attr7).Value = new Lookup();
  1551.                                     ((LookupProperty)attr7).Value.Value = accid;
  1552.                                     ((LookupProperty)attr7).Value.name = accountname;
  1553.                                     ((LookupProperty)attr7).Value.type = "account";
  1554.  
  1555.                                     Property attr123 = new StringProperty();
  1556.                                     ((StringProperty)attr123).Name = "new_mpsid";
  1557.                                     ((StringProperty)attr123).Value = mpsid;
  1558.  
  1559.                                     Property attrflag = new CrmBooleanProperty();
  1560.                                     ((CrmBooleanProperty)attrflag).Name = "new_flag";
  1561.                                     ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  1562.                                     ((CrmBooleanProperty)attrflag).Value.Value = false;
  1563.  
  1564.                                     entity.Properties.Add(attrflag);
  1565.                                     entity.Properties.Add(attr123);
  1566.                                     entity.Properties.Add(attr);
  1567.                                     entity.Properties.Add(attr2);
  1568.                                     entity.Properties.Add(attr3);
  1569.                                     entity.Properties.Add(attr4);
  1570.                                     entity.Properties.Add(attr5);
  1571.                                     entity.Properties.Add(attr6);
  1572.                                     entity.Properties.Add(attr7);
  1573.                                     entity.Properties.Add(attr8);
  1574.                                     entity.Properties.Add(attr11);
  1575.                                     entity.Properties.Add(attr66);
  1576.                                     entity.Properties.Add(attr667);
  1577.                                     entity.Properties.Add(attr166);
  1578.  
  1579.                                     context.InputParameters["Target"] = entity;
  1580.                                     flag = true;
  1581.  
  1582.                                 }
  1583.                             }
  1584.                         }
  1585.  
  1586.                     }
  1587.                     catch
  1588.                     {
  1589.                         Property attrflag2 = new CrmBooleanProperty();
  1590.                             ((CrmBooleanProperty)attrflag2).Name = "new_flag3";
  1591.                             ((CrmBooleanProperty)attrflag2).Value = new CrmBoolean();
  1592.                             ((CrmBooleanProperty)attrflag2).Value.Value = true;
  1593.  
  1594.                             Property attrflag = new CrmBooleanProperty();
  1595.                             ((CrmBooleanProperty)attrflag).Name = "new_flag";
  1596.                             ((CrmBooleanProperty)attrflag).Value = new CrmBoolean();
  1597.                             ((CrmBooleanProperty)attrflag).Value.Value = false;
  1598.  
  1599.                             entity.Properties.Add(attrflag);
  1600.                             entity.Properties.Add(attrflag2);
  1601.  
  1602.  
  1603.                             context.InputParameters.Properties["Target"] = entity;
  1604.                     }
  1605.                     }
  1606.                    
  1607.                 }
  1608.             }
  1609.             /*
  1610.             public int getcount(string policyid)
  1611.             {
  1612.                 decimal cnt = 0;
  1613.                 string conection = "Data Source=hditst; User Id=****; Password=****;";
  1614.                 //string query = "select name from user$ where name is not null";
  1615.                 string query = @"select count(padej.id_policy)
  1616.                 from orahdi_inspolicy.policy_padeji_pol padej
  1617.                 where padej.id_policy = '";
  1618.                 query += policyid;
  1619.  
  1620.                 query += "'";
  1621.                 OracleConnection con = new OracleConnection(conection);
  1622.                 con.Open();
  1623.  
  1624.                 //try
  1625.                 //{
  1626.                 OracleCommand command = new OracleCommand(query);
  1627.                 command.Connection = con;
  1628.                 command.CommandType = CommandType.Text;
  1629.  
  1630.                 OracleDataReader reader = command.ExecuteReader();
  1631.  
  1632.                 //OracleDataReader reader = command.ExecuteReader();
  1633.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  1634.                 adapter.SelectCommand = command;
  1635.  
  1636.                 //DataSet ds = new DataSet();
  1637.                 //adapter.Fill(ds);
  1638.                 using (reader)
  1639.                     while (reader.Read())
  1640.                         if (reader[0] != System.DBNull.Value)
  1641.                             cnt = (decimal)reader[0];
  1642.  
  1643.                 return (int)cnt;
  1644.  
  1645.             }*/
  1646.             public int getcount(string policyid)
  1647.             {
  1648.                 decimal cnt = 0;
  1649.                 string conection = "Data Source=hditst; User Id=****; Password=****;";
  1650.                 //string query = "select name from user$ where name is not null";
  1651.                 string query = @"select count(padej.id_policy)
  1652.                from orahdi_inspolicy.policy_padeji_pol padej
  1653.                where padej.id_policy = '";
  1654.                 query += policyid;
  1655.  
  1656.                 query += "'";
  1657.                 OracleConnection con = new OracleConnection(conection);
  1658.                 con.Open();
  1659.  
  1660.                 //try
  1661.                 //{
  1662.                 OracleCommand command = new OracleCommand(query);
  1663.                 command.Connection = con;
  1664.                 command.CommandType = CommandType.Text;
  1665.  
  1666.                 OracleDataReader reader = command.ExecuteReader();
  1667.  
  1668.                 //OracleDataReader reader = command.ExecuteReader();
  1669.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  1670.                 adapter.SelectCommand = command;
  1671.  
  1672.                 //DataSet ds = new DataSet();
  1673.                 //adapter.Fill(ds);
  1674.                 using (reader)
  1675.                     while (reader.Read())
  1676.                         if (reader[0] != System.DBNull.Value)
  1677.                             cnt = (decimal)reader[0];
  1678.  
  1679.                 return (int)cnt;
  1680.  
  1681.             }
  1682.             public danni getsumncount(string policyid)
  1683.             {
  1684.                 decimal cnt = 0;
  1685.                 decimal sum = 0;
  1686.                 string conection = "Data Source=hditst; User Id=****; Password=****;";
  1687.                 //string query = "select name from user$ where name is not null";
  1688.                 string query = @"select count(padej.id_policy), sum(padej.padej_paid_amn)
  1689.                                from orahdi_inspolicy.policy_padeji_pol padej
  1690.                                where padej.id_policy = '";
  1691.                 query += policyid + "'";
  1692.                 query += "and padej.padej_paid_amn is not null";
  1693.  
  1694.                 OracleConnection con = new OracleConnection(conection);
  1695.                 con.Open();
  1696.  
  1697.                 //try
  1698.                 //{
  1699.                 OracleCommand command = new OracleCommand(query);
  1700.                 command.Connection = con;
  1701.                 command.CommandType = CommandType.Text;
  1702.  
  1703.                 OracleDataReader reader = command.ExecuteReader();
  1704.  
  1705.                 //OracleDataReader reader = command.ExecuteReader();
  1706.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  1707.                 adapter.SelectCommand = command;
  1708.  
  1709.                 //DataSet ds = new DataSet();
  1710.                 //adapter.Fill(ds);
  1711.                 using (reader)
  1712.                     while (reader.Read())
  1713.                     {
  1714.                         if (reader[0] != System.DBNull.Value)
  1715.                             cnt = (decimal)reader[0];
  1716.                         if (reader[1] != System.DBNull.Value)
  1717.                             sum = (decimal)reader[1];
  1718.                     }
  1719.                 danni danni = new danni();
  1720.                 danni.count = cnt;
  1721.                 danni.sum = sum;
  1722.                 return danni;
  1723.                 //return (int)cnt;
  1724.             }
  1725.             public owner getowner(string mpsid)
  1726.             {
  1727.                 string conection = "Data Source=hditst; User Id=****; Password=****;";
  1728.                 //string query = "select name from user$ where name is not null";
  1729.                 string query = @"select cu.FIRSTNAME, cu.LASTNAME, cu.EGN, cu.BULSTAT
  1730.                                            from ORAHDI_DOCSYS.R3000090 m,
  1731.                                            ORAHDI_INSPOLICY.auto_owners ao,
  1732.                                            ORAHDI_CUST.customs cu
  1733.                                             where   ao.ID_MPS = m.F3000090001 and
  1734.                                                ao.id_cust = cu.ID and
  1735.                                                m.F3000090001 = '";
  1736.                 query += mpsid + "'";
  1737.  
  1738.  
  1739.                 OracleConnection con = new OracleConnection(conection);
  1740.                 con.Open();
  1741.  
  1742.                 //try
  1743.                 //{
  1744.                 OracleCommand command = new OracleCommand(query);
  1745.                 command.Connection = con;
  1746.                 command.CommandType = CommandType.Text;
  1747.  
  1748.                 OracleDataReader reader = command.ExecuteReader();
  1749.  
  1750.                 //OracleDataReader reader = command.ExecuteReader();
  1751.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  1752.                 adapter.SelectCommand = command;
  1753.  
  1754.                 //DataSet ds = new DataSet();
  1755.                 //adapter.Fill(ds);
  1756.                 string fname = "";
  1757.                 string lname = "";
  1758.                 string egnbul = "";
  1759.                 bool account = false;
  1760.                 using (reader)
  1761.                     while (reader.Read())
  1762.                     {
  1763.                         if (reader[0] != System.DBNull.Value)
  1764.                             fname = (string)reader[0];
  1765.                         if (reader[1] != System.DBNull.Value)
  1766.                             lname = (string)reader[1];
  1767.                         if (reader[2] != System.DBNull.Value)
  1768.                             egnbul = (string)reader[2];
  1769.                         if (reader[3] != System.DBNull.Value)
  1770.                         {
  1771.                             egnbul = (string)reader[3];
  1772.                             account = true;
  1773.                         }
  1774.                     }
  1775.                 owner own = new owner();
  1776.                 if (fname.Length > 0)
  1777.                     own.fname = fname;
  1778.                 if (lname.Length > 0)
  1779.                     own.lname = lname;
  1780.                 if (egnbul.Length > 0)
  1781.                     own.egnbul = egnbul;
  1782.                 own.account = account;
  1783.                 return own;
  1784.             }
  1785.             public class kartoteka_mps
  1786.             {
  1787.                 public string vid_mps_id = "";
  1788.                 public string vid_mps_name = "";
  1789.                 public Lookup vid_mps_lkp = new Lookup();
  1790.  
  1791.                 public string marka_id = "";
  1792.                 public string marka_name = "";
  1793.                 public Lookup marka_lkp = new Lookup();
  1794.  
  1795.                 public string model_id = "";
  1796.                 public string model_name = "";
  1797.                 public Lookup model_lkp = new Lookup();
  1798.  
  1799.                 public string modification = "";
  1800.                 public string vrati = "";
  1801.                 public CrmNumber godina_proizv = new CrmNumber(0);
  1802.  
  1803.                 public string class_mps_id = "";
  1804.                 public string class_pls_name = "";
  1805.                 public Lookup class_mps_lkp = new Lookup();
  1806.  
  1807.                 public CrmNumber obem_dvg = new CrmNumber(0);
  1808.  
  1809.                 public Picklist vid_gorivo = new Picklist(6);
  1810.  
  1811.                 public Picklist proizvodstvo = new Picklist(2);
  1812.  
  1813.                 public string shasi = "";
  1814.  
  1815.                 public string cvqt_id = "";
  1816.                 public string cvqt_name = "";
  1817.                 public Lookup cvqt_lkp = new Lookup();
  1818.  
  1819.                 public string boq_id = "";
  1820.                 public string boq_name = "";
  1821.                 public Lookup boq_lkp = new Lookup();
  1822.  
  1823.                 public Picklist prednaznachenie = new Picklist(6);
  1824.  
  1825.             };
  1826.             public class owner
  1827.             {
  1828.                 public string fname;
  1829.                 public string lname;
  1830.                 public string egnbul;
  1831.                 public bool account;
  1832.             };
  1833.             public class danni
  1834.             {
  1835.                 public decimal count;
  1836.                 public decimal sum;
  1837.             };
  1838.             public class acc_cont
  1839.             {
  1840.                 public Guid entityID;
  1841.                 public string name;
  1842.             };
  1843.             private Lookup customer(owner own3r, IPluginExecutionContext context)
  1844.             {
  1845.  
  1846.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  1847.                 //check EGN/BULSTAT
  1848.  
  1849.                 DynamicEntity customer = new DynamicEntity();
  1850.  
  1851.                 Property accountname = new StringProperty();
  1852.                 ((StringProperty)accountname).Name = "name";
  1853.                 ((StringProperty)accountname).Value = own3r.fname + " " + own3r.lname;
  1854.  
  1855.                 Property contactname = new StringProperty();
  1856.                 ((StringProperty)contactname).Name = "lastname";
  1857.                 ((StringProperty)contactname).Value = own3r.fname + " " + own3r.lname;
  1858.  
  1859.                 Property engbul = new StringProperty();
  1860.                 ((StringProperty)engbul).Name = "new_egn_bulstat";
  1861.                 ((StringProperty)engbul).Value = own3r.egnbul;
  1862.  
  1863.                 Property egn = new StringProperty();
  1864.                 ((StringProperty)egn).Name = "new_egn";
  1865.                 ((StringProperty)egn).Value = own3r.egnbul;
  1866.  
  1867.                 Property acctype = new PicklistProperty();
  1868.                 ((PicklistProperty)acctype).Name = "new_accounttype";
  1869.                 ((PicklistProperty)acctype).Value = new Picklist();
  1870.                 ((PicklistProperty)acctype).Value.Value = 3;
  1871.  
  1872.                 if (own3r.account == true)
  1873.                 {
  1874.                     customer.Name = EntityName.account.ToString();
  1875.                     customer.Properties = new Microsoft.Crm.Sdk.PropertyCollection();
  1876.                     customer.Properties.Add(accountname);
  1877.                     customer.Properties.Add(engbul);
  1878.                     customer.Properties.Add(acctype);
  1879.                 }
  1880.                 else
  1881.                 {
  1882.                     customer.Name = EntityName.contact.ToString();
  1883.                     customer.Properties = new Microsoft.Crm.Sdk.PropertyCollection();
  1884.                     customer.Properties.Add(contactname);
  1885.                     customer.Properties.Add(egn);
  1886.                 }
  1887.                 Lookup lookup = new Lookup();
  1888.  
  1889.                 TargetCreateDynamic target = new TargetCreateDynamic();
  1890.                 target.Entity = customer;
  1891.  
  1892.                 CreateRequest request = new CreateRequest();
  1893.                 request.Target = target;
  1894.  
  1895.                 CreateResponse response = (CreateResponse)service.Execute(request);
  1896.                 Guid lookupid = new Guid();
  1897.                 lookupid = response.id;
  1898.                 string taip = "";
  1899.                 if (own3r.account == true)
  1900.                 {
  1901.                     taip = "account";
  1902.                 }
  1903.                 else
  1904.                 {
  1905.                     taip = "contact";
  1906.                 }
  1907.                 lookup.name = own3r.fname + " " + own3r.lname;
  1908.                 lookup.type = taip;
  1909.                 lookup.Value = lookupid;
  1910.                 return lookup;
  1911.             }
  1912.             private void create_postradal(Lookup obekt, Lookup case_lkp, Lookup subject, IPluginExecutionContext context)
  1913.             {
  1914.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  1915.  
  1916.                 /*
  1917.                  *  new_claim_vehicle
  1918.                     _________________
  1919.                     new_claim_subjectid //lookup - subj
  1920.                     new_claimvehicleid //lookup - case
  1921.                     new_guilt //picklist value = 1/3 kasko/go
  1922.                     new_name //string dkn
  1923.                  * new_objectid
  1924.                  Property namee = new StringProperty();
  1925.                 ((StringProperty)namee).Name = "new_name";
  1926.                 ((StringProperty)namee).Value = acc_cont.name;
  1927.                 */
  1928.                 DynamicEntity postradal = new DynamicEntity();
  1929.                 postradal.Name = "new_claim_vehicle";
  1930.                 postradal.Properties = new Microsoft.Crm.Sdk.PropertyCollection();
  1931.                 Property namee = new StringProperty();
  1932.                 ((StringProperty)namee).Name = "new_name";
  1933.                 ((StringProperty)namee).Value = obekt.name;
  1934.  
  1935.                 Property obekta = new LookupProperty();
  1936.                 ((LookupProperty)obekta).Name = "new_objectid";
  1937.                 ((LookupProperty)obekta).Value = obekt;
  1938.  
  1939.  
  1940.                 Property subj_lkp = new LookupProperty();
  1941.                 ((LookupProperty)subj_lkp).Name = "new_claim_subjectid";
  1942.                 ((LookupProperty)subj_lkp).Value = subject;
  1943.  
  1944.  
  1945.                 Property keis = new LookupProperty();
  1946.                 ((LookupProperty)keis).Name = "new_claimvehicleid";
  1947.                 ((LookupProperty)keis).Value = case_lkp;
  1948.  
  1949.                 Property new_guilt = new PicklistProperty();
  1950.                 ((PicklistProperty)new_guilt).Name = "new_guilt";
  1951.                 ((PicklistProperty)new_guilt).Value = new Picklist();
  1952.  
  1953.                 string sname = subject.name;
  1954.                 if (sname == "Каско на МПС")
  1955.                 {
  1956.                     ((PicklistProperty)new_guilt).Value.Value = 1;
  1957.                 }
  1958.                 else if ((sname == "ГО на МПС") || (sname == "ГО на МПС 2007"))
  1959.                 {
  1960.                     ((PicklistProperty)new_guilt).Value.Value = 3;
  1961.                 }
  1962.                 postradal.Properties.Add(namee);
  1963.                 postradal.Properties.Add(keis);
  1964.                 postradal.Properties.Add(obekta);
  1965.                 postradal.Properties.Add(new_guilt);
  1966.                 postradal.Properties.Add(subj_lkp);
  1967.  
  1968.                 TargetCreateDynamic target = new TargetCreateDynamic();
  1969.                 target.Entity = postradal;
  1970.  
  1971.                 CreateRequest request = new CreateRequest();
  1972.                 request.Target = target;
  1973.  
  1974.                 CreateResponse response = (CreateResponse)service.Execute(request);
  1975.  
  1976.  
  1977.  
  1978.  
  1979.             }
  1980.             private void create_object_owner(Lookup acc_cont, Lookup obekt, owner ownr, IPluginExecutionContext context)
  1981.             {
  1982.  
  1983.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  1984.  
  1985.                 /*
  1986.                 new_name //string
  1987.                 new_owneraccountid / new_ownercontactid //lookup
  1988.                 new_ownership //decimal - 100
  1989.                 new_objectid //lookup
  1990.                 */
  1991.  
  1992.                 Property namee = new StringProperty();
  1993.                 ((StringProperty)namee).Name = "new_name";
  1994.                 ((StringProperty)namee).Value = acc_cont.name;
  1995.  
  1996.                 Property ouner_a_c = new LookupProperty();
  1997.                 if (ownr.account)
  1998.                 {
  1999.                     ((LookupProperty)ouner_a_c).Name = "new_owneraccountid";
  2000.                     ((LookupProperty)ouner_a_c).Value = new Lookup();
  2001.                     ((LookupProperty)ouner_a_c).Value.Value = acc_cont.Value;
  2002.                     ((LookupProperty)ouner_a_c).Value.name = acc_cont.name;
  2003.                     ((LookupProperty)ouner_a_c).Value.type = "account";
  2004.                 }
  2005.                 else
  2006.                 {
  2007.                     ((LookupProperty)ouner_a_c).Name = "new_ownercontactid";
  2008.                     ((LookupProperty)ouner_a_c).Value = new Lookup();
  2009.                     ((LookupProperty)ouner_a_c).Value.Value = acc_cont.Value;
  2010.                     ((LookupProperty)ouner_a_c).Value.name = acc_cont.name;
  2011.                     ((LookupProperty)ouner_a_c).Value.type = "contact";
  2012.                 }
  2013.  
  2014.                 Property obekta = new LookupProperty();
  2015.                 ((LookupProperty)obekta).Name = "new_objectid";
  2016.                 ((LookupProperty)obekta).Value = new Lookup();
  2017.                 ((LookupProperty)obekta).Value.Value = obekt.Value;
  2018.                 ((LookupProperty)obekta).Value.name = obekt.name;
  2019.                 ((LookupProperty)obekta).Value.type = obekt.type;
  2020.  
  2021.                 CrmDecimal number = new CrmDecimal(100);
  2022.                 Property ownership = new CrmDecimalProperty();
  2023.                 ((CrmDecimalProperty)ownership).Name = "new_ownership";
  2024.                 ((CrmDecimalProperty)ownership).Value = number;
  2025.  
  2026.                 DynamicEntity ouner = new DynamicEntity();
  2027.                 ouner.Name = "new_new_owner";
  2028.                 ouner.Properties = new Microsoft.Crm.Sdk.PropertyCollection();
  2029.                 ouner.Properties.Add(namee);
  2030.                 ouner.Properties.Add(ouner_a_c);
  2031.                 ouner.Properties.Add(obekta);
  2032.                 ouner.Properties.Add(ownership);
  2033.  
  2034.  
  2035.  
  2036.                 TargetCreateDynamic target = new TargetCreateDynamic();
  2037.                 target.Entity = ouner;
  2038.  
  2039.                 CreateRequest request = new CreateRequest();
  2040.                 request.Target = target;
  2041.  
  2042.                 CreateResponse response = (CreateResponse)service.Execute(request);
  2043.  
  2044.  
  2045.             }
  2046.             public class mps_marka_model
  2047.             {
  2048.                 public string marka_id = "";
  2049.                 public string marka_name = "";
  2050.                 public string model_id = "";
  2051.                 public string model_name = "";
  2052.                 public Lookup marka_lkp = new Lookup();
  2053.                 public Lookup model_lkp = new Lookup();
  2054.                 public void check_marka(string markaname, IPluginExecutionContext context)
  2055.                 {
  2056.                     ICrmService service = (ICrmService)context.CreateCrmService(true);
  2057.  
  2058.                     ConditionExpression con = new ConditionExpression();
  2059.                     con.AttributeName = "new_name";
  2060.                     con.Operator = ConditionOperator.Like;
  2061.                     con.Values = new string[] { markaname };
  2062.                     FilterExpression filter = new FilterExpression();
  2063.                     filter.FilterOperator = LogicalOperator.And;
  2064.                     filter.AddCondition(con);
  2065.                     QueryExpression query = new QueryExpression();
  2066.                     query.EntityName = "new_mfg";
  2067.                     query.ColumnSet = new AllColumns();
  2068.                     query.Criteria = filter;
  2069.                     RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
  2070.                     retrieve.Query = query;
  2071.                     retrieve.ReturnDynamicEntities = true;
  2072.                     RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
  2073.                     DynamicEntity entity = new DynamicEntity();
  2074.                     if (retrieved.BusinessEntityCollection.BusinessEntities.Count > 0)
  2075.                     {
  2076.                         entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2077.                         if(entity.Properties.Contains("new_mfgid"))
  2078.                         {
  2079.                             Key new_mfgid = (Key)entity.Properties["new_mfgid"];
  2080.                             this.marka_lkp.Value = new_mfgid.Value;
  2081.                         }
  2082.                         this.marka_lkp.type = "new_mfg";
  2083.                         this.marka_lkp.name = markaname;
  2084.                     }
  2085.                 }
  2086.                 public void check_model(string modelname, IPluginExecutionContext context)
  2087.                 {
  2088.                     ICrmService service = (ICrmService)context.CreateCrmService(true);
  2089.  
  2090.                     ConditionExpression con = new ConditionExpression();
  2091.                     con.AttributeName = "new_name";
  2092.                     con.Operator = ConditionOperator.Like;
  2093.                     con.Values = new string[] { modelname };
  2094.                     FilterExpression filter = new FilterExpression();
  2095.                     filter.FilterOperator = LogicalOperator.And;
  2096.                     filter.AddCondition(con);
  2097.                     QueryExpression query = new QueryExpression();
  2098.                     query.EntityName = "new_model";
  2099.                     query.ColumnSet = new AllColumns();
  2100.                     query.Criteria = filter;
  2101.                     RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
  2102.                     retrieve.Query = query;
  2103.                     retrieve.ReturnDynamicEntities = true;
  2104.                     RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
  2105.                     DynamicEntity entity = new DynamicEntity();
  2106.                     if (retrieved.BusinessEntityCollection.BusinessEntities.Count > 0)
  2107.                     {
  2108.                         entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2109.                         if (entity.Properties.Contains("new_modelid"))
  2110.                         {
  2111.                             Key new_mfgid = (Key)entity.Properties["new_modelid"];
  2112.                             this.model_lkp.Value = new_mfgid.Value;
  2113.                         }
  2114.                         this.model_lkp.type = "new_model";
  2115.                         this.model_lkp.name = modelname;
  2116.                     }
  2117.                 }
  2118.                 public void get_marka_name(string markaID)
  2119.                 {
  2120.                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  2121.                 //string query = "select name from user$ where name is not null";
  2122.                     string query = @"select ma.name_brand
  2123.                                    from orahdi_inspolicy.mpsmarka ma
  2124.                                    where ma.id_nom like '";
  2125.                     query += markaID + "'";
  2126.                     OracleConnection con = new OracleConnection(conection);
  2127.                 con.Open();
  2128.  
  2129.                 //try
  2130.                 //{
  2131.                 OracleCommand command = new OracleCommand(query);
  2132.                 command.Connection = con;
  2133.                 command.CommandType = CommandType.Text;
  2134.  
  2135.                 OracleDataReader reader = command.ExecuteReader();
  2136.  
  2137.                 //OracleDataReader reader = command.ExecuteReader();
  2138.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  2139.                 adapter.SelectCommand = command;
  2140.  
  2141.                 //DataSet ds = new DataSet();
  2142.                 //adapter.Fill(ds);
  2143.                
  2144.                 using (reader)
  2145.                     while (reader.Read())
  2146.                     {
  2147.                         if (reader[0] != System.DBNull.Value)
  2148.                            this.marka_name  = (string)reader[0];
  2149.                     }
  2150.                    
  2151.                 }
  2152.                 public void get_model_name(string modelID)
  2153.                 {
  2154.                     string conection = "Data Source=hditst; User Id=****; Password=****;";
  2155.                     //string query = "select name from user$ where name is not null";
  2156.                     string query = @"select mo.name_model
  2157.                                    from orahdi_inspolicy.mpsmodel mo
  2158.                                    where mo.id_nom like '";
  2159.                     query += modelID + "'";
  2160.                     OracleConnection con = new OracleConnection(conection);
  2161.                     con.Open();
  2162.  
  2163.                     //try
  2164.                     //{
  2165.                     OracleCommand command = new OracleCommand(query);
  2166.                     command.Connection = con;
  2167.                     command.CommandType = CommandType.Text;
  2168.  
  2169.                     OracleDataReader reader = command.ExecuteReader();
  2170.  
  2171.                     //OracleDataReader reader = command.ExecuteReader();
  2172.                     OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  2173.                     adapter.SelectCommand = command;
  2174.  
  2175.                     //DataSet ds = new DataSet();
  2176.                     //adapter.Fill(ds);
  2177.  
  2178.                     using (reader)
  2179.                         while (reader.Read())
  2180.                         {
  2181.                             if (reader[0] != System.DBNull.Value)
  2182.                                 this.model_name = (string)reader[0];
  2183.                         }
  2184.                 }
  2185.  
  2186.             };
  2187.             private kartoteka_mps getkartoteka(string mpsid)
  2188.             {
  2189.                 kartoteka_mps kartoteka = new kartoteka_mps();
  2190.                 string conection = "Data Source=hditst; User Id=****; Password=****;";
  2191.                 //string query = "select name from user$ where name is not null";
  2192.                 string query = @"select m.F3000090007, m.F3000090008, m.F3000090009, m.F3000090010, m.F3000090024, m.F3000090020, m.F3000090032, m.F3000090021, m.F3000090011, m.F3000090018, m.F3000090016, m.F3000090017, m.F3000090019
  2193.                                            from ORAHDI_DOCSYS.R3000090 m
  2194.                                            where m.F3000090001 = '";
  2195.                 query += mpsid + "'";
  2196.                
  2197.  
  2198.                 OracleConnection con = new OracleConnection(conection);
  2199.                 con.Open();
  2200.  
  2201.                 //try
  2202.                 //{
  2203.                 OracleCommand command = new OracleCommand(query);
  2204.                 command.Connection = con;
  2205.                 command.CommandType = CommandType.Text;
  2206.  
  2207.                 OracleDataReader reader = command.ExecuteReader();
  2208.  
  2209.                 //OracleDataReader reader = command.ExecuteReader();
  2210.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  2211.                 adapter.SelectCommand = command;
  2212.  
  2213.                 //DataSet ds = new DataSet();
  2214.                 //adapter.Fill(ds);
  2215.                
  2216.                 using (reader)
  2217.                     while (reader.Read())
  2218.                     {
  2219.                         if (reader[0] != System.DBNull.Value)
  2220.                             kartoteka.vid_mps_id = (string)reader[0];
  2221.                         if (reader[1] != System.DBNull.Value)
  2222.                             kartoteka.marka_id = (string)reader[1];
  2223.                         if (reader[2] != System.DBNull.Value)
  2224.                             kartoteka.model_id = (string)reader[2];
  2225.                         if (reader[3] != System.DBNull.Value)
  2226.                             kartoteka.modification = (string)reader[3];
  2227.                         if (reader[4] != System.DBNull.Value)
  2228.                             kartoteka.vrati = ((decimal)reader[4]).ToString();
  2229.                         if (reader[5] != System.DBNull.Value)
  2230.                             kartoteka.godina_proizv = new CrmNumber(Convert.ToInt32((decimal)reader[5]));
  2231.                         if (reader[6] != System.DBNull.Value)
  2232.                             kartoteka.class_mps_id = (string)reader[6];
  2233.                        
  2234.                         if (reader[7] != System.DBNull.Value)
  2235.                             kartoteka.obem_dvg = new CrmNumber(Convert.ToInt32((decimal)reader[7]));
  2236.                         if (reader[8] != System.DBNull.Value)
  2237.                             kartoteka.vid_gorivo = new Picklist(Convert.ToInt32((string)reader[8]));
  2238.                         if (reader[9] != System.DBNull.Value)
  2239.                             kartoteka.proizvodstvo = new Picklist(Convert.ToInt32((string)reader[9]));
  2240.                         if (reader[10] != System.DBNull.Value)
  2241.                             kartoteka.cvqt_id = (string)reader[10];
  2242.                         if (reader[11] != System.DBNull.Value)
  2243.                             kartoteka.boq_id = (string)reader[11];
  2244.                         if (reader[12] != System.DBNull.Value)
  2245.                         {
  2246.                             int taip = 0;
  2247.                             int picklistvalue = 6;
  2248.                             string id_ot_oracle = (string)reader[12];
  2249.                             taip = Convert.ToInt32(id_ot_oracle);
  2250.                             switch (taip)
  2251.                             {
  2252.                                 case 1:
  2253.                                     picklistvalue = 1;
  2254.                                     break;
  2255.                                 case 2:
  2256.                                     picklistvalue = 4;
  2257.                                     break;
  2258.                                 case 3:
  2259.                                     picklistvalue = 3;
  2260.                                     break;                                
  2261.                                 case 8:
  2262.                                     picklistvalue = 2;
  2263.                                     break;
  2264.  
  2265.                                 default:
  2266.                                     picklistvalue = 6;
  2267.                                     break;
  2268.                             }
  2269.                             kartoteka.prednaznachenie = new Picklist(picklistvalue);
  2270.  
  2271.                         }
  2272.                        
  2273.                     }
  2274.                
  2275.                 return kartoteka;
  2276.             }
  2277.             public string get_nom_name(string nom_id, string nom_type)
  2278.             {
  2279.                 //nomenklatura nomenkl = new nomenklatura();
  2280.                 //nomenkl.id = nom_id;
  2281.                 //nomenkl.type = nom_type;
  2282.                 //ORACLE
  2283.                 string conection = "Data Source=hditst; User Id=****; Password=****;";
  2284.                 //string query = "select name from user$ where name is not null";
  2285.                 string query = @"select nom.NOM_NAME from ORAHDI_RA.NOM_DATA nom
  2286.                                    where nom.NOM_ID = '";
  2287.                 query += nom_id +"'";
  2288.                 query += "and nom.NOM_TYPE = '" + nom_type + "'";
  2289.                                    
  2290.                
  2291.                 OracleConnection con = new OracleConnection(conection);
  2292.                 con.Open();
  2293.  
  2294.                 //try
  2295.                 //{
  2296.                 OracleCommand command = new OracleCommand(query);
  2297.                 command.Connection = con;
  2298.                 command.CommandType = CommandType.Text;
  2299.  
  2300.                 OracleDataReader reader = command.ExecuteReader();
  2301.  
  2302.                 //OracleDataReader reader = command.ExecuteReader();
  2303.                 OracleDataAdapter adapter = new OracleDataAdapter(query, con);
  2304.                 adapter.SelectCommand = command;
  2305.                 string name = "";
  2306.                 //DataSet ds = new DataSet();
  2307.                 //adapter.Fill(ds);
  2308.                 using (reader)
  2309.                     while (reader.Read())
  2310.                         if (reader[0] != System.DBNull.Value)
  2311.                             name = (string)reader[0];
  2312.                 return name;
  2313.             }
  2314.             public Lookup get_crm_lkp(string nom_name,string entity_name, IPluginExecutionContext context)
  2315.             {
  2316.                 Lookup lkp = new Lookup();
  2317.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  2318.  
  2319.                 ConditionExpression con = new ConditionExpression();
  2320.                 con.AttributeName = "new_name";
  2321.                 con.Operator = ConditionOperator.Like;
  2322.                 con.Values = new string[] { nom_name };
  2323.  
  2324.                 FilterExpression filter = new FilterExpression();
  2325.                 filter.FilterOperator = LogicalOperator.And;
  2326.                 filter.AddCondition(con);
  2327.  
  2328.                 QueryExpression query = new QueryExpression();
  2329.                 query.EntityName = entity_name;
  2330.                 query.ColumnSet = new AllColumns();
  2331.                 query.Criteria = filter;
  2332.  
  2333.                 RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
  2334.                 retrieve.Query = query;
  2335.                 retrieve.ReturnDynamicEntities = true;
  2336.  
  2337.                 RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
  2338.                 DynamicEntity entity = new DynamicEntity();
  2339.                 string keyid = entity_name + "id";
  2340.                 if (retrieved.BusinessEntityCollection.BusinessEntities.Count > 0)
  2341.                 {
  2342.                     entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2343.                     if (entity.Properties.Contains(keyid))
  2344.                     {
  2345.                         Key accountid_guid = (Key)entity.Properties[keyid];
  2346.                         //accountid = accountid_guid.Value.ToString();
  2347.                         lkp.Value = accountid_guid.Value;
  2348.                     }
  2349.                     if (entity.Properties.Contains("new_name"))
  2350.                     {
  2351.                         lkp.name = (string)entity.Properties["new_name"];
  2352.                     }
  2353.                     lkp.type = entity_name;
  2354.                 }
  2355.                 return lkp;
  2356.             }
  2357.             public class nomenklatura
  2358.             {
  2359.                 public string type = "";
  2360.                 public string id = "";
  2361.                 public string name = "";
  2362.             };
  2363.             public Lookup mepese_class(string classID, IPluginExecutionContext context)
  2364.             {
  2365.                 Lookup lkp = new Lookup();
  2366.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  2367.                 string nom_name = "";
  2368.                 int x = 0;
  2369.                 x = Convert.ToInt32(classID);
  2370.                 switch (x)
  2371.                 {
  2372.                     case 1:
  2373.                         nom_name = "A";
  2374.                         break;
  2375.                     case 2:
  2376.                         nom_name = "B";
  2377.                         break;
  2378.                     case 3:
  2379.                         nom_name = "C";
  2380.                         break;
  2381.                     case 4:
  2382.                         nom_name = "Джип";
  2383.                         break;
  2384.                     default:
  2385.                         return lkp;
  2386.                 }
  2387.                 string entity_name = "new_vehicleclass";
  2388.                 ConditionExpression con = new ConditionExpression();
  2389.                 con.AttributeName = "new_name";
  2390.                 con.Operator = ConditionOperator.Like;
  2391.                 con.Values = new string[] { nom_name };
  2392.  
  2393.                 FilterExpression filter = new FilterExpression();
  2394.                 filter.FilterOperator = LogicalOperator.And;
  2395.                 filter.AddCondition(con);
  2396.  
  2397.                 QueryExpression query = new QueryExpression();
  2398.                 query.EntityName = entity_name;
  2399.                 query.ColumnSet = new AllColumns();
  2400.                 query.Criteria = filter;
  2401.  
  2402.                 RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
  2403.                 retrieve.Query = query;
  2404.                 retrieve.ReturnDynamicEntities = true;
  2405.  
  2406.                 RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
  2407.                 DynamicEntity entity = new DynamicEntity();
  2408.                 string keyid = entity_name + "id";
  2409.                 if (retrieved.BusinessEntityCollection.BusinessEntities.Count > 0)
  2410.                 {
  2411.                     entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2412.                     if (entity.Properties.Contains(keyid))
  2413.                     {
  2414.                         Key accountid_guid = (Key)entity.Properties[keyid];
  2415.                         //accountid = accountid_guid.Value.ToString();
  2416.                         lkp.Value = accountid_guid.Value;
  2417.                     }
  2418.                     if (entity.Properties.Contains("new_name"))
  2419.                     {
  2420.                         lkp.name = (string)entity.Properties["new_name"];
  2421.                     }
  2422.                     lkp.type = entity_name;
  2423.                 }
  2424.                 return lkp;
  2425.             }
  2426.             private Lookup obj_of_ins(string dkn, string chassis, string mpsid, string subject, IPluginExecutionContext context)
  2427.             {
  2428.  
  2429.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  2430.  
  2431.                 //CHECK DKN
  2432.                 //static danni ot crmForm:
  2433.                 /*
  2434.                 new_type //picklist value=1
  2435.                 new_name //string dkn
  2436.                 new_licenceplate //string
  2437.                 new_chassis //string
  2438.                 */
  2439.                 DynamicEntity obj = new DynamicEntity();
  2440.                 obj.Name = "new_subjectofinsurance";
  2441.                 obj.Properties = new Microsoft.Crm.Sdk.PropertyCollection();
  2442.                 kartoteka_mps kartoteka = getkartoteka(mpsid);
  2443.                 //string abv = "abv";
  2444.                 if (kartoteka.vid_mps_id.Length > 0)
  2445.                 {
  2446.                     Property attr = new LookupProperty();
  2447.                     Lookup lkp = new Lookup();
  2448.                     string nom_name = get_nom_name(kartoteka.vid_mps_id, "InsPolicyAutoType");
  2449.                     lkp = get_crm_lkp(nom_name, "new_vehicletype", context);
  2450.                     if(lkp.name != null)
  2451.                     {
  2452.                         ((LookupProperty)attr).Name = "new_vehicletypeid";
  2453.                         ((LookupProperty)attr).Value = lkp;
  2454.                         obj.Properties.Add(attr);
  2455.                     }
  2456.                 }
  2457.                 mps_marka_model marka_i_model = new mps_marka_model();
  2458.                 if (kartoteka.marka_id.Length > 0)
  2459.                 {
  2460.                     marka_i_model.marka_id = kartoteka.marka_id;
  2461.                     marka_i_model.get_marka_name(kartoteka.marka_id);
  2462.                     if (marka_i_model.marka_name.Length > 0)
  2463.                     {
  2464.                         marka_i_model.check_marka(marka_i_model.marka_name, context);
  2465.                         Lookup marka_lkp = new Lookup();
  2466.                         if (marka_i_model.marka_lkp.name != null)
  2467.                         {
  2468.                             marka_lkp = marka_i_model.marka_lkp;
  2469.                             Property marka_lkp_property = new LookupProperty();
  2470.                             ((LookupProperty)marka_lkp_property).Name = "new_manufacturerid";
  2471.                             ((LookupProperty)marka_lkp_property).Value = marka_lkp;
  2472.                             obj.Properties.Add(marka_lkp_property);
  2473.                         }
  2474.                     }
  2475.                 }
  2476.                 if (kartoteka.model_id.Length > 0)
  2477.                 {
  2478.                     marka_i_model.model_id = kartoteka.model_id;
  2479.                     marka_i_model.get_model_name(kartoteka.model_id);
  2480.                     if (marka_i_model.model_name.Length > 0)
  2481.                     {
  2482.                         marka_i_model.check_model(marka_i_model.model_name, context);
  2483.                         Lookup model_lkp = new Lookup();
  2484.                         if (marka_i_model.model_lkp.name != null)
  2485.                         {
  2486.                             model_lkp = marka_i_model.model_lkp;
  2487.                             Property model_lkp_property = new LookupProperty();
  2488.                             ((LookupProperty)model_lkp_property).Name = "new_modelid";
  2489.                             ((LookupProperty)model_lkp_property).Value = model_lkp;
  2490.                             obj.Properties.Add(model_lkp_property);
  2491.                         }
  2492.                     }
  2493.                 }
  2494.                
  2495.                 if (kartoteka.cvqt_id.Length > 0)
  2496.                 {
  2497.                     Property attr1 = new LookupProperty();
  2498.                     Lookup lkp = new Lookup();
  2499.                     string nom_name = get_nom_name(kartoteka.vid_mps_id, "InsPolicyAutoColor");
  2500.                     lkp = get_crm_lkp(nom_name, "new_color", context);
  2501.                     if (lkp.name != null)
  2502.                     {
  2503.                         ((LookupProperty)attr1).Name = "new_colorid";
  2504.                         ((LookupProperty)attr1).Value = lkp;
  2505.                         obj.Properties.Add(attr1);
  2506.                     }
  2507.                 }
  2508.                 if (kartoteka.boq_id.Length > 0)
  2509.                 {
  2510.                     Property attr2 = new LookupProperty();
  2511.                     Lookup lkp = new Lookup();
  2512.                     string nom_name = get_nom_name(kartoteka.vid_mps_id, "InsPolicyAutoPaint");
  2513.                     lkp = get_crm_lkp(nom_name, "new_painttype", context);
  2514.                     if (lkp.name != null)
  2515.                     {
  2516.                         ((LookupProperty)attr2).Name = "new_painttypeid";
  2517.                         ((LookupProperty)attr2).Value = lkp;
  2518.                         obj.Properties.Add(attr2);
  2519.                     }
  2520.                 }
  2521.                
  2522.                     Property attr3 = new CrmNumberProperty();
  2523.                     ((CrmNumberProperty)attr3).Name = "new_yearofmanufacture";
  2524.                     ((CrmNumberProperty)attr3).Value = kartoteka.godina_proizv;
  2525.                                    
  2526.                     Property attr4 = new CrmNumberProperty();
  2527.                     ((CrmNumberProperty)attr4).Name = "new_volume";
  2528.                     ((CrmNumberProperty)attr4).Value = kartoteka.obem_dvg;
  2529.  
  2530.                     Property attr5 = new PicklistProperty();
  2531.                     ((PicklistProperty)attr5).Name = "new_fuel";
  2532.                     ((PicklistProperty)attr5).Value = kartoteka.vid_gorivo;
  2533.  
  2534.                     Property attr6 = new PicklistProperty();
  2535.                     ((PicklistProperty)attr6).Name = "new_manufacture";
  2536.                     ((PicklistProperty)attr6).Value = kartoteka.proizvodstvo;
  2537.  
  2538.                     Property new_usedfor = new PicklistProperty();
  2539.                     ((PicklistProperty)new_usedfor).Name = "new_usedfor";
  2540.                     ((PicklistProperty)new_usedfor).Value = kartoteka.prednaznachenie;
  2541.  
  2542.                     if (kartoteka.class_mps_id.Length > 0)
  2543.                     {
  2544.                         Property class_lkp = new LookupProperty();
  2545.                         Lookup lkp = new Lookup();
  2546.                         //string nom_name = "InsPolicyAutoClass";
  2547.                         lkp = mepese_class(kartoteka.class_mps_id, context);
  2548.  
  2549.                         if (lkp.name != null)
  2550.                         {
  2551.                             ((LookupProperty)class_lkp).Name = "new_vehicleclassid";
  2552.                             ((LookupProperty)class_lkp).Value = lkp;
  2553.                             obj.Properties.Add(class_lkp);
  2554.                         }
  2555.                     }
  2556.  
  2557.                     obj.Properties.Add(attr3);
  2558.                     obj.Properties.Add(attr4);
  2559.                     obj.Properties.Add(attr5);
  2560.                     obj.Properties.Add(attr6);
  2561.                     obj.Properties.Add(new_usedfor);
  2562.  
  2563.                 Property namee = new StringProperty();
  2564.                 ((StringProperty)namee).Name = "new_name";
  2565.                 ((StringProperty)namee).Value = dkn;
  2566.  
  2567.                 Property lp = new StringProperty();
  2568.                 ((StringProperty)lp).Name = "new_licenceplate";
  2569.                 ((StringProperty)lp).Value = dkn;
  2570.  
  2571.                 Property chasis = new StringProperty();
  2572.                 ((StringProperty)chasis).Name = "new_chassis";
  2573.                 ((StringProperty)chasis).Value = chassis;
  2574.  
  2575.                 Property objtype = new PicklistProperty();
  2576.                 ((PicklistProperty)objtype).Name = "new_type";
  2577.                 ((PicklistProperty)objtype).Value = new Picklist();
  2578.                 ((PicklistProperty)objtype).Value.Value = 1;
  2579.  
  2580.                
  2581.                 obj.Properties.Add(namee);
  2582.                 obj.Properties.Add(lp);
  2583.                 obj.Properties.Add(chasis);
  2584.                 obj.Properties.Add(objtype);
  2585.  
  2586.                 Lookup lookup = new Lookup();
  2587.  
  2588.                 TargetCreateDynamic target = new TargetCreateDynamic();
  2589.                 target.Entity = obj;
  2590.  
  2591.                 CreateRequest request = new CreateRequest();
  2592.                 request.Target = target;
  2593.                 //string xx = "xx";
  2594.                 CreateResponse response = (CreateResponse)service.Execute(request);
  2595.                 Guid lookupid = new Guid();
  2596.                 lookupid = response.id;
  2597.                 string taip = "new_subjectofinsurance";
  2598.  
  2599.                 //danni MPS ot ORACLE s mpsid
  2600.  
  2601.  
  2602.  
  2603.                 lookup.name = dkn;
  2604.                 lookup.type = taip;
  2605.                 lookup.Value = lookupid;
  2606.                 return lookup;
  2607.             }
  2608.             private DynamicEntity GetOffice(string nomernapolica, IPluginExecutionContext context)
  2609.             {
  2610.  
  2611.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  2612.                 string kodofis = nomernapolica.Substring(6, 4);
  2613.                 string x = kodofis;
  2614.                 ConditionExpression con = new ConditionExpression();
  2615.                 con.AttributeName = "new_officeid";
  2616.                 con.Operator = ConditionOperator.Like;
  2617.                 con.Values = new string[] { kodofis };
  2618.                 FilterExpression filter = new FilterExpression();
  2619.                 filter.FilterOperator = LogicalOperator.And;
  2620.                 filter.AddCondition(con);
  2621.                 QueryExpression query = new QueryExpression();
  2622.                 query.EntityName = "account";
  2623.                 query.ColumnSet = new AllColumns();
  2624.                 query.Criteria = filter;
  2625.                 RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
  2626.                 retrieve.Query = query;
  2627.                 retrieve.ReturnDynamicEntities = true;
  2628.                 RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
  2629.  
  2630.                 DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2631.  
  2632.                 return entity;
  2633.             }
  2634.             private DynamicEntity existing_auto_owner(owner ownr, IPluginExecutionContext context)
  2635.             {
  2636.  
  2637.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  2638.  
  2639.                 ConditionExpression con_acc = new ConditionExpression();
  2640.                 con_acc.AttributeName = "new_egn_bulstat";
  2641.                 con_acc.Operator = ConditionOperator.Like;
  2642.                 con_acc.Values = new string[] { ownr.egnbul };
  2643.  
  2644.                 ConditionExpression con_con = new ConditionExpression();
  2645.                 con_con.AttributeName = "new_egn";
  2646.                 con_con.Operator = ConditionOperator.Like;
  2647.                 con_con.Values = new string[] { ownr.egnbul };
  2648.  
  2649.                 FilterExpression filter_acc = new FilterExpression();
  2650.                 filter_acc.FilterOperator = LogicalOperator.And;
  2651.                 filter_acc.AddCondition(con_acc);
  2652.  
  2653.                 FilterExpression filter_con = new FilterExpression();
  2654.                 filter_con.FilterOperator = LogicalOperator.And;
  2655.                 filter_con.AddCondition(con_con);
  2656.  
  2657.                 QueryExpression query_acc = new QueryExpression();
  2658.                 query_acc.EntityName = "account";
  2659.                 query_acc.ColumnSet = new AllColumns();
  2660.                 query_acc.Criteria = filter_acc;
  2661.  
  2662.                 QueryExpression query_con = new QueryExpression();
  2663.                 query_con.EntityName = "contact";
  2664.                 query_con.ColumnSet = new AllColumns();
  2665.                 query_con.Criteria = filter_con;
  2666.  
  2667.                 RetrieveMultipleRequest retrieveM_C = new RetrieveMultipleRequest();
  2668.                 retrieveM_C.Query = query_con;
  2669.                 retrieveM_C.ReturnDynamicEntities = true;
  2670.                 RetrieveMultipleResponse retrieved_c = (RetrieveMultipleResponse)service.Execute(retrieveM_C);
  2671.  
  2672.                 RetrieveMultipleRequest retrieveM = new RetrieveMultipleRequest();
  2673.                 retrieveM.Query = query_con;
  2674.                 retrieveM.ReturnDynamicEntities = true;
  2675.                 RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieveM);
  2676.                 DynamicEntity entity = new DynamicEntity();
  2677.                 if (retrieved_c.BusinessEntityCollection.BusinessEntities.Count > 0)
  2678.                     return (DynamicEntity)retrieved_c.BusinessEntityCollection.BusinessEntities[0];
  2679.                 if (retrieved.BusinessEntityCollection.BusinessEntities.Count > 0)
  2680.                     entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2681.                 return entity;
  2682.  
  2683.  
  2684.             }
  2685.             private DynamicEntity check_existing_object(string dkn, IPluginExecutionContext context)
  2686.             {
  2687.  
  2688.                 ICrmService service = (ICrmService)context.CreateCrmService(true);
  2689.  
  2690.                 ConditionExpression con = new ConditionExpression();
  2691.                 con.AttributeName = "new_licenceplate";
  2692.                 con.Operator = ConditionOperator.Like;
  2693.                 con.Values = new string[] { dkn };
  2694.                 FilterExpression filter = new FilterExpression();
  2695.                 filter.FilterOperator = LogicalOperator.And;
  2696.                 filter.AddCondition(con);
  2697.                 QueryExpression query = new QueryExpression();
  2698.                 query.EntityName = "new_subjectofinsurance";
  2699.                 query.ColumnSet = new AllColumns();
  2700.                 query.Criteria = filter;
  2701.                 RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
  2702.                 retrieve.Query = query;
  2703.                 retrieve.ReturnDynamicEntities = true;
  2704.                 RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
  2705.                 DynamicEntity entity = new DynamicEntity();
  2706.                 if (retrieved.BusinessEntityCollection.BusinessEntities.Count > 0)
  2707.                     return (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
  2708.                 return entity;
  2709.             }
  2710.  
  2711.         }
  2712.     }
  2713. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement