using System; using System.Drawing; using System.IO; using System.Xml; namespace TProduct.UserSetting { public partial class SettingHelper { private const string XmlFileName = "Settings.xml"; private const string Version = "V1"; public static void Initial() { Setting.GetInstance(); string filePath = System.IO.Path.Combine(TProduct.DataFolderParas.FullPath, XmlFileName); if (!File.Exists(filePath)) { CreatXmlFile(filePath); //保存默认配置 SaveV1(Version); return; } Read(); } //读取用户配置 public static void Read() { string filePath = System.IO.Path.Combine( TProduct.DataFolderParas.FullPath, XmlFileName); if (!File.Exists(filePath)) { return; } System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(filePath); System.Xml.XmlElement rootNode = xmlDoc.DocumentElement;//根节点 if (rootNode == null) return; var nodeVersionInfo = rootNode.SelectSingleNode("VersionInfo"); if (nodeVersionInfo == null) return; if (nodeVersionInfo.InnerText == Version) { Read_V1(rootNode); } } //保存用户配置 public static bool Save() { string filePath = System.IO.Path.Combine(TProduct.DataFolderParas.FullPath, XmlFileName); if (!File.Exists(filePath)) { return false; } if (!SaveV1(Version)) return false; return true; } public static bool SaveLoginUser(Model.LoginUser user) { if (user == null) return false; TProduct.UserSetting.Setting.LastLoginUser.UserName = user.LoginName; TProduct.UserSetting.Setting.LastLoginUser.Pwd = user.LoginPwd; string filePath = System.IO.Path.Combine(TProduct.DataFolderParas.FullPath, XmlFileName); if (!File.Exists(filePath)) { return false; } System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(filePath); System.Xml.XmlElement rootNode = xmlDoc.DocumentElement;//根节点 if (rootNode == null) return false; #region LoginUser XmlNode nodeLoginUser = rootNode.SelectSingleNode("LoginUser"); if (nodeLoginUser == null) { nodeLoginUser = xmlDoc.CreateElement("LoginUser"); rootNode.AppendChild(nodeLoginUser); } var nodeUserName = nodeLoginUser.SelectSingleNode("UserName"); if (nodeUserName == null) { XmlNode addNodeUserName = xmlDoc.CreateElement("UserName"); addNodeUserName.InnerText = user.LoginName; nodeLoginUser.AppendChild(addNodeUserName); } else { nodeUserName.InnerText = user.LoginName; } var nodePwd = nodeLoginUser.SelectSingleNode("Pwd"); if (nodePwd == null) { XmlNode addNodePwd = xmlDoc.CreateElement("Pwd"); addNodePwd.InnerText = user.LoginPwd; nodeLoginUser.AppendChild(addNodePwd); } else { nodePwd.InnerText = user.LoginPwd; } #endregion xmlDoc.Save(filePath); return true; } //创建用户配置XML public static void CreatXmlFile(string Path) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null)); XmlNode rootNode = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(rootNode); //创建VersionInfo子节点 XmlNode VersionInfoNode = xmlDoc.CreateElement("VersionInfo"); XmlAttribute VersionInfoNodeAttribute = xmlDoc.CreateAttribute("Description"); VersionInfoNodeAttribute.Value = "XML_Version"; VersionInfoNode.InnerText = "V1"; VersionInfoNode.Attributes.Append(VersionInfoNodeAttribute); rootNode.AppendChild(VersionInfoNode); xmlDoc.Save(Path); } #region Color #region Main //主体色 public static System.Drawing.Color MainFromColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.MainFromColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.MainFromColor); ; return System.Drawing.SystemColors.HotTrack; } } #endregion #region Button //确认按钮 public static System.Drawing.Color ConfirmButtonColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.ConfirmButtonColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.ConfirmButtonColor); return System.Drawing.SystemColors.HotTrack; } } //取消按钮 public static System.Drawing.Color CancelButtonColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.CancelButtonColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.CancelButtonColor); return Color.DarkOrange; } } //生成按钮 public static System.Drawing.Color StartButtonColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.StartButtonColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.StartButtonColor); return Color.LawnGreen; } } #endregion #region View public static System.Drawing.Color FocusRowColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.FocusRowColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.FocusRowColor); return System.Drawing.Color.SteelBlue; } } public static System.Drawing.Color OddRowColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.OddRowColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.OddRowColor); return Color.LightGray; } } public static System.Drawing.Color EvenRowColor { get { if (!String.IsNullOrEmpty(TProduct.UserSetting.Setting.Skin.EvenRowColor)) return System.Drawing.ColorTranslator.FromHtml(TProduct.UserSetting.Setting.Skin.EvenRowColor); return Color.White; } } #endregion #endregion } }