Пример #1
0
        static void Main(string[] args)
        {
            ContatoService contatoService = new ContatoService(OrganizationName, IsOffline);
            ContaService   contaService   = new ContaService(OrganizationName, IsOffline);

            switch (args[0].ToUpper())
            {
            case "COLOCA_MASCARA_CONTATO":
                contatoService.ColocarMascara();
                break;

            case "COLOCA_MASCARA_CONTA":
                contaService.ColocarMascara();
                break;

            case "CNPJ_REPETIDO":
                try
                {
                    var reader = new StreamReader(File.OpenRead(@"c:\contas_mesmo_cnpjDEV2015.csv"));
                    //if (ErpConection.State == ConnectionState.Closed)
                    //    ErpConection.Open();
                    string[] linhas = reader.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                    for (int x = 0; x < linhas.Length; x++)
                    {
                        string[] valorAtual = linhas[x].Split(';');
                        string   cnpj = valorAtual[0], id = valorAtual[1].ToUpper(), codigo = valorAtual[2];

                        string[] valorProximo = linhas[x + 1].Split(';');
                        string   cnpjProx = valorProximo[0], idProx = valorProximo[1].ToUpper(), codigoProx = valorProximo[2];

                        if (cnpj != cnpjProx)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("CNPJ Triplicado: Linha " + x.ToString());
                            //Console.ReadKey();
                            continue;
                            //return x;
                        }
                        //string query = "Select [IdRevendaCRM] FROM Revendas where [cpfcnpj] = '" + cnpj + "'";
                        //SqlCommand cmd = new SqlCommand(query, ErpConection);
                        //SqlDataReader registroSellOut = cmd.ExecuteReader();
                        //if (registroSellOut.HasRows)
                        //{
                        //    registroSellOut.Read();
                        //    if (id == Convert.ToString(registroSellOut.GetValue(0)).ToUpper() && string.IsNullOrEmpty(codigo))
                        //        MergeContaCRM(new Guid(idProx), new Guid(id), false);
                        //    else //if (idProx == registroSellOut.GetString(0) && string.IsNullOrEmpty(codigoProx))
                        //        MergeContaCRM(new Guid(id), new Guid(idProx), false);
                        //}
                        //else
                        //{
                        if (string.IsNullOrEmpty(codigo))
                        {
                            MergeContaCRM(new Guid(idProx), new Guid(id), false);
                        }
                        else     //if (idProx == registroSellOut.GetString(0) && string.IsNullOrEmpty(codigoProx))
                        {
                            MergeContaCRM(new Guid(id), new Guid(idProx), true);
                        }
                        //}
                        //registroSellOut.Close();
                        //registroSellOut = null;
                        //cmd.Dispose();
                        //cmd = null;
                        x++;
                    }
                }
                catch (Exception ex)
                {
                    string messageError = SDKore.Helper.Error.Handler(ex);
                    Console.WriteLine("Erro : " + messageError);
                    GravaLog(messageError);
                    var hashcode = ex.GetHashCode();
                }

                break;
            }
        }