0
I need a help, I’m importing xml from Nfe, and I’m using the QTDA field to do a calculation, only the quantity field in xml is composed this way, 360.0000 and when I import that field is 3600000 because I’m turning to decimal in the code, and I also use this QTDA column to do an Ex calculation. QTDA / QTDA column. EMB. in the case would be 3600000 / 2 = 1.800.000,00 but this wrong this result the correct result should be 180 and the QTDA field should return from XML 360 and not 3600000 as it is returning. How can I fix this?
Follows the XML
<prod>
<cProd>CB60007/0180/6P32</cProd>
<cEAN/>
<xProd>CRODAPEARL AF-LQ-(BR) 006416</xProd>
<NCM>38249929</NCM>
<CEST>2806300</CEST>
<CFOP>5101</CFOP>
<uCom>KG</uCom>
<qCom>360.0000</qCom>
<vUnCom>8.5600000000</vUnCom>
<vProd>3081.60</vProd>
<cEANTrib/>
<uTrib>KG</uTrib>
<qTrib>360.0000</qTrib>
<vUnTrib>8.5600000000</vUnTrib>
<indTot>1</indTot>
<xPed>002459</xPed>
<nFCI>D89A9C05-4493-4740-937A-5DA6B9E675A8</nFCI>
</prod>
Code
private void btn_xml_Click(object sender, EventArgs e) {
string FileName = @ "C:\Xml_Entrada\" + txt_chave.Text + ".xml ";
List < ClasseItensXml > ListaItens = new List < ClasseItensXml > ();
XmlDocument doc = new XmlDocument();
doc.Load(FileName);
var proditens = doc.GetElementsByTagName("prod");
foreach(XmlElement nodo in proditens) {
ListaItens.Add(
new ClasseItensXml() {
CodigoProduto = nodo.GetElementsByTagName("cProd")[0].InnerText.Trim(),
NomeProduto = nodo.GetElementsByTagName("xProd")[0].InnerText.Trim(),
QuantidadeComercializada = Convert.ToDecimal(nodo.GetElementsByTagName("qCom")[0].InnerText.Trim())
});
}
dgw_Xml.DataSource = ListaItens;
}
private void dgw_Xml_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
foreach(DataGridViewRow row in dgw_Xml.Rows) {
if (e.ColumnIndex == dgw_Xml.Columns["QtdaEmbalagem"].Index) {
dgw_Xml.CurrentRow.Cells["ConferenciaPB"].Value = ConferirPB();
dgw_Xml.CurrentRow.Cells["ConferenciaPL"].Value = ConferirPL();
}
}
}
private decimal ConferirPB() {
decimal pesoBruto = Convert.ToDecimal(dgw_Xml.CurrentRow.Cells["PesoBruto"].Value);
decimal qtdaEmbalagem = Convert.ToDecimal(dgw_Xml.CurrentRow.Cells["QtdaEmbalagem"].Value);
return pesoBruto / qtdaEmbalagem;
}
private decimal ConferirPL() {
decimal pesoLiquido = Convert.ToDecimal(dgw_Xml.CurrentRow.Cells["QuantidadeComercializada"].Value);
decimal qtdaEmbalagem = Convert.ToDecimal(dgw_Xml.CurrentRow.Cells["QtdaEmbalagem"].Value);
return pesoLiquido / qtdaEmbalagem;
}
class ClasseItensXml {
public string CodigoProduto { get; set;}
public string NomeProduto { get; set;}
public decimal QuantidadeComercializada { get; set;}
public decimal PesoBruto { get; set;}
public decimal ConferenciaPB { get; set;}
public decimal ConferenciaPL { get; set;}
public decimal QtdaEmbalagem { get; set;}
public string LoteFornecedor { get; set;}
public DateTime DataFabricacao{ get; set;}
public DateTime DataValidade { get; set;}
}
Thank you Ricardo gave it right here vlw
– Junior Guerreiro