|
If it's checking to see if the session object is null or empty, that seems perfectly cromulent.
|
|
|
|
|
Cromulent
Used in an ironical sense to mean legitimate, and therefore, in reality, spurious and not at all legitimate.
Assumes common knowledge of the inherent Simpsons reference.
Excellent choice of words, I have to remember this one...
V.
|
|
|
|
|
Your prose will be the better for it.
|
|
|
|
|
IIRC it's an idiom commonly used in classic ASP to get rid of unwanted nulls when getting data from ADODB Recordset (nulls are quite tricky to test for in ASP3):
field = rs("field") & ""
or
field = CLng("0" & rs("field"))
Seems like some programmer out there has some nostalgy...
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|
Luca Leonardo Scorcia wrote: Seems like some programmer out there has some nostalgy...
It's not just nostalgia. If you move from a language that doesn't have a feature into one that does,
it can take quite a while to "discover" that feature. You've got a solution that works.
To my shame I only recently discovered (thanks to someone on CodeProject correcting me) that you can add methods to structs.
I've been using them as simple data structures for so long that it never crossed my mind to see if I could add methods and
constructors.
-Rd
|
|
|
|
|
If this sort of thing was implemented as a function, and I mean a VERY well-documented function, it would be ingenuous (especially if it was inline, where this is permitted). Otherwise, cute constructs like this are a pain in the tailbone unless you only hire coders who instantly recognize every trick in the book. Good luck with that
|
|
|
|
|
This code is based on true and real CRITICAL application.
In memory
private void ProcessaNota(TextReader txt, string cDestino)
{
string baseDir = InfoApp.PastaSchemas() + "\\nfe_v1.10.xsd";
if (!File.Exists(baseDir))
{
this.cMensagemErro += "Arquivo: " + baseDir +
" não encontrado" + Environment.NewLine;
return;
}
DataSet dsNfe = new DataSet();
dsNfe.ReadXmlSchema(baseDir);
dsNfe.EnforceConstraints = false;
DataRow dremit = dsNfe.Tables["emit"].NewRow();
DataRow drdest = dsNfe.Tables["dest"].NewRow();
DataRow drPISOutr = null;
DataRow drPISST = null;
DataRow drCOFINSOutr = null;
DataRow drCOFINSST = null;
DataRow drtransporta = null;
DataRow drIPITrib = null;
DataRow drVol = null;
string idprod = "";
int iControle = 1;
int nElementos;
int iLeitura;
string[] dados;
Int64 iTmp = 0;
bool vNovaNota = false;
bool vTiraxFant = false;
bool transpAdd = false;
this.nNF = 0;
int DIid = 0;
int prodID = 0;
int idcomb = 0;
int volid = 0;
int indadicid = 0;
while (cLinhaTXT != null)
{
cLinhaTXT = this.ConvertToOEM(this.cLinhaTXT);
bool reLe = false;
for (int x = 0; x < cLinhaTXT.Length - 1; ++x)
if ( char.IsControl(cLinhaTXT, x))
{
this.cMensagemErro += "Linha [" + this.iLinhaLida.ToString() +
"] coluna [" + (x + 1).ToString() + "] contem o caracter [" +
cLinhaTXT.Substring(x, 1) + "] que não é permitido" +
Environment.NewLine;
cLinhaTXT = txt.ReadLine();
iLinhaLida++;
reLe = true;
break;
}
if (reLe)
continue;
dados = cLinhaTXT.Split('|');
dados[0] = dados[0].ToUpper();
nElementos = dados.GetLength(0) - 1;
for (int n = 0; n < nElementos; ++n)
dados[n] = dados[n].Trim();
#region -- Segmentos
switch (dados[0])
{
case "NOTAFISCAL":
case "NOTA FISCAL":
break;
case "A":
#region -- A
if (this.nNF > 0)
{
vNovaNota = true;
}
else
{
DataRow dr = dsNfe.Tables["infNFe"].NewRow();
if (nElementos >= 1)
dr["versao"] = dados[1].Trim();
if (nElementos >= 2)
dr["id"] = dados[2];
dr["infNFe_Id"] = 0;
dsNfe.Tables["infNFe"].Rows.Add(dr);
this.Check(dados[0], "versao", dr, ObOp.Obrigatorio, 1, 4);
}
break;
#endregion
case "B":
#region -- B
{
DataRow dr = dsNfe.Tables["ide"].NewRow();
cChave = "";
this.PopulateDataRow(dr, dados, 18);
dr["infNFe_Id"] = 0;
dr["ide_Id"] = 0;
dr["procEmi"] = 0;
dsNfe.Tables["ide"].Rows.Add(dr);
if (dr["cUF"].ToString() == "")
dr["cUF"] = ConfiguracaoApp.UFCod;
this.Check(dados[0], "cUF", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "natOp", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "mod", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "serie", dr, ObOp.Obrigatorio, 1, 3);
this.Check(dados[0], "nNF", dr, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "dEmi", dr, ObOp.Obrigatorio);
this.Check(dados[0], "dSaiEnt", dr, ObOp.Opcional);
this.Check(dados[0], "tpNF", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "cMunFG", dr, ObOp.Obrigatorio, 7, 7);
this.Check(dados[0], "tpImp", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "tpEmis", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "cDV", dr, ObOp.Opcional, 1, 1);
this.Check(dados[0], "tpAmb", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "finNFe", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "procEmi", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "verProc", dr, ObOp.Obrigatorio, 1, 20);
serie = Convert.ToInt32("0" + dr["serie"].ToString());
nNF = Convert.ToInt32("0" + dr["nNF"].ToString());
cNF = Convert.ToInt32("0" + dr["cNF"].ToString());
cDV = Convert.ToInt32("0" + dr["cDV"].ToString()); ;
cChave = dr["cUF"].ToString() + dr["dEmi"].ToString().Substring(2, 2) +
dr["dEmi"].ToString().Substring(5, 2);
}
break;
#endregion
case "B13":
case "B14":
#region -- B13 ou B14
{
DataRow drNFref = dsNfe.Tables["NFref"].NewRow();
drNFref["ide_Id"] = 0;
drNFref["NFref_Id"] = iControle;
if (dados[0] == "B13")
{
if (nElementos >= 1)
if (dados[1].Trim() != "")
drNFref[0] = dados[1].Trim();
this.Check(dados[0], "refNFe", drNFref, ObOp.Obrigatorio, 44, 44);
}
dsNfe.Tables["NFref"].Rows.Add(drNFref);
if (dados[0] == "B14")
{
DataRow dr = dsNfe.Tables["refNF"].NewRow();
if (this.PopulateDataRow(dr, dados, 6))
{
dr["serie"] = Convert.ToInt32("0" + dr["serie"].ToString());
dr["NFref_Id"] = iControle;
dsNfe.Tables["refNF"].Rows.Add(dr);
this.Check(dados[0], "cUF", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "AAMM", dr, ObOp.Obrigatorio, 4, 4);
this.Check(dados[0], "CNPJ", dr, ObOp.Obrigatorio, 14, 14);
this.Check(dados[0], "mod", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "serie", dr, ObOp.Obrigatorio, 1, 3);
this.Check(dados[0], "nNF", dr, ObOp.Obrigatorio, 1, 9);
}
}
iControle = iControle + 1;
}
break;
#endregion
case "C":
#region -- C
{
dremit["IE"] = "";
dremit["infNFe_Id"] = 0;
dremit["emit_Id"] = 0;
dremit["xNome"] = dados[1];
if (nElementos > 1)
{
if (dados[2] != "")
dremit["xFant"] = dados[2];
if (nElementos > 2)
{
if (dados[3] != "")
dremit["IE"] = dados[3];
if (nElementos > 3)
{
if (dados[4] != "")
dremit["IEST"] = dados[4];
if (nElementos > 4)
{
if (dados[5] != "")
dremit["IM"] = dados[5];
if (nElementos > 5)
{
if (dados[6] != "")
dremit["CNAE"] = dados[6];
}
}
}
}
}
this.Check(dados[0], "xNome", dremit, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "xFant", dremit, ObOp.Opcional, 1, 60);
this.Check(dados[0], "IE", dremit, ObOp.Obrigatorio, 0, 14);
this.Check(dados[0], "IEST", dremit, ObOp.Opcional, 2, 14);
this.Check(dados[0], "IM", dremit, ObOp.Opcional, 1, 15);
this.Check(dados[0], "CNAE", dremit, ObOp.Opcional, 7, 7);
if (dremit["xFant"].ToString() == "")
{
vTiraxFant = true;
dremit["xFant"] = dremit["xNome"].ToString();
}
}
break;
#endregion
case "C02":
#region -- C02
if (nElementos >= 1)
if (dados[1].Trim() != "")
dremit[0] = dados[1].Trim();
this.Check(dados[0], "CNPJ", dremit, ObOp.Obrigatorio, 14, 14);
iTmp = Convert.ToInt64("0" + dremit["CNPJ"]);
cChave = cChave + iTmp.ToString("00000000000000") + "55";
break;
#endregion
case "C02A":
#region -- C02A
if (nElementos >= 1)
if (dados[1].Trim() != "")
dremit[1] = dados[1].Trim();
this.Check(dados[0], "CPF", dremit, ObOp.Obrigatorio, 11, 11);
break;
#endregion
case "C05":
#region -- C05
{
DataRow dr = dsNfe.Tables["enderEmit"].NewRow();
dr["emit_Id"] = 0;
dsNfe.Tables["emit"].Rows.Add(dremit);
if (this.PopulateDataRow(dr, dados, 11))
{
dsNfe.Tables["enderEmit"].Rows.Add(dr);
this.Check(dados[0], "xLgr", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "nro", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "xCpl", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "xBairro", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "cMun", dr, ObOp.Obrigatorio, 1, 7);
this.Check(dados[0], "xMun", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "UF", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "CEP", dr, ObOp.Opcional, 8, 8);
this.Check(dados[0], "cPais", dr, ObOp.Opcional, 4, 4);
this.Check(dados[0], "xPais", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "fone", dr, ObOp.Opcional, 1, 10);
}
}
break;
#endregion
case "D":
#region -- D
{
DataRow dr = dsNfe.Tables["avulsa"].NewRow();
if (this.PopulateDataRow(dr, dados, 11))
{
dr["infNFe_Id"] = 0;
dsNfe.Tables["avulsa"].Rows.Add(dr);
this.Check(dados[0], "CNPJ", dr, ObOp.Obrigatorio, 14, 14);
this.Check(dados[0], "xOrgao", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "matr", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "xAgente", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "fone", dr, ObOp.Obrigatorio, 1, 10);
this.Check(dados[0], "UF", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "nDAR", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "dEmi", dr, ObOp.Obrigatorio);
this.Check(dados[0], "vDAR", dr, ObOp.Obrigatorio, 1, 15);
this.Check(dados[0], "repEmi", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "dPag", dr, ObOp.Opcional);
}
}
break;
#endregion
case "E":
#region -- E
{
dsNfe.Tables["dest"].Columns["IE"].AllowDBNull = true;
drdest["IE"] = "";
for (iLeitura = 0; iLeitura <= Math.Min(nElementos, 3); iLeitura++)
{
if (iLeitura > 1 & dados[iLeitura] != null && dados[iLeitura - 1].Trim() != "")
drdest[iLeitura] = dados[iLeitura - 1].Trim();
}
drdest["dest_Id"] = 0;
drdest["infNFe_Id"] = 0;
this.Check(dados[0], "xNome", drdest, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "IE", drdest, ObOp.Obrigatorio, 0, 14);
this.Check(dados[0], "ISUF", drdest, ObOp.Opcional, 1, 9);
}
break;
#endregion
case "E02":
#region -- E02
if (nElementos >= 1)
if (dados[1].Trim() != "")
{
drdest["CNPJ"] = dados[1].Trim();
this.Check(dados[0], "CNPJ", drdest, ObOp.Obrigatorio, 14, 14);
}
dsNfe.Tables["dest"].Rows.Add(drdest);
break;
#endregion
case "E03":
#region -- E03
if (nElementos >= 1)
if (dados[1].Trim() != "")
{
drdest["CPF"] = dados[1].Trim();
this.Check(dados[0], "CPF", drdest, ObOp.Obrigatorio, 11, 11);
}
dsNfe.Tables["dest"].Rows.Add(drdest);
break;
#endregion
case "E05":
#region -- E05
{
DataRow drenderDest = dsNfe.Tables["enderDest"].NewRow();
if (this.PopulateDataRow(drenderDest, dados, 11))
{
drenderDest["dest_Id"] = 0;
dsNfe.Tables["enderDest"].Rows.Add(drenderDest);
this.Check(dados[0], "xLgr", drenderDest, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "nro", drenderDest, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "xCpl", drenderDest, ObOp.Opcional, 1, 60);
this.Check(dados[0], "xBairro", drenderDest, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "cMun", drenderDest, ObOp.Obrigatorio, 1, 7);
this.Check(dados[0], "xMun", drenderDest, ObOp.Opcional, 1, 60);
this.Check(dados[0], "UF", drenderDest, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "CEP", drenderDest, ObOp.Opcional, 8, 8);
this.Check(dados[0], "cPais", drenderDest, ObOp.Opcional, 1, 4);
this.Check(dados[0], "xPais", drenderDest, ObOp.Opcional, 1, 60);
this.Check(dados[0], "fone", drenderDest, ObOp.Opcional, 1, 10);
if (drenderDest["UF"].ToString() == "EX")
{
if (dsNfe.Tables["dest"].Rows.Count == 0)
dsNfe.Tables["dest"].Rows.Add(drdest);
dsNfe.Tables["dest"].Rows[0]["IE"] = "";
dsNfe.Tables["dest"].Rows[0]["CNPJ"] = "";
}
else
if (dsNfe.Tables["dest"].Rows.Count == 0)
this.cMensagemErro += "Falta definir o segmento [E02] ou [E03]" + Environment.NewLine;
}
}
break;
#endregion
case "F":
#region -- F
{
DataRow drretirada = dsNfe.Tables["retirada"].NewRow();
if (this.PopulateDataRow(drretirada, dados, 8))
{
drretirada["infNFe_Id"] = 0;
dsNfe.Tables["retirada"].Rows.Add(drretirada);
this.Check(dados[0], "CNPJ", drretirada, ObOp.Obrigatorio, 14, 14);
this.Check(dados[0], "xLgr", drretirada, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "nro", drretirada, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "xCpl", drretirada, ObOp.Opcional, 1, 60);
this.Check(dados[0], "xBairro", drretirada, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "cMun", drretirada, ObOp.Obrigatorio, 1, 7);
this.Check(dados[0], "xMun", drretirada, ObOp.Opcional, 1, 60);
this.Check(dados[0], "UF", drretirada, ObOp.Obrigatorio, 2, 2);
}
}
break;
#endregion
case "G":
#region -- G
{
DataRow drentrega = dsNfe.Tables["entrega"].NewRow();
if (this.PopulateDataRow(drentrega, dados, 8))
{
drentrega["infNFe_Id"] = 0;
dsNfe.Tables["entrega"].Rows.Add(drentrega);
this.Check(dados[0], "CNPJ", drentrega, ObOp.Obrigatorio, 14, 14);
this.Check(dados[0], "xLgr", drentrega, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "nro", drentrega, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "xCpl", drentrega, ObOp.Opcional, 1, 60);
this.Check(dados[0], "xBairro", drentrega, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "cMun", drentrega, ObOp.Obrigatorio, 1, 7);
this.Check(dados[0], "xMun", drentrega, ObOp.Opcional, 1, 60);
this.Check(dados[0], "UF", drentrega, ObOp.Obrigatorio, 2, 2);
}
}
break;
#endregion
case "H":
#region -- H
{
bool r = false;
DataRow drdet = dsNfe.Tables["det"].NewRow();
if (nElementos >= 1)
{
if (dados[1].Trim() != "")
{
drdet["nItem"] = dados[1].Trim();
r = true;
}
}
if (nElementos >= 2)
{
if (dados[2].Trim() != "")
drdet["infAdProd"] = dados[2].Trim();
else
drdet["infAdProd"] = "~-?-~";
}
else
drdet["infAdProd"] = "~-?-~";
if (r)
{
idprod = drdet["nItem"].ToString();
drdet["det_Id"] = idprod;
drdet["infNFe_Id"] = 0;
dsNfe.Tables["det"].Rows.Add(drdet);
this.Check(dados[0], "nItem", drdet, ObOp.Obrigatorio, 1, 3);
this.Check(dados[0], "infAdProd", drdet, ObOp.Opcional, 0, 500);
}
else
idprod = "";
prodID = Convert.ToInt32("0" + idprod);
}
break;
#endregion
case "I":
#region -- I
{
DataRow drprod = dsNfe.Tables["prod"].NewRow();
drprod["cEAN"] = "";
drprod["CEANTrib"] = "";
if (this.PopulateDataRow(drprod, dados, 18))
{
if (idprod == "")
{
cMensagemErro += "Segmento [I] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
drprod[19] = idprod.ToString();
drprod["prod_ID"] = prodID.ToString();
++prodID;
dsNfe.Tables["prod"].Rows.Add(drprod);
this.Check(dados[0], "cProd", drprod, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "cEAN", drprod, ObOp.Obrigatorio, 0, 14);
this.Check(dados[0], "xProd", drprod, ObOp.Obrigatorio, 1, 120);
this.Check(dados[0], "NCM", drprod, ObOp.Opcional, 8, 8);
this.Check(dados[0], "EXTIPI", drprod, ObOp.Opcional, 2, 3);
this.Check(dados[0], "genero", drprod, ObOp.Opcional, 2, 2);
this.Check(dados[0], "CFOP", drprod, ObOp.Obrigatorio, 4, 4);
this.Check(dados[0], "uCom", drprod, ObOp.Obrigatorio, 1, 6);
this.Check(dados[0], "qCom", drprod, ObOp.Obrigatorio, 1, 12, 4);
this.Check(dados[0], "vUnCom", drprod, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vProd", drprod, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "cEANTrib", drprod, ObOp.Obrigatorio, 0, 14);
this.Check(dados[0], "uTrib", drprod, ObOp.Obrigatorio, 1, 6);
this.Check(dados[0], "qTrib", drprod, ObOp.Obrigatorio, 1, 12, 4);
this.Check(dados[0], "vUnTrib", drprod, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vFrete", drprod, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vSeg", drprod, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vDesc", drprod, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "I18":
#region -- I18
{
DataRow drDI = dsNfe.Tables["DI"].NewRow();
if (this.PopulateDataRow(drDI, dados, 6))
{
++DIid;
drDI["prod_Id"] = idprod.ToString();
drDI["DI_Id"] = DIid.ToString();
dsNfe.Tables["DI"].Rows.Add(drDI);
this.Check(dados[0], "nDI", drDI, ObOp.Obrigatorio, 1, 10);
this.Check(dados[0], "dDI", drDI, ObOp.Obrigatorio);
this.Check(dados[0], "xLocDesemb", drDI, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "UFDesemb", drDI, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "dDesemb", drDI, ObOp.Obrigatorio);
this.Check(dados[0], "cExportador", drDI, ObOp.Obrigatorio, 1, 60);
}
}
break;
#endregion
case "I25":
#region -- I25
{
DataRow dradi = dsNfe.Tables["adi"].NewRow();
if (this.PopulateDataRow(dradi, dados, 4))
{
dradi["DI_Id"] = DIid.ToString();
dsNfe.Tables["adi"].Rows.Add(dradi);
this.Check(dados[0], "nAdicao", dradi, ObOp.Obrigatorio, 1, 3);
this.Check(dados[0], "nSeqAdic", dradi, ObOp.Obrigatorio, 1, 3);
this.Check(dados[0], "cFabricante", dradi, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "vDescDI", dradi, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "J":
#region -- J
{
DataRow drveicProd = dsNfe.Tables["veicProd"].NewRow();
if (this.PopulateDataRow(drveicProd, dados, 22))
{
drveicProd["prod_id"] = idprod;
dsNfe.Tables["veicProd"].Rows.Add(drveicProd);
this.Check(dados[0], "tpOp", drveicProd, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "chassi", drveicProd, ObOp.Obrigatorio, 1, 17);
this.Check(dados[0], "cCor", drveicProd, ObOp.Obrigatorio, 1, 4);
this.Check(dados[0], "xCor", drveicProd, ObOp.Obrigatorio, 1, 40);
this.Check(dados[0], "pot", drveicProd, ObOp.Obrigatorio, 1, 4);
this.Check(dados[0], "CM3", drveicProd, ObOp.Obrigatorio, 1, 4);
this.Check(dados[0], "pesoL", drveicProd, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "pesoB", drveicProd, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "nSerie", drveicProd, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "tpComb", drveicProd, ObOp.Obrigatorio, 1, 8);
this.Check(dados[0], "nMotor", drveicProd, ObOp.Obrigatorio, 1, 21);
this.Check(dados[0], "CMKG", drveicProd, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "dist", drveicProd, ObOp.Obrigatorio, 1, 4);
this.Check(dados[0], "RENAVAM", drveicProd, ObOp.Opcional, 1, 9);
this.Check(dados[0], "anoMod", drveicProd, ObOp.Obrigatorio, 4, 4);
this.Check(dados[0], "anoFab", drveicProd, ObOp.Obrigatorio, 4, 4);
this.Check(dados[0], "tpPint", drveicProd, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "tpVeic", drveicProd, ObOp.Obrigatorio, 1, 2);
this.Check(dados[0], "espVeic", drveicProd, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "VIN", drveicProd, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "condVeic", drveicProd, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "cMod", drveicProd, ObOp.Obrigatorio, 1, 6);
}
}
break;
#endregion
case "K":
#region -- K
{
DataRow drmed = dsNfe.Tables["med"].NewRow();
if (this.PopulateDataRow(drmed, dados, 5))
{
drmed["prod_Id"] = idprod;
dsNfe.Tables["med"].Rows.Add(drmed);
this.Check(dados[0], "nLote", drmed, ObOp.Obrigatorio, 20, 20);
this.Check(dados[0], "qLote", drmed, ObOp.Obrigatorio, 1, 11, 3);
this.Check(dados[0], "dFab", drmed, ObOp.Obrigatorio);
this.Check(dados[0], "dVal", drmed, ObOp.Obrigatorio);
this.Check(dados[0], "vPMC", drmed, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "L":
#region -- L
{
DataRow drarma = dsNfe.Tables["arma"].NewRow();
if (this.PopulateDataRow(drarma, dados, 4))
{
drarma["prod_Id"] = idprod;
dsNfe.Tables["arma"].Rows.Add(drarma);
this.Check(dados[0], "tpArma", drarma, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "nSerie", drarma, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "nCano", drarma, ObOp.Obrigatorio, 1, 9);
this.Check(dados[0], "descr", drarma, ObOp.Obrigatorio, 1, 256);
}
}
break;
#endregion
case "L01":
case "L1":
#region -- L01 ou L1
{
DataRow drcomb = dsNfe.Tables["comb"].NewRow();
if (this.PopulateDataRow(drcomb, dados, 3))
{
++idcomb;
drcomb["prod_Id"] = idprod;
drcomb["comb_Id"] = idcomb.ToString();
dsNfe.Tables["comb"].Rows.Add(drcomb);
this.Check(dados[0], "cProdANP", drcomb, ObOp.Opcional, 9, 9);
this.Check(dados[0], "CODIF", drcomb, ObOp.Opcional, 0, 21);
this.Check(dados[0], "qTemp", drcomb, ObOp.Opcional, 1, 16, 4);
}
}
break;
#endregion
case "L05":
case "L105":
#region -- L05 ou L105
{
DataRow drCIDE = dsNfe.Tables["CIDE"].NewRow();
if (this.PopulateDataRow(drCIDE, dados, 3))
{
drCIDE["comb_Id"] = idcomb.ToString();
dsNfe.Tables["CIDE"].Rows.Add(drCIDE);
this.Check(dados[0], "qBCprod", drCIDE, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", drCIDE, ObOp.Obrigatorio, 1, 15, 4);
this.Check(dados[0], "vCIDE", drCIDE, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "L09":
case "L109":
#region -- L09 ou L109
{
DataRow drICMSComb = dsNfe.Tables["ICMSComb"].NewRow();
if (this.PopulateDataRow(drICMSComb, dados, 4))
{
drICMSComb["comb_Id"] = idcomb.ToString();
dsNfe.Tables["ICMSComb"].Rows.Add(drICMSComb);
this.Check(dados[0], "vBCICMS", drICMSComb, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vICMS", drICMSComb, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vBCICMSST", drICMSComb, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vICMSST", drICMSComb, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "L114":
#region -- L114
{
DataRow drICMSInter = dsNfe.Tables["ICMSInter"].NewRow();
if (this.PopulateDataRow(drICMSInter, dados, 2))
{
drICMSInter["comb_Id"] = idcomb.ToString();
dsNfe.Tables["ICMSInter"].Rows.Add(drICMSInter);
this.Check(dados[0], "vBCICMSSTDest", drICMSInter, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vICMSSTDest", drICMSInter, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "L117":
#region -- L117
{
DataRow drICMSCons = dsNfe.Tables["ICMSCons"].NewRow();
if (this.PopulateDataRow(drICMSCons, dados, 3))
{
drICMSCons["comb_Id"] = idcomb.ToString();
dsNfe.Tables["ICMSCons"].Rows.Add(drICMSCons);
this.Check(dados[0], "vBCICMSSTCons", drICMSCons, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vICMSSTCons", drICMSCons, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "UFcons", drICMSCons, ObOp.Obrigatorio, 2, 2);
}
}
break;
#endregion
case "N":
#region -- N
{
if (idprod != "")
{
DataRow dr = dsNfe.Tables["imposto"].NewRow();
dr["imposto_Id"] = idprod.ToString();
dr["det_Id"] = idprod.ToString();
dsNfe.Tables["imposto"].Rows.Add(dr);
dr = dsNfe.Tables["ICMS"].NewRow();
dr["ICMS_Id"] = idprod.ToString();
dr["imposto_Id"] = idprod.ToString();
dsNfe.Tables["ICMS"].Rows.Add(dr);
}
else
cMensagemErro += "Segmento [N] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
break;
#endregion
case "N02":
#region -- N02
{
DataRow dr = dsNfe.Tables["ICMS00"].NewRow();
if (this.PopulateDataRow(dr, dados, 6))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N02] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS00"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBC", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "N03":
#region -- N03
{
DataRow dr = dsNfe.Tables["ICMS10"].NewRow();
if (this.PopulateDataRow(dr, dados, 12))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N03] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS10"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBC", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "modBCST", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pMVAST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "pRedBCST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vBCST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMSST", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMSST", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "N04":
#region -- N04
{
DataRow dr = dsNfe.Tables["ICMS20"].NewRow();
if (this.PopulateDataRow(dr, dados, 7))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N04] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS20"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBC", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pRedBC", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "N05":
#region -- N05
{
DataRow dr = dsNfe.Tables["ICMS30"].NewRow();
if (this.PopulateDataRow(dr, dados, 8))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N05] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS30"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBCST", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pMVAST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "pRedBCST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vBCST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMSST", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMSST", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "N06":
#region -- N06
{
DataRow dr = dsNfe.Tables["ICMS40"].NewRow();
if (this.PopulateDataRow(dr, dados, 2))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N06] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS40"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
}
}
break;
#endregion
case "N07":
#region -- N07
{
DataRow dr = dsNfe.Tables["ICMS51"].NewRow();
if (this.PopulateDataRow(dr, dados, 7))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N07] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS51"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBC", dr, ObOp.Opcional, 1, 1);
this.Check(dados[0], "pRedBC", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vBC", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "pICMS", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "N08":
#region -- N08
{
DataRow dr = dsNfe.Tables["ICMS60"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N08] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS60"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "vBCST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vICMSST", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "N09":
#region -- N09
{
DataRow dr = dsNfe.Tables["ICMS70"].NewRow();
if (this.PopulateDataRow(dr, dados, 13))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N09] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS70"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBC", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pRedBC", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "modBCST", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pMVAST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "pRedBCST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vBCST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMSST", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMSST", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "N10":
#region -- N10
{
DataRow dr = dsNfe.Tables["ICMS90"].NewRow();
if (this.PopulateDataRow(dr, dados, 13))
{
if (idprod == "")
{
cMensagemErro += "Segmento [N10] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["ICMS_Id"] = idprod.ToString();
dsNfe.Tables["ICMS90"].Rows.Add(dr);
this.Check(dados[0], "orig", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "modBC", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pRedBC", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "modBCST", dr, ObOp.Obrigatorio, 1, 1);
this.Check(dados[0], "pMVAST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "pRedBCST", dr, ObOp.Opcional, 1, 5, 2);
this.Check(dados[0], "vBCST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMSST", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMSST", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "O":
#region -- O
{
DataRow dr = dsNfe.Tables["IPI"].NewRow();
if (this.PopulateDataRow(dr, dados, 5))
{
if (idprod == "")
{
cMensagemErro += "Segmento [O] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["IPI_Id"] = idprod.ToString();
dr["imposto_Id"] = idprod.ToString();
dsNfe.Tables["IPI"].Rows.Add(dr);
this.Check(dados[0], "clEnq", dr, ObOp.Opcional, 5, 5);
this.Check(dados[0], "CNPJProd", dr, ObOp.Opcional, 14, 14);
this.Check(dados[0], "cSelo", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "qSelo", dr, ObOp.Opcional, 1, 12);
this.Check(dados[0], "cEnq", dr, ObOp.Obrigatorio, 3, 3);
}
}
break;
#endregion
case "O07":
case "O10":
case "O11":
#region -- O07, O08 e O11
{
if (dados[0] == "O07")
{
drIPITrib = dsNfe.Tables["IPITrib"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
drIPITrib["CST"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drIPITrib["vIPI"] = dados[2].Trim();
if (idprod == "")
{
cMensagemErro += "Segmento [O07] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
this.Check(dados[0], "CST", drIPITrib, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "vIPI", drIPITrib, ObOp.Obrigatorio, 1, 15, 2);
}
if (dados[0] == "O10")
{
if (nElementos >= 1)
if (dados[1].Trim() != "")
drIPITrib["vBC"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drIPITrib["pIPI"] = dados[2].Trim();
if (idprod == "")
{
cMensagemErro += "Segmento [O10] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
this.Check(dados[0], "vBC", drIPITrib, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pIPI", drIPITrib, ObOp.Obrigatorio, 1, 5, 2);
}
if (dados[0] == "O11")
{
if (nElementos >= 1)
if (dados[1].Trim() != "")
drIPITrib["vUnid"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drIPITrib["qUnid"] = dados[2].Trim();
if (idprod == "")
{
cMensagemErro += "Segmento [O11] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
this.Check(dados[0], "vUnid", drIPITrib, ObOp.Obrigatorio, 1, 15, 4);
this.Check(dados[0], "qUnid", drIPITrib, ObOp.Obrigatorio, 1, 16, 4);
}
drIPITrib["IPI_Id"] = idprod.ToString();
if (dados[0] != "O07")
dsNfe.Tables["IPITrib"].Rows.Add(drIPITrib);
}
break;
#endregion
case "O08":
#region -- O08
{
if (idprod == "")
{
cMensagemErro += "Segmento [O08] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
DataRow dr = dsNfe.Tables["IPINT"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
dr["CST"] = dados[1].Trim();
dr["IPI_Id"] = idprod.ToString();
dsNfe.Tables["IPINT"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
}
break;
#endregion
case "P":
#region -- P
{
DataRow dr = dsNfe.Tables["II"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
if (idprod == "")
{
cMensagemErro += "Segmento [P] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["imposto_Id"] = idprod.ToString();
dsNfe.Tables["II"].Rows.Add(dr);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vDespAdu", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vII", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vIOF", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "Q":
#region -- Q
{
if (idprod == "")
{
cMensagemErro += "Segmento [Q] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
DataRow dr = dsNfe.Tables["PIS"].NewRow();
dr["PIS_Id"] = idprod.ToString();
dr["imposto_Id"] = idprod.ToString();
dsNfe.Tables["PIS"].Rows.Add(dr);
}
break;
#endregion
case "Q02":
#region -- Q02
{
DataRow dr = dsNfe.Tables["PISAliq"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
if (idprod == "")
{
cMensagemErro += "Segmento [Q02] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["PIS_Id"] = idprod.ToString();
dsNfe.Tables["PISAliq"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pPIS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vPIS", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "Q03":
#region -- Q03
{
DataRow dr = dsNfe.Tables["PISQtde"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
if (idprod == "")
{
cMensagemErro += "Segmento [Q03] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["PIS_Id"] = idprod.ToString();
dsNfe.Tables["PISQtde"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "qBCProd", dr, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", dr, ObOp.Obrigatorio, 1, 15, 4);
this.Check(dados[0], "vPIS", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "Q04":
#region -- Q04
{
if (idprod == "")
{
cMensagemErro += "Segmento [Q04] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
DataRow dr = dsNfe.Tables["PISNT"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
dr["CST"] = dados[1].Trim();
dr["PIS_Id"] = idprod.ToString();
dsNfe.Tables["PISNT"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
}
break;
#endregion
case "Q05":
#region -- Q05
if (idprod == "")
{
cMensagemErro += "Segmento [Q05] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
drPISOutr = dsNfe.Tables["PISOutr"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
drPISOutr["CST"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drPISOutr["vPIS"] = dados[2].Trim();
drPISOutr["PIS_Id"] = idprod.ToString();
dsNfe.Tables["PISOutr"].Rows.Add(drPISOutr);
this.Check(dados[0], "CST", drPISOutr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "vPIS", drPISOutr, ObOp.Obrigatorio, 1, 15, 2);
break;
#endregion
case "Q07":
#region -- Q07
if (nElementos >= 1)
if (dados[1].Trim() != "")
drPISOutr["vBC"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drPISOutr["pPIS"] = dados[2].Trim();
this.Check(dados[0], "vBC", drPISOutr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pPIS", drPISOutr, ObOp.Obrigatorio, 1, 5, 2);
break;
#endregion
case "Q10":
#region -- Q10
if (nElementos >= 1)
if (dados[1].Trim() != "")
drPISOutr["qBCProd"] = dados[1];
if (nElementos >= 2)
if (dados[2].Trim() != "")
drPISOutr["vAliqProd"] = dados[2];
this.Check(dados[0], "qBCProd", drPISOutr, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", drPISOutr, ObOp.Obrigatorio, 1, 15, 4);
break;
#endregion
case "R":
#region -- R
drPISST = dsNfe.Tables["PISST"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
drPISST[4] = dados[1].Trim();
this.Check(dados[0], "vPIS", drPISST, ObOp.Obrigatorio, 1, 15, 2);
break;
#endregion
case "R02":
#region -- R02
if (nElementos >= 1)
if (dados[1].Trim() != "")
drPISST[0] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drPISST[1] = dados[2].Trim();
this.Check(dados[0], "vBC", drPISST, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pPIS", drPISST, ObOp.Obrigatorio, 1, 5, 2);
break;
#endregion
case "R04":
#region -- R04
if (nElementos >= 1)
if (dados[1].Trim() != "")
drPISST[2] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drPISST[3] = dados[2].Trim();
this.Check(dados[0], "qBCProd", drPISST, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", drPISST, ObOp.Obrigatorio, 1, 15, 4);
break;
#endregion
case "S":
#region -- S
{
if (idprod == "")
{
cMensagemErro += "Segmento [S] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
DataRow drCOFINS = dsNfe.Tables["COFINS"].NewRow();
drCOFINS["COFINS_Id"] = idprod.ToString();
drCOFINS["imposto_Id"] = idprod.ToString();
dsNfe.Tables["COFINS"].Rows.Add(drCOFINS);
}
break;
#endregion
case "S02":
#region -- S02
{
DataRow dr = dsNfe.Tables["COFINSAliq"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
if (idprod == "")
{
cMensagemErro += "Segmento [S02] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["COFINS_Id"] = idprod.ToString();
dsNfe.Tables["COFINSAliq"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pCOFINS", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vCOFINS", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "S03":
#region -- S03
{
DataRow dr = dsNfe.Tables["COFINSQtde"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
if (idprod == "")
{
cMensagemErro += "Segmento [S03] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["COFINS_Id"] = idprod.ToString();
dsNfe.Tables["COFINSQtde"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "qBCProd", dr, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", dr, ObOp.Obrigatorio, 1, 15, 4);
this.Check(dados[0], "vCOFINS", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "S04":
#region -- S04
{
if (idprod == "")
{
cMensagemErro += "Segmento [S04] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
DataRow dr = dsNfe.Tables["COFINSNT"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
dr["CST"] = dados[1].Trim();
dr["COFINS_Id"] = idprod.ToString();
dsNfe.Tables["COFINSNT"].Rows.Add(dr);
this.Check(dados[0], "CST", dr, ObOp.Obrigatorio, 2, 2);
}
break;
#endregion
case "S05":
#region -- S05
if (idprod == "")
{
cMensagemErro += "Segmento [S05] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
drCOFINSOutr = dsNfe.Tables["COFINSOutr"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
drCOFINSOutr["CST"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drCOFINSOutr["vCOFINS"] = dados[2].Trim();
drCOFINSOutr["COFINS_Id"] = idprod.ToString();
this.Check(dados[0], "CST", drCOFINSOutr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "vCOFINS", drCOFINSOutr, ObOp.Obrigatorio, 1, 15, 2);
break;
#endregion
case "S07":
#region -- S07
if (nElementos >= 1)
if (dados[1].Trim() != "")
drCOFINSOutr["vBC"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drCOFINSOutr["pCOFINS"] = dados[2].Trim();
dsNfe.Tables["COFINSOutr"].Rows.Add(drCOFINSOutr);
this.Check(dados[0], "vBC", drCOFINSOutr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pCOFINS", drCOFINSOutr, ObOp.Obrigatorio, 1, 5, 2);
break;
#endregion
case "S09":
#region -- S09
if (nElementos >= 1)
if (dados[1].Trim() != "")
drCOFINSOutr["qBCProd"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drCOFINSOutr["vAliqProd"] = dados[2].Trim();
dsNfe.Tables["COFINSOutr"].Rows.Add(drCOFINSOutr);
this.Check(dados[0], "qBCProd", drCOFINSOutr, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", drCOFINSOutr, ObOp.Obrigatorio, 1, 15, 4);
break;
#endregion
case "T":
#region -- T
drCOFINSST = dsNfe.Tables["COFINSST"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
drCOFINSST["vCOFINS"] = dados[1].Trim();
drCOFINSST["imposto_Id"] = idprod.ToString();
this.Check(dados[0], "vCOFINS", drCOFINSST, ObOp.Obrigatorio, 1, 15, 2);
break;
#endregion
case "T02":
#region -- T02
if (nElementos >= 1)
if (dados[1].Trim() != "")
drCOFINSST["vBC"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drCOFINSST["pCOFINS"] = dados[2].Trim();
dsNfe.Tables["COFINSST"].Rows.Add(drCOFINSST);
this.Check(dados[0], "vBC", drCOFINSST, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pCOFINS", drCOFINSST, ObOp.Obrigatorio, 1, 5, 2);
break;
#endregion
case "T04":
#region -- T04
if (nElementos >= 1)
if (dados[1].Trim() != "")
drCOFINSST["qBCProd"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drCOFINSST["vAliqProd"] = dados[2].Trim();
dsNfe.Tables["COFINSST"].Rows.Add(drCOFINSST);
this.Check(dados[0], "qBCProd", drCOFINSST, ObOp.Obrigatorio, 1, 16, 4);
this.Check(dados[0], "vAliqProd", drCOFINSST, ObOp.Obrigatorio, 1, 15, 4);
break;
#endregion
case "U":
#region -- U
{
DataRow dr = dsNfe.Tables["ISSQN"].NewRow();
if (this.PopulateDataRow(dr, dados, 5))
{
if (idprod == "")
{
cMensagemErro += "Segmento [U] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["imposto_Id"] = idprod;
dsNfe.Tables["ISSQN"].Rows.Add(dr);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vAliq", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vISSQN", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "cMunFG", dr, ObOp.Obrigatorio, 7, 7);
this.Check(dados[0], "cListServ", dr, ObOp.Obrigatorio, 3, 4);
}
}
break;
#endregion
case "W":
#region -- W
{
if (idprod == "")
{
cMensagemErro += "Segmento [W] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
DataRow dr = dsNfe.Tables["total"].NewRow();
dr["total_Id"] = idprod.ToString();
dr["infNFe_Id"] = 0;
dsNfe.Tables["total"].Rows.Add(dr);
}
break;
#endregion
case "W02":
#region -- W02
{
DataRow dr = dsNfe.Tables["ICMSTot"].NewRow();
if (this.PopulateDataRow(dr, dados, 14))
{
if (idprod == "")
{
cMensagemErro += "Segmento [W02] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["total_Id"] = idprod;
dsNfe.Tables["ICMSTot"].Rows.Add(dr);
this.Check(dados[0], "vBC", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vICMS", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vBCST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vST", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vProd", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vFrete", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vSeg", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vDesc", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vII", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vIPI", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vPIS", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vCOFINS", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vOutro", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vNF", dr, ObOp.Obrigatorio, 1, 15, 2);
}
}
break;
#endregion
case "W17":
#region -- W17
{
DataRow dr = dsNfe.Tables["ISSQNtot"].NewRow();
if (this.PopulateDataRow(dr, dados, 5))
{
if (idprod == "")
{
cMensagemErro += "Segmento [W17] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["total_Id"] = idprod.ToString();
dsNfe.Tables["ISSQNtot"].Rows.Add(dr);
this.Check(dados[0], "vServ", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vBC", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vISS", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vPIS", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vCOFINS", dr, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "W23":
#region -- W23
{
DataRow dr = dsNfe.Tables["retTrib"].NewRow();
bool lEntrou = false;
for (iLeitura = 0; iLeitura <= Math.Min(nElementos, 7); iLeitura++)
{
if (iLeitura > 0 & dados[iLeitura] != null && dados[iLeitura].Trim() != "")
{
dr[iLeitura - 1] = dados[iLeitura].Trim();
lEntrou = true;
}
}
if (lEntrou == true)
{
if (idprod == "")
{
cMensagemErro += "Segmento [W23] sem segmento [H]. Linha: " + iLinhaLida.ToString() + Environment.NewLine;
}
dr["total_Id"] = idprod.ToString();
dsNfe.Tables["retTrib"].Rows.Add(dr);
this.Check(dados[0], "vRetPIS", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vRetCOFINS", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vRetCSLL", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vBCIRRF", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vIRRF", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vBCRetPrev", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vRetPrev", dr, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "X":
#region -- X
{
DataRow dr = dsNfe.Tables["transp"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
dr["modFrete"] = dados[1].Trim();
dr["transp_Id"] = 0;
dr["infNFe_Id"] = 0;
dsNfe.Tables["transp"].Rows.Add(dr);
this.Check(dados[0], "modFrete", dr, ObOp.Obrigatorio, 1, 1);
}
break;
#endregion
case "X03":
#region -- X03
{
string temp = "";
for (int ii = nElementos - 1; ii >= 1; --ii)
temp += dados[ii].Trim();
if (temp != "")
{
transpAdd = false;
drtransporta = dsNfe.Tables["transporta"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
drtransporta["xNome"] = dados[1].Trim();
if (nElementos >= 2)
if (dados[2].Trim() != "")
drtransporta["IE"] = dados[2].Trim();
if (nElementos >= 3)
if (dados[3].Trim() != "")
drtransporta["xEnder"] = dados[3].Trim();
if (nElementos >= 4)
if (dados[4].Trim() != "")
drtransporta["UF"] = dados[4].Trim();
if (nElementos >= 5)
if (dados[5].Trim() != "")
drtransporta["xMun"] = dados[5].Trim();
drtransporta["transp_Id"] = 0;
this.Check(dados[0], "xNome", drtransporta, ObOp.Opcional, 1, 60);
this.Check(dados[0], "IE", drtransporta, ObOp.Opcional, 2, 14);
this.Check(dados[0], "xEnder", drtransporta, ObOp.Opcional, 1, 60);
this.Check(dados[0], "UF", drtransporta, ObOp.Opcional, 2, 2);
this.Check(dados[0], "xMun", drtransporta, ObOp.Opcional, 1, 60);
}
}
break;
#endregion
case "X04":
#region -- X04
if (nElementos >= 1 && drtransporta != null)
{
if (dados[1].Trim() != "")
drtransporta["CNPJ"] = dados[1].Trim();
dsNfe.Tables["transporta"].Rows.Add(drtransporta);
transpAdd = true;
this.Check(dados[0], "CNPJ", drtransporta, ObOp.Opcional, 14, 14);
}
break;
#endregion
case "X05":
#region --- X05
if (nElementos >= 1 && drtransporta != null)
{
if (dados[1].Trim() != "")
drtransporta["CPF"] = dados[1].Trim();
dsNfe.Tables["transporta"].Rows.Add(drtransporta);
transpAdd = true;
this.Check(dados[0], "CPF", drtransporta, ObOp.Opcional, 11, 11);
}
break;
#endregion
case "X11":
#region -- X11
{
DataRow dr = dsNfe.Tables["retTransp"].NewRow();
if (this.PopulateDataRow(dr, dados, 7))
{
dr["transp_Id"] = 0;
dsNfe.Tables["retTransp"].Rows.Add(dr);
this.Check(dados[0], "vServ", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "vBCRet", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "pICMSRet", dr, ObOp.Obrigatorio, 1, 5, 2);
this.Check(dados[0], "vICMSRet", dr, ObOp.Obrigatorio, 1, 15, 2);
this.Check(dados[0], "CFOP", dr, ObOp.Obrigatorio, 4, 4);
this.Check(dados[0], "cMunFG", dr, ObOp.Obrigatorio, 7, 7);
}
}
break;
#endregion
case "X18":
#region -- X18
{
DataRow dr = dsNfe.Tables["veicTransp"].NewRow();
if (this.PopulateDataRow(dr, dados, 3))
{
dr["transp_Id"] = 0;
dsNfe.Tables["veicTransp"].Rows.Add(dr);
this.Check(dados[0], "placa", dr, ObOp.Obrigatorio, 1, 8);
this.Check(dados[0], "UF", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "RNTC", dr, ObOp.Opcional, 1, 20);
}
}
break;
#endregion
case "X22":
#region -- X22
{
DataRow dr = dsNfe.Tables["reboque"].NewRow();
if (this.PopulateDataRow(dr, dados, 3))
{
dr["transp_Id"] = 0;
dsNfe.Tables["reboque"].Rows.Add(dr);
this.Check(dados[0], "placa", dr, ObOp.Obrigatorio, 1, 8);
this.Check(dados[0], "UF", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "RNTC", dr, ObOp.Opcional, 1, 20);
}
}
break;
#endregion
case "X26":
#region -- X26
{
drVol = dsNfe.Tables["vol"].NewRow();
if (this.PopulateDataRow(drVol, dados, 6))
{
++volid;
drVol["vol_Id"] = volid.ToString();
drVol["transp_Id"] = 0;
dsNfe.Tables["vol"].Rows.Add(drVol);
this.Check(dados[0], "qVol", drVol, ObOp.Opcional, 1, 15);
this.Check(dados[0], "esp", drVol, ObOp.Opcional, 1, 60);
this.Check(dados[0], "marca", drVol, ObOp.Opcional, 1, 60);
this.Check(dados[0], "nVol", drVol, ObOp.Opcional, 1, 60);
this.Check(dados[0], "pesoL", drVol, ObOp.Opcional, 1, 15, 3);
this.Check(dados[0], "pesoB", drVol, ObOp.Opcional, 1, 15, 3);
}
}
break;
#endregion
case "X33":
#region -- X33
{
DataRow dr = dsNfe.Tables["lacres"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
dr["nLacre"] = dados[1].Trim();
dr["vol_Id"] = volid.ToString();
dsNfe.Tables["lacres"].Rows.Add(dr);
this.Check(dados[0], "nLacre", dr, ObOp.Obrigatorio, 1, 60);
}
break;
#endregion
case "Y":
#region -- Y
{
DataRow dr = dsNfe.Tables["cobr"].NewRow();
dr["cobr_Id"] = 0;
dr["infNFe_Id"] = 0;
dsNfe.Tables["cobr"].Rows.Add(dr);
}
break;
#endregion
case "Y02":
#region -- Y02
{
DataRow dr = dsNfe.Tables["fat"].NewRow();
if (this.PopulateDataRow(dr, dados, 4))
{
dr["cobr_Id"] = 0;
dsNfe.Tables["fat"].Rows.Add(dr);
this.Check(dados[0], "nFat", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "vOrig", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vDesc", dr, ObOp.Opcional, 1, 15, 2);
this.Check(dados[0], "vLiq", dr, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "Y07":
#region -- Y07
{
DataRow dr = dsNfe.Tables["dup"].NewRow();
if (this.PopulateDataRow(dr, dados, 3))
{
dr["cobr_Id"] = 0;
dsNfe.Tables["dup"].Rows.Add(dr);
this.Check(dados[0], "nDup", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "dVenc", dr, ObOp.Opcional);
this.Check(dados[0], "vDup", dr, ObOp.Opcional, 1, 15, 2);
}
}
break;
#endregion
case "Z":
#region -- Z
{
bool r = false;
DataRow dr = dsNfe.Tables["infAdic"].NewRow();
if (nElementos >= 1)
if (dados[1].Trim() != "")
{
dr["infAdFisco"] = dados[1].Trim();
r = true;
}
if (nElementos >= 2)
if (dados[2].Trim() != "")
{
dr["infCpl"] = dados[2].Trim();
r = true;
}
if (r)
{
++indadicid;
dr["infAdic_Id"] = indadicid.ToString();
dr["infNFe_Id"] = 0;
dsNfe.Tables["infAdic"].Rows.Add(dr);
this.Check(dados[0], "infAdFisco", dr, ObOp.Opcional, 1, 256);
this.Check(dados[0], "infCpl", dr, ObOp.Opcional, 1, 5000);
dsNfe.Tables["infAdic"].Columns["infAdFisco"].AllowDBNull = true;
}
}
break;
#endregion
case "Z04":
#region -- Z04
{
DataRow dr = dsNfe.Tables["obsCont"].NewRow();
if (this.PopulateDataRow(dr, dados, 2))
{
dr["infAdic_Id"] = indadicid.ToString();
dsNfe.Tables["obsCont"].Rows.Add(dr);
this.Check(dados[0], "xCampo", dr, ObOp.Obrigatorio, 1, 20);
this.Check(dados[0], "xTexto", dr, ObOp.Obrigatorio, 1, 60);
}
}
break;
#endregion
case "Z10":
#region -- Z10
{
DataRow dr = dsNfe.Tables["procRef"].NewRow();
if (this.PopulateDataRow(dr, dados, 2))
{
dr["infAdic_Id"] = indadicid.ToString();
dsNfe.Tables["procRef"].Rows.Add(dr);
this.Check(dados[0], "nProc", dr, ObOp.Obrigatorio, 1, 60);
this.Check(dados[0], "indProc", dr, ObOp.Obrigatorio, 1, 1);
}
}
break;
#endregion
case "ZA":
#region -- ZA
{
DataRow dr = dsNfe.Tables["exporta"].NewRow();
if (this.PopulateDataRow(dr, dados, 2))
{
dr["infNFe_Id"] = 0;
dsNfe.Tables["exporta"].Rows.Add(dr);
this.Check(dados[0], "UFEmbarq", dr, ObOp.Obrigatorio, 2, 2);
this.Check(dados[0], "xLocEmbarq", dr, ObOp.Obrigatorio, 1, 60);
}
}
break;
#endregion
case "ZB":
#region -- ZB
{
DataRow dr = dsNfe.Tables["compra"].NewRow();
if (this.PopulateDataRow(dr, dados, 3))
{
dr["infNFe_Id"] = 0;
dsNfe.Tables["compra"].Rows.Add(dr);
this.Check(dados[0], "xNEmp", dr, ObOp.Opcional, 1, 17);
this.Check(dados[0], "xPed", dr, ObOp.Opcional, 1, 60);
this.Check(dados[0], "xCont", dr, ObOp.Opcional, 1, 60);
}
}
break;
#endregion
}
#endregion
if (vNovaNota)
break;
cLinhaTXT = txt.ReadLine();
iLinhaLida++;
}
if (cMensagemErro != "")
return;
if (cNF == 0)
{
cNF = GerarCodigoNumerico(Convert.ToInt32(dsNfe.Tables["ide"].Rows[0]["nNF"].ToString()));
}
if (cDV == 0)
{
string ccChave = cChave + serie.ToString("000") + nNF.ToString("000000000") + cNF.ToString("000000000");
cDV = this.GerarDigito(ccChave);
}
cChave += serie.ToString("000") + nNF.ToString("000000000") + cNF.ToString("000000000") + cDV.ToString("0");
if (drtransporta != null && !transpAdd)
dsNfe.Tables["transporta"].Rows.Add(drtransporta);
dsNfe.Tables["ide"].Rows[0]["serie"] = serie;
dsNfe.Tables["ide"].Rows[0]["nNF"] = nNF;
dsNfe.Tables["ide"].Rows[0]["cNF"] = cNF.ToString("000000000");
dsNfe.Tables["ide"].Rows[0]["cDV"] = cDV.ToString("0");
dsNfe.Tables["infNFe"].Rows[0]["Id"] = "NFe" + cChave;
dsNfe.AcceptChanges();
StringWriter TextoXml = new StringWriter();
TextoXml.NewLine = "";
dsNfe.WriteXml(TextoXml, XmlWriteMode.IgnoreSchema);
string sAux = limpa_texto(TextoXml.ToString());
TextoXml.GetStringBuilder().Remove(0, TextoXml.ToString().Length);
TextoXml.GetStringBuilder().Append(sAux);
if (TextoXml.ToString().IndexOf("<NFref>") > -1 && TextoXml.ToString().LastIndexOf("</NFref>") > -1)
{
sAux = TextoXml.ToString().Substring(TextoXml.ToString().IndexOf("<NFref>"), TextoXml.ToString().LastIndexOf("</NFref>") - TextoXml.ToString().IndexOf("<NFref>") + 8);
TextoXml.GetStringBuilder().Remove(TextoXml.ToString().IndexOf("<NFref>"), TextoXml.ToString().LastIndexOf("</NFref>") - TextoXml.ToString().IndexOf("<NFref>") + 8);
TextoXml.GetStringBuilder().Replace("<tpImp>", sAux + "<tpImp>");
}
sAux = "";
while (TextoXml.ToString().IndexOf("</infAdProd><prod>") > -1)
{
sAux = TextoXml.ToString().Substring(TextoXml.ToString().IndexOf("\"><infAdProd>") + 2, TextoXml.ToString().IndexOf("</infAdProd><prod>") - TextoXml.ToString().IndexOf("\"><infAdProd>") + 10);
if (TextoXml.ToString().IndexOf("</imposto></det>") == -1)
throw new Exception("tag </imposto> não encontrada");
if (TextoXml.ToString().IndexOf("\"><infAdProd>") == -1)
throw new Exception("tag <infAdProd> não encontrada");
TextoXml.GetStringBuilder().Remove(TextoXml.ToString().IndexOf("\"><infAdProd>") + 2, sAux.Length);
TextoXml.GetStringBuilder().Insert(TextoXml.ToString().IndexOf("</imposto></det>") + 10, sAux);
}
if (TextoXml.ToString().IndexOf("<xFant>") == -1)
throw new Exception("tag <xFant> não encontrada");
if (TextoXml.ToString().IndexOf("<enderEmit>") == -1)
throw new Exception("tag <enderEmit> não encontada");
sAux = TextoXml.ToString().Substring(TextoXml.ToString().IndexOf("<enderEmit>"), (TextoXml.ToString().IndexOf("</enderEmit>") - TextoXml.ToString().IndexOf("<enderEmit>")) + 12);
TextoXml.GetStringBuilder().Replace(sAux, "").Replace("NewDataSet", "NFe");
TextoXml.GetStringBuilder().Replace("</xFant>", "</xFant>" + sAux);
if (vTiraxFant)
{
sAux = TextoXml.ToString().Substring(TextoXml.ToString().IndexOf("<xFant>"));
sAux = sAux.Substring(0, sAux.IndexOf("</xFant>") + 8);
TextoXml.GetStringBuilder().Replace(sAux, "");
}
if (TextoXml.ToString().IndexOf("<enderDest>") == -1)
throw new Exception("tag <enderDest> não encontrada");
sAux = TextoXml.ToString().Substring(TextoXml.ToString().IndexOf("<enderDest>"), (TextoXml.ToString().IndexOf("</enderDest>") - TextoXml.ToString().IndexOf("<enderDest>")) + 12);
TextoXml.GetStringBuilder().Replace(sAux, "");
if (TextoXml.ToString().IndexOf("<dest>") == -1)
throw new Exception("tag <dest> não encontrada");
string sAux2 = TextoXml.ToString().Substring(TextoXml.ToString().IndexOf("<dest>"), (TextoXml.ToString().IndexOf("</dest>") - TextoXml.ToString().IndexOf("<dest>")) + 7);
if (sAux2.IndexOf("<IE>") == -1 && sAux2.IndexOf("<IE/>") == -1)
throw new Exception("tag <IE> não encontrada na tag <dest>");
if (sAux2.IndexOf("<IE>") == -1)
TextoXml.GetStringBuilder().Insert(TextoXml.ToString().IndexOf("<IE/>", TextoXml.ToString().IndexOf("<dest>")), sAux);
else
TextoXml.GetStringBuilder().Insert(TextoXml.ToString().IndexOf("<IE>", TextoXml.ToString().IndexOf("<dest>")), sAux);
if (cChave.Substring(0, 2) == "29")
{
TextoXml.GetStringBuilder().Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "");
}
TextoXml.GetStringBuilder().Replace("<infAdProd>~-?-~</infAdProd>", "");
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(TextoXml.ToString());
if (cDestino.Substring(cDestino.Length - 1, 1) == @"\")
cDestino = cDestino.Substring(0, cDestino.Length - 1);
if (!Directory.Exists(cDestino + "\\convertidos"))
{
System.IO.Directory.CreateDirectory(cDestino + "\\convertidos");
}
this.cRetorno.Add(new txtTOxmlClassRetorno(cChave + ExtXml.Nfe, cChave, nNF, serie));
string strRetorno = cDestino + "\\convertidos\\" + cChave + ExtXml.Nfe;
XmlTextWriter xWriter = new XmlTextWriter(@strRetorno, Encoding.UTF8);
xWriter.Formatting = Formatting.None;
xdoc.Save(xWriter);
xWriter.Close();
}
Marcelo Palladino
Brasil
|
|
|
|
|
|
Considered the joke icon on this, but no...
I'm sure he's got at least one point, but I'm certainly not searching for it. Already seen too many haystacks, and I don't need another needle.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
The cases are listed alphabetically. But they forgot two of them: case "M" and case "V".
Maybe that's the reason why their chemical facility burnt down...
|
|
|
|
|
I thought his subject line made it quite plain what he regarded as wrong here:
Don't Repeat Yourself - There's a lot of copy-and-paste style repetition all over that method.
Separation of Concerns - This one method seems to cover a lot of ground.
Inversion of Control - This looks like classical procedural code to me.
Keep It Simple Stupid - 'nuff said.
Generally, any method over 20-30 lines should often be regarded as suspect. This is a true horror.
|
|
|
|
|
You got my points, Rob.
And Yes, it's a real life horror!
Marcelo Palladino
Brasil
|
|
|
|
|
This sort of horror is quite normal, but seldom are we given an example that we DON'T have to read...and thank you, those who did so!
|
|
|
|
|
No need to post the whole bloody thing.
|
|
|
|
|
You're right, PIEBALDconsult. Excuse me for this, okay? (Sorry, guys!)
I wanted to give a dramatic effect and, as a big fan of Tarantino, exaggerate the amount of blood.
I have this code posted on a blog on wordpress. You think I should edit my post and replace the entire code for a link pointing to the post in wordpress?
Marcelo Palladino
Brasil
|
|
|
|
|
Testing CP forum post limit may be.
...byte till it megahertz...
|
|
|
|
|
Hey, bleedingfingers, had not thought of this ... but now that you said, I was testing. I was testing ...
Marcelo Palladino
Brasil
|
|
|
|
|
That looks like at least a few dozens of function points to me.
|
|
|
|
|
Hey don't you have source control? No need to dump your code here
|
|
|
|
|
Good idea! I hadn't thought of that... use CP as an offsite backup facility. Hmmm. I wonder if the hamsters will complain...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
hahaha, this is not my code, but you gave a good idea. Can I even do versioning of my sources here...
Marcelo Palladino
Brasil
|
|
|
|
|
I think that this piece of code is adorable (in a coding horror kind of way). Reminds me of a scene in Tarantino's Kill Bill pt.1, the one where Uma Thurman was slaughtering bad guys in Japan )))
I've really enjoyed all these cases in the code, but it is the size of this method that makes me dizzy.
I still wonder how the PM or co-workers haven't done something before this method grow that big.
|
|
|
|
|
makumazan84, when PIEBALDconsult talked about blood, I thought that exact scene you described. Kill Bill is a masterpiece ... and the code, of a very particular way, it is also.
As you get dizzy, I think in Visual Studio that could be solved with several sections #region.
Marcelo Palladino
Brasil
|
|
|
|
|
hmmm...in VS2003 and in VS2008SP1, you can't define #regions within a function body
|
|
|
|
|
Dammit!
Marcelo Palladino
Brasil
Twitter: @ProgrammerHead
Blog (pt-BR): http://programmerhead.wordpress.com
|
|
|
|
|