1 Star 1 Fork 1

卖萌小老头/网络驱动器连接管理

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
NetDriveEditWindow.xaml.cs 3.27 KB
一键复制 编辑 原始数据 按行查看 历史
卖萌小老头 提交于 2022-09-23 03:40 . 驱动器信息管理功能完成
using NetDriveManage.Core;
using NetDriveManage.Entity;
using NetDriveManage.Message;
using System.Collections.Generic;
using System.Windows;
using TextLocator.Util;
namespace NetDriveManage
{
/// <summary>
/// NetDriveEditWindow.xaml 的交互逻辑
/// </summary>
public partial class NetDriveEditWindow : Window
{
private NetDriveInfo _driveInfo;
public NetDriveEditWindow(NetDriveInfo driveInfo)
{
InitializeComponent();
_driveInfo = driveInfo;
if (_driveInfo == null)
{
_driveInfo = new NetDriveInfo()
{
DriveId = System.Guid.NewGuid().ToString("N")
};
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.NetDriveName.Text = _driveInfo.DriveName;
this.NetDriveTag.Text = _driveInfo.DriveTag;
this.Host.Text = _driveInfo.Host;
this.Folder.Text = _driveInfo.Folder;
this.User.Text = _driveInfo.User;
this.Password.Text = _driveInfo.Password;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string driveName = this.NetDriveName.Text.Trim();
string driveTag = this.NetDriveTag.Text.Trim();
string host = this.Host.Text.Trim();
string folder = this.Folder.Text.Trim();
string user = this.User.Text.Trim();
string password = this.Password.Text.Trim();
if (string.IsNullOrEmpty(driveName))
{
MessageCore.ShowWarning("驱动器别称不能为空");
return;
}
if (string.IsNullOrEmpty(driveTag))
{
MessageCore.ShowWarning("驱动器盘符不能为空,且不能重复。");
return;
}
if (string.IsNullOrEmpty(host))
{
MessageCore.ShowWarning("主机Host不能为空");
return;
}
_driveInfo.DriveName = driveName;
_driveInfo.DriveTag = driveTag;
_driveInfo.Host = host;
_driveInfo.Folder = folder;
_driveInfo.User = user;
_driveInfo.Password = password;
// 保存区域信息
// AreaUtil.SaveAreaInfo(_areaInfo);
List<NetDriveInfo> driveInfos = CacheUtil.Get<List<NetDriveInfo>>(AppConst.NET_DRIVE_INFOS_KEY);
if (driveInfos.Contains(_driveInfo))
{
for (int i = 0; i < driveInfos.Count; i++)
{
NetDriveInfo driveInfo = driveInfos[i];
if (_driveInfo.DriveId == driveInfo.DriveId)
{
driveInfos[i] = _driveInfo;
}
break;
}
}
else
{
driveInfos.Add(_driveInfo);
}
CacheUtil.Put(AppConst.NET_DRIVE_INFOS_KEY, driveInfos);
this.DialogResult = true;
this.Close();
}
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/liulei901112/NetDriveManage.git
git@gitee.com:liulei901112/NetDriveManage.git
liulei901112
NetDriveManage
网络驱动器连接管理
master

搜索帮助