public static string Convert(ClientConfigV2 config) { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.AppendChild(dec); XmlElement root = doc.CreateElement("RootNote"); XmlElement secNode1 = doc.CreateElement("ClientNo"); secNode1.InnerText = config.ClientNo; root.AppendChild(secNode1); XmlElement secNode2 = doc.CreateElement("ChooseSeatMothed"); secNode2.InnerText = ((int)config.SelectMethod).ToString(); root.AppendChild(secNode2); XmlElement secNode3 = doc.CreateElement("Nokeyboard"); secNode3.InnerText = ConfigConvert.ConvertToString(config.UsingEnterNoForSeat); root.AppendChild(secNode3); XmlElement secNode4 = doc.CreateElement("OftenSeat"); secNode4.InnerText = ConfigConvert.ConvertToString(config.UsingOftenUsedSeat.Used); secNode4.SetAttribute("LengthTime", config.UsingOftenUsedSeat.LengthDays.ToString()); secNode4.SetAttribute("SeatCount", config.UsingOftenUsedSeat.SeatCount.ToString()); root.AppendChild(secNode4); XmlElement secNode5 = doc.CreateElement("isPrint"); secNode5.InnerText = ((int)config.UsingPrintSlip).ToString(); root.AppendChild(secNode5); XmlElement nodeShowClosedRoom = doc.CreateElement("IsShowClosedRoom"); nodeShowClosedRoom.InnerText = ConfigConvert.ConvertToString(config.IsShowClosedRoom); root.AppendChild(nodeShowClosedRoom); XmlElement secNode6 = doc.CreateElement("Activation"); secNode6.InnerText = ConfigConvert.ConvertToString(config.UsingActiveBespeakSeat); root.AppendChild(secNode6); XmlElement secNode11 = doc.CreateElement("IsShowInitPOS"); secNode11.InnerText = ConfigConvert.ConvertToString(config.IsShowInitPOS); root.AppendChild(secNode11); XmlElement secNode7 = doc.CreateElement("POSRestrict"); secNode7.SetAttribute("Minutes", config.PosTimes.Minutes.ToString()); secNode7.SetAttribute("Times", config.PosTimes.Times.ToString()); secNode7.SetAttribute("IsUsed", config.PosTimes.IsUsed.ToString()); root.AppendChild(secNode7); XmlElement secNode8 = doc.CreateElement("AddReadingRoom"); foreach (string roomNo in config.Rooms) { XmlElement thirdNode = doc.CreateElement("ReadRoomID"); thirdNode.InnerText = roomNo; secNode8.AppendChild(thirdNode); } root.AppendChild(secNode8); XmlElement secNode9 = doc.CreateElement("img"); foreach (string elementName in config.BackImgage.Keys) { XmlElement thirdNode = doc.CreateElement("backgroundimg"); thirdNode.InnerText = config.BackImgage[elementName]; thirdNode.SetAttribute("id", elementName); secNode9.AppendChild(thirdNode); } root.AppendChild(secNode9); XmlElement secNode10 = doc.CreateElement("Resolution"); XmlElement thirdNode1 = doc.CreateElement("FormSet"); XmlElement fourthNode1 = doc.CreateElement("size"); fourthNode1.SetAttribute("x", config.SystemResoultion.WindowSize.Size.X.ToString()); fourthNode1.SetAttribute("y", config.SystemResoultion.WindowSize.Size.Y.ToString()); thirdNode1.AppendChild(fourthNode1); XmlElement fourthNode2 = doc.CreateElement("location"); fourthNode2.SetAttribute("x", config.SystemResoultion.WindowSize.Location.X.ToString()); fourthNode2.SetAttribute("y", config.SystemResoultion.WindowSize.Location.Y.ToString()); thirdNode1.AppendChild(fourthNode2); secNode10.AppendChild(thirdNode1); XmlElement thirdNode2 = doc.CreateElement("TooltipSet"); XmlElement fourthNode3 = doc.CreateElement("size"); fourthNode3.SetAttribute("x", config.SystemResoultion.TooltipSize.Size.X.ToString()); fourthNode3.SetAttribute("y", config.SystemResoultion.TooltipSize.Size.Y.ToString()); thirdNode2.AppendChild(fourthNode3); XmlElement fourthNode4 = doc.CreateElement("location"); fourthNode4.SetAttribute("x", config.SystemResoultion.TooltipSize.Location.X.ToString()); fourthNode4.SetAttribute("y", config.SystemResoultion.TooltipSize.Location.Y.ToString()); thirdNode2.AppendChild(fourthNode4); secNode10.AppendChild(thirdNode2); root.AppendChild(secNode10); XmlElement secNode12 = doc.CreateElement("WinCountDown"); secNode12.SetAttribute("AccessActive", config.WinCountDown.AccessActive.ToString()); secNode12.SetAttribute("LastSeatWindow", config.WinCountDown.LastSeatWindow.ToString()); secNode12.SetAttribute("LeaveWindow", config.WinCountDown.LeaveWindow.ToString()); secNode12.SetAttribute("LogSerachWindow", config.WinCountDown.LogSerachWindow.ToString()); secNode12.SetAttribute("MessageWindow", config.WinCountDown.MessageWindow.ToString()); secNode12.SetAttribute("RoomWindow", config.WinCountDown.RoomWindow.ToString()); secNode12.SetAttribute("SeatWindow", config.WinCountDown.SeatWindow.ToString()); secNode12.SetAttribute("KeyboardWindow", config.WinCountDown.KeyboardWindow.ToString()); secNode12.SetAttribute("ReaderNoticeWindow", config.WinCountDown.ReaderNoticeWindow.ToString()); secNode12.SetAttribute("UsuallySeatWindow", config.WinCountDown.UsuallySeatWindow.ToString()); root.AppendChild(secNode12); doc.AppendChild(root); return(doc.OuterXml); }
/// <summary> /// /// </summary> /// <param name="xmlClientConfig"></param> /// <returns></returns> public static ClientConfigV2 Convert(string xmlClientConfig) { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xmlClientConfig); ClientConfigV2 config = new ClientConfigV2(); XmlNode node = doc.SelectSingleNode("//RootNote/ClientNo"); if (node != null) { config.ClientNo = node.InnerText; } node = doc.SelectSingleNode("//RootNote/ChooseSeatMothed"); if (node != null) { config.SelectMethod = (SelectSeatMode)int.Parse(node.InnerText); } node = doc.SelectSingleNode("//RootNote/Nokeyboard"); if (node != null) { config.UsingEnterNoForSeat = ConfigConvert.ConvertToBool(node.InnerText); } node = doc.SelectSingleNode("//RootNote/IsShowInitPOS"); if (node != null) { config.IsShowInitPOS = ConfigConvert.ConvertToBool(node.InnerText); } node = doc.SelectSingleNode("//RootNote/IsShowClosedRoom"); if (node != null) { config._IsShowClosedRoom = ConfigConvert.ConvertToBool(node.InnerText); } node = doc.SelectSingleNode("//RootNote/OftenSeat"); if (node != null) { config.UsingOftenUsedSeat.Used = ConfigConvert.ConvertToBool(node.InnerText); config.UsingOftenUsedSeat.LengthDays = int.Parse(node.Attributes["LengthTime"].Value); config.UsingOftenUsedSeat.SeatCount = int.Parse(node.Attributes["SeatCount"].Value); } node = doc.SelectSingleNode("//RootNote/isPrint"); if (node != null) { config.UsingPrintSlip = (PrintSlipMode)int.Parse(node.InnerText); } node = doc.SelectSingleNode("//RootNote/Activation"); if (node != null) { config.UsingActiveBespeakSeat = ConfigConvert.ConvertToBool(node.InnerText); } node = doc.SelectSingleNode("//RootNote/POSRestrict"); if (node != null) { if (node.Attributes["IsUsed"] != null) { config.PosTimes.IsUsed = bool.Parse(node.Attributes["IsUsed"].Value); } config.PosTimes.Minutes = int.Parse(node.Attributes["Minutes"].Value); config.PosTimes.Times = int.Parse(node.Attributes["Times"].Value); } XmlNodeList nodes = doc.SelectNodes("//RootNote/AddReadingRoom/ReadRoomID"); foreach (XmlNode element in nodes) { config.Rooms.Add(element.InnerText); } nodes = doc.SelectNodes("//RootNote/img/backgroundimg"); foreach (XmlNode element in nodes) { config.BackImgage[element.Attributes["id"].Value] = element.InnerText; } node = doc.SelectSingleNode("//RootNote/Resolution/FormSet/size"); config.SystemResoultion.WindowSize.Size.X = int.Parse(node.Attributes["x"].Value); config.SystemResoultion.WindowSize.Size.Y = int.Parse(node.Attributes["y"].Value); node = doc.SelectSingleNode("//RootNote/Resolution/FormSet/location"); config.SystemResoultion.WindowSize.Location.X = int.Parse(node.Attributes["x"].Value); config.SystemResoultion.WindowSize.Location.Y = int.Parse(node.Attributes["y"].Value); node = doc.SelectSingleNode("//RootNote/Resolution/TooltipSet/size"); config.SystemResoultion.TooltipSize.Size.X = int.Parse(node.Attributes["x"].Value); config.SystemResoultion.TooltipSize.Size.Y = int.Parse(node.Attributes["y"].Value); node = doc.SelectSingleNode("//RootNote/Resolution/TooltipSet/location"); config.SystemResoultion.TooltipSize.Location.X = int.Parse(node.Attributes["x"].Value); config.SystemResoultion.TooltipSize.Location.Y = int.Parse(node.Attributes["y"].Value); node = doc.SelectSingleNode("//RootNote/WinCountDown"); if (node != null) { config.WinCountDown.AccessActive = int.Parse(node.Attributes["AccessActive"].Value); config.WinCountDown.LastSeatWindow = int.Parse(node.Attributes["LastSeatWindow"].Value); config.WinCountDown.LeaveWindow = int.Parse(node.Attributes["LeaveWindow"].Value); config.WinCountDown.LogSerachWindow = int.Parse(node.Attributes["LogSerachWindow"].Value); config.WinCountDown.MessageWindow = int.Parse(node.Attributes["MessageWindow"].Value); if (node.Attributes["RoomWindow"] != null) { config.WinCountDown.RoomWindow = int.Parse(node.Attributes["RoomWindow"].Value); } if (node.Attributes["SeatWindow"] != null) { config.WinCountDown.SeatWindow = int.Parse(node.Attributes["SeatWindow"].Value); } if (node.Attributes["UsuallySeatWindow"] != null) { config.WinCountDown.UsuallySeatWindow = int.Parse(node.Attributes["UsuallySeatWindow"].Value); } if (node.Attributes["ReaderNoticeWindow"] != null) { config.WinCountDown.ReaderNoticeWindow = int.Parse(node.Attributes["ReaderNoticeWindow"].Value); } if (node.Attributes["KeyboardWindow"] != null) { config.WinCountDown.KeyboardWindow = int.Parse(node.Attributes["KeyboardWindow"].Value); } } return(config); } catch (Exception ex) { throw ex; } }