// Partially taken from https://github.com/kipusoep/UrlTracker/blob/b2bc998adaae2f74779e1119fd7b1e97a3b71ed2/UI/Installer/UrlTrackerInstallerService.asmx.cs public static bool InstallDashboard(string section, string caption, string control) { bool result = false; try { string dashboardConfig; string dashboardConfigPath = HttpContext.Current.Server.MapPath("~/config/dashboard.config"); using (StreamReader streamReader = File.OpenText(dashboardConfigPath)) dashboardConfig = streamReader.ReadToEnd(); if (string.IsNullOrEmpty(dashboardConfig)) throw new Exception("Unable to add dashboard: Couldn't read current ~/config/dashboard.config, permissions issue?"); XDocument dashboardDoc = XDocument.Parse(dashboardConfig, LoadOptions.PreserveWhitespace); if (dashboardDoc == null) throw new Exception("Unable to add dashboard: Unable to parse current ~/config/dashboard.config file, invalid XML?"); XElement dashBoardElement = dashboardDoc.Element("dashBoard"); if (dashBoardElement == null) throw new Exception("Unable to add dashboard: dashBoard element not found in ~/config/dashboard.config file"); List<XElement> sectionElements = dashBoardElement.Elements("section").ToList(); if (sectionElements == null || !sectionElements.Any()) throw new Exception("Unable to add dashboard: No section elements found in ~/config/dashboard.config file"); XElement existingSectionElement = sectionElements.SingleOrDefault(x => x.Attribute("alias") != null && x.Attribute("alias").Value == section); if (existingSectionElement == null) throw new Exception(string.Format("Unable to add dashboard: '{0}' section not found in ~/config/dashboard.config", section)); List<XElement> tabs = existingSectionElement.Elements("tab").ToList(); if (!tabs.Any()) throw new Exception(string.Format("Unable to add dashboard: No existing tabs found within the '{0}' section", section)); List<XElement> existingTabs = tabs.Where(x => x.Attribute("caption").Value == caption).ToList(); if (existingTabs.Any()) { foreach (XElement tab in existingTabs) { List<XElement> existingTabControls = tab.Elements("control").ToList(); if (existingTabControls.Any(x => x.Value == control)) return true; } } XElement lastTab = tabs.Last(); XElement newTab = new XElement("tab"); newTab.Add(new XAttribute("caption", caption)); XElement newControl = new XElement("control"); newControl.Add(new XAttribute("addPanel", true)); newControl.SetValue(control); newTab.Add(newControl); newControl.AddBeforeSelf(string.Concat(Environment.NewLine, " ")); newControl.AddAfterSelf(string.Concat(Environment.NewLine, " ")); lastTab.AddAfterSelf(newTab); lastTab.AddAfterSelf(string.Concat(Environment.NewLine, " ")); dashboardDoc.Save(dashboardConfigPath, SaveOptions.None); result = true; } catch (Exception ex) { ExceptionHelper.LogExceptionMessage(typeof(DashboardHelper), ex); } return result; }
private void ReplaceAtBookmark_Add(string toInsert, XElement bookmark) { var run = HelperFunctions.FormatInput(toInsert, null); bookmark.AddAfterSelf(run); runs = Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).ToList(); HelperFunctions.RenumberIDs(Document); }
/// <summary> /// Tests AddAfterSelf on Node. /// </summary> /// <param name="context"></param> /// <returns></returns> //[Variation(Desc = "NodeAddAfterSelf")] public void NodeAddAfterSelf() { XElement parent = new XElement("parent"); XElement child = new XElement("child"); parent.Add(child); XText sibling1 = new XText("sibling1"); XElement sibling2 = new XElement("sibling2"); XComment sibling3 = new XComment("sibling3"); child.AddAfterSelf(sibling1); Validate.EnumeratorDeepEquals(parent.Nodes(), new XNode[] { child, sibling1 }); child.AddAfterSelf(sibling2, sibling3); Validate.EnumeratorDeepEquals( parent.Nodes(), new XNode[] { child, sibling2, sibling3, sibling1 }); }
public void NodeAddAfterSelf() { XElement parent = new XElement("parent"); XElement child = new XElement("child"); parent.Add(child); XText sibling1 = new XText("sibling1"); XElement sibling2 = new XElement("sibling2"); XComment sibling3 = new XComment("sibling3"); child.AddAfterSelf(sibling1); Assert.Equal(new XNode[] { child, sibling1 }, parent.Nodes(), XNode.EqualityComparer); child.AddAfterSelf(sibling2, sibling3); Assert.Equal(new XNode[] { child, sibling2, sibling3, sibling1 }, parent.Nodes(), XNode.EqualityComparer); }
public void ParseInstrument() { if (tree.Type != BlaiseParser.DATA_MODEL) { throw new InvalidOperationException("A DATAMODEL was not found in the instrument"); } ITree label = tree.GetChild(0); ITree modelSettings = tree.GetChild(1); Block outer = WalkSubModel(tree, null); if (outer != null) { string instrumentName = outer.Title; string description = outer.Description; var nameElement = new XElement(Ddi.InstrumentName, Ddi.XmlLang(MainLanguage), instrumentName); this.Instrument.AddFirst(nameElement); var descElement = new XElement(Ddi.Description, Ddi.XmlLang(MainLanguage), description); nameElement.AddAfterSelf(descElement); } // Create a QuestionScheme for each BLOCK. foreach (var kvpBlock in this.blocks) { string blockName = kvpBlock.Key; Block block = kvpBlock.Value; // Create a question scheme that contains all FIELDs. if (block.Fields.Count > 0) { XElement questionScheme = Ddi.Element(Ddi.QuestionScheme); questionScheme.Add(new XElement( Ddi.QuestionSchemeName, Ddi.XmlLang(MainLanguage), block.Title)); bool hasQuestions = false; foreach (var kvpField in block.Fields) { Field field = kvpField.Value; if (field.Question != null && field.Question.Count > 0) { XElement question = CreateQuestion(field, block.Title, block); questionScheme.Add(question); hasQuestions = true; } } if (hasQuestions) { this.ResourcePackage.Add(questionScheme); } } } // Create the instrument flow. XElement outerConstruct = GetBlockControlConstruct(outer, outer.Title); Instrument.Add(Ddi.GetReference(Ddi.ControlConstructReference, outerConstruct)); foreach (var catScheme in categorySchemes) { ResourcePackage.Add(catScheme); } foreach (var codeScheme in codeSchemes) { ResourcePackage.Add(codeScheme); } }
void ModelGen(String connectionString, String providerName, String modelName, String targetSchema, Version yver) { String baseDir = Environment.CurrentDirectory; String fpssdl3 = Path.Combine(baseDir, modelName + ".ssdl"); String fpcsdl3 = Path.Combine(baseDir, modelName + ".csdl"); String fpmsl3 = Path.Combine(baseDir, modelName + ".msl"); String fpedmx3 = Path.Combine(baseDir, modelName + ".edmx"); String fpconfig = Path.Combine(baseDir, modelName + ".App.config"); if (false) { } else if (yver == new Version(1, 0)) { xEDMX = "{" + NS.EDMXv1 + "}"; xSSDL = "{" + NS.SSDLv1 + "}"; xCSDL = "{" + NS.CSDLv1 + "}"; xMSL = "{" + NS.MSLv1 + "}"; trace.TraceEvent(TraceEventType.Information, 101, "ModelGen v1"); } else if (yver == new Version(3, 0)) { xEDMX = "{" + NS.EDMXv3 + "}"; xSSDL = "{" + NS.SSDLv3 + "}"; xCSDL = "{" + NS.CSDLv3 + "}"; xMSL = "{" + NS.MSLv3 + "}"; trace.TraceEvent(TraceEventType.Information, 101, "ModelGen v3"); } else throw new NotSupportedException(String.Format("Version '{0}', from 1.0 3.0 ", yver)); trace.TraceEvent(TraceEventType.Information, 101, "Getting System.Data.Common.DbProviderFactory from '{0}'", providerName); var fac = System.Data.Common.DbProviderFactories.GetFactory(providerName); if (fac == null) throw new ApplicationException(); trace.TraceEvent(TraceEventType.Information, 101, fac.GetType().AssemblyQualifiedName); trace.TraceEvent(TraceEventType.Information, 101, "Ok"); using (var db = fac.CreateConnection()) { trace.TraceEvent(TraceEventType.Information, 101, "Connecting"); db.ConnectionString = connectionString; db.Open(); trace.TraceEvent(TraceEventType.Information, 101, "Connected"); trace.TraceEvent(TraceEventType.Information, 101, "Getting System.Data.Entity.Core.Common.DbProviderServices from '{0}'", providerName); var providerServices = ((IServiceProvider)fac).GetService(typeof(DbProviderServices)) as DbProviderServices; if (providerServices == null) providerServices = DbProviderServices.GetProviderServices(db); trace.TraceEvent(TraceEventType.Information, 101, providerServices.GetType().AssemblyQualifiedName); trace.TraceEvent(TraceEventType.Information, 101, "Ok"); trace.TraceEvent(TraceEventType.Information, 101, "Get ProviderManifestToken"); var providerManifestToken = providerServices.GetProviderManifestToken(db); trace.TraceEvent(TraceEventType.Information, 101, "Get ProviderManifest"); var providerManifest = providerServices.GetProviderManifest(providerManifestToken) as DbProviderManifest; trace.TraceEvent(TraceEventType.Information, 101, "Get StoreSchemaDefinition"); var storeSchemaDefinition = providerManifest.GetInformation("StoreSchemaDefinition") as XmlReader; trace.TraceEvent(TraceEventType.Information, 101, "Get StoreSchemaMapping"); var storeSchemaMapping = providerManifest.GetInformation("StoreSchemaMapping") as XmlReader; trace.TraceEvent(TraceEventType.Information, 101, "Write temporary ProviderManifest ssdl"); XDocument tSsdl; String fpssdl = Path.Combine(baseDir, "__" + providerName + ".ssdl"); String fpssdl2 = Path.Combine(baseDir, "__" + providerName + ".ssdl.xml"); { tSsdl = XDocument.Load(storeSchemaDefinition); tSsdl.Save(fpssdl); tSsdl.Save(fpssdl2); } trace.TraceEvent(TraceEventType.Information, 101, "Write temporary ProviderManifest msl"); XDocument tMsl; String fpmsl = Path.Combine(baseDir, "__" + providerName + ".msl"); String fpmsl2 = Path.Combine(baseDir, "__" + providerName + ".msl.xml"); { tMsl = XDocument.Load(storeSchemaMapping); tMsl.Save(fpmsl); tMsl.Save(fpmsl2); } trace.TraceEvent(TraceEventType.Information, 101, "Checking ProviderManifest version."); XmlReader xrCsdl = null; if (false) { } else if (tSsdl.Element("{" + NS.SSDLv1 + "}" + "Schema") != null && tMsl.Element("{" + NS.MSLv1 + "}" + "Mapping") != null) { pCSDL = "{" + NS.CSDLv1 + "}"; pMSL = "{" + NS.MSLv1 + "}"; pSSDL = "{" + NS.SSDLv1 + "}"; #if ENTITIES6 xrCsdl = DbProviderServices.GetConceptualSchemaDefinition(DbProviderManifest.ConceptualSchemaDefinition); #else xrCsdl = XmlReader.Create(new MemoryStream(Resources.ConceptualSchemaDefinition)); #endif trace.TraceEvent(TraceEventType.Information, 101, "ProviderManifest v1"); } else if (tSsdl.Element("{" + NS.SSDLv3 + "}" + "Schema") != null && tMsl.Element("{" + NS.MSLv3 + "}" + "Mapping") != null) { pCSDL = "{" + NS.CSDLv3 + "}"; pMSL = "{" + NS.MSLv3 + "}"; pSSDL = "{" + NS.SSDLv3 + "}"; #if ENTITIES6 xrCsdl = DbProviderServices.GetConceptualSchemaDefinition(DbProviderManifest.ConceptualSchemaDefinitionVersion3); #else xrCsdl = XmlReader.Create(new MemoryStream(Resources.ConceptualSchemaDefinitionVersion3)); #endif trace.TraceEvent(TraceEventType.Information, 101, "ProviderManifest v3"); } else { trace.TraceEvent(TraceEventType.Error, 101, "ProviderManifest version unknown"); throw new ApplicationException("ProviderManifest version unknown"); } trace.TraceEvent(TraceEventType.Information, 101, "Write temporary ProviderManifest csdl"); String fpcsdl = Path.Combine(baseDir, "__" + providerName + ".csdl"); XDocument tCsdl; { tCsdl = XDocument.Load(xrCsdl); tCsdl.Save(fpcsdl); } nut.providerManifest = providerManifest; nut.modelName = modelName; nut.targetSchema = targetSchema; var entityConnectionString = "" + "Provider=" + providerName + ";" + "Provider Connection String=\"" + db.ConnectionString + "\";" + "Metadata=" + fpcsdl + "|" + fpssdl + "|" + fpmsl + ";" ; XElement mssdl, mcsdl, mmsl; XDocument mEdmx = new XDocument(); // XDocument: ModelGen edmx mEdmx.Add(new XElement(xEDMX + "Edmx", new XAttribute("Version", yver.ToString(2)), new XElement(xEDMX + "Runtime", mssdl = new XElement(xEDMX + "StorageModels"), mcsdl = new XElement(xEDMX + "ConceptualModels"), mmsl = new XElement(xEDMX + "Mappings") ) ) ); trace.TraceEvent(TraceEventType.Information, 101, "Getting SchemaInformation"); using (var Context = new SchemaInformation(entityConnectionString)) { trace.TraceEvent(TraceEventType.Information, 101, "Ok"); String ssdlNs = nut.SsdlNs(); XElement ssdlSchema = new XElement(xSSDL + "Schema" , new XAttribute("Namespace", ssdlNs) , new XAttribute("Alias", "Self") , new XAttribute("Provider", providerName) , new XAttribute("ProviderManifestToken", providerManifestToken) ); mssdl.Add(ssdlSchema); XElement ssdlEntityContainer = new XElement(xSSDL + "EntityContainer" , new XAttribute("Name", nut.SsdlContainer()) ); ssdlSchema.Add(ssdlEntityContainer); String csdlNs = nut.CsdlNs(); XElement csdlSchema = new XElement(xCSDL + "Schema" , new XAttribute("Namespace", csdlNs) , new XAttribute("Alias", "Self") ); mcsdl.Add(csdlSchema); XElement csdlEntityContainer = new XElement(xCSDL + "EntityContainer" , new XAttribute("Name", nut.CsdlContainer()) ); csdlSchema.Add(csdlEntityContainer); XElement mslMapping = new XElement(xMSL + "Mapping" , new XAttribute("Space", "C-S") ); mmsl.Add(mslMapping); XElement mslEntityContainerMapping = new XElement(xMSL + "EntityContainerMapping" , new XAttribute("StorageEntityContainer", nut.SsdlContainer()) , new XAttribute("CdmEntityContainer", nut.CsdlContainer()) ); mslMapping.Add(mslEntityContainerMapping); var vecTableOrView = Context.Tables.Cast<TableOrView>().Union(Context.Views); foreach (var dbt in vecTableOrView) { trace.TraceEvent(TraceEventType.Information, 101, "{2}: {0}.{1}", dbt.SchemaName, dbt.Name, (dbt is Table) ? "Table" : "View"); if (dbt.SchemaName != targetSchema) continue; XElement ssdlEntitySet = new XElement(xSSDL + "EntitySet" , new XAttribute("Name", nut.SsdlEntitySet(dbt)) , new XAttribute("EntityType", nut.SsdlEntityTypeRef(dbt)) , new XAttribute(xSTORE + "Type", "Tables") , new XAttribute("Schema", dbt.SchemaName) ); ssdlEntityContainer.Add(ssdlEntitySet); XElement ssdlEntityType = new XElement(xSSDL + "EntityType" , new XAttribute("Name", nut.SsdlEntityType(dbt)) ); ssdlSchema.Add(ssdlEntityType); XElement csdlEntitySet = new XElement(xCSDL + "EntitySet" , new XAttribute("Name", nut.CsdlEntitySet(dbt)) , new XAttribute("EntityType", nut.CsdlEntityTypeRef(dbt)) ); csdlEntityContainer.Add(csdlEntitySet); XElement csdlEntityType = new XElement(xCSDL + "EntityType" , new XAttribute("Name", nut.CsdlEntityType(dbt)) ); csdlSchema.Add(csdlEntityType); XElement mslEntitySetMapping = new XElement(xMSL + "EntitySetMapping" , new XAttribute("Name", nut.CsdlEntitySet(dbt)) ); mslEntityContainerMapping.Add(mslEntitySetMapping); XElement mslEntityTypeMapping = new XElement(xMSL + "EntityTypeMapping" , new XAttribute("TypeName", nut.CsdlEntityTypeRef(dbt)) ); mslEntitySetMapping.Add(mslEntityTypeMapping); XElement mslMappingFragment = new XElement(xMSL + "MappingFragment" , new XAttribute("StoreEntitySet", nut.SsdlEntitySet(dbt)) ); mslEntityTypeMapping.Add(mslMappingFragment); XElement ssdlKey = null; XElement csdlKey = null; bool hasKey = false; // http://social.msdn.microsoft.com/Forums/en-US/94c227d3-3764-45b2-8c6b-e45b6cc8e169/keyless-object-workaround bool hasId = dbt.Columns.Any(p => p.IsIdentity || p.Constraints.OfType<PrimaryKeyConstraint>().Any()); foreach (var dbc in dbt.Columns) { trace.TraceEvent(TraceEventType.Information, 101, " TableColumn: {0}", dbc.Name); bool isIdGen = dbc.IsIdentity; bool isId = isIdGen || dbc.Constraints.OfType<PrimaryKeyConstraint>().Any() || (hasId ? false : !dbc.IsNullable); String ssdlName; XElement ssdlProperty = new XElement(xSSDL + "Property" , new XAttribute("Name", ssdlName = nut.SsdlProp(dbc)) , new XAttribute("Type", nut.SsdlPropType(dbc)) ); ssdlEntityType.Add(ssdlProperty); bool deleteMe = nut.CsdlPropType(dbc) == null; String csdlName; XElement csdlProperty = new XElement(xCSDL + "Property" , new XAttribute("Name", csdlName = nut.CsdlProp(dbc)) , new XAttribute("Type", nut.CsdlPropType(dbc) ?? "?") ); csdlEntityType.Add(csdlProperty); XElement mslScalarProperty = new XElement(xMSL + "ScalarProperty" , new XAttribute("Name", csdlName) , new XAttribute("ColumnName", ssdlName) ); mslMappingFragment.Add(mslScalarProperty); if (!dbc.IsNullable) { ssdlProperty.SetAttributeValue("Nullable", "false"); csdlProperty.SetAttributeValue("Nullable", "false"); } if (dbc.ColumnType.MaxLength.HasValue) { int maxLen = dbc.ColumnType.MaxLength.Value; if (maxLen != -1 && maxLen != 0x3FFFFFFF && maxLen != 0x7FFFFFFF) { ssdlProperty.SetAttributeValue("MaxLength", dbc.ColumnType.MaxLength.Value + ""); csdlProperty.SetAttributeValue("MaxLength", dbc.ColumnType.MaxLength.Value + ""); } } if (isId) { hasKey = true; if (ssdlKey == null) { ssdlKey = new XElement(xSSDL + "Key"); ssdlEntityType.AddFirst(ssdlKey); } ssdlKey.Add(new XElement(xSSDL + "PropertyRef" , new XAttribute("Name", ssdlName) )); if (isIdGen) ssdlProperty.SetAttributeValue("StoreGeneratedPattern", "Identity"); if (isIdGen) ssdlProperty.SetAttributeValue(xAnno + "StoreGeneratedPattern", "Identity"); } if (isId) { if (csdlKey == null) { csdlKey = new XElement(xCSDL + "Key"); csdlEntityType.AddFirst(csdlKey); } csdlKey.Add(new XElement(xCSDL + "PropertyRef" , new XAttribute("Name", csdlName) )); if (isIdGen) csdlProperty.SetAttributeValue(xAnno + "StoreGeneratedPattern", "Identity"); } if (deleteMe) { ssdlProperty.AddAfterSelf(new XComment(String.Format("Property {0} removed. Unknown type.", ssdlProperty.Attribute("Name")))); csdlProperty.AddAfterSelf(new XComment(String.Format("Property {0} removed. Unknown type.", csdlProperty.Attribute("Name")))); mslScalarProperty.AddAfterSelf(new XComment(String.Format("ScalarProperty {0} removed. Unknown type.", mslScalarProperty.Attribute("Name")))); ssdlProperty.Remove(); csdlProperty.Remove(); mslScalarProperty.Remove(); } } if (!hasKey) { ssdlEntitySet.AddAfterSelf(new XComment(String.Format("EntitySet {0} removed. No identical keys found.", ssdlEntitySet.Attribute("Name")))); csdlEntitySet.AddAfterSelf(new XComment(String.Format("EntitySet {0} removed. No identical keys found.", csdlEntitySet.Attribute("Name")))); mslEntitySetMapping.AddAfterSelf(new XComment(String.Format("EntitySetMapping {0} removed. No identical keys found.", mslEntityTypeMapping.Attribute("Name")))); ssdlEntityType.AddAfterSelf(new XComment(String.Format("EntityType {0} removed. No identical keys found.", ssdlEntityType.Attribute("Name")))); csdlEntityType.AddAfterSelf(new XComment(String.Format("EntityType {0} removed. No identical keys found.", csdlEntityType.Attribute("Name")))); mslEntityTypeMapping.AddAfterSelf(new XComment(String.Format("EntityTypeMapping {0} removed. No identical keys found.", mslEntityTypeMapping.Attribute("Name")))); ssdlEntitySet.Remove(); csdlEntitySet.Remove(); mslEntitySetMapping.Remove(); ssdlEntityType.Remove(); csdlEntityType.Remove(); mslEntityTypeMapping.Remove(); } } foreach (var dbco in Context.TableConstraints.OfType<ForeignKeyConstraint>()) { trace.TraceEvent(TraceEventType.Information, 101, "Constraint: {0}", dbco.Name); if (dbco.Parent.SchemaName != targetSchema) continue; // ssdl var ssdlAssociationSet = new XElement(xSSDL + "AssociationSet" , new XAttribute("Name", nut.SsdlAssociationSet(dbco)) , new XAttribute("Association", nut.SsdlAssociationRef(dbco)) ); ssdlEntityContainer.Add(ssdlAssociationSet); var ssdlAssociation = new XElement(xSSDL + "Association" , new XAttribute("Name", nut.SsdlAssociation(dbco)) ); ssdlSchema.Add(ssdlAssociation); var ssdlReferentialConstraint = new XElement(xSSDL + "ReferentialConstraint" ); // csdl var csdlAssociationSet = new XElement(xCSDL + "AssociationSet" , new XAttribute("Name", nut.CsdlAssociationSet(dbco)) , new XAttribute("Association", nut.CsdlAssociationRef(dbco)) ); csdlEntityContainer.Add(csdlAssociationSet); var csdlAssociation = new XElement(xCSDL + "Association" , new XAttribute("Name", nut.CsdlAssociation(dbco)) ); csdlSchema.Add(csdlAssociation); var csdlReferentialConstraint = new XElement(xCSDL + "ReferentialConstraint" ); foreach (var dbfk in dbco.ForeignKeys) { Addfkc(csdlSchema, dbfk, dbfk.ToColumn, dbfk.FromColumn, false, dbfk.FromColumn.IsNullable ? "0..1" : "1" , ssdlAssociationSet, ssdlAssociation, ssdlReferentialConstraint, csdlAssociationSet, csdlAssociation, csdlReferentialConstraint); Addfkc(csdlSchema, dbfk, dbfk.FromColumn, dbfk.ToColumn, true, "*" , ssdlAssociationSet, ssdlAssociation, ssdlReferentialConstraint, csdlAssociationSet, csdlAssociation, csdlReferentialConstraint); } ssdlAssociation.Add(ssdlReferentialConstraint); csdlAssociation.Add(csdlReferentialConstraint); } if (xSSDL != NS.SSDLv1) foreach (var dbr in Context.Functions.Cast<Routine>().Union(Context.Procedures)) { trace.TraceEvent(TraceEventType.Information, 101, "{2}: {0}.{1}", dbr.SchemaName, dbr.Name, (dbr is Function) ? "Function" : "Procedure"); if (dbr.SchemaName != targetSchema) continue; // http://msdn.microsoft.com/ja-jp/library/bb738614(v=vs.90).aspx var ssdlFunction = new XElement(xSSDL + "Function" , new XAttribute("Name", dbr.Name) , new XAttribute("StoreFunctionName", nut.SsdlFunction(dbr)) , new XAttribute("IsComposable", "false") , new XAttribute("ParameterTypeSemantics", "AllowImplicitConversion") , new XAttribute("Schema", nut.SsdlFunctionSchema(dbr)) ); // http://msdn.microsoft.com/ja-jp/library/vstudio/cc716710.aspx var csdlFunctionImport = new XElement(xCSDL + "FunctionImport" , new XAttribute("Name", nut.CsdlFunction(dbr)) ); csdlEntityContainer.Add(csdlFunctionImport); // http://msdn.microsoft.com/ja-jp/library/vstudio/cc716759.aspx var mslFunctionImportMapping = new XElement(xMSL + "FunctionImportMapping" , new XAttribute("FunctionImportName", nut.CsdlFunction(dbr)) , new XAttribute("FunctionName", nut.SsdlFunctionRef(dbr)) ); mslEntityContainerMapping.Add(mslFunctionImportMapping); var dbf = dbr as Function; if (dbf != null) { if (dbf.IsBuiltIn.HasValue) ssdlFunction.SetAttributeValue("BuiltIn", dbf.IsBuiltIn.Value ? "true" : "false"); if (dbf.IsNiladic.HasValue) ssdlFunction.SetAttributeValue("NiladicFunction", dbf.IsNiladic.Value ? "true" : "false"); } var dbsf = dbr as ScalarFunction; if (dbsf != null) { if (dbsf.IsAggregate.HasValue) ssdlFunction.SetAttributeValue("Aggregate", dbsf.IsAggregate.Value ? "true" : "false"); //if (dbsf.ReturnType != null) ssdlFunction.SetAttributeValue("ReturnType", nut.SsdlPropType(dbsf.ReturnType)); if (dbsf.ReturnType != null) csdlFunctionImport.SetAttributeValue("ReturnType", nut.CsdlPropCollType(dbsf.ReturnType)); } ssdlSchema.Add(ssdlFunction); foreach (var dbfp in dbr.Parameters) { trace.TraceEvent(TraceEventType.Information, 101, " Parameter: {0}", dbfp.Name); // ssdl var ssdlParameter = new XElement(xSSDL + "Parameter" , new XAttribute("Name", nut.SsdlParameterName(dbfp)) , new XAttribute("Mode", nut.SsdlParameterMode(dbfp)) , new XAttribute("Type", nut.SsdlPropType(dbfp.ParameterType)) ); ssdlFunction.Add(ssdlParameter); // csdl var csdlParameter = new XElement(xCSDL + "Parameter" , new XAttribute("Name", nut.CsdlParameterName(dbfp)) , new XAttribute("Mode", nut.CsdlParameterMode(dbfp)) , new XAttribute("Type", nut.CsdlPropType(dbfp.ParameterType)) ); csdlFunctionImport.Add(csdlParameter); // msl } } csdlSchema.Save(fpcsdl3); mslMapping.Save(fpmsl3); ssdlSchema.Save(fpssdl3); } { XDocument xAppconfig = new XDocument( new XElement("configuration" , new XElement("connectionStrings" , new XComment("for EF4.x (NET4.0/NET4.5)") , new XElement("add" , new XAttribute("name", String.Format("{0}Entities", modelName)) , new XAttribute("connectionString", String.Format("metadata={0}.csdl|{0}.ssdl|{0}.msl;provider={1};provider connection string=\"{2}\"" , modelName , providerName , connectionString // UUt.UrlEncode("\"" + connectionString + "\"") )) , new XAttribute("providerName", "System.Data.EntityClient") ) ) ) ); xAppconfig.Save(fpconfig); } mEdmx.Save(fpedmx3); } }
public void InsertStatementAfter( XElement target, long id, int value, ElementType type) { target.AddAfterSelf(CreateStatementNode(target, id, value, type)); }
public string InstallDashboard() { try { Wait(); string dashboardConfig; string dashboardConfigPath = HttpContext.Current.Server.MapPath("~/config/dashboard.config"); using (StreamReader streamReader = File.OpenText(dashboardConfigPath)) dashboardConfig = streamReader.ReadToEnd(); if (string.IsNullOrEmpty(dashboardConfig)) throw new Exception("Unable to add dashboard: Couldn't read current ~/config/dashboard.config, permissions issue?"); XDocument dashboardDoc = XDocument.Parse(dashboardConfig, LoadOptions.PreserveWhitespace); if (dashboardDoc == null) throw new Exception("Unable to add dashboard: Unable to parse current ~/config/dashboard.config file, invalid XML?"); XElement dashBoardElement = dashboardDoc.Element("dashBoard"); if (dashBoardElement == null) throw new Exception("Unable to add dashboard: dashBoard element not found in ~/config/dashboard.config file"); List<XElement> sectionElements = dashBoardElement.Elements("section").ToList(); if (sectionElements == null || !sectionElements.Any()) throw new Exception("Unable to add dashboard: No section elements found in ~/config/dashboard.config file"); XElement startupDashboardSectionElement = sectionElements.SingleOrDefault(x => x.Attribute("alias") != null && x.Attribute("alias").Value == "StartupDashboardSection"); if (startupDashboardSectionElement == null) throw new Exception("Unable to add dashboard: StartupDashboardSection not found in ~/config/dashboard.config"); List<XElement> tabs = startupDashboardSectionElement.Elements("tab").ToList(); if (!tabs.Any()) throw new Exception("Unable to add dashboard: No existing tabs found within the StartupDashboardSection"); List<XElement> urlTrackerTabs = tabs.Where(x => x.Attribute("caption").Value == "Url Tracker").ToList(); if (urlTrackerTabs.Any()) { foreach (XElement tab in urlTrackerTabs) { List<XElement> urlTrackerTabControls = tab.Elements("control").ToList(); if (urlTrackerTabControls.Any(x => x.Value == "/Umbraco/UrlTracker/InfoCaster.Umbraco.UrlTracker.UI.UrlTrackerManagerWrapper.ascx")) throw new Exception("Dashboard is already installed."); } } XElement lastTab = tabs.Last(); XElement urlTrackerTab = new XElement("tab"); urlTrackerTab.Add(new XAttribute("caption", "Url Tracker")); XElement urlTrackerControl = new XElement("control"); urlTrackerControl.Add(new XAttribute("addPanel", true)); urlTrackerControl.SetValue("/Umbraco/UrlTracker/InfoCaster.Umbraco.UrlTracker.UI.UrlTrackerManagerWrapper.ascx"); urlTrackerTab.Add(urlTrackerControl); urlTrackerControl.AddBeforeSelf(string.Concat(Environment.NewLine, " ")); urlTrackerControl.AddAfterSelf(string.Concat(Environment.NewLine, " ")); lastTab.AddAfterSelf(urlTrackerTab); lastTab.AddAfterSelf(string.Concat(Environment.NewLine, " ")); dashboardDoc.Save(dashboardConfigPath, SaveOptions.None); } catch (Exception ex) { return HandleException(ex); } return string.Empty; }
public static void HandleProjectElements(XDocument doc) { var applicationXMLVersion = new XElement("applicationXmlVersion"); applicationXMLVersion.Value = "1.0"; doc.Root.Element("catroidVersionName").AddAfterSelf(applicationXMLVersion); var platform = new XElement("platform"); platform.Value = "Android"; doc.Root.Element("deviceName").AddAfterSelf(platform); var platformVersion = new XElement("platformVersion"); platformVersion.Value = doc.Root.Element("androidVersion").Value; platform.AddAfterSelf(platformVersion); XElement elementToRemove = null; foreach (XElement element in doc.Root.Elements()) { if (element.Name == "androidVersion") elementToRemove = element; else if (element.Name == "catroidVersionCode") element.Name = "applicationVersionCode"; else if (element.Name == "catroidVersionName") element.Name = "applicationVersionName"; } if (elementToRemove != null) elementToRemove.Remove(); }
public void GeraLoteXmlEnvio() { try { string sNomeArquivo = daoUtil.RetornaNomeArqNFe(); this.sPathLote = (Acesso.TP_EMIS == 2 ? Pastas.CONTINGENCIA + sNomeArquivo : Pastas.ENVIO + sNomeArquivo); List<string> nfes = new List<string>(); belIde objide; int iCount = 0; if (File.Exists(sPathLote)) { File.Delete(sPathLote); } string sCasasVlUnit = (Acesso.QTDE_CASAS_VL_UNIT == "" ? "000000" : ("").PadLeft(Convert.ToInt32(Acesso.QTDE_CASAS_VL_UNIT), '0')); foreach (belInfNFe nota in lNotas) { string sUF; XDocument xdoc = new XDocument(); #region XML_Cabeçalho XNamespace pf = "http://www.portalfiscal.inf.br/nfe"; XContainer concabec = (new XElement(pf + "NFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"))); XContainer coninfnfe = (new XElement(pf + "infNFe", new XAttribute("Id", nota.chaveNFe), new XAttribute("versao", "2.00"))); #endregion #region Ide XContainer conide; try { objide = nota.ide; #region XML_ide conide = (new XElement(pf + "ide", new XElement(pf + "cUF", objide.Cuf.ToString()), new XElement(pf + "cNF", objide.Cnf.ToString()), new XElement(pf + "natOp", objide.Natop.ToString()), new XElement(pf + "indPag", objide.Indpag.ToString()), new XElement(pf + "mod", objide.Mod.ToString()), new XElement(pf + "serie", objide.Serie.ToString()), new XElement(pf + "nNF", objide.Nnf.ToString()), new XElement(pf + "dEmi", objide.Demi.ToString("yyyy-MM-dd")), new XElement(pf + "dSaiEnt", objide.Dsaient.ToString("yyyy-MM-dd")), new XElement(pf + "hSaiEnt", daoUtil.GetDateServidor().ToString("HH:mm:ss")), // NFe_2.0 new XElement(pf + "tpNF", objide.Tpnf.ToString()), new XElement(pf + "cMunFG", objide.Cmunfg.ToString()), (objide.belNFref != null ? (from c in objide.belNFref select new XElement(pf + "NFref", (!String.IsNullOrEmpty(c.RefNFe) ? new XElement(pf + "refNFe", c.RefNFe) : null), (!String.IsNullOrEmpty(c.cUF) ? (new XElement(pf + "refNF", (!String.IsNullOrEmpty(c.cUF) ? new XElement(pf + "cUF", c.cUF) : null), (!String.IsNullOrEmpty(c.AAMM) ? new XElement(pf + "AAMM", c.AAMM) : null), (!String.IsNullOrEmpty(c.CNPJ) ? new XElement(pf + "CNPJ", c.CNPJ) : null), (!String.IsNullOrEmpty(c.mod) ? new XElement(pf + "mod", c.mod) : null), (!String.IsNullOrEmpty(c.serie) ? new XElement(pf + "serie", c.serie) : null), (!String.IsNullOrEmpty(c.nNF) ? new XElement(pf + "nNF", c.nNF) : null))) : null))) : null),//NFe_2.0_Verificar ID B14 - B20a - B20i - new XElement(pf + "tpImp", objide.Tpimp.ToString()), new XElement(pf + "tpEmis", objide.Tpemis.ToString()), new XElement(pf + "cDV", objide.Cdv.ToString()), new XElement(pf + "tpAmb", objide.Tpamb.ToString()), new XElement(pf + "finNFe", objide.Finnfe.ToString()), new XElement(pf + "procEmi", objide.Procemi.ToString()), new XElement(pf + "verProc", objide.Verproc.ToString()), ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) || (objide.Tpemis.Equals("6")) ? // os_svc new XElement(pf + "dhCont", daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss")) : null), // NFe_2.0 ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) || (objide.Tpemis.Equals("6")) ? new XElement(pf + "xJust", (Acesso.TP_EMIS == 2 ? "FALHA DE CONEXÃO COM INTERNET" : "FALHA COM WEB SERVICE DO ESTADO")) : null)));// NFe_2.0 #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML, Regiao XML_ide - " + x.Message); } #endregion #region Emit XContainer conemit; try { belEmit objemit = nota.emit; #region XML_Emit conemit = (new XElement(pf + "emit", (new XElement(pf + "CNPJ", objemit.Cnpj.ToString())), new XElement(pf + "xNome", objemit.Xnome.ToString()), new XElement(pf + "xFant", objemit.Xfant.ToString()), new XElement(pf + "enderEmit", new XElement(pf + "xLgr", objemit.Xlgr.ToString()), new XElement(pf + "nro", objemit.Nro.ToString()), (!String.IsNullOrEmpty(objemit.Xcpl) ? new XElement(pf + "xCpl", objemit.Xcpl.ToString()) : null), new XElement(pf + "xBairro", objemit.Xbairro.ToString()), new XElement(pf + "cMun", objemit.Cmun.ToString()), new XElement(pf + "xMun", objemit.Xmun.ToString()), new XElement(pf + "UF", objemit.Uf.ToString()), new XElement(pf + "CEP", objemit.Cep.ToString()), new XElement(pf + "cPais", objemit.Cpais.ToString()), new XElement(pf + "xPais", objemit.Xpais.ToString()), (!String.IsNullOrEmpty(objemit.Fone) ? new XElement(pf + "fone", objemit.Fone.ToString()) : null)), (!String.IsNullOrEmpty(objemit.Ie) ? new XElement(pf + "IE", objemit.Ie.ToString()) : null), (!String.IsNullOrEmpty(objemit.Iest) ? new XElement(pf + "IEST", objemit.Iest.ToString()) : null), (!String.IsNullOrEmpty(objemit.Im) ? new XElement(pf + "IM", objemit.Im.ToString()) : null), (!String.IsNullOrEmpty(objemit.Cnae) ? new XElement(pf + "CNAE", objemit.Cnae.ToString()) : null), new XElement(pf + "CRT", objemit.CRT.ToString()))); // NFe_2.0 #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML, Regiao XML_Emit - " + x.Message); } #endregion #region Dest XContainer condest; try { belDest objdest = nota.dest; sUF = objdest.Uf.ToString(); #region XML_Dest objdest.Ie = (objdest.Ie == null ? "" : objdest.Ie); condest = (new XElement(pf + "dest", (objdest.Cnpj == "EXTERIOR" ? new XElement(pf + "CNPJ") : (!String.IsNullOrEmpty(objdest.Cnpj) ? new XElement(pf + "CNPJ", objdest.Cnpj) : new XElement(pf + "CPF", objdest.Cpf))), new XElement(pf + "xNome", (Acesso.TP_EMIS == 2 ? "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL" : objdest.Xnome.ToString().Trim())), new XElement(pf + "enderDest", new XElement(pf + "xLgr", objdest.Xlgr.ToString()), new XElement(pf + "nro", (!String.IsNullOrEmpty(objdest.Nro) ? objdest.Nro.ToString() : "0")), (objdest.Xcpl != "" ? new XElement(pf + "xCpl", objdest.Xcpl.ToString()) : null), new XElement(pf + "xBairro", objdest.Xbairro.ToString()), new XElement(pf + "cMun", objdest.Cmun.ToString()), new XElement(pf + "xMun", objdest.Xmun.ToString()), new XElement(pf + "UF", objdest.Uf.ToString()), (!String.IsNullOrEmpty(objdest.Cep) ? new XElement(pf + "CEP", objdest.Cep.ToString()) : null), new XElement(pf + "cPais", objdest.Cpais.ToString()), (!String.IsNullOrEmpty(objdest.Xpais) ? new XElement(pf + "xPais", objdest.Xpais.ToString()) : null), (!String.IsNullOrEmpty(objdest.Fone) ? new XElement(pf + "fone", objdest.Fone.ToString()) : null)), (!String.IsNullOrEmpty(objdest.Ie) ? (objdest.Ie != "EXTERIOR" ? new XElement(pf + "IE", objdest.Ie.ToString().Trim()) : new XElement(pf + "IE")) : null), (!String.IsNullOrEmpty(objdest.Isuf) ? new XElement(pf + "ISUF", objdest.Isuf.ToString()) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML, Regiao XML_Dest - " + x.Message); } #endregion #region Det List<XElement> lcondet = new List<XElement>(); try { List<belDet> objdet = nota.det; #region XML_Detalhes List<string> lCfopNotTagII = new List<string>(); lCfopNotTagII.Add("3201"); lCfopNotTagII.Add("3202"); lCfopNotTagII.Add("3211"); lCfopNotTagII.Add("3503"); lCfopNotTagII.Add("3553"); foreach (belDet det in objdet) { //det.imposto.belIpi = null; XElement condet = (new XElement(pf + "det", new XAttribute("nItem", det.nitem), new XElement(pf + "prod", (!String.IsNullOrEmpty(det.prod.Cprod) ? new XElement(pf + "cProd", det.prod.Cprod.ToString().Replace(" ", "")) : null), (new XElement(pf + "cEAN", det.prod.Cean.ToString())), (!String.IsNullOrEmpty(det.prod.Xprod) ? new XElement(pf + "xProd", det.prod.Xprod.ToString()) : null), (!String.IsNullOrEmpty(det.prod.Ncm) ? new XElement(pf + "NCM", det.prod.Ncm.ToString()) : new XElement(pf + "NCM", det.prod.Ncm = "00000000")), //Claudinei - o.s. 24200 - 01/03/2010 (!String.IsNullOrEmpty(det.prod.Extipi) ? new XElement(pf + "EXTIPI", det.prod.Extipi.ToString()) : null), (!String.IsNullOrEmpty(det.prod.Genero) ? new XElement(pf + "genero", det.prod.Genero.ToString()) : null), (!String.IsNullOrEmpty(det.prod.Cfop) ? new XElement(pf + "CFOP", det.prod.Cfop.ToString()) : null), (!String.IsNullOrEmpty(det.prod.Ucom) ? new XElement(pf + "uCom", det.prod.Ucom.ToString()) : null), (new XElement(pf + "qCom", det.prod.Qcom.ToString("#0.0000").Replace(",", "."))), (new XElement(pf + "vUnCom", det.prod.Vuncom.ToString("#0." + sCasasVlUnit).Replace(",", "."))), (new XElement(pf + "vProd", det.prod.Vprod.ToString("#0.00").Replace(",", "."))), (new XElement(pf + "cEANTrib", det.prod.Ceantrib.ToString())), (!String.IsNullOrEmpty(det.prod.Utrib) ? new XElement(pf + "uTrib", det.prod.Utrib.ToString()) : null), (new XElement(pf + "qTrib", det.prod.Qtrib.ToString("#0.0000").Replace(",", "."))), (new XElement(pf + "vUnTrib", det.prod.Vuntrib.ToString("#0." + sCasasVlUnit).Replace(",", "."))), (det.prod.Vfrete != 0 ? new XElement(pf + "vFrete", det.prod.Vfrete.ToString("#0.00").Replace(",", ".")) : null), (det.prod.Vseg != 0 ? new XElement(pf + "vSeg", det.prod.Vseg.ToString("#0.00").Replace(",", ".")) : null), (det.prod.Vdesc > 0 ? new XElement(pf + "vDesc", det.prod.Vdesc.ToString("#0.00").Replace(",", ".")) : null), (det.prod.VOutro != 0 ? new XElement(pf + "vOutro", det.prod.VOutro.ToString("#0.00").Replace(",", ".")) : null), //NFe_2.0 (det.prod.IndTot != null ? new XElement(pf + "indTot", det.prod.IndTot.ToString()) : null), //NFe_2.0 ((det.prod.belDI != null) ? from DI in det.prod.belDI where DI.nDI != null && DI.xLocDesemb != null && DI.UFDesemb != null && DI.cExportador != null select new XElement(pf + "DI", (DI.nDI != "" ? new XElement(pf + "nDI", DI.nDI) : null), new XElement(pf + "dDI", DI.DDI.ToString("yyyy-MM-dd")), (DI.xLocDesemb != "" ? new XElement(pf + "xLocDesemb", DI.xLocDesemb) : null), (DI.UFDesemb != "" ? new XElement(pf + "UFDesemb", DI.UFDesemb) : null), new XElement(pf + "dDesemb", DI.dDesemb.ToString("yyyy-MM-dd")), (DI.cExportador != "" ? new XElement(pf + "cExportador", DI.cExportador) : null), from adic in DI.adi where adic.cFabricante != null select new XElement(pf + "adi", new XElement(pf + "nAdicao", adic.nAdicao), new XElement(pf + "nSeqAdic", adic.nSeqAdic), (adic.cFabricante != "" ? new XElement(pf + "cFabricante", adic.cFabricante) : null), new XElement(pf + "vDescDI", adic.vDescDI))) : null), ((det.prod.XPed != "") ? new XElement(pf + "xPed", det.prod.XPed) : null), ((det.prod.NItemPed != "") ? new XElement(pf + "nItemPed", det.prod.NItemPed) : null), (det.prod.nFCI != "" ? new XElement(pf + "nFCI", det.prod.nFCI.ToString()) : null), //29280 (det.prod.belMed != null ? from med in det.prod.belMed select new XElement(pf + "med", new XElement(pf + "nLote", med.Nlote), new XElement(pf + "qLote", Convert.ToDecimal(med.Qlote).ToString("#0.000").Replace(",", ".")), new XElement(pf + "dFab", med.DFab.ToString("yyyy-MM-dd")), new XElement(pf + "dVal", med.Dval.ToString("yyyy-MM-dd")), new XElement(pf + "vPMC", med.Vpmc)) : null), (det.prod.belcomb != null ? new XElement(pf + "comb", new XElement(pf + "cProdANP", det.prod.belcomb.cProdANP), new XElement(pf + "UFCons", det.prod.belcomb.UFCons)) : null)), new XElement(pf + "imposto", new XElement(pf + "vTotTrib", det.prod.vTotTrib.ToString("#0.00").Replace(",", ".")), //---------------ICMS-----------------// new XElement(pf + "ICMS", //-------------ICMS00-------------// (det.imposto.belIcms.belIcms00 != null ? new XElement(pf + "ICMS00", (det.imposto.belIcms.belIcms00.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms00.Orig.ToString()) : null), (det.imposto.belIcms.belIcms00.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms00.Cst.ToString()) : null), (det.imposto.belIcms.belIcms00.Modbc != null ? new XElement(pf + "modBC", det.imposto.belIcms.belIcms00.Modbc.ToString()) : null), (det.imposto.belIcms.belIcms00.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIcms.belIcms00.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms00.Picms != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belIcms00.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms00.Vicms != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms00.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS10-------------// (det.imposto.belIcms.belIcms10 != null ? new XElement(pf + "ICMS10", (det.imposto.belIcms.belIcms10.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms10.Orig.ToString()) : null), (det.imposto.belIcms.belIcms10.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms10.Cst.ToString()) : null), (det.imposto.belIcms.belIcms10.Modbc != null ? new XElement(pf + "modBC", det.imposto.belIcms.belIcms10.Modbc.ToString()) : null), (det.imposto.belIcms.belIcms10.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIcms.belIcms10.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms10.Picms != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belIcms10.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms10.Vicms != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms10.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms10.Modbcst != null ? new XElement(pf + "modBCST", det.imposto.belIcms.belIcms10.Modbcst.ToString()) : null), (det.imposto.belIcms.belIcms10.Pmvast != 0 ? new XElement(pf + "pMVAST", det.imposto.belIcms.belIcms10.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 11/03/2010 (det.imposto.belIcms.belIcms10.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.imposto.belIcms.belIcms10.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms10.Vbcst != null ? new XElement(pf + "vBCST", det.imposto.belIcms.belIcms10.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms10.Picmsst != null ? new XElement(pf + "pICMSST", det.imposto.belIcms.belIcms10.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms10.Vicmsst != null ? new XElement(pf + "vICMSST", det.imposto.belIcms.belIcms10.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS20-------------// (det.imposto.belIcms.belIcms20 != null ? new XElement(pf + "ICMS20", (det.imposto.belIcms.belIcms20.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms20.Orig.ToString()) : null), (det.imposto.belIcms.belIcms20.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms20.Cst.ToString()) : null), (det.imposto.belIcms.belIcms20.Modbc != null ? new XElement(pf + "modBC", det.imposto.belIcms.belIcms20.Modbc.ToString()) : null), (det.imposto.belIcms.belIcms20.Predbc != null ? new XElement(pf + "pRedBC", det.imposto.belIcms.belIcms20.Predbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms20.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIcms.belIcms20.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms20.Picms != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belIcms20.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms20.Vicms != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms20.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS30-------------// (det.imposto.belIcms.belIcms30 != null ? new XElement(pf + "ICMS30", (det.imposto.belIcms.belIcms30.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms30.Orig.ToString()) : null), (det.imposto.belIcms.belIcms30.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms30.Cst.ToString()) : null), (det.imposto.belIcms.belIcms30.Modbcst != null ? new XElement(pf + "modBCST", det.imposto.belIcms.belIcms30.Modbcst.ToString()) : null), (det.imposto.belIcms.belIcms30.Pmvast != 0 ? new XElement(pf + "pMVAST", det.imposto.belIcms.belIcms30.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010 (det.imposto.belIcms.belIcms30.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.imposto.belIcms.belIcms30.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms30.Vbcst != null ? new XElement(pf + "vBCST", det.imposto.belIcms.belIcms30.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms30.Picmsst != null ? new XElement(pf + "pICMSST", det.imposto.belIcms.belIcms30.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms30.Vicmsst != null ? new XElement(pf + "vICMSST", det.imposto.belIcms.belIcms30.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS40-------------// (det.imposto.belIcms.belIcms40 != null ? new XElement(pf + "ICMS40", (det.imposto.belIcms.belIcms40.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms40.Orig.ToString()) : null), (det.imposto.belIcms.belIcms40.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms40.Cst.ToString()) : null), (det.imposto.belIcms.belIcms40.Vicms > 0 ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms40.Vicms.ToString("#0.00").Replace(",", ".")) : null), //NFe_2.0 (det.imposto.belIcms.belIcms40.Vicms > 0 ? new XElement(pf + "motDesICMS", det.imposto.belIcms.belIcms40.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS41-------------// (det.imposto.belIcms.belIcms41 != null ? new XElement(pf + "ICMS41", (det.imposto.belIcms.belIcms41.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms41.Orig.ToString()) : null), (det.imposto.belIcms.belIcms41.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms41.Cst.ToString()) : null), (det.imposto.belIcms.belIcms41.Vicms > 0 ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms41.Vicms.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 (det.imposto.belIcms.belIcms41.motDesICMS > 0 ? new XElement(pf + "motDesICMS", det.imposto.belIcms.belIcms41.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS50-------------// (det.imposto.belIcms.belIcms50 != null ? new XElement(pf + "ICMS50", (det.imposto.belIcms.belIcms50.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms50.Orig.ToString()) : null), (det.imposto.belIcms.belIcms50.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms50.Cst.ToString()) : null), (det.imposto.belIcms.belIcms50.Vicms > 0 ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms50.Vicms.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 (det.imposto.belIcms.belIcms50.motDesICMS > 0 ? new XElement(pf + "motDesICMS", det.imposto.belIcms.belIcms50.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS51-------------// (det.imposto.belIcms.belIcms51 != null ? new XElement(pf + "ICMS51", (det.imposto.belIcms.belIcms51.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms51.Orig.ToString()) : null), (det.imposto.belIcms.belIcms51.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms51.Cst.ToString()) : null), (det.imposto.belIcms.belIcms51.Modbc != null ? new XElement(pf + "modBC", det.imposto.belIcms.belIcms51.Modbc.ToString()) : null), (det.imposto.belIcms.belIcms51.Predbc != null ? new XElement(pf + "pRedBC", det.imposto.belIcms.belIcms51.Predbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms51.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIcms.belIcms51.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms51.Picms != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belIcms51.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms51.Vicms != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms51.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS60-------------// (det.imposto.belIcms.belIcms60 != null ? new XElement(pf + "ICMS60",//Danner - o.s. sem - 12/03/2010 (det.imposto.belIcms.belIcms60.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms60.Orig.ToString()) : null), (det.imposto.belIcms.belIcms60.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms60.Cst.ToString()) : null), (det.imposto.belIcms.belIcms60.Vbcstret != null ? new XElement(pf + "vBCSTRet", det.imposto.belIcms.belIcms60.Vbcstret.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 - Mudança de nome de Tag (det.imposto.belIcms.belIcms60.Vicmsstret != null ? new XElement(pf + "vICMSSTRet", det.imposto.belIcms.belIcms60.Vicmsstret.ToString("#0.00").Replace(",", ".")) : null)) : null),//NFe_2.0 Mudança de nome de Tag //-------------ICMS70-------------// (det.imposto.belIcms.belIcms70 != null ? new XElement(pf + "ICMS70", (det.imposto.belIcms.belIcms70.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms70.Orig.ToString()) : null), (det.imposto.belIcms.belIcms70.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms70.Cst.ToString()) : null), (det.imposto.belIcms.belIcms70.Modbc != null ? new XElement(pf + "modBC", det.imposto.belIcms.belIcms70.Modbc.ToString()) : null), (det.imposto.belIcms.belIcms70.Predbc != null ? new XElement(pf + "pRedBC", det.imposto.belIcms.belIcms70.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 (det.imposto.belIcms.belIcms70.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIcms.belIcms70.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms70.Picms != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belIcms70.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms70.Vicms != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms70.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms70.Modbcst != null ? new XElement(pf + "modBCST", det.imposto.belIcms.belIcms70.Modbcst.ToString()) : null), (det.imposto.belIcms.belIcms70.Pmvast != 0 ? new XElement(pf + "pMVAST", det.imposto.belIcms.belIcms70.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010 (det.imposto.belIcms.belIcms70.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.imposto.belIcms.belIcms70.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms70.Vbcst != null ? new XElement(pf + "vBCST", det.imposto.belIcms.belIcms70.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms70.Picmsst != null ? new XElement(pf + "pICMSST", det.imposto.belIcms.belIcms70.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms70.Vicmsst != null ? new XElement(pf + "vICMSST", det.imposto.belIcms.belIcms70.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS90-------------// (det.imposto.belIcms.belIcms90 != null ? new XElement(pf + "ICMS90", (det.imposto.belIcms.belIcms90.Orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belIcms90.Orig.ToString()) : null), (det.imposto.belIcms.belIcms90.Cst != null ? new XElement(pf + "CST", det.imposto.belIcms.belIcms90.Cst.ToString()) : null), (det.imposto.belIcms.belIcms90.Modbc != null ? new XElement(pf + "modBC", det.imposto.belIcms.belIcms90.Modbc.ToString()) : null), (det.imposto.belIcms.belIcms90.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIcms.belIcms90.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms90.Predbc != 0 ? new XElement(pf + "pRedBC", det.imposto.belIcms.belIcms90.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 //Claudinei - o.s. sem - 24/02/2010 (det.imposto.belIcms.belIcms90.Picms != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belIcms90.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms90.Vicms != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belIcms90.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms90.Modbcst != null ? new XElement(pf + "modBCST", det.imposto.belIcms.belIcms90.Modbcst.ToString()) : null), (det.imposto.belIcms.belIcms90.Pmvast != 0 ? new XElement(pf + "pMVAST", det.imposto.belIcms.belIcms90.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010 (det.imposto.belIcms.belIcms90.Predbcst != 0 ? new XElement(pf + "pRedBCST", det.imposto.belIcms.belIcms90.Predbcst.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010 (det.imposto.belIcms.belIcms90.Vbcst != null ? new XElement(pf + "vBCST", det.imposto.belIcms.belIcms90.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms90.Picmsst != null ? new XElement(pf + "pICMSST", det.imposto.belIcms.belIcms90.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belIcms90.Vicmsst != null ? new XElement(pf + "vICMSST", det.imposto.belIcms.belIcms90.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN101--------------// (det.imposto.belIcms.belICMSSN101 != null ? new XElement(pf + "ICMSSN101", (det.imposto.belIcms.belICMSSN101.orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belICMSSN101.orig.ToString()) : null), new XElement(pf + "CSOSN", det.imposto.belIcms.belICMSSN101.CSOSN.ToString()), (det.imposto.belIcms.belICMSSN101.pCredSN != null ? new XElement(pf + "pCredSN", det.imposto.belIcms.belICMSSN101.pCredSN.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN101.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.imposto.belIcms.belICMSSN101.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN102--------------// (det.imposto.belIcms.belICMSSN102 != null ? new XElement(pf + "ICMSSN102", (det.imposto.belIcms.belICMSSN102.orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belICMSSN102.orig.ToString()) : null), new XElement(pf + "CSOSN", det.imposto.belIcms.belICMSSN102.CSOSN.ToString())) : null), //-------------ICMSSN201--------------// (det.imposto.belIcms.belICMSSN201 != null ? new XElement(pf + (det.imposto.belIcms.belICMSSN201.CSOSN.Equals("201") ? "ICMSSN201" : "ICMSSN202"), (det.imposto.belIcms.belICMSSN201.orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belICMSSN201.orig.ToString()) : null), new XElement(pf + "CSOSN", det.imposto.belIcms.belICMSSN201.CSOSN.ToString()), (det.imposto.belIcms.belICMSSN201.modBCST != null ? new XElement(pf + "modBCST", det.imposto.belIcms.belICMSSN201.modBCST.ToString()) : null), (det.imposto.belIcms.belICMSSN201.pMVAST != 0 ? new XElement(pf + "pMVAST", det.imposto.belIcms.belICMSSN201.pMVAST.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN201.pRedBCST.ToString() != "0" ? new XElement(pf + "pRedBCST", det.imposto.belIcms.belICMSSN201.pRedBCST.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN201.vBCST != null ? new XElement(pf + "vBCST", det.imposto.belIcms.belICMSSN201.vBCST.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN201.pICMSST != null ? new XElement(pf + "pICMSST", det.imposto.belIcms.belICMSSN201.pICMSST.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN201.vICMSST != null ? new XElement(pf + "vICMSST", det.imposto.belIcms.belICMSSN201.vICMSST.ToString("#0.00").Replace(",", ".")) : null), ((det.imposto.belIcms.belICMSSN201.pCredSN != null && det.imposto.belIcms.belICMSSN201.CSOSN.Equals("201")) ? new XElement(pf + "pCredSN", det.imposto.belIcms.belICMSSN201.pCredSN.ToString("#0.00").Replace(",", ".")) : null), ((det.imposto.belIcms.belICMSSN201.vCredICMSSN != null && det.imposto.belIcms.belICMSSN201.CSOSN.Equals("201")) ? new XElement(pf + "vCredICMSSN", det.imposto.belIcms.belICMSSN201.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN500--------------// (det.imposto.belIcms.belICMSSN500 != null ? new XElement(pf + "ICMSSN500", (det.imposto.belIcms.belICMSSN500.orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belICMSSN500.orig.ToString()) : null), new XElement(pf + "CSOSN", det.imposto.belIcms.belICMSSN500.CSOSN.ToString()), (det.imposto.belIcms.belICMSSN500.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.imposto.belIcms.belICMSSN500.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN500.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.imposto.belIcms.belICMSSN500.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN900--------------// //(det.imposto.belIcms.belICMSSN900 != null ? // new XElement(pf + "ICMSSN900", // (det.imposto.belIcms.belICMSSN900.orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belICMSSN900.orig.ToString()) : null), // new XElement(pf + "CSOSN", det.imposto.belIcms.belICMSSN900.CSOSN.ToString())) : null)), //(det.imposto.belIcms.belICMSSN900.modBC != null ? new XElement(pf + "modBC", det.imposto.belIcms.belICMSSN900.modBC.ToString()) : null), //(det.imposto.belIcms.belICMSSN900.vBC != null ? new XElement(pf + "vBC", det.imposto.belIcms.belICMSSN900.vBC.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.pRedBC != null ? new XElement(pf + "pRedBC", det.imposto.belIcms.belICMSSN900.pRedBC.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.pICMS != null ? new XElement(pf + "pICMS", det.imposto.belIcms.belICMSSN900.pICMS.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vICMS != null ? new XElement(pf + "vICMS", det.imposto.belIcms.belICMSSN900.vICMS.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.modBCST != null ? new XElement(pf + "modBCST", det.imposto.belIcms.belICMSSN900.modBCST.ToString()) : null), //(det.imposto.belIcms.belICMSSN900.pMVAST != null ? new XElement(pf + "pMVAST", det.imposto.belIcms.belICMSSN900.pMVAST.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.pRedBCST != null ? new XElement(pf + "pRedBCST", det.imposto.belIcms.belICMSSN900.pRedBCST.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vBCST != null ? new XElement(pf + "vBCST", det.imposto.belIcms.belICMSSN900.vBCST.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.pICMSST != null ? new XElement(pf + "pICMSST", det.imposto.belIcms.belICMSSN900.pICMSST.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vICMSST != null ? new XElement(pf + "vICMSST", det.imposto.belIcms.belICMSSN900.vICMSST.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.imposto.belIcms.belICMSSN900.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.imposto.belIcms.belICMSSN900.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.pCredSN != null ? new XElement(pf + "pCredSN", det.imposto.belIcms.belICMSSN900.pCredSN.ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.imposto.belIcms.belICMSSN900.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null)), (det.imposto.belIcms.belICMSSN900 != null ? new XElement(pf + "ICMSSN900", (det.imposto.belIcms.belICMSSN900.orig != null ? new XElement(pf + "orig", det.imposto.belIcms.belICMSSN900.orig.ToString()) : null), new XElement(pf + "CSOSN", det.imposto.belIcms.belICMSSN900.CSOSN.ToString()), (det.imposto.belIcms.belICMSSN900.modBC != null ? new XElement(pf + "modBC", det.imposto.belIcms.belICMSSN900.modBC.ToString()) : null), (det.imposto.belIcms.belICMSSN900.vBC != null ? new XElement(pf + "vBC", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vBC).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.pRedBC > 0 ? new XElement(pf + "pRedBC", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.pRedBC).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.pICMS != null ? new XElement(pf + "pICMS", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.pICMS).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.vICMS != null ? new XElement(pf + "vICMS", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vICMS).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.modBCST != null ? new XElement(pf + "modBCST", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.modBCST).ToString()) : null), (det.imposto.belIcms.belICMSSN900.pMVAST > 0 ? new XElement(pf + "pMVAST", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.pMVAST).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.pRedBCST > 0 ? new XElement(pf + "pRedBCST", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.pRedBCST).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.vBCST != null ? new XElement(pf + "vBCST", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vBCST).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.pICMSST != null ? new XElement(pf + "pICMSST", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.pICMSST).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.vICMSST != null ? new XElement(pf + "vICMSST", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vICMSST).ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vBCSTRet != null ? new XElement(pf + "vBCSTRet", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vBCSTRet).ToString("#0.00").Replace(",", ".")) : null), //(det.imposto.belIcms.belICMSSN900.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vICMSSTRet).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.pCredSN != null ? new XElement(pf + "pCredSN", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.pCredSN).ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIcms.belICMSSN900.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", Convert.ToDecimal(det.imposto.belIcms.belICMSSN900.vCredICMSSN).ToString("#0.00").Replace(",", ".")) : null)) : null)), //---------------IPI-------------// (det.imposto.belIpi != null ? new XElement(pf + "IPI", (det.imposto.belIpi.Clenq != null ? new XElement(pf + "clEnq", det.imposto.belIpi.Clenq.ToString()) : null), (det.imposto.belIpi.Cnpjprod != null ? new XElement(pf + "CNPJProd", det.imposto.belIpi.Cnpjprod.ToString()) : null), (det.imposto.belIpi.Cselo != null ? new XElement(pf + "cSelo", det.imposto.belIpi.Cselo.ToString()) : null), (det.imposto.belIpi.Qselo != null ? new XElement(pf + "qSelo", det.imposto.belIpi.Qselo.ToString()) : null), (det.imposto.belIpi.Cenq != null ? new XElement(pf + "cEnq", det.imposto.belIpi.Cenq.ToString()) : null), //-----------IPITrib-----------// (det.imposto.belIpi.belIpitrib != null ? new XElement(pf + "IPITrib", (det.imposto.belIpi.belIpitrib.Cst != null ? new XElement(pf + "CST", det.imposto.belIpi.belIpitrib.Cst.ToString()) : null), (det.imposto.belIpi.belIpitrib.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIpi.belIpitrib.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIpi.belIpitrib.Qunid > 0 ? new XElement(pf + "qUnid", det.imposto.belIpi.belIpitrib.Qunid.ToString("#0.0000").Replace(",", ".")) : null), (det.imposto.belIpi.belIpitrib.Vunid > 0 ? new XElement(pf + "vUnid", det.imposto.belIpi.belIpitrib.Vunid.ToString("#0.0000").Replace(",", ".")) : null), (det.imposto.belIpi.belIpitrib.Pipi != null ? new XElement(pf + "pIPI", det.imposto.belIpi.belIpitrib.Pipi.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIpi.belIpitrib.Vipi != null ? new XElement(pf + "vIPI", det.imposto.belIpi.belIpitrib.Vipi.ToString("#0.00").Replace(",", ".")) : null)) : null), //-----------IPINT-----------// (det.imposto.belIpi.belIpint != null ? new XElement(pf + "IPINT", (det.imposto.belIpi.belIpint != null ? new XElement(pf + "CST", det.imposto.belIpi.belIpint.Cst.ToString()) : null)) : null)) : null), //--------------II--------------// ((!lCfopNotTagII.Contains(det.prod.Cfop)) ? new XElement(pf + "II", (det.imposto.belIi.Vbc != null ? new XElement(pf + "vBC", det.imposto.belIi.Vbc.ToString("#0.00").Replace(',', '.')) : null), (det.imposto.belIi.Vdespadu != null ? new XElement(pf + "vDespAdu", det.imposto.belIi.Vdespadu.ToString("#0.00").Replace(',', '.')) : null), (det.imposto.belIi.Vii != null ? new XElement(pf + "vII", det.imposto.belIi.Vii.ToString("0.00").Replace(',', '.')) : null), (det.imposto.belIi.Viof != null ? new XElement(pf + "vIOF", det.imposto.belIi.Viof.ToString("#0.00").Replace(',', '.')) : null)) : null), //----------------PIS------------// (det.imposto.belPis != null ? new XElement(pf + "PIS", //-----------PISAliq----------// (det.imposto.belPis.belPisaliq != null ? new XElement(pf + "PISAliq", (det.imposto.belPis.belPisaliq.Cst != null ? new XElement(pf + "CST", det.imposto.belPis.belPisaliq.Cst.ToString()) : null), (det.imposto.belPis.belPisaliq.Vbc != null ? new XElement(pf + "vBC", det.imposto.belPis.belPisaliq.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belPis.belPisaliq.Ppis != null ? new XElement(pf + "pPIS", det.imposto.belPis.belPisaliq.Ppis.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belPis.belPisaliq.Vpis != null ? new XElement(pf + "vPIS", det.imposto.belPis.belPisaliq.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null), //-----------PISQtde-----------// (det.imposto.belPis.belPisqtde != null ? new XElement(pf + "PISQtde", (det.imposto.belPis.belPisqtde.Cst != null ? new XElement(pf + "CST", det.imposto.belPis.belPisqtde.Cst.ToString()) : null), (det.imposto.belPis.belPisqtde.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.imposto.belPis.belPisqtde.Qbcprod.ToString()) : null), (det.imposto.belPis.belPisqtde.Valiqprod != null ? new XElement(pf + "vAliqProd", det.imposto.belPis.belPisqtde.Valiqprod.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belPis.belPisqtde.Vpis != null ? new XElement(pf + "vPIS", det.imposto.belPis.belPisqtde.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null), //----------PISNT------------// (det.imposto.belPis.belPisnt != null ? new XElement(pf + "PISNT", (det.imposto.belPis.belPisnt.Cst != null ? new XElement(pf + "CST", det.imposto.belPis.belPisnt.Cst.ToString()) : null)) : null), //----------PISOutr-----------// (det.imposto.belPis.belPisoutr != null ? new XElement(pf + "PISOutr", (det.imposto.belPis.belPisoutr.Cst != null ? new XElement(pf + "CST", det.imposto.belPis.belPisoutr.Cst.ToString()) : null), (det.imposto.belPis.belPisoutr.Vbc != null ? new XElement(pf + "vBC", det.imposto.belPis.belPisoutr.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belPis.belPisoutr.Ppis != null ? new XElement(pf + "pPIS", det.imposto.belPis.belPisoutr.Ppis.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belPis.belPisoutr.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.imposto.belPis.belPisoutr.Qbcprod.ToString()) : null), (det.imposto.belPis.belPisoutr.Valiqprod != 0 ? new XElement(pf + "vAliqProd", det.imposto.belPis.belPisoutr.Valiqprod.ToString("#0.0000").Replace(",", ".")) : null), (det.imposto.belPis.belPisoutr.Vpis != null ? new XElement(pf + "vPIS", det.imposto.belPis.belPisoutr.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null)) : null), //---------------COFINS---------------// (det.imposto.belCofins != null ? new XElement(pf + "COFINS", //-----------COFINSAliq------------// (det.imposto.belCofins.belCofinsaliq != null ? new XElement(pf + "COFINSAliq", new XElement(pf + "CST", det.imposto.belCofins.belCofinsaliq.Cst.ToString()), new XElement(pf + "vBC", det.imposto.belCofins.belCofinsaliq.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "pCOFINS", det.imposto.belCofins.belCofinsaliq.Pcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.imposto.belCofins.belCofinsaliq.Vcofins.ToString("#0.00").Replace(",", "."))) : null), //------------COFINSQtde------------// (det.imposto.belCofins.belCofinsqtde != null ? new XElement(pf + "COFINSQtde", new XElement(pf + "CST", det.imposto.belCofins.belCofinsqtde.Cst.ToString()), new XElement(pf + "pBCProd", det.imposto.belCofins.belCofinsqtde.Qbcprod.ToString()), new XElement(pf + "vAliqProd", det.imposto.belCofins.belCofinsqtde.Valiqprod.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.imposto.belCofins.belCofinsqtde.Vcofins.ToString("#0.00").Replace(",", "."))) : null), //------------COFINSNT--------------// (det.imposto.belCofins.belCofinsnt != null ? new XElement(pf + "COFINSNT", (det.imposto.belCofins.belCofinsnt.Cst != null ? new XElement(pf + "CST", det.imposto.belCofins.belCofinsnt.Cst.ToString()) : null)) : null), //------------COFINSOutr--------------// (det.imposto.belCofins.belCofinsoutr != null ? new XElement(pf + "COFINSOutr", new XElement(pf + "CST", det.imposto.belCofins.belCofinsoutr.Cst.ToString()), new XElement(pf + "vBC", det.imposto.belCofins.belCofinsoutr.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "pCOFINS", det.imposto.belCofins.belCofinsoutr.Pcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.imposto.belCofins.belCofinsoutr.Vcofins.ToString("#0.00").Replace(",", "."))) : null)) : null), //----------------ISSQN-----------------// (det.imposto.belIss != null ? new XElement(pf + "ISSQN", (det.imposto.belIss.Vbc != 0 ? new XElement(pf + "vBC", det.imposto.belIss.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIss.Valiq != 0 ? new XElement(pf + "vAliq", det.imposto.belIss.Valiq.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIss.Vissqn != 0 ? new XElement(pf + "vISSQN", det.imposto.belIss.Vissqn.ToString("#0.00").Replace(",", ".")) : null), (det.imposto.belIss.Cmunfg != null ? new XElement(pf + "cMunFG", det.imposto.belIss.Cmunfg.ToString()) : null), (det.imposto.belIss.Clistserv != 0 ? new XElement(pf + "cListServ", det.imposto.belIss.Clistserv.ToString()) : null), (det.imposto.belIss.cSitTrib != null ? new XElement(pf + "cSitTrib", det.imposto.belIss.cSitTrib.ToString()) : null)) : null)), // NFe_2.0 Tratar item //-----------INFADPROD-------------// (!String.IsNullOrEmpty(det.infAdProd.Infadprid) ? (new XElement(pf + "infAdProd", det.infAdProd.Infadprid.ToString())) : null))); lcondet.Add(condet); } #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML, Regiao XML_Detalhes - " + x.Message); } #endregion //Total XContainer contotal; try { belTotal objtotal = nota.total; #region XML_Total contotal = (new XElement(pf + "total", (objtotal.belIcmstot != null ? new XElement(pf + "ICMSTot", new XElement(pf + "vBC", objtotal.belIcmstot.Vbc.ToString("#0.00").Replace(",", ".")),//Danner - o.s. 24271 - 15/03/2010 new XElement(pf + "vICMS", objtotal.belIcmstot.Vicms.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vBCST", objtotal.belIcmstot.Vbcst.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vST", objtotal.belIcmstot.Vst.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vProd", objtotal.belIcmstot.Vprod.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vFrete", objtotal.belIcmstot.Vfrete.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vSeg", objtotal.belIcmstot.Vseg.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vDesc", objtotal.belIcmstot.Vdesc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vII", objtotal.belIcmstot.Vii.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vIPI", objtotal.belIcmstot.Vipi.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vPIS", objtotal.belIcmstot.Vpis.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", objtotal.belIcmstot.Vcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vOutro", objtotal.belIcmstot.Voutro.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vNF", objtotal.belIcmstot.Vnf.ToString("#0.00").Replace(",", ".")) , new XElement(pf + "vTotTrib", objtotal.belIcmstot.vTotTrib.ToString("#0.00").Replace(",", ".")) ) : null), (objtotal.belIssqntot.Vserv > 0 ? new XElement(pf + "ISSQNtot", new XElement(pf + "vServ", objtotal.belIssqntot.Vserv.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vBC", objtotal.belIssqntot.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vISS", objtotal.belIssqntot.Viss.ToString("#0.00").Replace(",", ".")), (objtotal.belIssqntot.Vpis != 0 ? new XElement(pf + "vPIS", objtotal.belIssqntot.Vpis.ToString("#0.00").Replace(",", ".")) : null), (objtotal.belIssqntot.Vcofins != 0 ? new XElement(pf + "vCOFINS", objtotal.belIssqntot.Vcofins.ToString("#0.00").Replace(",", ".")) : null) ) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML, Regiao XML_Total - " + x.Message); } //Fim - Total //Frete XContainer contransp = null; belTransp objtransp; try { objtransp = nota.transp; #region XML_Transporte contransp = (new XElement(pf + "transp", new XElement(pf + "modFrete", objtransp.Modfrete.ToString()), (objtransp.Modfrete != "9" ? new XElement(pf + "transporta", (!String.IsNullOrEmpty(objtransp.belTransportadora.Cnpj) ? new XElement(pf + "CNPJ", objtransp.belTransportadora.Cnpj.ToString()) : (objtransp.belTransportadora.Cpf != null ? new XElement(pf + "CPF", objtransp.belTransportadora.Cpf.ToString()) : null)), (!String.IsNullOrEmpty(objtransp.belTransportadora.Xnome) ? new XElement(pf + "xNome", objtransp.belTransportadora.Xnome.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belTransportadora.Ie) ? new XElement(pf + "IE", objtransp.belTransportadora.Ie.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belTransportadora.Xender) ? new XElement(pf + "xEnder", objtransp.belTransportadora.Xender.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belTransportadora.Xmun) ? new XElement(pf + "xMun", objtransp.belTransportadora.Xmun.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belTransportadora.Uf) ? new XElement(pf + "UF", objtransp.belTransportadora.Uf.ToString()) : null)) : null), (objtransp.belRetTransp.Cfop != null && objtransp.Modfrete != "9" ? (new XElement(pf + "retTransp", new XElement(pf + "vServ", objtransp.belRetTransp.Vserv.ToString("#0.00").Replace(',', '.')), new XElement(pf + "vBCRet", objtransp.belRetTransp.Vbvret.ToString("#0.00").Replace(',', '.')), new XElement(pf + "pICMSRet", objtransp.belRetTransp.Picmsret.ToString()), new XElement(pf + "vICMSRet", objtransp.belRetTransp.Vicmsret.ToString("#0.00").Replace(',', '.')), (!String.IsNullOrEmpty(objtransp.belRetTransp.Cfop) ? new XElement(pf + "CFOP", objtransp.belRetTransp.Cfop.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belRetTransp.Cmunfg) ? new XElement(pf + "cMunFG", objtransp.belRetTransp.Cmunfg.ToString()) : null))) : null), (objtransp.belVeicTransp.Placa != null && objtransp.Modfrete != "9" ? (new XElement(pf + "veicTransp", (!String.IsNullOrEmpty(objtransp.belVeicTransp.Placa) ? new XElement(pf + "placa", objtransp.belVeicTransp.Placa.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belVeicTransp.Uf) ? new XElement(pf + "UF", objtransp.belVeicTransp.Uf.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belVeicTransp.Rntc) ? new XElement(pf + "RNTC", objtransp.belVeicTransp.Rntc.ToString()) : null))) : null), (objtransp.belReboque.Placa != null && objtransp.Modfrete != "9" ? new XElement(pf + "reboque", (!String.IsNullOrEmpty(objtransp.belReboque.Placa) ? new XElement(pf + "placa", objtransp.belReboque.Placa.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belReboque.Uf) ? new XElement(pf + "UF", objtransp.belReboque.Uf.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belReboque.Rntc) ? new XElement(pf + "RNTC", objtransp.belReboque.Rntc.ToString()) : null)) : null), (objtransp.belVol != null && objtransp.Modfrete != "9" ? new XElement(pf + "vol", (objtransp.belVol.Qvol > 0 ? new XElement(pf + "qVol", Convert.ToInt32(objtransp.belVol.Qvol).ToString()) : null), (!String.IsNullOrEmpty(objtransp.belVol.Esp) ? new XElement(pf + "esp", objtransp.belVol.Esp.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belVol.Marca) ? new XElement(pf + "marca", objtransp.belVol.Marca.ToString()) : null), (!String.IsNullOrEmpty(objtransp.belVol.Nvol) ? new XElement(pf + "nVol", objtransp.belVol.Nvol.ToString()) : null), new XElement(pf + "pesoL", objtransp.belVol.PesoL.ToString("#0.000").Replace(",", ".")), new XElement(pf + "pesoB", objtransp.belVol.PesoB.ToString("#0.000").Replace(",", "."))) : null), (objtransp.belLacres.Nlacre != null && objtransp.Modfrete != "9" ? new XElement(pf + "lacres", new XElement(pf + "nLacre", "")) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + " - Erro na geração do XML, Regiao XML_Transporte - " + x.Message); } //Fim - Frete //Duplicata XContainer concobr = null; belCobr objcob; try { objcob = nota.cobr; #region XML_Cobrança if (Acesso.NM_EMPRESA != "LORENZON") { if (objcob.Fat != null) { concobr = (new XElement(pf + "cobr", new XElement(pf + "fat", new XElement(pf + "nFat", objcob.Fat.Nfat.ToString()), (objcob.Fat.Vorig != 0 ? new XElement(pf + "vOrig", objcob.Fat.Vorig.ToString("#0.00").Replace(",", ".")) : null), (objcob.Fat.Vdesc != null && objcob.Fat.Vdesc != 0 ? new XElement(pf + "vDesc", objcob.Fat.Vdesc.ToString("#0.00").Replace(",", ".")) : null), (objcob.Fat.Vliq != 0 ? new XElement(pf + "vLiq", objcob.Fat.Vliq.ToString("#0.00").Replace(",", ".")) : null)), (objcob.Fat.belDup != null ? from dup in objcob.Fat.belDup select new XElement(pf + "dup", new XElement(pf + "nDup", dup.Ndup.ToString()), new XElement(pf + "dVenc", dup.Dvenc.ToString("yyyy-MM-dd")), (Acesso.NM_EMPRESA != "LORENZON" ? new XElement(pf + "vDup", dup.Vdup.ToString("#0.00").Replace(",", ".")) : null)) : null))); } } #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML, Region XML_Cobrança - " + x.Message); } //Fim - Duplicata //Obs XContainer conobs; belInfAdic objobs; try { objobs = nota.infAdic; #region XML_Obs if (sUF.Equals("EX") && objobs.Infcpl == null) { objobs.Infcpl = "SEM OBSERVACAO"; } conobs = new XElement(pf + "infAdic", (!String.IsNullOrEmpty(objobs.Infcpl) ? new XElement(pf + "infCpl", objobs.Infcpl.ToString()) : null)); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na geração do XML,Regiao XML_Obs - " + x.Message); } //Fim - Obs //OS_25679 #region Exporta XContainer conExporta = null; belExporta objExporta = nota.exporta; if ((objExporta.Ufembarq != "") && (objExporta.Xlocembarq != "")) { conExporta = new XElement(pf + "exporta", new XElement(pf + "UFEmbarq", objExporta.Ufembarq), new XElement(pf + "xLocEmbarq", objExporta.Xlocembarq)); } #endregion //Uniao dos Containers try { concabec.Add(coninfnfe); coninfnfe.Add(conide); conide.AddAfterSelf(conemit); conemit.AddAfterSelf(condest); condest.AddAfterSelf(contotal); contotal.AddAfterSelf(contransp); if (concobr != null) { contransp.AddAfterSelf(concobr); if (objobs.Infcpl != null) concobr.AddAfterSelf(conobs); } else { if (objobs.Infcpl != null) contransp.AddAfterSelf(conobs); } if (conExporta != null) conobs.AddAfterSelf(conExporta); foreach (XElement x in lcondet) { contotal.AddBeforeSelf(x); } } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro na montagem do XML, União dos Containers - " + x.Message); } try { belAssinaXml Assinatura = new belAssinaXml(); string nfe = Assinatura.ConfigurarArquivo(concabec.ToString(), "infNFe", Acesso.cert_NFe); nfes.Add(nfe); XElement xnfe = XElement.Parse(nfe); XDocument xdocsalvanfesemlot = new XDocument(xnfe); DirectoryInfo dPastaData = new DirectoryInfo(Pastas.ENVIO + "\\" + nota.chaveNFe.Substring(5, 4)); if (!dPastaData.Exists) { dPastaData.Create(); } if (Acesso.TP_EMIS == 2) { xdocsalvanfesemlot.Save(Pastas.CONTINGENCIA + "\\" + nota.chaveNFe.Replace("NFe", "") + "-nfe.xml"); } else { xdocsalvanfesemlot.Save(Pastas.ENVIO + "\\" + nota.chaveNFe.Substring(5, 4) + "\\" + nota.chaveNFe.Replace("NFe", "") + "-nfe.xml"); } } catch (Exception x) { throw new Exception("Nota de Sequência - " + nota.ide.Cnf + "Erro ao assinar a nfe de sequencia " + nota.ide.Cnf + x.Message); } iCount++; } string sXmlComp = ""; foreach (var i in nfes) { sXmlComp = sXmlComp + i; } //Estou inserindo o enviNFe pois se eu transformar o arquivo xml assinado em xml e depois em texto usando um toString, //a assinatura se torna invalida. Então depois de assinado do trabalho em forma de texto como xml ateh envia-lo pra fazenda. string sXmlfull = "<?xml version=\"1.0\" encoding=\"utf-8\"?><enviNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\"><idLote>" + sNomeArquivo.Substring(7, 15) + "</idLote>" + sXmlComp + "</enviNFe>"; StreamWriter sw = new StreamWriter(sPathLote); sw.Write(sXmlfull); sw.Close(); belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_NFE + "\\enviNFe_v2.00.xsd", sPathLote); for (int i = 0; i < lNotas.Count; i++) { } } catch (Exception ex) { if (!ex.Message.Contains("'vTotTrib'")) throw ex; } }
/// <summary> /// Gera a Estrutura do XML da NF-e /// </summary> /// <param name="sNF"></param> /// <param name="cert"></param> /// <param name="sEmp"></param> /// <param name="sNomeArq"></param> /// <param name="iStatusAtualSistema"</param> public void geraArquivoNFE(List<string> sNF, X509Certificate2 cert, string sEmp, string sNomeArq) { string sPath = ""; sPath = (sFormaEmiNFe.Equals("2") ? belStaticPastas.CONTINGENCIA + @sNomeArq : belStaticPastas.ENVIO + @sNomeArq); Globais glob = new Globais(); int iCount = 0; if (File.Exists(sPath)) { File.Delete(sPath); } string sCasasVlUnit = glob.LeRegConfig("QtdeCasasVlUnit"); sCasasVlUnit = (sCasasVlUnit == "" ? "000000" : ("").PadLeft(Convert.ToInt32(sCasasVlUnit), '0')); foreach (var i in lTotNota) { string sUF; string sNota = sNF[iCount]; string sNFe = "NFe" + GeraChave(sEmp, sNota); XDocument xdoc = new XDocument(); #region XML_Principal XNamespace pf = "http://www.portalfiscal.inf.br/nfe"; //XContainer conenv = new XElement(pf + "enviNFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"), // new XAttribute("versao", "2.00"), // new XElement(pf + "idLote", sNomeArq.Substring(7, 15))); #endregion #region XML_Cabeçalho //new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), XContainer concabec = (new XElement(pf + "NFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"))); XContainer coninfnfe = (new XElement(pf + "infNFe", new XAttribute("Id", sNFe), new XAttribute("versao", "2.00"))); #endregion #region Ide XContainer conide; try { belIde objide = i[0] as belIde; #region XML_ide conide = (new XElement(pf + "ide", new XElement(pf + "cUF", objide.Cuf.ToString()), new XElement(pf + "cNF", objide.Cnf.ToString()), new XElement(pf + "natOp", objide.Natop.ToString()), new XElement(pf + "indPag", objide.Indpag.ToString()), new XElement(pf + "mod", objide.Mod.ToString()), new XElement(pf + "serie", objide.Serie.ToString()), new XElement(pf + "nNF", objide.Nnf.ToString()), new XElement(pf + "dEmi", objide.Demi.ToString("yyyy-MM-dd")), new XElement(pf + "dSaiEnt", objide.Dsaient.ToString("yyyy-MM-dd")), new XElement(pf + "hSaiEnt", objide.HSaiEnt.ToString("HH:mm:ss")), // NFe_2.0 new XElement(pf + "tpNF", objide.Tpnf.ToString()), new XElement(pf + "cMunFG", objide.Cmunfg.ToString()), (objide.belNFref != null ? (from c in objide.belNFref select new XElement(pf + "NFref", (c.RefNFe != null ? new XElement(pf + "refNFe", c.RefNFe) : null), (c.cUF != null ? (new XElement(pf + "refNF", (c.cUF != null ? new XElement(pf + "cUF", c.cUF) : null), (c.AAMM != null ? new XElement(pf + "AAMM", c.AAMM) : null), (c.CNPJ != null ? new XElement(pf + "CNPJ", c.CNPJ) : null), (c.mod != null ? new XElement(pf + "mod", c.mod) : null), (c.serie != null ? new XElement(pf + "serie", c.serie) : null), (c.nNF != null ? new XElement(pf + "nNF", c.nNF) : null))) : null))) : null),//NFe_2.0_Verificar ID B14 - B20a - B20i - new XElement(pf + "tpImp", objide.Tpimp.ToString()), new XElement(pf + "tpEmis", objide.Tpemis.ToString()), new XElement(pf + "cDV", objide.Cdv.ToString()), new XElement(pf + "tpAmb", objide.Tpamb.ToString()), new XElement(pf + "finNFe", objide.Finnfe.ToString()), new XElement(pf + "procEmi", objide.Procemi.ToString()), new XElement(pf + "verProc", objide.Verproc.ToString()), ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ? new XElement(pf + "dhCont", HLP.Util.Util.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss")) : null), // NFe_2.0 ((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ? new XElement(pf + "xJust", (iStatusAtualSistema == 2 ? "FALHA DE CONEXÃO COM INTERNET" : "FALHA COM WEB SERVICE DO ESTADO")) : null)));// NFe_2.0 #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_ide - " + x.Message); } #endregion #region Emit XContainer conemit; try { belEmit objemit = i[1] as belEmit; #region XML_Emit conemit = (new XElement(pf + "emit", (new XElement(pf + "CNPJ", objemit.Cnpj.ToString())), new XElement(pf + "xNome", objemit.Xnome.ToString()), new XElement(pf + "xFant", objemit.Xfant.ToString()), new XElement(pf + "enderEmit", new XElement(pf + "xLgr", objemit.Xlgr.ToString()), new XElement(pf + "nro", objemit.Nro.ToString()), (objemit.Xcpl != null ? new XElement(pf + "xCpl", objemit.Xcpl.ToString()) : null), new XElement(pf + "xBairro", objemit.Xbairro.ToString()), new XElement(pf + "cMun", objemit.Cmun.ToString()), new XElement(pf + "xMun", objemit.Xmun.ToString()), new XElement(pf + "UF", objemit.Uf.ToString()), new XElement(pf + "CEP", objemit.Cep.ToString()), new XElement(pf + "cPais", objemit.Cpais.ToString()), new XElement(pf + "xPais", objemit.Xpais.ToString()), (objemit.Fone != null ? new XElement(pf + "fone", objemit.Fone.ToString()) : null)), (objemit.Ie != null ? new XElement(pf + "IE", objemit.Ie.ToString()) : null), (objemit.Iest != null ? new XElement(pf + "IEST", objemit.Iest.ToString()) : null), (objemit.Im != null ? new XElement(pf + "IM", objemit.Im.ToString()) : null), (objemit.Cnae != null ? new XElement(pf + "CNAE", objemit.Cnae.ToString()) : null), new XElement(pf + "CRT", objemit.CRT.ToString()))); // NFe_2.0 #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Emit - " + x.Message); } #endregion #region Dest XContainer condest; try { belDest objdest = i[2] as belDest; sUF = objdest.Uf.ToString(); #region XML_Dest objdest.Ie = (objdest.Ie == null ? "" : objdest.Ie); condest = (new XElement(pf + "dest", (objdest.Cnpj == "EXTERIOR" ? new XElement(pf + "CNPJ") : (objdest.Cnpj != null ? new XElement(pf + "CNPJ", objdest.Cnpj) : new XElement(pf + "CPF", objdest.Cpf))), new XElement(pf + "xNome", (belStatic.TpAmb == 2 ? "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL" : objdest.Xnome.ToString().Trim())), new XElement(pf + "enderDest", new XElement(pf + "xLgr", objdest.Xlgr.ToString()), new XElement(pf + "nro", (objdest.Nro != null ? objdest.Nro.ToString() : "0")), (objdest.Xcpl != "" ? new XElement(pf + "xCpl", objdest.Xcpl.ToString()) : null), new XElement(pf + "xBairro", objdest.Xbairro.ToString()), new XElement(pf + "cMun", objdest.Cmun.ToString()), new XElement(pf + "xMun", objdest.Xmun.ToString()), new XElement(pf + "UF", objdest.Uf.ToString()), (objdest.Cep != null ? new XElement(pf + "CEP", objdest.Cep.ToString()) : null), new XElement(pf + "cPais", objdest.Cpais.ToString()), (objdest.Xpais != null ? new XElement(pf + "xPais", objdest.Xpais.ToString()) : null), (objdest.Fone != null ? new XElement(pf + "fone", objdest.Fone.ToString()) : null)), ((objdest.Ie != null) ? (objdest.Ie != "EXTERIOR" ? new XElement(pf + "IE", objdest.Ie.ToString().Trim()) : new XElement(pf + "IE")) : null), //Claudinei - o.s. sem - 11/02/2010 (objdest.Isuf != null ? new XElement(pf + "ISUF", objdest.Isuf.ToString()) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Dest - " + x.Message); } #endregion #region Det List<XElement> lcondet = new List<XElement>(); try { List<belDet> objdet = new List<belDet>(); objdet = i[4] as List<belDet>; #region XML_Detalhes foreach (var det in objdet) { XElement condet = (new XElement(pf + "det", new XAttribute("nItem", det.Nitem), new XElement(pf + "prod", (det.belProd.Cprod != null ? new XElement(pf + "cProd", det.belProd.Cprod.ToString()) : null), (det.belProd.Cean != null ? new XElement(pf + "cEAN", det.belProd.Cean.ToString()) : null), (det.belProd.Xprod != null ? new XElement(pf + "xProd", det.belProd.Xprod.ToString()) : null), (det.belProd.Ncm != null ? new XElement(pf + "NCM", det.belProd.Ncm.ToString()) : new XElement(pf + "NCM", det.belProd.Ncm = "00000000")), //Claudinei - o.s. 24200 - 01/03/2010 (det.belProd.Extipi != null ? new XElement(pf + "EXTIPI", det.belProd.Extipi.ToString()) : null), (det.belProd.Genero != null ? new XElement(pf + "genero", det.belProd.Genero.ToString()) : null), (det.belProd.Cfop != null ? new XElement(pf + "CFOP", det.belProd.Cfop.ToString()) : null), (det.belProd.Ucom != null ? new XElement(pf + "uCom", det.belProd.Ucom.ToString()) : null), (det.belProd.Qcom != null ? new XElement(pf + "qCom", det.belProd.Qcom.ToString("#0.0000").Replace(",", ".")) : null), (det.belProd.Vuncom != null ? new XElement(pf + "vUnCom", det.belProd.Vuncom.ToString("#0." + sCasasVlUnit).Replace(",", ".")) : null), (det.belProd.Vprod != null ? new XElement(pf + "vProd", det.belProd.Vprod.ToString("#0.00").Replace(",", ".")) : null), (det.belProd.Ceantrib != null ? new XElement(pf + "cEANTrib", det.belProd.Ceantrib.ToString()) : null), (det.belProd.Utrib != null ? new XElement(pf + "uTrib", det.belProd.Utrib.ToString()) : null), (det.belProd.Qtrib != null ? new XElement(pf + "qTrib", det.belProd.Qtrib.ToString("#0.0000").Replace(",", ".")) : null), (det.belProd.Vuntrib != null ? new XElement(pf + "vUnTrib", det.belProd.Vuntrib.ToString("#0." + sCasasVlUnit).Replace(",", ".")) : null), ((det.belProd.Vfrete != null) && (det.belProd.Vfrete != 0) ? new XElement(pf + "vFrete", det.belProd.Vfrete.ToString("#0.00").Replace(",", ".")) : null), ((det.belProd.Vseg != null) && (det.belProd.Vseg != 0) ? new XElement(pf + "vSeg", det.belProd.Vseg.ToString("#0.00").Replace(",", ".")) : null), (((det.belProd.Vdesc != null) && (det.belProd.Vdesc != 0)) ? new XElement(pf + "vDesc", det.belProd.Vdesc.ToString("#0.00").Replace(",", ".")) : null), ((det.belProd.VOutro != null) && (det.belProd.VOutro != 0) ? new XElement(pf + "vOutro", det.belProd.VOutro.ToString("#0.00").Replace(",", ".")) : null), //NFe_2.0 (det.belProd.IndTot != null ? new XElement(pf + "indTot", det.belProd.IndTot.ToString()) : null), //NFe_2.0 ((det.belProd.belDI != null) ? from DI in det.belProd.belDI where DI.nDI != null && DI.xLocDesemb != null && DI.UFDesemb != null && DI.cExportador != null select new XElement(pf + "DI", (DI.nDI != "" ? new XElement(pf + "nDI", DI.nDI) : null), new XElement(pf + "dDI", DI.DDI.ToString("yyyy-MM-dd")), (DI.xLocDesemb != "" ? new XElement(pf + "xLocDesemb", DI.xLocDesemb) : null), (DI.UFDesemb != "" ? new XElement(pf + "UFDesemb", DI.UFDesemb) : null), new XElement(pf + "dDesemb", DI.dDesemb.ToString("yyyy-MM-dd")), (DI.cExportador != "" ? new XElement(pf + "cExportador", DI.cExportador) : null), from adic in DI.adi where adic.cFabricante != null select new XElement(pf + "adi", new XElement(pf + "nAdicao", adic.nAdicao), new XElement(pf + "nSeqAdic", adic.nSeqAdic), (adic.cFabricante != "" ? new XElement(pf + "cFabricante", adic.cFabricante) : null), new XElement(pf + "vDescDI", adic.vDescDI))) : null), ((det.belProd.XPed != "") ? new XElement(pf + "xPed", det.belProd.XPed) : null), ((det.belProd.NItemPed != "") ? new XElement(pf + "nItemPed", det.belProd.NItemPed) : null)), new XElement(pf + "imposto", //---------------ICMS-----------------// new XElement(pf + "ICMS", //-------------ICMS00-------------// (det.belImposto.belIcms.belIcms00 != null ? new XElement(pf + "ICMS00", (det.belImposto.belIcms.belIcms00.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms00.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms00.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms00.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms00.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms00.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms00.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms00.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms00.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms00.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms00.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms00.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS10-------------// (det.belImposto.belIcms.belIcms10 != null ? new XElement(pf + "ICMS10", (det.belImposto.belIcms.belIcms10.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms10.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms10.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms10.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms10.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms10.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms10.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms10.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms10.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms10.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms10.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms10.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms10.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 11/03/2010 (det.belImposto.belIcms.belIcms10.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms10.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms10.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms10.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms10.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms10.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS20-------------// (det.belImposto.belIcms.belIcms20 != null ? new XElement(pf + "ICMS20", (det.belImposto.belIcms.belIcms20.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms20.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms20.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms20.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms20.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms20.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms20.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms20.Predbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms20.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms20.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms20.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms20.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms20.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms20.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS30-------------// (det.belImposto.belIcms.belIcms30 != null ? new XElement(pf + "ICMS30", (det.belImposto.belIcms.belIcms30.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms30.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms30.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms30.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms30.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms30.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms30.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms30.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010 (det.belImposto.belIcms.belIcms30.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms30.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms30.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms30.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms30.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms30.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms30.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms30.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS40-------------// (det.belImposto.belIcms.belIcms40 != null ? new XElement(pf + "ICMS40", (det.belImposto.belIcms.belIcms40.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms40.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms40.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms40.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms40.Vicms > 0 ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms40.Vicms.ToString()) : null), //NFe_2.0 (det.belImposto.belIcms.belIcms40.Vicms > 0 ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms40.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS41-------------// (det.belImposto.belIcms.belIcms41 != null ? new XElement(pf + "ICMS41", (det.belImposto.belIcms.belIcms41.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms41.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms41.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms41.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms41.Vicms > 0 ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms41.Vicms.ToString()) : null),//NFe_2.0 (det.belImposto.belIcms.belIcms41.motDesICMS > 0 ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms41.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS50-------------// (det.belImposto.belIcms.belIcms50 != null ? new XElement(pf + "ICMS50", (det.belImposto.belIcms.belIcms50.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms50.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms50.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms50.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms50.Vicms > 0 ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms50.Vicms.ToString()) : null),//NFe_2.0 (det.belImposto.belIcms.belIcms50.motDesICMS > 0 ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms50.motDesICMS.ToString()) : null)) : null),//NFe_2.0 //-------------ICMS51-------------// (det.belImposto.belIcms.belIcms51 != null ? new XElement(pf + "ICMS51", (det.belImposto.belIcms.belIcms51.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms51.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms51.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms51.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms51.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms51.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms51.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms51.Predbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms51.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms51.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms51.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms51.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms51.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms51.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS60-------------// (det.belImposto.belIcms.belIcms60 != null ? new XElement(pf + "ICMS60",//Danner - o.s. sem - 12/03/2010 (det.belImposto.belIcms.belIcms60.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms60.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms60.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms60.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms60.Vbcst != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belIcms60.Vbcst.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 - Mudança de nome de Tag (det.belImposto.belIcms.belIcms60.Vicmsst != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belIcms60.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),//NFe_2.0 Mudança de nome de Tag //-------------ICMS70-------------// (det.belImposto.belIcms.belIcms70 != null ? new XElement(pf + "ICMS70", (det.belImposto.belIcms.belIcms70.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms70.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms70.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms70.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms70.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms70.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms70.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms70.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 (det.belImposto.belIcms.belIcms70.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms70.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms70.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms70.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms70.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms70.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms70.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010 (det.belImposto.belIcms.belIcms70.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms70.Predbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms70.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms70.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms70.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms70.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMS90-------------// (det.belImposto.belIcms.belIcms90 != null ? new XElement(pf + "ICMS90", (det.belImposto.belIcms.belIcms90.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms90.Orig.ToString()) : null), (det.belImposto.belIcms.belIcms90.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms90.Cst.ToString()) : null), (det.belImposto.belIcms.belIcms90.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms90.Modbc.ToString()) : null), (det.belImposto.belIcms.belIcms90.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms90.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Predbc != 0 ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms90.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 //Claudinei - o.s. sem - 24/02/2010 (det.belImposto.belIcms.belIcms90.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms90.Picms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms90.Vicms.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms90.Modbcst.ToString()) : null), (det.belImposto.belIcms.belIcms90.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms90.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010 (det.belImposto.belIcms.belIcms90.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms90.Predbcst.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010 (det.belImposto.belIcms.belIcms90.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms90.Vbcst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms90.Picmsst.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belIcms90.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms90.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN101--------------// (det.belImposto.belIcms.belICMSSN101 != null ? new XElement(pf + "ICMSSN101", (det.belImposto.belIcms.belICMSSN101.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN101.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN101.CSOSN.ToString()), (det.belImposto.belIcms.belICMSSN101.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN101.pCredSN.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN101.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN101.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN102--------------// (det.belImposto.belIcms.belICMSSN102 != null ? new XElement(pf + "ICMSSN102", (det.belImposto.belIcms.belICMSSN102.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN102.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN102.CSOSN.ToString())) : null), //-------------ICMSSN201--------------// (det.belImposto.belIcms.belICMSSN201 != null ? new XElement(pf + (det.belImposto.belIcms.belICMSSN201.CSOSN.Equals("201") ? "ICMSSN201" : "ICMSSN202"), (det.belImposto.belIcms.belICMSSN201.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN201.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN201.CSOSN.ToString()), (det.belImposto.belIcms.belICMSSN201.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN201.modBCST.ToString()) : null), (det.belImposto.belIcms.belICMSSN201.pMVAST != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN201.pMVAST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.pRedBCST.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN201.pRedBCST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN201.vBCST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN201.pICMSST.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN201.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN201.vICMSST.ToString("#0.00").Replace(",", ".")) : null), ((det.belImposto.belIcms.belICMSSN201.pCredSN != null && det.belImposto.belIcms.belICMSSN201.CSOSN.Equals("201")) ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN201.pCredSN.ToString("#0.00").Replace(",", ".")) : null), ((det.belImposto.belIcms.belICMSSN201.vCredICMSSN != null && det.belImposto.belIcms.belICMSSN201.CSOSN.Equals("201")) ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN201.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN500--------------// (det.belImposto.belIcms.belICMSSN500 != null ? new XElement(pf + "ICMSSN500", (det.belImposto.belIcms.belICMSSN500.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN500.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN500.CSOSN.ToString()), (det.belImposto.belIcms.belICMSSN500.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN500.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIcms.belICMSSN500.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN500.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null)) : null), //-------------ICMSSN900--------------// (det.belImposto.belIcms.belICMSSN900 != null ? new XElement(pf + "ICMSSN900", (det.belImposto.belIcms.belICMSSN900.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN900.orig.ToString()) : null), new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN900.CSOSN.ToString())) : null)), //(det.belImposto.belIcms.belICMSSN900.modBC != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belICMSSN900.modBC.ToString()) : null), //(det.belImposto.belIcms.belICMSSN900.vBC != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belICMSSN900.vBC.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pRedBC != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belICMSSN900.pRedBC.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pICMS != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belICMSSN900.pICMS.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vICMS != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belICMSSN900.vICMS.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN900.modBCST.ToString()) : null), //(det.belImposto.belIcms.belICMSSN900.pMVAST != null ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN900.pMVAST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pRedBCST != null ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN900.pRedBCST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN900.vBCST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN900.pICMSST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN900.vICMSST.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN900.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN900.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN900.pCredSN.ToString("#0.00").Replace(",", ".")) : null), //(det.belImposto.belIcms.belICMSSN900.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN900.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null)), //---------------IPI-------------// (det.belImposto.belIpi != null ? new XElement(pf + "IPI", (det.belImposto.belIpi.Clenq != null ? new XElement(pf + "clEnq", det.belImposto.belIpi.Clenq.ToString()) : null), (det.belImposto.belIpi.Cnpjprod != null ? new XElement(pf + "CNPJProd", det.belImposto.belIpi.Cnpjprod.ToString()) : null), (det.belImposto.belIpi.Cselo != null ? new XElement(pf + "cSelo", det.belImposto.belIpi.Cselo.ToString()) : null), (det.belImposto.belIpi.Qselo != null ? new XElement(pf + "qSelo", det.belImposto.belIpi.Qselo.ToString()) : null), (det.belImposto.belIpi.Cenq != null ? new XElement(pf + "cEnq", det.belImposto.belIpi.Cenq.ToString()) : null), //-----------IPITrib-----------// (det.belImposto.belIpi.belIpitrib != null ? new XElement(pf + "IPITrib", (det.belImposto.belIpi.belIpitrib.Cst != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpitrib.Cst.ToString()) : null), (det.belImposto.belIpi.belIpitrib.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIpi.belIpitrib.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIpi.belIpitrib.Qunid != null ? new XElement(pf + "qUnid", det.belImposto.belIpi.belIpitrib.Qunid.ToString()) : null), (det.belImposto.belIpi.belIpitrib.Vunid != 0 ? new XElement(pf + "vUnid", det.belImposto.belIpi.belIpitrib.Vunid.ToString("#0.0000").Replace(",", ".")) : null), (det.belImposto.belIpi.belIpitrib.Pipi != null ? new XElement(pf + "pIPI", det.belImposto.belIpi.belIpitrib.Pipi.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIpi.belIpitrib.Vipi != null ? new XElement(pf + "vIPI", det.belImposto.belIpi.belIpitrib.Vipi.ToString("#0.00").Replace(",", ".")) : null)) : null), //-----------IPINT-----------// (det.belImposto.belIpi.belIpint != null ? new XElement(pf + "IPINT", (det.belImposto.belIpi.belIpint != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpint.Cst.ToString()) : null)) : null)) : null), //--------------II--------------// (det.belImposto.belIi != null ? new XElement(pf + "II", (det.belImposto.belIi.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIi.Vbc.ToString("#0.00").Replace(',', '.')) : null), (det.belImposto.belIi.Vdespadu != null ? new XElement(pf + "vDespAdu", det.belImposto.belIi.Vdespadu.ToString()) : null), (det.belImposto.belIi.Vii != null ? new XElement(pf + "vII", det.belImposto.belIi.Vii.ToString("0.00").Replace(',', '.')) : null), (det.belImposto.belIi.Viof != null ? new XElement(pf + "vIOF", det.belImposto.belIi.Viof.ToString("#0.00").Replace(',', '.')) : null)) : null), //----------------PIS------------// (det.belImposto.belPis != null ? new XElement(pf + "PIS", //-----------PISAliq----------// (det.belImposto.belPis.belPisaliq != null ? new XElement(pf + "PISAliq", (det.belImposto.belPis.belPisaliq.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisaliq.Cst.ToString()) : null), (det.belImposto.belPis.belPisaliq.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisaliq.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisaliq.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisaliq.Ppis.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisaliq.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisaliq.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null), //-----------PISQtde-----------// (det.belImposto.belPis.belPisqtde != null ? new XElement(pf + "PISQtde", (det.belImposto.belPis.belPisqtde.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisqtde.Cst.ToString()) : null), (det.belImposto.belPis.belPisqtde.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisqtde.Qbcprod.ToString()) : null), (det.belImposto.belPis.belPisqtde.Valiqprod != null ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisqtde.Valiqprod.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisqtde.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisqtde.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null), //----------PISNT------------// (det.belImposto.belPis.belPisnt != null ? new XElement(pf + "PISNT", (det.belImposto.belPis.belPisnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisnt.Cst.ToString()) : null)) : null), //----------PISOutr-----------// (det.belImposto.belPis.belPisoutr != null ? new XElement(pf + "PISOutr", (det.belImposto.belPis.belPisoutr.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisoutr.Cst.ToString()) : null), (det.belImposto.belPis.belPisoutr.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisoutr.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisoutr.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisoutr.Ppis.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belPis.belPisoutr.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisoutr.Qbcprod.ToString()) : null), (det.belImposto.belPis.belPisoutr.Valiqprod != 0 ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisoutr.Valiqprod.ToString("#0.0000").Replace(",", ".")) : null), (det.belImposto.belPis.belPisoutr.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisoutr.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null)) : null), //---------------COFINS---------------// (det.belImposto.belCofins != null ? new XElement(pf + "COFINS", //-----------COFINSAliq------------// (det.belImposto.belCofins.belCofinsaliq != null ? new XElement(pf + "COFINSAliq", new XElement(pf + "CST", det.belImposto.belCofins.belCofinsaliq.Cst.ToString()), new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsaliq.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsaliq.Pcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsaliq.Vcofins.ToString("#0.00").Replace(",", "."))) : null), //------------COFINSQtde------------// (det.belImposto.belCofins.belCofinsqtde != null ? new XElement(pf + "COFINSQtde", new XElement(pf + "CST", det.belImposto.belCofins.belCofinsqtde.Cst.ToString()), new XElement(pf + "pBCProd", det.belImposto.belCofins.belCofinsqtde.Qbcprod.ToString()), new XElement(pf + "vAliqProd", det.belImposto.belCofins.belCofinsqtde.Valiqprod.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsqtde.Vcofins.ToString("#0.00").Replace(",", "."))) : null), //------------COFINSNT--------------// (det.belImposto.belCofins.belCofinsnt != null ? new XElement(pf + "COFINSNT", (det.belImposto.belCofins.belCofinsnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belCofins.belCofinsnt.Cst.ToString()) : null)) : null), //------------COFINSOutr--------------// (det.belImposto.belCofins.belCofinsoutr != null ? new XElement(pf + "COFINSOutr", new XElement(pf + "CST", det.belImposto.belCofins.belCofinsoutr.Cst.ToString()), new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsoutr.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsoutr.Pcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsoutr.Vcofins.ToString("#0.00").Replace(",", "."))) : null)) : null), //----------------ISSQN-----------------// (det.belImposto.belIss != null ? new XElement(pf + "ISSQN", (det.belImposto.belIss.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIss.Vbc.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIss.Valiq != null ? new XElement(pf + "vAliq", det.belImposto.belIss.Valiq.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIss.Vissqn != null ? new XElement(pf + "vISSQN", det.belImposto.belIss.Vissqn.ToString("#0.00").Replace(",", ".")) : null), (det.belImposto.belIss.Cmunfg != null ? new XElement(pf + "cMunFG", det.belImposto.belIss.Cmunfg.ToString()) : null), (det.belImposto.belIss.Clistserv != null ? new XElement(pf + "cListServ", det.belImposto.belIss.Clistserv.ToString()) : null), (det.belImposto.belIss.cSitTrib != null ? new XElement(pf + "cSitTrib", det.belImposto.belIss.cSitTrib.ToString()) : null)) : null)), // NFe_2.0 Tratar item //-----------INFADPROD-------------// (det.belInfadprod != null ? (det.belInfadprod.Infadprid != null ? new XElement(pf + "infAdProd", det.belInfadprod.Infadprid.ToString()) : null) : null))); //Danner - o.s. sem -21/12/2009 lcondet.Add(condet); } #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Detalhes - " + x.Message); } #endregion //Total XContainer contotal; try { belTotal objtotal = i[5] as belTotal; #region XML_Total contotal = (new XElement(pf + "total", (objtotal.belIcmstot != null ? new XElement(pf + "ICMSTot", new XElement(pf + "vBC", objtotal.belIcmstot.Vbc.ToString("#0.00").Replace(",", ".")),//Danner - o.s. 24271 - 15/03/2010 new XElement(pf + "vICMS", objtotal.belIcmstot.Vicms.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vBCST", objtotal.belIcmstot.Vbcst.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vST", objtotal.belIcmstot.Vst.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vProd", objtotal.belIcmstot.Vprod.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vFrete", objtotal.belIcmstot.Vfrete.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vSeg", objtotal.belIcmstot.Vseg.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vDesc", objtotal.belIcmstot.Vdesc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vII", objtotal.belIcmstot.Vii.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vIPI", objtotal.belIcmstot.Vipi.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vPIS", objtotal.belIcmstot.Vpis.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vCOFINS", objtotal.belIcmstot.Vcofins.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vOutro", objtotal.belIcmstot.Voutro.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vNF", objtotal.belIcmstot.Vnf.ToString("#0.00").Replace(",", "."))) : null), (objtotal.belIssqntot != null ? new XElement(pf + "ISSQNtot", new XElement(pf + "vServ", objtotal.belIssqntot.Vserv.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vBC", objtotal.belIssqntot.Vbc.ToString("#0.00").Replace(",", ".")), new XElement(pf + "vISS", objtotal.belIssqntot.Viss.ToString("#0.00").Replace(",", ".")), (objtotal.belIssqntot.Vpis != 0 ? new XElement(pf + "vPIS", objtotal.belIssqntot.Vpis.ToString("#0.00").Replace(",", ".")) : null), (objtotal.belIssqntot.Vcofins != 0 ? new XElement(pf + "vCOFINS", objtotal.belIssqntot.Vcofins.ToString("#0.00").Replace(",", ".")) : null)) : null))); //(objtotal.belRetTrib != null ? new XElement(pf + "retTrib", // new XElement(pf + "vRetPIS", objtotal.belRetTrib.Vretpis.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vRetCOFINS", objtotal.belRetTrib.Vretcofins.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vRetCSLL", objtotal.belRetTrib.Vretcsll.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vBCIRRF", objtotal.belRetTrib.Vbcirrf.ToString("#0.00"), // new XElement(pf + "vIRRF", objtotal.belRetTrib.Virrf.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vBCRetPrev", objtotal.belRetTrib.Vbcretprev.ToString("#0.00").Replace(",", ".")), // new XElement(pf + "vRetPrev", objtotal.belRetTrib.Vretprev.ToString("#0.00").Replace(",", "."))) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Total - " + x.Message); } //Fim - Total //Frete XContainer contransp; belTransp objtransp; try { objtransp = i[6] as belTransp; #region XML_Transporte contransp = (new XElement(pf + "transp", new XElement(pf + "modFrete", objtransp.Modfrete.ToString()), new XElement(pf + "transporta", (objtransp.belTransportadora.Cnpj != null ? new XElement(pf + "CNPJ", objtransp.belTransportadora.Cnpj.ToString()) : (objtransp.belTransportadora.Cpf != null ? new XElement(pf + "CPF", objtransp.belTransportadora.Cpf.ToString()) : null)), (objtransp.belTransportadora.Xnome != null ? new XElement(pf + "xNome", objtransp.belTransportadora.Xnome.ToString()) : null), (objtransp.belTransportadora.Ie != null ? new XElement(pf + "IE", objtransp.belTransportadora.Ie.ToString()) : null), (objtransp.belTransportadora.Xender != null ? new XElement(pf + "xEnder", objtransp.belTransportadora.Xender.ToString()) : null), (objtransp.belTransportadora.Xmun != null ? new XElement(pf + "xMun", objtransp.belTransportadora.Xmun.ToString()) : null), (objtransp.belTransportadora.Uf != null ? new XElement(pf + "UF", objtransp.belTransportadora.Uf.ToString()) : null)), (objtransp.belRetTransp != null ? (new XElement(pf + "retTransp", new XElement(pf + "vServ", objtransp.belRetTransp.Vserv.ToString("#0.00").Replace(',', '.')), new XElement(pf + "vBCRet", objtransp.belRetTransp.Vbvret.ToString("#0.00").Replace(',', '.')), new XElement(pf + "pICMSRet", objtransp.belRetTransp.Picmsret.ToString()), new XElement(pf + "vICMSRet", objtransp.belRetTransp.Vicmsret.ToString("#0.00").Replace(',', '.')), new XElement(pf + "CFOP", objtransp.belRetTransp.Cfop.ToString()), new XElement(pf + "cMunFG", objtransp.belRetTransp.Cmunfg.ToString()))) : null), (objtransp.belVeicTransp != null ? (new XElement(pf + "veicTransp", (objtransp.belVeicTransp.Placa != null ? new XElement(pf + "placa", objtransp.belVeicTransp.Placa.ToString()) : null), (objtransp.belVeicTransp.Uf != null ? new XElement(pf + "UF", objtransp.belVeicTransp.Uf.ToString()) : null), (objtransp.belVeicTransp.Rntc != null ? new XElement(pf + "RNTC", objtransp.belVeicTransp.Rntc.ToString()) : null))) : null), (objtransp.belReboque != null ? new XElement(pf + "reboque", (objtransp.belReboque.Placa != null ? new XElement(pf + "placa", objtransp.belReboque.Placa.ToString()) : null), (objtransp.belReboque.Uf != null ? new XElement(pf + "UF", objtransp.belReboque.Uf.ToString()) : null), (objtransp.belReboque.Rntc != null ? new XElement(pf + "RNTC", objtransp.belReboque.Rntc.ToString()) : null)) : null), (objtransp.belVol != null ? new XElement(pf + "vol", (objtransp.belVol.Qvol > 0 ? new XElement(pf + "qVol", objtransp.belVol.Qvol.ToString("#")) : null), (objtransp.belVol.Esp != "" ? new XElement(pf + "esp", objtransp.belVol.Esp.ToString()) : null), (objtransp.belVol.Marca != "" ? new XElement(pf + "marca", objtransp.belVol.Marca.ToString()) : null), (objtransp.belVol.Nvol != null ? new XElement(pf + "nVol", objtransp.belVol.Nvol.ToString()) : null),//Danner - o.s. 24385 - 26/04/2010 new XElement(pf + "pesoL", objtransp.belVol.PesoL.ToString("#0.000").Replace(",", ".")), new XElement(pf + "pesoB", objtransp.belVol.PesoB.ToString("#0.000").Replace(",", "."))) : null), (objtransp.belLacres != null ? new XElement(pf + "lacres", new XElement(pf + "nLacre", "")) : null))); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Transporte - " + x.Message); } //Fim - Frete //Duplicata XContainer concobr = null; belCobr objcob; try { if (belStatic.sNomeEmpresa != "LORENZON") { objcob = i[7] as belCobr; #region XML_Cobrança concobr = (new XElement(pf + "cobr", new XElement(pf + "fat", new XElement(pf + "nFat", objcob.belFat.Nfat.ToString()), (objcob.belFat.Vorig != 0 ? new XElement(pf + "vOrig", objcob.belFat.Vorig.ToString("#0.00").Replace(",", ".")) : null), (objcob.belFat.Vdesc != null && objcob.belFat.Vdesc != 0 ? new XElement(pf + "vDesc", objcob.belFat.Vdesc.ToString("#0.00").Replace(",", ".")) : null), (objcob.belFat.Vliq != 0 ? new XElement(pf + "vLiq", objcob.belFat.Vliq.ToString("#0.00").Replace(",", ".")) : null)), (objcob.belFat.belDup != null ? from dup in objcob.belFat.belDup select new XElement(pf + "dup", new XElement(pf + "nDup", dup.Ndup.ToString()), new XElement(pf + "dVenc", dup.Dvenc.ToString("yyyy-MM-dd")), (belStatic.sNomeEmpresa != "LORENZON" ? new XElement(pf + "vDup", dup.Vdup.ToString("#0.00").Replace(",", ".")) : null)) : null))); #endregion } } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Region XML_Cobrança - " + x.Message); } //Fim - Duplicata //Obs XContainer conobs; belInfAdic objobs; try { objobs = i[8] as belInfAdic; #region XML_Obs if (sUF.Equals("EX") && objobs.Infcpl == null) { objobs.Infcpl = "SEM OBSERVACAO"; } conobs = new XElement(pf + "infAdic", (objobs.Infcpl != null ? new XElement(pf + "infCpl", objobs.Infcpl.ToString()) : null)); #endregion } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML,Regiao XML_Obs - " + x.Message); } //Fim - Obs //OS_25679 #region Exporta XContainer conExporta = null; belExporta objExporta = i[9] as belExporta; if ((objExporta.Ufembarq != "") && (objExporta.Xlocembarq != "")) { conExporta = new XElement(pf + "exporta", new XElement(pf + "UFEmbarq", objExporta.Ufembarq), new XElement(pf + "xLocEmbarq", objExporta.Xlocembarq)); } #endregion //Uniao dos Containers try { concabec.Add(coninfnfe); coninfnfe.Add(conide); conide.AddAfterSelf(conemit); conemit.AddAfterSelf(condest); condest.AddAfterSelf(contotal); contotal.AddAfterSelf(contransp); if (concobr != null) { contransp.AddAfterSelf(concobr); if (objobs.Infcpl != null) concobr.AddAfterSelf(conobs); } else { if (objobs.Infcpl != null) contransp.AddAfterSelf(conobs); } if (conExporta != null) { conobs.AddAfterSelf(conExporta); } foreach (XElement x in lcondet) { contotal.AddBeforeSelf(x); } } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro na montagem do XML, União dos Containers - " + x.Message); } try { AssinaNFeXml Assinatura = new AssinaNFeXml(); string nfe = Assinatura.ConfigurarArquivo(concabec.ToString(), "infNFe", cert); nfes.Add(nfe); XElement xnfe = XElement.Parse(nfe); XDocument xdocsalvanfesemlot = new XDocument(xnfe); DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.ENVIO + "\\" + sNFe.Substring(5, 4)); if (!dPastaData.Exists) { dPastaData.Create(); } if (sFormaEmiNFe.Equals("2")) { xdocsalvanfesemlot.Save(belStaticPastas.CONTINGENCIA + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); } else { xdocsalvanfesemlot.Save(belStaticPastas.ENVIO + "\\" + sNFe.Substring(5, 4) + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); // OS_25024 } //StreamWriter swnfe = new StreamWriter(glob.LeRegWin("PastaXmlEnvio").ToString() + "\\" + sNFe.Replace("NFe", "") + "-nfe.xml"); //swnfe.Write(nfe); //swnfe.Close(); } catch (Exception x) { throw new Exception("Nota de Sequência - " + sNota + "Erro ao assinar a nfe de sequencia " + sNota + x.Message); } iCount++; } //Concatenando as NFes. string sXmlComp = ""; //Junta todos os XML's em texto foreach (var i in nfes) { sXmlComp = sXmlComp + i; } //Estou inserindo o enviNFe pois se eu transformar o arquivo xml assinado em xml e depois em texto usando um toString, //a assinatura se torna invalida. Então depois de assinado do trabalho em forma de texto como xml ateh envia-lo pra fazenda. sXmlfull = "<?xml version=\"1.0\" encoding=\"utf-8\"?><enviNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\"><idLote>" + sNomeArq.Substring(7, 15) + "</idLote>" + sXmlComp + "</enviNFe>"; //Grava StreamWriter sw = new StreamWriter(sPath); sw.Write(sXmlfull); sw.Close(); #region Valida_Xml Globais getschema = new Globais(); //string sXml = File.OpenText(sPath).ReadToEnd(); XmlSchemaCollection myschema = new XmlSchemaCollection(); XmlValidatingReader reader; //Danner - o.s. 23732 - 06/11/2009 try { XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); reader = new XmlValidatingReader(sXmlfull, XmlNodeType.Element, context); myschema.Add("http://www.portalfiscal.inf.br/nfe", belStaticPastas.SCHEMA_NFE + "\\enviNFe_v2.00.xsd"); reader.ValidationType = ValidationType.Schema; reader.Schemas.Add(myschema); while (reader.Read()) { } } catch (XmlException x) { File.Delete(sPath); throw new Exception(x.Message); } catch (XmlSchemaException x) { File.Delete(sPath); throw new Exception(x.Message); } //Fim - Danner - o.s. 23732 - 06/11/2009 #endregion }
private XElement ProcessStaticCells(XElement currentElement, XElement previous) { var staticCells = currentElement.ElementsBeforeSelf(WordMl.TableCellName) .Where(element => element.IsBefore(previous)) .ToList(); if (staticCells.Any()) { if (previous == null) { var parentRow = staticCells.First().Parent; staticCells.Remove(); parentRow.Add(staticCells); previous = staticCells.Last(); } else { staticCells.Remove(); previous.AddAfterSelf(staticCells); previous = staticCells.Last(); } } return previous; }
private XElement ProcessCell(TableElement tableElement, XElement previous, string text) { var isInnerCell = tableElement.HasCell(); var currentCell = this.CurrentCell(tableElement); previous = this.ProcessStaticCells(tableElement, previous); var parent = isInnerCell ? currentCell: tableElement.StartTag.Parent; var result = DocxHelper.CreateTextElement( tableElement.StartTag, parent, text); if (!isInnerCell) { tableElement.StartTag.AddAfterSelf(result); } else { if (currentCell.Elements(WordMl.ParagraphName).Any()) { currentCell.Elements(WordMl.ParagraphName).Remove(); } currentCell.Add(result); } if (previous != null && !previous.Equals(currentCell)) { currentCell.Remove(); previous.AddAfterSelf(currentCell); } else if (previous == null) { var parentRow = isInnerCell ? tableElement.StartTag.Parent : currentCell.Parent; currentCell.Remove(); parentRow.Add(currentCell); } return currentCell; }
private XElement ProcessItemIfElement(TableElement itemIfElement, DataReader dataReader, int index, XElement previous) { bool condition; try { condition = bool.Parse(dataReader.ReadText(itemIfElement.Expression)); } catch (FormatException) { condition = false; } catch (System.Xml.XPath.XPathException) { condition = false; } var currentCell = itemIfElement.StartTag.Ancestors().First(element => element.Name == WordMl.TableCellName); if (condition) { this.ProcessElements(itemIfElement.TagElements, dataReader, index, previous, false); itemIfElement.StartTag.Remove(); itemIfElement.EndTag.Remove(); if (previous != null && !previous.Equals(currentCell)) { currentCell.Remove(); previous.AddAfterSelf(currentCell); } } else { this.CleanUp(itemIfElement.StartTag, itemIfElement.EndTag); if (!currentCell.Elements(WordMl.ParagraphName).Any()) { currentCell.Add(new XElement(WordMl.ParagraphName)); } if (previous != null && !previous.Equals(currentCell)) { currentCell.Remove(); previous.AddAfterSelf(currentCell); } else if (previous == null) { var parentRow = currentCell.Parent; currentCell.Remove(); parentRow.Add(currentCell); } } return currentCell; }