private void tbPaved_LostFocus(object sender, RoutedEventArgs e) { if (sender == tbPavedColumns) { if (int.TryParse(tbPavedColumns.Text, out int columns)) { if (mw.pavedConfigModel.Columns == columns) { return; } mw.pavedConfigModel.Columns = columns; XmlSerializerBusiness.Save(mw.pavedConfigModel, "Config/paved.xml"); } } else { tbPavedColumns.Select(0, tbPavedColumns.Text.Length); } if (sender == tbPavedMax) { if (int.TryParse(tbPavedMax.Text, out int max)) { if (mw.pavedConfigModel.Columns == max) { return; } mw.pavedConfigModel.Max = max; XmlSerializerBusiness.Save(mw.pavedConfigModel, "Config/paved.xml"); } } else { tbPavedMax.Select(0, tbPavedMax.Text.Length); } }
public static void WebToModel <T>(String url, ref T obj) where T : class { StringBuilder sb = new StringBuilder(); WebClient wclient = new WebClient(); //实例化WebClient类对象 wclient.BaseAddress = url; //设置WebClient的基URI wclient.Encoding = Encoding.UTF8; //指定下载字符串的编码方式 //为WebClient类对象添加标头 wclient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); //不加会导致请求被中止: 未能创建 SSL/TLS 安全通道 ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; //使用OpenRead方法获取指定网站的数据,并保存到Stream流中 Stream stream = wclient.OpenRead(url); //使用流Stream声明一个流读取变量sreader StreamReader sreader = new StreamReader(stream); string str = string.Empty;//声明一个变量,用来保存一行从WebCliecnt下载的数据 while ((str = sreader.ReadLine()) != null) { sb.Append(str + Environment.NewLine); } using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(sb.ToString()))) { XmlSerializerBusiness.Load(ref obj, ms); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (type == 1) { Title = "修改设备"; XmlSerializerBusiness.Load(ref virtualDevice, AppDomain.CurrentDomain.BaseDirectory + @"Device\" + xmlName + ".xml"); tbDeviceName.Text = xmlName; if (virtualDevice.MyDeviceType == VirtualDeviceModel.DeviceType.LaunchpadPro) { cbDeviceType.SelectedIndex = 0; } String strBg = virtualDevice.DeviceBackGround; tbBackGround.Text = strBg; if (strBg[0] == '#' || strBg.Length == 7) { Color c = Color.FromArgb(255, (byte)Convert.ToInt32(strBg.Substring(1, 2), 16), (byte)Convert.ToInt32(strBg.Substring(3, 2), 16), (byte)Convert.ToInt32(strBg.Substring(5, 2), 16)); tbBackGround.Background = new SolidColorBrush(Color.FromArgb(255, c.R, c.G, c.B)); } try { if (virtualDevice.IsMembrane.Equals("true")) { cbMembrane.IsChecked = true; } } catch { } } }
private void cbShowNumber_Checked(object sender, RoutedEventArgs e) { if (iuc != null) { lbMain.Items.Clear(); foreach (var item in iuc.rangeDictionary) { StringBuilder builder = new StringBuilder(); builder.Append(item.Key + ":"); foreach (int i in item.Value) { builder.Append(i + " "); } lbMain.Items.Add(builder.ToString()); } if (iuc.mw.hideConfigModel.RangeListNumber) { return; } iuc.mw.hideConfigModel.RangeListNumber = true; XmlSerializerBusiness.Save(iuc.mw.hideConfigModel, "Config/hide.xml"); } }
/// <summary> /// 初始化关于窗口(第一次登陆会弹出关于窗口) /// </summary> private void InitIsFirst() { XmlSerializerBusiness.Load(ref view.isFirstConfigModel, "Config/isfirst.xml"); if (view.isFirstConfigModel.Value) { //view.ShowAbout(); view.isFirstConfigModel.Value = false; XmlSerializerBusiness.Save(view.isFirstConfigModel, "Config/isfirst.xml"); } }
private void TbRemove_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { int position = spDevices.Children.IndexOf(((sender as TextBlock).Parent as Panel)); if (position != -1) { mw.deviceConfigModel.Devices.RemoveAt(position - 1); XmlSerializerBusiness.Save(mw.deviceConfigModel, "Config/device.xml"); spDevices.Children.RemoveAt(position); } }
/// <summary> /// 初始化插件 /// </summary> private void InitPlugs() { if (!File.Exists("Config/plugs.xml")) { view.plugsConfigModel = new PlugsConfigModel(); } else { XmlSerializerBusiness.Load(ref view.plugsConfigModel, "Config/plugs.xml"); } }
private void SetEnable(bool isEnable) { if (lbMain.SelectedIndex == -1) { return; } mw.plugsConfigModel.Plugs[lbMain.SelectedIndex].Enable = isEnable; XmlSerializerBusiness.Save(mw.plugsConfigModel, "Config/plugs.xml"); Change(); Restart(); }
private void btnOk_Click(object sender, RoutedEventArgs e) { string deviceName = String.Empty; if (type == 0) { deviceName = tbDeviceName.Text.Trim(); if (deviceName.Equals(string.Empty)) { tbDeviceName.Focus(); return; } if (tbDeviceSize.Text.Trim().Equals(string.Empty)) { tbDeviceSize.Focus(); return; } if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Device\" + deviceName)) { System.Windows.Forms.MessageBox.Show("文件已存在!"); tbDeviceName.Select(0, tbDeviceName.Text.Length); tbDeviceName.Focus(); return; } else { //FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"Device\" + deviceName + ".xml", FileMode.CreateNew); //fs.Close(); } } else { deviceName = xmlName; } virtualDevice.MyDeviceType = (DeviceType)cbDeviceType.SelectedIndex; virtualDevice.DeviceBackGround = tbBackGround.Text; if (cbMembrane.IsChecked == true) { virtualDevice.IsMembrane = true; } else { virtualDevice.IsMembrane = false; } XmlSerializerBusiness.Load(ref virtualDevice, AppDomain.CurrentDomain.BaseDirectory + @"Device\" + deviceName + ".xml"); DialogResult = true; }
private void cbShowNumber_Unchecked(object sender, RoutedEventArgs e) { if (iuc != null) { lbMain.Items.Clear(); foreach (var item in iuc.rangeDictionary) { lbMain.Items.Add(item.Key); } if (!iuc.mw.hideConfigModel.RangeListNumber) { return; } iuc.mw.hideConfigModel.RangeListNumber = false; XmlSerializerBusiness.Save(iuc.mw.hideConfigModel, "Config/hide.xml"); } }
private void B_Install_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var plug = new Business.Model.Config.PlugsConfigModel.Plug { Path = installPath, Enable = true }; mw.plugsConfigModel.Plugs.Add(plug); XmlSerializerBusiness.Save(mw.plugsConfigModel, "Config/plugs.xml"); mw.Plugs.Add(mw.FilePathToPlug(installPath)); DataContext = new People(mw.Plugs); lbMain.SelectedIndex = lbMain.Items.Count - 1; bInstall.Visibility = Visibility.Collapsed; Restart(); }
private void btnLocationHelpExeFilePath_Click(object sender, RoutedEventArgs e) { String ExeFilePath = mw.helpConfigModel.ExeFilePath; String fName; System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); if (File.Exists(ExeFilePath)) { openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(ExeFilePath); //注意这里写路径时要用c:\\而不是c:\ } openFileDialog.Filter = "可执行文件|*.exe"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fName = openFileDialog.FileName; mw.helpConfigModel.ExeFilePath = fName; //tbColortabPath.Text = fName; XmlSerializerBusiness.Save(mw.helpConfigModel, "Config/help.xml"); } }
private void B_UnInstall_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //目前为 直接删除xml文件中的内容 //之后改为弹窗可以勾选是否删除本地文件 //new ConfirmWindowDialog(this).Show(); if (lbMain.SelectedIndex == -1) { return; } mw.plugsConfigModel.Plugs.RemoveAt(lbMain.SelectedIndex); XmlSerializerBusiness.Save(mw.plugsConfigModel, "Config/plugs.xml"); mw.Plugs.RemoveAt(lbMain.SelectedIndex); //lbMain.SelectedIndex = -1; //Change(); DataContext = new People(mw.Plugs); Change(); Restart(); }
private void sOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (mw == null) { return; } int nowOpacity = Convert.ToInt32(sOpacity.Value); if (mw.testConfigModel.Opacity == nowOpacity) { return; } mw.testConfigModel.Opacity = nowOpacity; mw.Opacity = nowOpacity / 100.0; XmlSerializerBusiness.Save(mw.testConfigModel, "Config/test.xml"); //XmlDocument doc = new XmlDocument(); //doc.Load(AppDomain.CurrentDomain.BaseDirectory + "/Config/test.xml"); //XmlNode testRoot = doc.DocumentElement; //XmlNode testOpacity = testRoot.SelectSingleNode("Opacity"); //testOpacity.InnerText = nowOpacity.ToString(); //doc.Save(AppDomain.CurrentDomain.BaseDirectory + "/Config/test.xml"); }
/// <summary> /// 初始化平铺属性 /// </summary> private void InitPaved() { XmlSerializerBusiness.Load(ref view.pavedConfigModel, "Config/paved.xml"); }
/// <summary> /// 初始化隐藏 /// </summary> private void InitHide() { XmlSerializerBusiness.Load(ref view.hideConfigModel, "Config/hide.xml"); }
private void AddEquipment(object sender, RoutedEventArgs e) { mw.deviceConfigModel.Devices.Add(new Business.Model.Config.DeviceConfigModel.Device(cbRealDeviceIn.SelectedItem.ToString(), cbRealDevice.SelectedItem.ToString(), cbPassageway.SelectedIndex)); ShowAddDevice(); XmlSerializerBusiness.Save(mw.deviceConfigModel, "Config/device.xml"); }
/// <summary> /// 保存文件设置 /// </summary> public void SaveFile() { XmlSerializerBusiness.Save(view.projectConfigModel, "Config/project.xml"); XmlSerializerBusiness.Save(view.hintWindowConfigModel, "Config/hintwindow.xml"); }
/// <summary> /// 初始化项目 /// </summary> private void InitProject() { XmlSerializerBusiness.Load(ref view.projectConfigModel, "Config/project.xml"); }
/// <summary> /// 获取语言 /// </summary> private void GetLanguage() { XmlSerializerBusiness.Load(ref view.languageConfigModel, "Config/language.xml"); view.strMyLanguage = view.languageConfigModel.MyLanguage; }
/// <summary> /// 初始化测试 /// </summary> private void InitTest() { XmlSerializerBusiness.Load(ref view.testConfigModel, "Config/test.xml"); view.Opacity = view.testConfigModel.Opacity / 100.0; }
/// <summary> /// 初始化基础设置 /// </summary> private void InitBasic() { XmlSerializerBusiness.Load(ref view.basicConfigModel, "Config/basic.xml"); }
/// <summary> /// 初始化提示窗口 /// </summary> private void InitHintWindow() { XmlSerializerBusiness.Load(ref view.hintWindowConfigModel, "Config/hintwindow.xml"); }
/// <summary> /// 初始化设备 /// </summary> private void InitDevice() { XmlSerializerBusiness.Load(ref view.deviceConfigModel, "Config/device.xml"); }