/// <summary> /// Reads item info from csv file to itemList. /// </summary> private void ReadFromItemInfo() { string path = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\..\\..\\.\\Resources\\", "itemInfo.csv"); using (StreamReader reader = new StreamReader(path)) { while (!reader.EndOfStream) { var values = reader.ReadLine().Split(','); var location = values[0]; var item = values[1]; var description = values[2]; var manuf = values[3]; var price = (int)double.Parse(values[4]); DestinyItem newResources = new DestinyItem(location, item, description, manuf, price); DestinyItems.Add(newResources); } } }
public bool CreateExportXML(string filePathToImport, string purchaseOrder, DestinyItem item) { ReadFromImport(filePathToImport); doc = new XmlDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); //"FSC-DestinyAssetImport" XmlElement destinyAssetImport = doc.CreateElement("FSC-Destiny-AssetImport"); XmlAttribute assertImportVer = destinyAssetImport.Attributes.Append(doc.CreateAttribute("version")); assertImportVer.Value = "1"; XmlAttribute assertImportDate = destinyAssetImport.Attributes.Append(doc.CreateAttribute("date")); assertImportDate.Value = today.Year.ToString() + today.Month.ToString() + today.Day.ToString(); doc.AppendChild(destinyAssetImport); //Asset group XmlElement assetGroup = doc.CreateElement("AssetGroup"); //AssetEntry XmlElement assetEntry = doc.CreateElement("AssetEntry"); //OrganizationCode XmlElement organizationCode = doc.CreateElement("OrganizationCode"); organizationCode.AppendChild(doc.CreateCDataSection("GSD")); assetEntry.AppendChild(organizationCode); //End - OrganizationCode //Template XmlElement template = doc.CreateElement("Template"); template.AppendChild(doc.CreateCDataSection(item.Template)); assetEntry.AppendChild(template); //End - Template CreateFieldElements(assetEntry, "Description", item.Model); CreateFieldElements(assetEntry, "Replacement Price", item.Price.ToString()); CreateFieldElements(assetEntry, "Model", item.Description); CreateFieldElements(assetEntry, "Manufacturer", item.Manufacturer); foreach (ImportItem importItem in ImportItems) { AddItem(importItem, item, assetEntry, purchaseOrder); } //End - AssetEntry assetGroup.AppendChild(assetEntry); destinyAssetImport.AppendChild(assetGroup); try { string path = Directory.GetParent(filePathToImport) + @"\DestinyConversion.xml"; if (File.Exists(path)) { File.Delete(path); } doc.Save(path); } catch (Exception) { return(false); } return(true); }
private void AddItem(ImportItem theItem, DestinyItem destinyItem, XmlElement root, string order) { bool additionalComment = Constants.HasAdditionalNote; bool hasMacComment = Constants.HasMacComment; string date = today.Year + "-" + today.Month + "-" + today.Day; XmlElement item = doc.CreateElement("item"); XmlElement barcode = doc.CreateElement("Barcode"); XmlElement shortName = doc.CreateElement("SiteShortName"); XmlElement status = doc.CreateElement("Status"); XmlElement condition = doc.CreateElement("Condition"); XmlElement districtID = doc.CreateElement("DistrictIdentifier"); XmlElement price = doc.CreateElement("PurchasePrice"); XmlElement acquired = doc.CreateElement("DateAcquired"); XmlElement purchaseOrder = doc.CreateElement("PurchaseOrder"); XmlElement lifespan = doc.CreateElement("ProjectedLife"); XmlElement salvageValue = doc.CreateElement("SalvageValue"); XmlElement serialNumber = doc.CreateElement("SerialNumber"); XmlElement lastMaint = doc.CreateElement("LastPreventitiveMaintenanceDate"); XmlElement home = doc.CreateElement("HomeLocation"); XmlElement note = doc.CreateElement("ItemNote"); Console.WriteLine(Constants.HasBarcode); if (Constants.HasBarcode) { appendCData(barcode, theItem.Barcode); } else { appendCData(barcode, theItem.SerialNumber); } appendCData(shortName, "wlkjr"); appendCData(status, Constants.CurrentStatus); appendCData(condition, Constants.Condition); appendCData(districtID, theItem.DistrictId); appendCData(price, destinyItem.Price.ToString()); appendCData(purchaseOrder, order); appendCData(lifespan, "5"); appendCData(salvageValue, "0"); appendCData(serialNumber, theItem.SerialNumber); XmlElement name = doc.CreateElement("Name"); name.AppendChild(doc.CreateCDataSection("Student")); home.AppendChild(name); string comment = ""; if (hasMacComment) { comment += "MAC: " + theItem.DistrictId + "\n"; } if (additionalComment) { comment += Constants.AdditionalNote + "\n"; } lastMaint.AppendChild(doc.CreateCDataSection(date)); acquired.AppendChild(doc.CreateCDataSection(date)); item.AppendChild(barcode); item.AppendChild(shortName); item.AppendChild(status); item.AppendChild(condition); item.AppendChild(districtID); item.AppendChild(price); item.AppendChild(purchaseOrder); item.AppendChild(lifespan); item.AppendChild(salvageValue); item.AppendChild(serialNumber); item.AppendChild(lastMaint); item.AppendChild(home); if (hasMacComment || additionalComment) { appendCData(note, comment); item.AppendChild(note); } CreateFieldElements(item, "Item Description/Number", destinyItem.Description); root.AppendChild(item); }