/*-STATIC-*/ public static string DeleteProfile(string pProfileName) { PrintSetupData vPrintSetupData = ReadFromFile(); //string vErr = vPrintSetupData.Validate(pProfileName, pPrinterSettings); //if (vErr != "") //{ // return vErr; //} vPrintSetupData.Profiles.Remove(pProfileName); WriteToFile(vPrintSetupData); return(""); }
private void FetchProfiles() { /* * GET DATA FROM FILE */ fPrintSetupData = PrintSetupData.ReadFromFile(); SortedList <string, PrintSetupProfile> vProfiles = fPrintSetupData.Profiles; /* * LOAD DATA INTO LISTBOX */ foreach (KeyValuePair <string, PrintSetupProfile> kvp in vProfiles) { PrintSetupProfile vProfile = kvp.Value; cboProfileName.Items.Add(vProfile.ProfileName); } }
/*-STATIC-*/ public static string NewProfile(string pProfileName, PrinterSettings pPrinterSettings) { PrintSetupData vPrintSetupData = ReadFromFile(); string vErr = vPrintSetupData.Validate(pProfileName, pPrinterSettings, ""); if (vErr != "") { return(vErr); } PrintSetupProfile vProfile = PrintSetupProfile.ToProfile(pProfileName, pPrinterSettings); vPrintSetupData.Profiles.Add(pProfileName, vProfile); WriteToFile(vPrintSetupData); return(""); }
/*-STATIC-*/ public static PrintSetupData ReadFromFile() { PrintSetupData vPrintSetup = new PrintSetupData(); XmlDocument doc = new XmlDocument(); doc.Load(Global.GetAbsolutePath(FileName)); XmlNodeList vProfileNodeList = doc.DocumentElement.GetElementsByTagName("Profiles"); foreach (XmlNode vProfileNode in vProfileNodeList[0].ChildNodes) { PrintSetupProfile vProfile = new PrintSetupProfile(); /// foreach (XmlNode vNode in vProfileNode.ChildNodes) { switch (vNode.Name) { case "ProfileName": vProfile.ProfileName = vNode.InnerText; break; case "PrinterName": vProfile.PrinterName = vNode.InnerText; break; case "PaperSizeName": vProfile.PaperSizeName = vNode.InnerText; break; case "PaperSizeKind": vProfile.PaperSizeKind = Convert.ToInt32(vNode.InnerText); break; case "PaperSizeRawKind": vProfile.PaperSizeRawKind = Convert.ToInt32(vNode.InnerText); break; case "PaperSizeUWidth": vProfile.PaperSizeUWidth = Convert.ToInt32(vNode.InnerText); break; case "PaperSizeUHeight": vProfile.PaperSizeUHeight = Convert.ToInt32(vNode.InnerText); break; case "PaperSourceName": vProfile.PaperSourceName = vNode.InnerText; break; case "PaperSourceKind": vProfile.PaperSourceKind = Convert.ToInt32(vNode.InnerText); break; case "PaperSourceRawKind": vProfile.PaperSourceRawKind = Convert.ToInt32(vNode.InnerText); break; case "PrinterResolutionKind": vProfile.PrinterResolutionKind = Convert.ToInt32(vNode.InnerText); break; case "PrinterResolutionX": vProfile.PrinterResolutionX = Convert.ToInt32(vNode.InnerText); break; case "PrinterResolutionY": vProfile.PrinterResolutionY = Convert.ToInt32(vNode.InnerText); break; case "Landscape": vProfile.Landscape = Convert.ToBoolean(vNode.InnerText); break; case "Color": vProfile.Color = Convert.ToBoolean(vNode.InnerText); break; case "MarginLeft": vProfile.MarginLeft = Convert.ToInt32(vNode.InnerText); break; case "MarginRight": vProfile.MarginRight = Convert.ToInt32(vNode.InnerText); break; case "MarginTop": vProfile.MarginTop = Convert.ToInt32(vNode.InnerText); break; case "MarginBottom": vProfile.MarginBottom = Convert.ToInt32(vNode.InnerText); break; } } /// vPrintSetup.Profiles.Add(vProfile.ProfileName, vProfile); } XmlNodeList vMappingNodeList = doc.DocumentElement.GetElementsByTagName("Mappings"); foreach (XmlNode vMappingNode in vMappingNodeList[0].ChildNodes) { PrintSetupMap vMap = new PrintSetupMap(); /// foreach (XmlNode vNode in vMappingNode.ChildNodes) { switch (vNode.Name) { case "PrintModuleName": vMap.PrintModuleName = vNode.InnerText; break; case "ProfileName": vMap.ProfileName = vNode.InnerText; break; } } /// vPrintSetup.Mappings.Add(vMap.PrintModuleName, vMap); } return(vPrintSetup); }
/*-STATIC-*/ public static void WriteToFile(PrintSetupData vPrintSetupData) { XmlWriterSettings xset = new XmlWriterSettings(); xset.Indent = true; xset.IndentChars = " "; XmlWriter wr = XmlWriter.Create(Global.GetAbsolutePath(FileName), xset); wr.WriteStartDocument(); wr.WriteStartElement("PrinterSettings"); wr.WriteStartElement("Profiles"); foreach (KeyValuePair <string, PrintSetupProfile> kvp in vPrintSetupData.Profiles) { PrintSetupProfile vProfile = kvp.Value; wr.WriteStartElement("Profile"); wr.WriteStartElement("ProfileName"); wr.WriteValue(vProfile.ProfileName); wr.WriteEndElement(); wr.WriteStartElement("PrinterName"); wr.WriteValue(vProfile.PrinterName); wr.WriteEndElement(); wr.WriteStartElement("PaperSizeName"); wr.WriteValue(vProfile.PaperSizeName); wr.WriteEndElement(); wr.WriteStartElement("PaperSizeKind"); wr.WriteValue(vProfile.PaperSizeKind); wr.WriteEndElement(); wr.WriteStartElement("PaperSizeRawKind"); wr.WriteValue(vProfile.PaperSizeRawKind); wr.WriteEndElement(); wr.WriteStartElement("PaperSizeUWidth"); wr.WriteValue(vProfile.PaperSizeUWidth); wr.WriteEndElement(); wr.WriteStartElement("PaperSizeUHeight"); wr.WriteValue(vProfile.PaperSizeUHeight); wr.WriteEndElement(); wr.WriteStartElement("PaperSourceName"); wr.WriteValue(vProfile.PaperSourceName); wr.WriteEndElement(); wr.WriteStartElement("PaperSourceKind"); wr.WriteValue(vProfile.PaperSourceKind); wr.WriteEndElement(); wr.WriteStartElement("PaperSourceRawKind"); wr.WriteValue(vProfile.PaperSourceRawKind); wr.WriteEndElement(); wr.WriteStartElement("PrinterResolutionKind"); wr.WriteValue(vProfile.PrinterResolutionKind); wr.WriteEndElement(); wr.WriteStartElement("PrinterResolutionX"); wr.WriteValue(vProfile.PrinterResolutionX); wr.WriteEndElement(); wr.WriteStartElement("PrinterResolutionY"); wr.WriteValue(vProfile.PrinterResolutionY); wr.WriteEndElement(); wr.WriteStartElement("Landscape"); wr.WriteValue(vProfile.Landscape); wr.WriteEndElement(); wr.WriteStartElement("Color"); wr.WriteValue(vProfile.Color); wr.WriteEndElement(); wr.WriteStartElement("MarginLeft"); wr.WriteValue(vProfile.MarginLeft); wr.WriteEndElement(); wr.WriteStartElement("MarginRight"); wr.WriteValue(vProfile.MarginRight); wr.WriteEndElement(); wr.WriteStartElement("MarginTop"); wr.WriteValue(vProfile.MarginTop); wr.WriteEndElement(); wr.WriteStartElement("MarginBottom"); wr.WriteValue(vProfile.MarginBottom); wr.WriteEndElement(); wr.WriteEndElement(); //Profile } wr.WriteEndElement(); //Profiles wr.WriteStartElement("Mappings"); foreach (KeyValuePair <string, PrintSetupMap> kvp in vPrintSetupData.Mappings) { PrintSetupMap vMap = kvp.Value; wr.WriteStartElement("Mapping"); wr.WriteStartElement("PrintModuleName"); wr.WriteValue(vMap.PrintModuleName); wr.WriteEndElement(); wr.WriteStartElement("ProfileName"); wr.WriteValue(vMap.ProfileName); wr.WriteEndElement(); wr.WriteEndElement(); //Mapping } wr.WriteEndElement(); //Mappings wr.WriteEndElement(); //Root wr.WriteEndDocument(); wr.Flush(); wr.Close(); }