Advertisement
Guest User

Untitled

a guest
May 8th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xrm.Sdk.Client;
  7. using Microsoft.Crm;
  8. using System.Runtime.Serialization;
  9. using Microsoft.Xrm.Client;
  10. using Microsoft.Xrm.Client.Services;
  11. using Microsoft.Xrm.Sdk;
  12. using System.Data.SqlClient;
  13. using System.Data;
  14. using Microsoft.Xrm.Sdk.Query;
  15.  
  16.  
  17. namespace Import_cust
  18. {
  19.     class importCust
  20.     {
  21.         //static string connectionString = "Url=http://192.168.0.237/TestDemo; Domain =petpackaging; Username=xrmcrm; Password=Xr`mpTEdcRm@2016;"; //pasijungimas
  22.         static string connectionString = "Url=https://192.168.0.238/CRM; Domain =petpackaging; Username=xrmcrm; Password=Xr`mpTEdcRm@2016;"; //pasijungimas
  23.         static string connectionDB = @"server = 192.168.0.250 ; database = Soltus ; user id = soltus; password = Soltus2011";
  24.         static OrganizationService os;
  25.  
  26.         public static void Main(string[] args)
  27.         {
  28.  
  29.             logIn();
  30.             //createAccTest();
  31.             getData();
  32.            
  33.  
  34.  
  35.         }
  36.  
  37.         public static void logIn()
  38.         {
  39.  
  40.             CrmConnection connection = CrmConnection.Parse(connectionString);
  41.             os = new OrganizationService(connection);
  42.             System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  43.  
  44.         }
  45.  
  46.         public static void createAcc(string no, string name, string regnr, string creditlimit, string currentdebt, string overduedebt ,string salesperson)
  47.         {
  48.             Entity account = new Entity("account");            
  49.             account["accountnumber"] = no;
  50.             account["xs_customerid"] = no;
  51.             account["name"] = name;
  52.             account["xs_accountcode"] = regnr ;
  53.             account["xs_navresponsible"] = salesperson;
  54.             account["xs_creditlimit"] = new Money(Convert.ToDecimal(creditlimit));
  55.             account["xs_currentdebt"] = new Money(Convert.ToDecimal(currentdebt));
  56.             account["xs_overduedebt"] = new Money(Convert.ToDecimal(overduedebt));
  57.             os.Create(account);
  58.             Console.WriteLine("Account created: " + account["name"]);
  59.  
  60.         }
  61.  
  62.         public static void getData()
  63.         {
  64.             SqlConnection c = new SqlConnection(connectionDB); //prisijungimas i db
  65.             SqlConnection c2 = new SqlConnection(connectionDB); // updeitinimo prisijungimas
  66.             c.Open();
  67.             c2.Open();
  68.             SqlCommand co = new SqlCommand(
  69.             @"SELECT  [No_]
  70.            ,[Name]
  71.            ,[regnr]
  72.            ,[creditlimit]
  73.            ,[currentdebt]
  74.            ,[overduedebt]
  75.            ,[Salesperson Code] as sp
  76.            FROM [Soltus].[dbo].[getAccounts]
  77.           "
  78.                , c);
  79.  
  80.             SqlDataReader r = co.ExecuteReader();
  81.  
  82.             while (r.Read())
  83.             {
  84.                 createAcc(
  85.                     r["No_"].ToString(),
  86.                     r["Name"].ToString(),
  87.                     r["regnr"].ToString(),
  88.                     r["creditlimit"].ToString(),
  89.                     r["currentdebt"].ToString(),
  90.                     r["overduedebt"].ToString(),
  91.                     r["sp"].ToString()
  92.                     );
  93.                 insertLog(r["No_"].ToString(), c2);
  94.  
  95.             }
  96.  
  97.             c.Close();
  98.             c2.Close();
  99.             Console.WriteLine("pabaiga");
  100.        
  101.  
  102.         }
  103.  
  104.         public static void insertLog(string no,SqlConnection c2)
  105.         {
  106.             //iraso log'a
  107.             SqlCommand co = new SqlCommand("dbo.insertLog",c2);
  108.             co.CommandType = CommandType.StoredProcedure;
  109.             co.Parameters.Add(new SqlParameter("@No",no));
  110.             co.Parameters.Add(new SqlParameter("@Tipas", "Account"));
  111.             co.Parameters.Add(new SqlParameter("@Veiksmas", "I"));
  112.             co.ExecuteNonQuery();
  113.  
  114.             //updeitina timestamp
  115.             co.CommandType = CommandType.Text;
  116.             co.CommandText = @"update  f
  117.            set f.Laikas = c.timestamp
  118.            from [Soltus].[dbo].[CrmIntegracija] f
  119.            join [NAVDB].[dbo].[Putokšnis$Customer] c
  120.            on f.No_ = c.No_ collate Latin1_General_CI_AI
  121.            where
  122.            f.Veiksmas = 'I' and
  123.            f.No_ = '" + no + "'";
  124.             co.ExecuteNonQuery();
  125.  
  126.  
  127.  
  128.         }
  129.  
  130.         /*
  131.         public static void createAccTest()
  132.         {
  133.             Entity account = new Entity("account");
  134.             account["name"] = "Soltus2";
  135.             account["accountnumber"] = "SOL";
  136.             account["xs_accountcode"] = "SOL123" ;
  137.             account["xs_creditlimit"] = new Money(Convert.ToDecimal("123,00")) ;
  138.             account["xs_currentdebt"] = new Money(Convert.ToDecimal("456,00")) ;
  139.             account["xs_overduedebt"] = new Money(Convert.ToDecimal("789,22")) ;
  140.             os.Create(account);
  141.             Console.WriteLine("Account created: " + account["name"]);
  142.  
  143.         }
  144.         */
  145.  
  146.  
  147.  
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement