Beispiel #1
0
 public override void Editar()
 {
     LogIBPT log = new LogIBPT(GUID);
     log.Caminho = @"C:\Teste\teste2.txt";
     log.Save();
     DumpElement(log);
 }
Beispiel #2
0
 public override void Gravar()
 {
     LogIBPT log = new LogIBPT();
     log.Caminho = @"C:\Teste\teste.txt";
     log.MD5 = "12345678912345678912345688";
     log.NomeMaquina = System.Environment.MachineName;
     log.IP = "192.168.0.1";// Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
     log.TipoEvento = Enuns.TipoEvento.Create;
     log.Evento = "Teste das classes";
     log.Descricao = "Teste das classes";
     log.DataHoraEvento = System.DateTime.Today;
     GUID = log.Save();
 }
Beispiel #3
0
 public override void Popular()
 {
     LogIBPT log = new LogIBPT(GUID);
     DumpElement(log);
 }
Beispiel #4
0
        public static bool Import(String filePath, IEstado estado, System.Windows.Forms.ProgressBar progress = null, System.Windows.Forms.Label lblprogress = null, bool raiseErrorFileAlreadyImp = true)
        {
            // verifica se arquivo já foi importado
            string md5 = Cryptography.Files.MD5.GetMD5Hash(filePath);
            IList<ILogIBPT> log = new LogIBPT()
                                            .Find<ILogIBPT>(new Where()
                                            {
                                                {
                                                    "sis_logibpt.md5", md5
                                                }
                                            });
            if (log.Count != 0 && raiseErrorFileAlreadyImp)
                throw new ArquivoJaImportado();

            // verifica se arquivo é do mesmo estado da empresa
            String stateEmp = estado.UF.Sigla;
            String stateFile = filePath.Split('\\')
                                        .Last().Substring(12, 2);
            if (!stateEmp.Equals(stateFile))
                throw new EstadoInvalido();

            Connection connection = null;
            int linhas = 0;
            try
            {
                connection = DbContext.CreateConnection();
                connection.BeginTransaction();

                // Abre arquivo para importação
                INCM ncm = null;
                IList<INCM> ncms = new NCM().Find<INCM>();
                String line = null;
                if (progress != null &&
                    lblprogress != null)
                {
                    progress.Maximum = File.ReadAllLines(filePath).Length;
                    progress.Step = 1;
                    lblprogress.Visible = true;
                    lblprogress.Text = string.Format("{0}% Concluído", (100 * progress.Value) / progress.Maximum);
                    lblprogress.Refresh();
                }
                using (StreamReader str = new StreamReader(filePath, Encoding.Default))
                {

                    while ((line = str.ReadLine()) != null)
                    {
                        string[] sections = line.Split(';');

                        if (linhas == 0 || !String.IsNullOrEmpty(sections[1]))
                        {
                            linhas++;
                            if (progress != null &&
                                lblprogress != null)
                            {
                                progress.Increment(1);
                                lblprogress.Text = string.Format("{0}% Concluído", (100 * progress.Value) / progress.Maximum);
                                lblprogress.Refresh();
                            }
                            continue;
                        }
                        ncm = ncms.FirstOrDefault(w => w.NCM.Trim() == sections[0]);
                        if (ncm == null) ncm = new NCM();

                        ncm.NCM = sections[0];
                        ncm.IPI = 0;
                        ncm.II = 0;
                        ncm.Descricao = sections[3];
                        ncm.ImpostoAproxEstadual = Unimake.Convert.ToDouble(sections[6]);
                        ncm.ImpostoAproximado = Unimake.Convert.ToDouble(sections[6]);
                        ncm.ImpostoAproxImport = Unimake.Convert.ToDouble(sections[5]);
                        ncm.ImpostoAproxMunicip = Unimake.Convert.ToDouble(sections[7]);
                        ncm.ChaveIBPT = sections[10];
                        ncm.Save();
                        linhas++;
                        if (progress != null &&
                            lblprogress != null)
                        {
                            progress.Increment(1);
                            progress.Refresh();
                            lblprogress.Text = string.Format("{0}% Concluído", (100 * progress.Value) / progress.Maximum);
                            lblprogress.Refresh();
                        }
                    }
                }

                if (progress != null &&
                            lblprogress != null)
                {
                    lblprogress.Text = "Arquivo importado com sucesso!";
                    lblprogress.Refresh();

                }
                LogIBPT.Save(new LogIBPT()
                {
                    Evento = "Importação de arquivos de NCM",
                    TipoEvento = Enuns.TipoEvento.Import,
                    Caminho = filePath,
                    MD5 = md5
                });
                connection.CommitTransaction();
            }
            catch
            {
                if (connection != null)
                    connection.RollbackTransaction();

                if (progress != null &&
                           lblprogress != null)
                {
                    lblprogress.Text = "Ocorreu algum erro durante a importação!";
                    lblprogress.Refresh();
                }

                throw;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }
            return true;
        }