liteon/FeiYu/SoftSelect.xaml.cs
2025-07-12 14:05:35 +08:00

254 lines
7.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Model;
using System.Collections.ObjectModel;
using DAL;
using Community;
using System.Configuration;
using System.IO;
namespace FeiYu
{
/// <summary>
/// SoftSelect.xaml 的交互逻辑
/// </summary>
public partial class SoftSelect : Window
{
SoftSelectClass ssc;
public SoftSelect()
{
InitializeComponent();
ssc = new SoftSelectClass();
this.DataContext = ssc;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Storyboard sbd = Resources["leafLeave"] as Storyboard;
sbd.Begin();
Storyboard baiyun = Resources["cloudMove"] as Storyboard;
baiyun.Begin();
}
/// <summary>
/// 拖动窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
/// <summary>
/// 获得鼠标焦点时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Image_MouseEnter(object sender, MouseEventArgs e)
{
Image ig = sender as Image;
if (ig.Tag.ToString() == "close")
{
Uri ur = new Uri(@"Resources\LoginTip\close1.png", UriKind.Relative);
BitmapImage bp = new BitmapImage(ur);
ig.Source = bp;
}
else
{
Uri ur = new Uri(@"Resources\LoginTip\mini1.png", UriKind.Relative);
BitmapImage bp = new BitmapImage(ur);
ig.Source = bp;
}
}
/// <summary>
/// 鼠标焦点离开时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Image_MouseLeave(object sender, MouseEventArgs e)
{
Image ig = sender as Image;
if (ig.Tag.ToString() == "close")
{
Uri ur = new Uri(@"Resources\LoginTip\close0.png", UriKind.Relative);
BitmapImage bp = new BitmapImage(ur);
ig.Source = bp;
}
else
{
Uri ur = new Uri(@"Resources\LoginTip\mini0.png", UriKind.Relative);
BitmapImage bp = new BitmapImage(ur);
ig.Source = bp;
}
}
/// <summary>
/// 最小化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Image ig = sender as Image;
if (ig.Tag.ToString() == "close")
{
this.Close();
}
else this.WindowState = System.Windows.WindowState.Minimized;
}
/// <summary>
/// 主窗体对象
/// </summary>
public MainWindow MWVM { get; set; }
private void butLogin_Click(object sender, RoutedEventArgs e)
{
//if (ssc.SystemSelectItems != null)
//{
// MWVM = new MainWindow(ssc.SystemSelectItems.ShortCode);
// this.Close();
// ssc.UpdataFile(ssc.SystemSelectItems.ShortCode);
// MWVM.ShowDialog();
//}
//else
//{
// MessageBox.Show("请选择要登入的机台对应软件");
//}
}
private void btnKeep_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
#region 软件系统选择逻辑类
/// <summary>
/// 软件系统选择逻辑类
/// </summary>
public class SoftSelectClass : NotificationObject
{
private List<CommonClass> systemList;
/// <summary>
/// 所有系统软件集合
/// </summary>
public List<CommonClass> SystemList
{
get { return systemList; }
set
{
systemList = value;
this.RaisePropertyChanged("SystemList");
}
}
private CommonClass systemSelectItems;
/// <summary>
/// 选中的软件对象
/// </summary>
public CommonClass SystemSelectItems
{
get { return systemSelectItems; }
set
{
systemSelectItems = value;
this.RaisePropertyChanged("SystemSelectItems");
}
}
public SoftSelectClass()
{
SystemList = new List<CommonClass>() { new CommonClass() { ID=1, CommonName="点胶机", ShortCode="djj"},
new CommonClass() { ID=2, CommonName="螺丝机",ShortCode="lsj"}};
string str = ReadFile();
if (!string.IsNullOrEmpty(str))
{
SystemSelectItems = SystemList.Where(a => a.ShortCode == str).First();
}
else
{
SystemSelectItems = SystemList[0];
}
}
/// <summary>
/// 读取默认软件
/// </summary>
/// <returns></returns>
private string ReadFile()
{
string str = "";
//指定路径地址
string textFile = @"Config.txt";
//如果指定路径的文件存在 就打开并显示
if (File.Exists(textFile))
{
using (StreamReader sr = new StreamReader(textFile, Encoding.Default))
{
while (sr.Peek() > 0)
{
str = str + sr.ReadLine();
}
}
}
return str;
}
/// <summary>
/// 保存默认软件
/// </summary>
/// <param name="str"></param>
public void UpdataFile(string str)
{
//指定路径地址
string textFile = @"Config.txt";
//打开或创建文件并覆盖
FileStream FS = File.Open(textFile, FileMode.Create);
//获得字节数组
byte[] data = System.Text.Encoding.Default.GetBytes(str);
//写入通讯信息
FS.Write(data, 0, data.Length);
//清空缓冲区、关闭流
FS.Flush();
FS.Close();
}
}
#endregion
}
}