コード例 #1
0
        protected void gvNotasFiscaisReferenciadas_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EXCLUIR_NF")
            {
                var index = Convert.ToInt32(e.CommandArgument);

                var id = this.gvNotasFiscaisReferenciadas.DataKeys[index]["Id"].ToString().ToInt();

                if (id > 0)
                {
                    notaFiscalDAO.ExcluirNotaFiscal(id);
                    ListarNotas();
                }
            }
        }
コード例 #2
0
        public static string RemoverNotaFiscalRemessa(int id)
        {
            var documentoUnicoExportacaoDAO = new DocumentoUnicoExportacaoDAO();
            var notaFiscalDAO = new NotaFiscalDAO();

            var nota = notaFiscalDAO.ObterNotaFiscalPorId(id);

            if (nota == null)
            {
                return("Nota Fiscal não encontrada");
            }

            notaFiscalDAO.ExcluirNotaFiscal(id);

            var notas = documentoUnicoExportacaoDAO.ObterNotasFiscaisRemessaDUE(nota.ChaveNFReferencia, nota.DueId);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(notas));
        }
コード例 #3
0
        //importar arquivos
        protected void btnImportar_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtUpload.PostedFile == null)
                {
                    ModelState.AddModelError(string.Empty, "Nenhum arquivo informado");
                }

                if (this.txtUpload.PostedFile.ContentLength == 0)
                {
                    ModelState.AddModelError(string.Empty, "Arquivo inválido");
                }

                if (this.txtNCM_Default.Text != string.Empty)
                {
                    if (this.txtNCM_Default.Text.Replace(".", "").Length != 8)
                    {
                        ModelState.AddModelError(string.Empty, "NCM inválido. Informe um NCM de 8 dígitos");
                    }
                }


                //if (!this.txtUpload.PostedFile.FileName.ToUpper().EndsWith("TXT") && !this.txtUpload.PostedFile.FileName.ToUpper().EndsWith("CSV"))
                //ModelState.AddModelError(string.Empty, "É permitido apenas importação de arquivos .txt");

                if (_notaFiscalDAO.ExisteNotaFiscalPorNomeArquivo(this.txtUpload.PostedFile.FileName))
                {
                    ModelState.AddModelError(string.Empty, string.Format("O arquivo {0} já foi importado.", this.txtUpload.PostedFile.FileName));
                }

                if (this.chkCriarItensDUE.Checked)
                {
                    if (this.cbCondicaoVenda_Default.SelectedValue == string.Empty)
                    {
                        ModelState.AddModelError(string.Empty, "Selecione a Condição de Venda");
                        this.chkCriarItensDUE.Checked = false;
                    }
                }

                if (!ModelState.IsValid)
                {
                    return;
                }

                if (!UploadArquivo(this.txtUpload))
                {
                    throw new Exception("O arquivo não pode ser processado. Certifique-se que já não esteja aberto em outro programa");
                }

                int quantidadeImportada = 0;

                var notasFiscais = ProcessarArquivo(this.txtUpload.PostedFile.InputStream, ";");

                ExcluirNotasReferenciadas(notasFiscais);

                foreach (var nf in notasFiscais)
                {
                    nf.Arquivo = this.txtUpload.FileName;
                    nf.Usuario = Convert.ToInt32(Session["UsuarioId"].ToString());
                    nf.VMLE    = this.txtValorUnitVMLE_Default.Text.ToDecimal();
                    nf.VMCV    = this.txtValorUnitVMCV_Default.Text.ToDecimal();

                    var existeNf = _notaFiscalDAO.ExisteNotaFiscal(nf);

                    if (existeNf > 0)
                    {
                        _notaFiscalDAO.ExcluirNotaFiscal(existeNf);
                    }

                    nf.Id = _notaFiscalDAO.Cadastrar(nf);

                    quantidadeImportada++;
                }

                int dueId = 0;

                if (this.chkCriarItensDUE.Checked)
                {
                    dueId = CriarItensDUEAutomaticamente(notasFiscais);
                    _documentoUnicoExportacaoDAO.MarcarComoAutomatica(dueId);
                    ViewState["DueId"]        = dueId;
                    this.pnlDueCriada.Visible = true;
                }

                ValidarNotasSiscomex(quantidadeImportada, notasFiscais);

                ViewState["Sucesso"]             = true;
                ViewState["TotalNotasFiscais"]   = notasFiscais.Count;
                ViewState["QuantidadeImportada"] = quantidadeImportada;
            }
            catch (Exception ex)
            {
                DeletarArquivo(this.txtUpload);
                LogsService.Logar("CadastrarDUE.aspx", ex.ToString());
                ModelState.AddModelError(string.Empty, ex.Message);
            }
        }