!提交代码

This commit is contained in:
hehaibing-1996
2024-04-15 18:43:28 +08:00
commit e89b64ea3a
232 changed files with 22292 additions and 0 deletions

View File

@ -0,0 +1,316 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using WCS.Model;
namespace .Api
{
public static class ApiHelp
{
public static HttpClient httpClient;
static ApiHelp()
{
httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(10);
httpClient.DefaultRequestHeaders.Add("UserModel-Agent", "Chrome/95.0.4638.69 Safari/537.36");
ServicePointManager.Expect100Continue = false;
}
public static async Task<ResponseBase> Get(string uri, object? query = null, object? body = null)
{
return await Send(HttpMethod.Get, uri, query, body);
}
public static async Task<ResponseBase> Get(IEnumerable<object> uri, object? query = null, object? body = null)
{
return await Send(HttpMethod.Get, uri, query, body);
}
public static async Task<T> Get<T>(string uri, object? query = null, object? body = null)
{
return await Send<T>(HttpMethod.Get, uri, query, body);
}
public static async Task<T> Get<T>(IEnumerable<object> uri, object? query = null, object? body = null)
{
return await Send<T>(HttpMethod.Get, uri, query, body);
}
public static async Task<ResponseBase> Post(string uri, object? body = null, object? query = null)
{
return await Send(HttpMethod.Post, uri, query, body);
}
public static async Task<ResponseBase> Post(IEnumerable<object> uri, object? body = null, object? query = null)
{
return await Send(HttpMethod.Post, uri, query, body);
}
public static async Task<T> Post<T>(string uri, object? body = null, object? query = null)
{
return await Send<T>(HttpMethod.Post, uri, query, body);
}
public static async Task<T> Post<T>(IEnumerable<object> uri, object? body = null, object? query = null)
{
return await Send<T>(HttpMethod.Post, uri, query, body);
}
public static async Task<ResponseBase> Send(HttpMethod method, string uri, object? query = null, object? body = null)
{
return await Send(method, new string[] { uri }, query, body);
}
public static async Task<ResponseBase> Send(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, "".AppendPathSegments(uri).SetQueryParams(query));
if (body != null)
{
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
httpRequestMessage.Content = content;
}
var re = await httpClient.SendAsync(httpRequestMessage);
if (!re.IsSuccessStatusCode)
return new ResponseBase() { Code = (int)re.StatusCode };
var con = await re.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<ResponseBase>(con) ?? new ResponseBase();
}
public static async Task<T> Send<T>(HttpMethod method, string uri, object? query = null, object? body = null)
{
return await Send<T>(method, new string[] { uri }, query, body);
}
public static async Task<T> Send<T>(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
{
try
{
var url = "".AppendPathSegments(uri).SetQueryParams(query);
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, url);
if (body != null)
{
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
httpRequestMessage.Content = content;
}
var re = await httpClient.SendAsync(httpRequestMessage);
if (!re.IsSuccessStatusCode)
return default(T);
var con = await re.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(con) ?? default(T); ;
}
catch (Exception ex)
{
return default(T);
}
}
/// <summary>
/// 追加路径片段有更高要求可以使用Flurl库
/// </summary>
/// <param name="url">地址,如 https://www.baidu.com</param>
/// <param name="segments">路径片段</param>
/// <returns>地址</returns>
public static string AppendPathSegments(this string url, IEnumerable<object> segments)
{
string urlStr = url.Trim();
foreach (var segment in segments)
{
var val = segment?.ToString()?.Trim() ?? "";
if (string.IsNullOrWhiteSpace(val))
continue;
if (urlStr.EndsWith("/"))
urlStr = urlStr.Substring(0, urlStr.Length - 1);
if (val.Length > 0)
urlStr += string.IsNullOrEmpty(urlStr) || val.StartsWith("/") ? val : $"/{val}";
}
return urlStr;
}
/// <summary>
/// 设置Query参数有更高要求可以使用Flurl库
/// </summary>
/// <param name="url">地址,如 https://www.baidu.com/s</param>
/// <param name="values">参数,支持字典和对象</param>
/// <returns>地址</returns>
public static string SetQueryParams(this string url, object? values)
{
string urlStr = url;
if (values == null)
return urlStr;
List<string> kv = new List<string>();
if (values is IEnumerable jh)
{
if (jh is IDictionary dict)
{
foreach (DictionaryEntry item in dict)
kv.Add($"{item.Key?.ToString()}={item.Value?.ToString()}");
}
}
else
{
foreach (var item in values.GetType().GetProperties())
{
if (item.CanRead)
kv.Add($"{item.Name}={item.GetValue(values)?.ToString()}");
}
}
if (kv.Any())
{
if (!urlStr.Contains("?"))
urlStr += "?";
else
{
if (!urlStr.EndsWith("&"))
urlStr += "&";
}
urlStr += string.Join("&", kv);
}
return urlStr;
}
/// <summary>
/// Post方式下载Excel文件
/// </summary>
/// <param name="localFilePath">文件保存的路径</param>
/// <param name="method"></param>
/// <param name="requestUrl"></param>
/// <param name="body"></param>
/// <returns></returns>
public static async Task PostDownloadFileAsync(string localFilePath, HttpMethod method, string requestUrl, object? body = null)
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, requestUrl);
if (body != null)
{
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
httpRequestMessage.Content = content;
}
using (var response = await httpClient.SendAsync(httpRequestMessage))
{
response.EnsureSuccessStatusCode(); // 确保请求成功
// 获取内容头中的文件名(如果需要的话)
//var contentDisposition = ContentDispositionHeaderValue.Parse(response.Content.Headers.ContentDisposition.ToString());
//string filename = contentDisposition.FileName.Trim('"'); // 去除引号
var filename = string.Empty;
// 如果提供的本地文件路径没有文件名,则使用从响应头中获取的文件名
if (Path.GetFileName(localFilePath) == string.Empty)
{
localFilePath = Path.Combine(Path.GetDirectoryName(localFilePath), filename);
}
// 写入文件
using (var fileStream = new FileStream(localFilePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true))
{
await response.Content.CopyToAsync(fileStream);
}
}
}
/// <summary>
/// Post方式导入Excel文件
/// </summary>
/// <param name="localFilePath">文件保存的路径</param>
/// <param name="method"></param>
/// <param name="requestUrl"></param>
/// <param name="body"></param>
/// <returns></returns>
public static async Task<T> PostImportFileAsync<T>(string localFilePath, HttpMethod method, string requestUrl, string userName, string deviceType)
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, requestUrl);
using (var content = new MultipartFormDataContent())
{
var fileContent = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
content.Add(fileContent, "excelFile", Path.GetFileName(localFilePath));
var userNameContent = new StringContent(userName);
userNameContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
content.Add(userNameContent, "userName");
var deviceTypeContent = new StringContent(deviceType);
deviceTypeContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("multipart/form-data");
content.Add(deviceTypeContent, "deviceType");
httpRequestMessage.Content = content;
using (var response = await httpClient.SendAsync(httpRequestMessage))
{
response.EnsureSuccessStatusCode(); // 确保请求成功
var filename = string.Empty;
if (!response.IsSuccessStatusCode)
return default(T);
var con = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(con) ?? default(T); ;
}
}
}
public static T GetDataFromHttp<T>(string url, object dataObj, string httpMethod, bool isSaveLog = false)
{
Guid guid = Guid.NewGuid();
var data = JsonConvert.SerializeObject(dataObj);
try
{
if (isSaveLog)
Logs.Write($"【{guid}】开始请求调用接口 url{url} 请求方式:{httpMethod} 数据:{data}");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = httpMethod;
request.ContentType = "application/json";
request.Timeout = 100000;
if (!string.IsNullOrEmpty(data))
{
string strContent = data; //参数data
using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
{
dataStream.Write(strContent);
dataStream.Close();
}
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
{
encoding = "UTF-8"; //默认编码
}
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
string retString = reader.ReadToEnd();
if (isSaveLog)
Logs.Write($"【{guid}】请求调用接口结束 返回数据为{retString}");
return JsonConvert.DeserializeObject<T>(retString);
}
catch (Exception ex)
{
Logs.Write($"【{guid}】请求调用遇到异常 异常信息为{ex.Message}");
return default(T);
}
}
}
}

View File

@ -0,0 +1,29 @@
<Application x:Class="货架标准上位机.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:货架标准上位机"
StartupUri="Views/MainWindows/MainWindow1.xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:hc="https://handyorg.github.io/handycontrol">
<Application.Resources>
<ResourceDictionary>
<!--框架-->
<ResourceDictionary.MergedDictionaries>
<!--Ping9719.WpfEx-->
<ResourceDictionary Source="pack://application:,,,/Ping9719.WpfEx;component/Themes/Theme.xaml"/>
<!--HandyControl-->
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--转换器-->
<local:AuthConverter x:Key="AuthConverter"/>
<local:AuthVisConverter x:Key="AuthVisConverter"/>
<local:AuthVisHidConverter x:Key="AuthVisHidConverter"/>
<!--字体-->
<FontFamily x:Key="IconFont">pack://application,,,/货架标准上位机;component/Fonts/#iconfont</FontFamily>
<!--字符串-->
<sys:String x:Key="AboutInfo1">卓越盟讯</sys:String>
<sys:String x:Key="AboutInfo2">智造未来</sys:String>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}

View File

@ -0,0 +1,54 @@
using HandyControl.Tools;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace
{
/// <summary>
/// 权限转换器转为bool
/// </summary>
public class AuthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (DesignerHelper.IsInDesignMode)
return true;
return AuthConverter.IsAuth(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
/// <summary>
/// 是否有权限
/// </summary>
/// <param name="value">认证项</param>
/// <returns></returns>
public static bool IsAuth(object value)
{
if (UserInfoView.viewModel.User == null || UserInfoView.viewModel.Roles == null || !UserInfoView.viewModel.Roles.Any())
return false;
if (UserInfoView.viewModel.User.IsAdmin || UserInfoView.viewModel.Roles.Any(o => o.IsAdmin))
return true;
if (value == null)
return false;
if (UserInfoView.viewModel.Roles.Any(o => o.Auths.Contains((int)value)))
return true;
else
return false;
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;
using HandyControl.Tools;
namespace
{
/// <summary>
/// 权限转换器
/// </summary>
public class AuthVisConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (DesignerHelper.IsInDesignMode)
return Visibility.Visible;
return AuthConverter.IsAuth(parameter) ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;
using HandyControl.Tools;
namespace
{
/// <summary>
/// 权限转换器
/// </summary>
public class AuthVisHidConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (DesignerHelper.IsInDesignMode)
return Visibility.Visible;
return AuthConverter.IsAuth(parameter) ? Visibility.Visible : Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,29 @@
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 默认数据库
/// </summary>
public static class DataDb
{
public static SqlSugarScope db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = LocalFile.Config.MySql,
DbType = DbType.MySqlConnector,
IsAutoCloseConnection = true
}, db =>
{
db.Aop.OnError = ex =>
{
Logs.Write($@"{nameof(DataDb)}{Environment.NewLine}SQL:{ex?.Sql}{Environment.NewLine}Parametres:{JsonConvert.SerializeObject(ex?.Parametres)}{Environment.NewLine}InnerException:{ex?.InnerException?.ToString()}{Environment.NewLine}Exception:{ex?.ToString()}{Environment.NewLine}", LogsType.DbErr);
};
});
}
}

View File

@ -0,0 +1,20 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
[SugarTable("test_table")]
public class MyTestTable
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]//主键、自增
public long Id { get; set; }
public string Info1 { get; set; }
public string Info2 { get; set; }
public string Status { get; set; }
public DateTime Time { get; set; }
}
}

View File

@ -0,0 +1,130 @@
using HandyControl.Tools.Extension;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 警告信息数据库
/// </summary>
public static class WarnInfoDb
{
/// <summary>
/// 是否启用
/// </summary>
public static bool IsEnabled = false;
public static SqlSugarScope db = new SqlSugarScope(new ConnectionConfig()
{
ConnectionString = $"Data Source={Path.Combine(LocalFile.DataDir, "WarnInfo.db3")};Version=3;journal_mode=WAL;",//并发写加入journal_mode=WAL;
DbType = DbType.Sqlite,//[Sqlite]安装[System.Data.SQLite.Core];
IsAutoCloseConnection = true
}, db =>
{
db.Aop.OnError = ex =>
{
Logs.Write($@"{nameof(WarnInfoDb)}{Environment.NewLine}SQL:{ex?.Sql}{Environment.NewLine}Parametres:{JsonConvert.SerializeObject(ex?.Parametres)}{Environment.NewLine}InnerException:{ex?.InnerException?.ToString()}{Environment.NewLine}Exception:{ex?.ToString()}{Environment.NewLine}", LogsType.DbErr);
};
});
/// <summary>
/// 初始化数据
/// </summary>
public static void Ini()
{
//不存在创建数据库,存在不会创建
db.DbMaintenance.CreateDatabase();
//创建表根据实体类
db.CodeFirst.InitTables(typeof(WarnInfoItemDb));
IsEnabled = true;
}
/// <summary>
/// 清除数据
/// </summary>
/// <param name="time">保留时间</param>
/// <returns>清理的数量</returns>
public static int Clear(TimeSpan time)
{
try
{
var dt = DateTime.Now.Date.AddDays(1) - time;
return WarnInfoDb.db.Deleteable<WarnInfoItemDb>().Where(o => o.TimeGo < dt).ExecuteCommand();
}
catch (Exception)
{
return 0;
}
}
}
/// <summary>
/// 警告信息
/// </summary>
[SugarTable("WarnInfoItem")]
[SugarIndex("index_TimeGo", nameof(WarnInfoItemDb.TimeGo), OrderByType.Desc)]
public class WarnInfoItemDb
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
public string Id { get; set; }
/// <summary>
/// 来源
/// </summary>
[SugarColumn(IsNullable = true)]
public string Source { get; set; }
/// <summary>
/// 文本信息
/// </summary>
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
public string Text { get; set; }
/// <summary>
/// 级别(提示、警告、错误、致命)
/// </summary>
[SugarColumn(IsNullable = true)]
public string Level { get; set; }
/// <summary>
/// 解决方案
/// </summary>
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
public string Solution { get; set; }
/// <summary>
/// 警告类型
/// </summary>
public string WarnType { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime TimeGo { get; set; }
/// <summary>
/// 结束时间
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? TimeTo { get; set; }
/// <summary>
/// 持续时间
/// </summary>
[SugarColumn(IsIgnore = true)]
public string DuraTime { get => TimeTo.HasValue ? $"{((int)(TimeTo.Value - TimeGo).TotalHours).ToString().PadLeft(2, '0')}:{(TimeTo.Value - TimeGo).Minutes.ToString().PadLeft(2, '0')}:{(TimeTo.Value - TimeGo).Seconds.ToString().PadLeft(2, '0')}" : ""; }
public static List<WarnInfoItemDb> GetList(IEnumerable<WarnInfoItem> warnInfos)
{
return warnInfos.Select(o => new WarnInfoItemDb()
{
Id = o.Id,
Source = o.Source,
Text = o.Text,
Level = o.Level,
Solution = o.Solution,
WarnType = o.WarnType == WarnInfoType.AlwayWarn ? "常驻错误" : "循环错误",
TimeGo = o.TimeGo,
TimeTo = o.TimeTo,
}).ToList();
}
}
}

View File

@ -0,0 +1,539 @@
/* Logo 字体 */
@font-face {
font-family: "iconfont logo";
src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834');
src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834#iefix') format('embedded-opentype'),
url('https://at.alicdn.com/t/font_985780_km7mi63cihi.woff?t=1545807318834') format('woff'),
url('https://at.alicdn.com/t/font_985780_km7mi63cihi.ttf?t=1545807318834') format('truetype'),
url('https://at.alicdn.com/t/font_985780_km7mi63cihi.svg?t=1545807318834#iconfont') format('svg');
}
.logo {
font-family: "iconfont logo";
font-size: 160px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* tabs */
.nav-tabs {
position: relative;
}
.nav-tabs .nav-more {
position: absolute;
right: 0;
bottom: 0;
height: 42px;
line-height: 42px;
color: #666;
}
#tabs {
border-bottom: 1px solid #eee;
}
#tabs li {
cursor: pointer;
width: 100px;
height: 40px;
line-height: 40px;
text-align: center;
font-size: 16px;
border-bottom: 2px solid transparent;
position: relative;
z-index: 1;
margin-bottom: -1px;
color: #666;
}
#tabs .active {
border-bottom-color: #f00;
color: #222;
}
.tab-container .content {
display: none;
}
/* 页面布局 */
.main {
padding: 30px 100px;
width: 960px;
margin: 0 auto;
}
.main .logo {
color: #333;
text-align: left;
margin-bottom: 30px;
line-height: 1;
height: 110px;
margin-top: -50px;
overflow: hidden;
*zoom: 1;
}
.main .logo a {
font-size: 160px;
color: #333;
}
.helps {
margin-top: 40px;
}
.helps pre {
padding: 20px;
margin: 10px 0;
border: solid 1px #e7e1cd;
background-color: #fffdef;
overflow: auto;
}
.icon_lists {
width: 100% !important;
overflow: hidden;
*zoom: 1;
}
.icon_lists li {
width: 100px;
margin-bottom: 10px;
margin-right: 20px;
text-align: center;
list-style: none !important;
cursor: default;
}
.icon_lists li .code-name {
line-height: 1.2;
}
.icon_lists .icon {
display: block;
height: 100px;
line-height: 100px;
font-size: 42px;
margin: 10px auto;
color: #333;
-webkit-transition: font-size 0.25s linear, width 0.25s linear;
-moz-transition: font-size 0.25s linear, width 0.25s linear;
transition: font-size 0.25s linear, width 0.25s linear;
}
.icon_lists .icon:hover {
font-size: 100px;
}
.icon_lists .svg-icon {
/* 通过设置 font-size 来改变图标大小 */
width: 1em;
/* 图标和文字相邻时,垂直对齐 */
vertical-align: -0.15em;
/* 通过设置 color 来改变 SVG 的颜色/fill */
fill: currentColor;
/* path 和 stroke 溢出 viewBox 部分在 IE 下会显示
normalize.css 中也包含这行 */
overflow: hidden;
}
.icon_lists li .name,
.icon_lists li .code-name {
color: #666;
}
/* markdown 样式 */
.markdown {
color: #666;
font-size: 14px;
line-height: 1.8;
}
.highlight {
line-height: 1.5;
}
.markdown img {
vertical-align: middle;
max-width: 100%;
}
.markdown h1 {
color: #404040;
font-weight: 500;
line-height: 40px;
margin-bottom: 24px;
}
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
color: #404040;
margin: 1.6em 0 0.6em 0;
font-weight: 500;
clear: both;
}
.markdown h1 {
font-size: 28px;
}
.markdown h2 {
font-size: 22px;
}
.markdown h3 {
font-size: 16px;
}
.markdown h4 {
font-size: 14px;
}
.markdown h5 {
font-size: 12px;
}
.markdown h6 {
font-size: 12px;
}
.markdown hr {
height: 1px;
border: 0;
background: #e9e9e9;
margin: 16px 0;
clear: both;
}
.markdown p {
margin: 1em 0;
}
.markdown>p,
.markdown>blockquote,
.markdown>.highlight,
.markdown>ol,
.markdown>ul {
width: 80%;
}
.markdown ul>li {
list-style: circle;
}
.markdown>ul li,
.markdown blockquote ul>li {
margin-left: 20px;
padding-left: 4px;
}
.markdown>ul li p,
.markdown>ol li p {
margin: 0.6em 0;
}
.markdown ol>li {
list-style: decimal;
}
.markdown>ol li,
.markdown blockquote ol>li {
margin-left: 20px;
padding-left: 4px;
}
.markdown code {
margin: 0 3px;
padding: 0 5px;
background: #eee;
border-radius: 3px;
}
.markdown strong,
.markdown b {
font-weight: 600;
}
.markdown>table {
border-collapse: collapse;
border-spacing: 0px;
empty-cells: show;
border: 1px solid #e9e9e9;
width: 95%;
margin-bottom: 24px;
}
.markdown>table th {
white-space: nowrap;
color: #333;
font-weight: 600;
}
.markdown>table th,
.markdown>table td {
border: 1px solid #e9e9e9;
padding: 8px 16px;
text-align: left;
}
.markdown>table th {
background: #F7F7F7;
}
.markdown blockquote {
font-size: 90%;
color: #999;
border-left: 4px solid #e9e9e9;
padding-left: 0.8em;
margin: 1em 0;
}
.markdown blockquote p {
margin: 0;
}
.markdown .anchor {
opacity: 0;
transition: opacity 0.3s ease;
margin-left: 8px;
}
.markdown .waiting {
color: #ccc;
}
.markdown h1:hover .anchor,
.markdown h2:hover .anchor,
.markdown h3:hover .anchor,
.markdown h4:hover .anchor,
.markdown h5:hover .anchor,
.markdown h6:hover .anchor {
opacity: 1;
display: inline-block;
}
.markdown>br,
.markdown>p>br {
clear: both;
}
.hljs {
display: block;
background: white;
padding: 0.5em;
color: #333333;
overflow-x: auto;
}
.hljs-comment,
.hljs-meta {
color: #969896;
}
.hljs-string,
.hljs-variable,
.hljs-template-variable,
.hljs-strong,
.hljs-emphasis,
.hljs-quote {
color: #df5000;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-type {
color: #a71d5d;
}
.hljs-literal,
.hljs-symbol,
.hljs-bullet,
.hljs-attribute {
color: #0086b3;
}
.hljs-section,
.hljs-name {
color: #63a35c;
}
.hljs-tag {
color: #333333;
}
.hljs-title,
.hljs-attr,
.hljs-selector-id,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo {
color: #795da3;
}
.hljs-addition {
color: #55a532;
background-color: #eaffea;
}
.hljs-deletion {
color: #bd2c00;
background-color: #ffecec;
}
.hljs-link {
text-decoration: underline;
}
/* 代码高亮 */
/* PrismJS 1.15.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/
code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"]::-moz-selection,
pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection,
code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}
pre[class*="language-"]::selection,
pre[class*="language-"] ::selection,
code[class*="language-"]::selection,
code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}
@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}
:not(pre)>code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}
/* Inline code */
:not(pre)>code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #999;
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #9a6e3a;
background: hsla(0, 0%, 100%, .5);
}
.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}
.token.function,
.token.class-name {
color: #DD4A68;
}
.token.regex,
.token.important,
.token.variable {
color: #e90;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,269 @@
@font-face {
font-family: "iconfont"; /* Project id 3809552 */
src: url('iconfont.ttf?t=1699499055878') format('truetype');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-com004:before {
content: "\e62d";
}
.icon-wangluo:before {
content: "\e630";
}
.icon-lanya:before {
content: "\e63f";
}
.icon-wifiwuxianwang:before {
content: "\e6f1";
}
.icon-zidongzhihang:before {
content: "\e6e3";
}
.icon-shoudong:before {
content: "\e729";
}
.icon-biancheng-01:before {
content: "\e678";
}
.icon-erweima:before {
content: "\e60c";
}
.icon-31saoma:before {
content: "\e60e";
}
.icon-qigang:before {
content: "\e638";
}
.icon-quanxian:before {
content: "\e612";
}
.icon-dianwei:before {
content: "\e6dd";
}
.icon-liucheng:before {
content: "\e63a";
}
.icon-liucheng1:before {
content: "\e6d3";
}
.icon-zhuliucheng:before {
content: "\e63e";
}
.icon-sifumada:before {
content: "\e607";
}
.icon-p1-3-1:before {
content: "\e60a";
}
.icon-jiumingahelp16:before {
content: "\e940";
}
.icon-tianjia:before {
content: "\e657";
}
.icon-xiugai:before {
content: "\e8cf";
}
.icon-zhongmingming:before {
content: "\e606";
}
.icon-qingchu:before {
content: "\e62c";
}
.icon-24gl-trash2:before {
content: "\eb45";
}
.icon-yunliankeji_gongyinglianfuben:before {
content: "\e618";
}
.icon-tubiaozhizuomoban-116:before {
content: "\e633";
}
.icon-baozhuang:before {
content: "\e61b";
}
.icon-45kejichuangxin-chuansongdai:before {
content: "\e639";
}
.icon-liebiao2:before {
content: "\e605";
}
.icon-yuan:before {
content: "\e62f";
}
.icon-dantupailie:before {
content: "\e604";
}
.icon-quanping_o:before {
content: "\eb99";
}
.icon-pifu1:before {
content: "\e62b";
}
.icon-yanseku:before {
content: "\ee22";
}
.icon-zhaoming2:before {
content: "\e65a";
}
.icon-shijian:before {
content: "\e64d";
}
.icon-quxiao:before {
content: "\e601";
}
.icon-qidong:before {
content: "\e67d";
}
.icon-24gl-pauseCircle:before {
content: "\ea6d";
}
.icon-zhaoming:before {
content: "\e62e";
}
.icon-huopinleixing-:before {
content: "\e632";
}
.icon-fuwei:before {
content: "\e61f";
}
.icon-buhege:before {
content: "\e602";
}
.icon-hege:before {
content: "\e603";
}
.icon-duigou:before {
content: "\e65d";
}
.icon-jiqiren:before {
content: "\e60d";
}
.icon-jiqiren_o:before {
content: "\eb62";
}
.icon-help:before {
content: "\e60b";
}
.icon-guanyu:before {
content: "\e608";
}
.icon-zhuye1:before {
content: "\e625";
}
.icon-icon_shiyongwendang:before {
content: "\eb91";
}
.icon-rizhiguanli:before {
content: "\e61d";
}
.icon-pifu:before {
content: "\e743";
}
.icon-gongzuo:before {
content: "\e609";
}
.icon-gongzuoliugongzuoliuguanli:before {
content: "\e64c";
}
.icon-chaxun1:before {
content: "\ec4c";
}
.icon-liujisuan:before {
content: "\ec56";
}
.icon-hand:before {
content: "\e91a";
}
.icon-gengduo:before {
content: "\e600";
}
.icon-shezhi:before {
content: "\e64b";
}
.icon-yonghu:before {
content: "\e649";
}
.icon-tiaoshi:before {
content: "\eb61";
}
.icon-yonghu1:before {
content: "\e616";
}
.icon-zhexiantu:before {
content: "\ec66";
}
.icon-chaxun:before {
content: "\e63b";
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,457 @@
{
"id": "3809552",
"name": "font1",
"font_family": "iconfont",
"css_prefix_text": "icon-",
"description": "",
"glyphs": [
{
"icon_id": "1286979",
"name": "COM004",
"font_class": "com004",
"unicode": "e62d",
"unicode_decimal": 58925
},
{
"icon_id": "6582325",
"name": "网络2",
"font_class": "wangluo",
"unicode": "e630",
"unicode_decimal": 58928
},
{
"icon_id": "6582355",
"name": "蓝牙",
"font_class": "lanya",
"unicode": "e63f",
"unicode_decimal": 58943
},
{
"icon_id": "20009354",
"name": "wifi无线网",
"font_class": "wifiwuxianwang",
"unicode": "e6f1",
"unicode_decimal": 59121
},
{
"icon_id": "1790443",
"name": "自动执行",
"font_class": "zidongzhihang",
"unicode": "e6e3",
"unicode_decimal": 59107
},
{
"icon_id": "8791338",
"name": "手动",
"font_class": "shoudong",
"unicode": "e729",
"unicode_decimal": 59177
},
{
"icon_id": "27100643",
"name": "126-编程",
"font_class": "biancheng-01",
"unicode": "e678",
"unicode_decimal": 59000
},
{
"icon_id": "77191",
"name": "二维码",
"font_class": "erweima",
"unicode": "e60c",
"unicode_decimal": 58892
},
{
"icon_id": "201568",
"name": "3.1-扫码",
"font_class": "31saoma",
"unicode": "e60e",
"unicode_decimal": 58894
},
{
"icon_id": "35634503",
"name": "气缸",
"font_class": "qigang",
"unicode": "e638",
"unicode_decimal": 58936
},
{
"icon_id": "736503",
"name": "权限",
"font_class": "quanxian",
"unicode": "e612",
"unicode_decimal": 58898
},
{
"icon_id": "26992661",
"name": "点位",
"font_class": "dianwei",
"unicode": "e6dd",
"unicode_decimal": 59101
},
{
"icon_id": "6193798",
"name": "流程",
"font_class": "liucheng",
"unicode": "e63a",
"unicode_decimal": 58938
},
{
"icon_id": "9874504",
"name": "KHCFDC_流程 ",
"font_class": "liucheng1",
"unicode": "e6d3",
"unicode_decimal": 59091
},
{
"icon_id": "11121496",
"name": "主流程",
"font_class": "zhuliucheng",
"unicode": "e63e",
"unicode_decimal": 58942
},
{
"icon_id": "12844268",
"name": "伺服马达",
"font_class": "sifumada",
"unicode": "e607",
"unicode_decimal": 58887
},
{
"icon_id": "22615372",
"name": "编辑流程",
"font_class": "p1-3-1",
"unicode": "e60a",
"unicode_decimal": 58890
},
{
"icon_id": "866275",
"name": "救命啊_help16",
"font_class": "jiumingahelp16",
"unicode": "e940",
"unicode_decimal": 59712
},
{
"icon_id": "145479",
"name": "添加",
"font_class": "tianjia",
"unicode": "e657",
"unicode_decimal": 58967
},
{
"icon_id": "2076418",
"name": "修改",
"font_class": "xiugai",
"unicode": "e8cf",
"unicode_decimal": 59599
},
{
"icon_id": "5923116",
"name": "重命名",
"font_class": "zhongmingming",
"unicode": "e606",
"unicode_decimal": 58886
},
{
"icon_id": "1130641",
"name": "清除",
"font_class": "qingchu",
"unicode": "e62c",
"unicode_decimal": 58924
},
{
"icon_id": "7596941",
"name": "24gl-trash2",
"font_class": "24gl-trash2",
"unicode": "eb45",
"unicode_decimal": 60229
},
{
"icon_id": "5800277",
"name": "电子制造业",
"font_class": "yunliankeji_gongyinglianfuben",
"unicode": "e618",
"unicode_decimal": 58904
},
{
"icon_id": "17619289",
"name": "生产制造",
"font_class": "tubiaozhizuomoban-116",
"unicode": "e633",
"unicode_decimal": 58931
},
{
"icon_id": "5652692",
"name": "包装",
"font_class": "baozhuang",
"unicode": "e61b",
"unicode_decimal": 58907
},
{
"icon_id": "20531556",
"name": "传送带",
"font_class": "45kejichuangxin-chuansongdai",
"unicode": "e639",
"unicode_decimal": 58937
},
{
"icon_id": "162727",
"name": "列表2",
"font_class": "liebiao2",
"unicode": "e605",
"unicode_decimal": 58885
},
{
"icon_id": "1028153",
"name": "圆",
"font_class": "yuan",
"unicode": "e62f",
"unicode_decimal": 58927
},
{
"icon_id": "1278",
"name": "单图排列",
"font_class": "dantupailie",
"unicode": "e604",
"unicode_decimal": 58884
},
{
"icon_id": "5387948",
"name": "全屏_o",
"font_class": "quanping_o",
"unicode": "eb99",
"unicode_decimal": 60313
},
{
"icon_id": "8765149",
"name": "皮肤",
"font_class": "pifu1",
"unicode": "e62b",
"unicode_decimal": 58923
},
{
"icon_id": "22385724",
"name": "颜色库",
"font_class": "yanseku",
"unicode": "ee22",
"unicode_decimal": 60962
},
{
"icon_id": "13638717",
"name": "照明",
"font_class": "zhaoming2",
"unicode": "e65a",
"unicode_decimal": 58970
},
{
"icon_id": "629339",
"name": "时间",
"font_class": "shijian",
"unicode": "e64d",
"unicode_decimal": 58957
},
{
"icon_id": "5645008",
"name": "取消",
"font_class": "quxiao",
"unicode": "e601",
"unicode_decimal": 58881
},
{
"icon_id": "7435512",
"name": "启动",
"font_class": "qidong",
"unicode": "e67d",
"unicode_decimal": 59005
},
{
"icon_id": "7594046",
"name": "24gl-pauseCircle",
"font_class": "24gl-pauseCircle",
"unicode": "ea6d",
"unicode_decimal": 60013
},
{
"icon_id": "8400546",
"name": "照明",
"font_class": "zhaoming",
"unicode": "e62e",
"unicode_decimal": 58926
},
{
"icon_id": "11673858",
"name": "货品类型-01",
"font_class": "huopinleixing-",
"unicode": "e632",
"unicode_decimal": 58930
},
{
"icon_id": "20599684",
"name": "复位",
"font_class": "fuwei",
"unicode": "e61f",
"unicode_decimal": 58911
},
{
"icon_id": "24008052",
"name": "不合格",
"font_class": "buhege",
"unicode": "e602",
"unicode_decimal": 58882
},
{
"icon_id": "24008053",
"name": "合格",
"font_class": "hege",
"unicode": "e603",
"unicode_decimal": 58883
},
{
"icon_id": "145486",
"name": "对勾",
"font_class": "duigou",
"unicode": "e65d",
"unicode_decimal": 58973
},
{
"icon_id": "2614301",
"name": "机器人",
"font_class": "jiqiren",
"unicode": "e60d",
"unicode_decimal": 58893
},
{
"icon_id": "5387814",
"name": "机器人_o",
"font_class": "jiqiren_o",
"unicode": "eb62",
"unicode_decimal": 60258
},
{
"icon_id": "376340",
"name": "帮助",
"font_class": "help",
"unicode": "e60b",
"unicode_decimal": 58891
},
{
"icon_id": "508243",
"name": "关于",
"font_class": "guanyu",
"unicode": "e608",
"unicode_decimal": 58888
},
{
"icon_id": "595407",
"name": "主页",
"font_class": "zhuye1",
"unicode": "e625",
"unicode_decimal": 58917
},
{
"icon_id": "4347599",
"name": "icon_使用文档",
"font_class": "icon_shiyongwendang",
"unicode": "eb91",
"unicode_decimal": 60305
},
{
"icon_id": "12316649",
"name": "日志管理",
"font_class": "rizhiguanli",
"unicode": "e61d",
"unicode_decimal": 58909
},
{
"icon_id": "4933365",
"name": "皮肤",
"font_class": "pifu",
"unicode": "e743",
"unicode_decimal": 59203
},
{
"icon_id": "1116004",
"name": "工作",
"font_class": "gongzuo",
"unicode": "e609",
"unicode_decimal": 58889
},
{
"icon_id": "4772822",
"name": "工作流—工作流管理",
"font_class": "gongzuoliugongzuoliuguanli",
"unicode": "e64c",
"unicode_decimal": 58956
},
{
"icon_id": "5961297",
"name": "查询",
"font_class": "chaxun1",
"unicode": "ec4c",
"unicode_decimal": 60492
},
{
"icon_id": "5961310",
"name": "流计算",
"font_class": "liujisuan",
"unicode": "ec56",
"unicode_decimal": 60502
},
{
"icon_id": "18169504",
"name": "手,手掌,巴掌",
"font_class": "hand",
"unicode": "e91a",
"unicode_decimal": 59674
},
{
"icon_id": "77822",
"name": "更多",
"font_class": "gengduo",
"unicode": "e600",
"unicode_decimal": 58880
},
{
"icon_id": "629333",
"name": "设置",
"font_class": "shezhi",
"unicode": "e64b",
"unicode_decimal": 58955
},
{
"icon_id": "1010173",
"name": "用户",
"font_class": "yonghu",
"unicode": "e649",
"unicode_decimal": 58953
},
{
"icon_id": "3868257",
"name": "调试",
"font_class": "tiaoshi",
"unicode": "eb61",
"unicode_decimal": 60257
},
{
"icon_id": "5270862",
"name": "用户群体-业务查询",
"font_class": "yonghu1",
"unicode": "e616",
"unicode_decimal": 58902
},
{
"icon_id": "5961328",
"name": "折线图",
"font_class": "zhexiantu",
"unicode": "ec66",
"unicode_decimal": 60518
},
{
"icon_id": "17228485",
"name": "查询",
"font_class": "chaxun",
"unicode": "e63b",
"unicode_decimal": 58939
}
]
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,105 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 本地文件
/// </summary>
public class LocalFile
{
/// <summary>
/// 程序运行名称(货架标准上位机.exe
/// </summary>
public static readonly string AppName = AppDomain.CurrentDomain.FriendlyName.Contains('.') ? AppDomain.CurrentDomain.FriendlyName : $"{AppDomain.CurrentDomain.FriendlyName}.exe";//多环境兼容性
/// <summary>
/// 程序运行目录
/// </summary>
public static readonly string AppDir = AppDomain.CurrentDomain.BaseDirectory;
/// <summary>
/// 数据目录
/// </summary>
public static readonly string DataDir = Path.Combine(AppDir, "data");
/// <summary>
/// 日志目录
/// </summary>
public static readonly string LogDir = Path.Combine(AppDir, "logs");
/// <summary>
/// 运行主程序
/// </summary>
public static readonly string AppPath = Path.Combine(AppDir, AppName);
/// <summary>
/// 配置文件路径
/// </summary>
public static readonly string ConfigPath = Path.Combine(DataDir, "jsconfig.json");
/// <summary>
/// 设备手动点位文档路径
/// </summary>
public static readonly string PlcDotPath = Path.Combine(DataDir, "设备手动点位.xlsx");
/// <summary>
/// 帮助文档路径
/// </summary>
public static readonly string DocPath = Path.Combine(DataDir, "操作说明书.docx");
static object lockConfig = new object();
static JsConfig config;
/// <summary>
/// 配置信息
/// </summary>
public static JsConfig Config
{
get
{
if (config != null)
return config;
else
{
try
{
UpdateConfig();
}
catch (Exception)
{
config = null;
}
}
return config ?? new JsConfig();
}
}
/// <summary>
/// 刷新配置信息。将本地的配置信息重新加载到内存中
/// </summary>
public static void UpdateConfig()
{
if (File.Exists(ConfigPath))
lock (lockConfig)
config = JsonConvert.DeserializeObject<JsConfig>(File.ReadAllText(ConfigPath, Encoding.UTF8));
else
config = null;
}
/// <summary>
/// 保存配置信息。将内存中的配置信息保存到本地
/// </summary>
public static void SaveConfig()
{
try
{
lock (lockConfig)
File.WriteAllText(ConfigPath, JsonConvert.SerializeObject(Config, Formatting.Indented), Encoding.UTF8);
}
catch (Exception ex)
{
UpdateConfig();
throw ex;
}
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 本地全局静态
/// </summary>
public static class LocalStatic
{
/// <summary>
/// 前端当前登录的用户名
/// </summary>
public static string CurrentUser { get; set; } = "未登录";
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 认证项
/// </summary>
public enum AuthEnum
{
= 1000,
= 2000,
= 3000,
= 4000,
}
public class EnumTreeAttribute : Attribute
{
public EnumTreeAttribute() { }
public EnumTreeAttribute(AuthEnum parent)
{
Parent = parent;
}
public EnumTreeAttribute(AuthEnum[] childs)
{
Childs = childs;
}
public EnumTreeAttribute(AuthEnum parent, AuthEnum[] childs)
{
Parent = parent;
Childs = childs;
}
/// <summary>
/// 父级
/// </summary>
public AuthEnum? Parent { get; set; } = null;
/// <summary>
/// 子级
/// </summary>
public AuthEnum[]? Childs { get; set; } = null;
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 增删改查CRUD枚举
/// </summary>
public enum CrudEnum
{
Create, Read, Update, Delete
}
}

View File

@ -0,0 +1,213 @@
using .ViewModel;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 设备监控
/// </summary>
public class ExcelDeviceReadModel
{
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public static List<DeviceReadModel> GetDatas(string excelPath = null, string sheetName = "设备监控")
{
if (string.IsNullOrEmpty(excelPath))
excelPath = LocalFile.PlcDotPath;
return MiniExcelLibs.MiniExcel.Query<ExcelDeviceReadModel>(excelPath, sheetName)
.Where(o => !string.IsNullOrWhiteSpace(o.))
.Select(o => new DeviceReadModel()
{
Name = o.,
ExcelTag = o,
}).ToList();
}
}
/// <summary>
/// 设备控制
/// </summary>
public class ExcelDeviceWriteModel
{
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public static List<DeviceWriteModel> GetDatas(string excelPath = null, string sheetName = "设备控制")
{
if (string.IsNullOrEmpty(excelPath))
excelPath = LocalFile.PlcDotPath;
return MiniExcelLibs.MiniExcel.Query<ExcelDeviceWriteModel>(excelPath, sheetName)
.Where(o => !string.IsNullOrWhiteSpace(o.))
.Select(o => new DeviceWriteModel()
{
Name = o.,
ExcelTag = o,
}).ToList();
}
}
/// <summary>
/// 设备气缸
/// </summary>
public class ExcelDeviceUrnModel
{
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public static List<DeviceUrnModel> GetDatas(string excelPath = null, string sheetName = "设备气缸")
{
if (string.IsNullOrEmpty(excelPath))
excelPath = LocalFile.PlcDotPath;
return MiniExcelLibs.MiniExcel.Query<ExcelDeviceUrnModel>(excelPath, sheetName)
.Where(o => !string.IsNullOrWhiteSpace(o.))
.Select(o => new DeviceUrnModel()
{
Name = o.,
ExcelTag = o,
}).ToList();
}
}
/// <summary>
/// 设备伺服
/// </summary>
public class ExcelDeviceServoModel
{
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public static List<DeviceServoModel> GetDatas(string excelPath = null, string sheetName = "设备伺服")
{
if (string.IsNullOrEmpty(excelPath))
excelPath = LocalFile.PlcDotPath;
return MiniExcelLibs.MiniExcel.Query<ExcelDeviceServoModel>(excelPath, sheetName)
.Where(o => !string.IsNullOrWhiteSpace(o.))
.Select(o => new DeviceServoModel()
{
Name = o.,
ExcelTag = o,
}).ToList();
}
}
/// <summary>
/// 设备报警
/// </summary>
public class ExcelDeviceAlarmModel
{
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public string { get; set; }
public static List<ExcelDeviceAlarmModel> GetDatas(string excelPath = null, string sheetName = "设备报警")
{
if (string.IsNullOrEmpty(excelPath))
excelPath = LocalFile.PlcDotPath;
return MiniExcelLibs.MiniExcel.Query<ExcelDeviceAlarmModel>(excelPath, sheetName).Where(o => !string.IsNullOrWhiteSpace(o.)).ToList();
}
/// <summary>
/// 是否触发警报
/// </summary>
public bool IsOnAlarm(object? val)
{
try
{
if (val == null)
return false;
string vs = val.ToString().ToLower();
if (.Trim().ToLower().Contains("bool"))
{
if (vs == .Trim().ToLower())
return true;
else
return false;
}
else if (.Trim().ToLower().Contains("int"))
{
if (string.IsNullOrWhiteSpace())
return false;
if (!.Contains(vs))
return false;
foreach (var item in .Split(';'))
{
var kv = item.Split(':');
if (kv.Length != 2)
continue;
if (kv[0] == vs)
return true;
}
}
return false;
}
catch (Exception)
{
return false;
}
}
}
public class IotDevice
{
public static Action<IotDevice> UserChange;
/// <summary>
/// 控件名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 控件类型
/// </summary>
public string Type { get; set; }
/// <summary>
/// 控件值
/// </summary>
public object Val { get; set; }
/// <summary>
/// 功能
/// </summary>
public string Funct { get; set; }
/// <summary>
/// 操作方式(点动、切换)
/// </summary>
public string Mode { get; set; }
}
}

View File

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 树节点
/// </summary>
public interface ITreeNode<T>
{
/// <summary>
/// 主键Id
/// </summary>
public object Id { get; set; }
/// <summary>
/// 父Id
/// </summary>
public object Pid { get; set; }
/// <summary>
/// 子节点
/// </summary>
public List<T> Children { get; set; }
}
/// <summary>
/// 树节点扩展
/// </summary>
public static class TreeNodeEx
{
/// <summary>
/// 转为树结构
/// </summary>
/// <param name="treeNodes">树节点</param>
/// <returns>树节点带子节点Children</returns>
public static List<T> ToTree<T>(this List<T> treeNodes) where T : ITreeNode<T>
{
if (treeNodes == null || !treeNodes.Any())
return treeNodes ?? new List<T>();
if (treeNodes.Any(o => o.Id == o.Pid))
throw new Exception("存在id和pid相同的数据无限循环引用");
var group = treeNodes.GroupBy(x => x.Pid).ToDictionary(x => x.Key, s => s.ToList());
foreach (var item in treeNodes)
{
if (group.ContainsKey(item.Id))
{
var treeNode = group[item.Id];
if (treeNode.Any(o => o.Id == item.Pid && o.Pid == item.Id))
throw new Exception("存在id和pid交叉引用(如:{Id='我是你',Pid='你是我'} 和 {Id='你是我',Pid='我是你'})");
if (item.Children == null)
item.Children = new List<T>();
item.Children.AddRange(treeNode);
}
}
//查找顶级节点
var ids = treeNodes.Select(o => o.Id).Distinct();
var pids = treeNodes.Select(o => o.Pid).Distinct();
var c = pids.Except(ids);
return group.Where(o => c.Contains(o.Key)).SelectMany(o => o.Value).ToList();
}
/// <summary>
/// 将指定的id节点转为树结构
/// </summary>
/// <param name="treeNodes">树节点</param>
/// <param name="id">id节点</param>
/// <returns>树节点带子节点Children</returns>
public static T? ToTree<T>(this List<T> treeNodes, object id) where T : ITreeNode<T>
{
if (treeNodes == null || !treeNodes.Any())
return default(T);
if (treeNodes.Any(o => o.Id == o.Pid))
throw new Exception("存在id和pid相同的数据无限循环引用");
var group = treeNodes.GroupBy(x => x.Pid).ToDictionary(x => x.Key, s => s.ToList());
foreach (var item in treeNodes)
{
if (group.ContainsKey(item.Id))
{
var treeNode = group[item.Id];
if (treeNode.Any(o => o.Id == item.Pid && o.Pid == item.Id))
throw new Exception("存在id和pid交叉引用(如:{Id='我是你',Pid='你是我'} 和 {Id='你是我',Pid='我是你'})");
if (item.Children == null)
item.Children = new List<T>();
item.Children.AddRange(treeNode);
}
}
return treeNodes.FirstOrDefault(o => o.Id == id);
}
/// <summary>
/// 转为树节点
/// </summary>
/// <param name="treeNodes">树节点</param>
/// <returns>树节点带子节点Children</returns>
public static List<T> ToTreeNode<T>(this List<T> treeNodes) where T : ITreeNode<T>
{
if (treeNodes == null || !treeNodes.Any())
return treeNodes ?? new List<T>();
List<T> trees = new List<T>();
foreach (var item in treeNodes)
{
trees.Add(item);
if (item.Children != null && item.Children.Any())
{
var aaa = ToTreeNode(item.Children);
trees.AddRange(aaa);
}
}
return trees;
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// Ip和端口
/// </summary>
public class IpPort
{
/// <summary>
/// Ip地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 端口
/// </summary>
public int Port { get; set; }
[Newtonsoft.Json.JsonIgnore]
public IPEndPoint IPEndPoint { get => new IPEndPoint(IPAddress.Parse(Address), Port); }
public override string ToString()
{
return Port <= 0 ? Address : $"{Address}:{Port}";
}
}
/// <summary>
/// Ip和端口扩展
/// </summary>
public static class IpPortEx
{
/// <summary>
/// 将字符串转为Ip和端口
/// </summary>
/// <param name="IpPortStr">Ip和端口字符串</param>
/// <returns>Ip和端口</returns>
public static IpPort ToIpPort(this string IpPortStr)
{
IpPortStr = IpPortStr?.Trim() ?? "";
if (string.IsNullOrEmpty(IpPortStr))
return new IpPort();
var aaa = IpPortStr.Split(new char[] { ':', '' }, StringSplitOptions.RemoveEmptyEntries);
if (!aaa.Any())
return new IpPort();
else if (aaa.Length == 2)
return new IpPort() { Address = aaa[0], Port = Convert.ToInt32(aaa[1]) };
else if (aaa.Length == 1)
if (aaa[0].Contains("."))
return new IpPort() { Address = aaa[0] };
else
return new IpPort() { Address = "", Port = Convert.ToInt32(aaa[0]) };
else
return new IpPort();
}
}
}

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// json配置文件
/// </summary>
public class JsConfig
{
/// <summary>
/// mysql链接字符串
/// </summary>
public string MySql { get; set; }
/// <summary>
/// 货架服务器的Ip和端口号
/// </summary>
public string ApiIpHost { get; set; }
public List<string> GroupName { get; set; }
public string DeviceType { get; set; }
/// <summary>
/// 系统配置
/// </summary>
public JsSysConfig Sys { get; set; }
/// <summary>
/// 货架类的是否软件启动后自检
/// </summary>
public bool IsBootSelfTest { get; set; }
/// <summary>
/// 扫码枪Com口列表
/// </summary>
public List<string> ScannerComList { get; set; }
/// <summary>
/// 串口扫码枪延时
/// </summary>
public int ScannerTimeOut { get; set; }
}
public class JsSysConfig
{
/// <summary>
/// 是否保存登录历史
/// </summary>
public bool IsSaveLogin { get; set; }
/// <summary>
/// 登录历史
/// </summary>
public List<string> SaveLogin { get; set; }
/// <summary>
/// 登录历史数量
/// </summary>
public int SaveLoginCount { get; set; }
/// <summary>
/// 开机启动
/// </summary>
public bool Powerboot { get; set; }
/// <summary>
/// 启动全屏
/// </summary>
public bool StartupFull { get; set; }
/// <summary>
/// 日志保存天数
/// </summary>
public int SaveLogDay { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //<2F><><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>Դ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
//(δ<><CEB4>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Դʱʹ<CAB1>ã<EFBFBD>
//<2F><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ҵ<EFBFBD>ʱʹ<CAB1><CAB9>)
ResourceDictionaryLocation.SourceAssembly //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
//(δ<><CEB4>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Դʱʹ<CAB1>ã<EFBFBD>
//<2F><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD><EFBFBD><EFBFBD>ר<EFBFBD><D7A8><EFBFBD><EFBFBD>Դ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ҵ<EFBFBD>ʱʹ<CAB1><CAB9>)
)]

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.SerialPorts;
using TouchSocket.Sockets;
using .Views.Controls;
namespace
{
public static class ScannerManager
{
public static List<Scanner> Scanners = new List<Scanner>();
public static void InitScanners()
{
//获取当前配置文件的串口号
var ScannerComList = LocalFile.Config.ScannerComList;
//通过配置的串口号生成对象
ScannerComList.ForEach(COM =>
{
try
{
var client = new SerialPortClient();
//成功连接到端口
client.Connected = (client, e) =>
{
Logs.Write($"扫码枪{client.MainSerialPort.PortName},已成功连接!", LogsType.Scanner);
//初始化扫码枪对象
var Scanner = new Scanner()
{
SerialPortClient = (SerialPortClient)client,
//ScannerDisplayControl = new ScannerDisplayControl(client.MainSerialPort.PortName),
COM = client.MainSerialPort.PortName,
TempCode = string.Empty,
};
Scanners.Add(Scanner);
return EasyTask.CompletedTask;
};
client.Received = async (c, e) =>
{
;
};
client.Setup(new TouchSocket.Core.TouchSocketConfig()
.SetSerialPortOption(new SerialPortOption()
{
BaudRate = 9600,//波特率
DataBits = 8,//数据位
Parity = System.IO.Ports.Parity.None,//校验位
PortName = COM,
StopBits = System.IO.Ports.StopBits.One//停止位
}));
client.Connect(LocalFile.Config.ScannerTimeOut, new CancellationToken());
}
catch (Exception ex)
{
Logs.Write($"初始化扫码枪异常!{ex.Message}", LogsType.Scanner);
}
});
}
}
public class Scanner()
{
public SerialPortClient SerialPortClient { get; set; }
public ScannerDisplayControl ScannerDisplayControl { get; set; }
/// <summary>
/// 是否在入库模式中
/// </summary>
public bool IsInstoreMode { get; set; }
/// <summary>
/// 串口号
/// </summary>
public string COM { get; set; }
/// <summary>
/// 暂存的码
/// </summary>
public string TempCode { get; set; } = string.Empty;
public string ShelfCode { get; set; } = string.Empty;
public string ModulesStr { get; set; } = string.Empty;
public string MatSn { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 文件夹操作
/// </summary>
public static class Folder
{
/// <summary>
/// 打开目录
/// </summary>
/// <param name="folderPath">目录路径比如C:\Users\Administrator\</param>
public static void OpenFolder(string folderPath)
{
if (string.IsNullOrEmpty(folderPath))
return;
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
psi.Arguments = folderPath;
process.StartInfo = psi;
try
{
process.Start();
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
/// <summary>
/// 打开目录且选中文件
/// </summary>
/// <param name="filePathAndName">文件的路径和名称比如C:\Users\Administrator\test.txt</param>
public static void OpenFolderAndSelectedFile(string filePathAndName)
{
if (string.IsNullOrEmpty(filePathAndName))
return;
Process process = new Process();
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe");
psi.Arguments = "/e,/select," + filePathAndName;
process.StartInfo = psi;
//process.StartInfo.UseShellExecute = true;
try
{
process.Start();
}
catch (Exception ex)
{
throw ex;
}
finally
{
process?.Close();
}
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using WCS.Model;
using WCS.Model.ApiModel.Home;
using .Api;
namespace .Tool
{
public static class GetBaseData
{
public static List<ShelfTypeModel> GetShelfType()
{
var body = new RequestBase()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<ShelfTypeModel>>(LocalFile.Config.ApiIpHost + "home/getShelfTypes", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists.Count() > 0)
{
return Result.Data.Lists;
}
else { return new List<ShelfTypeModel>(); }
}
}
}

View File

@ -0,0 +1,38 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// json时间转换器
/// </summary>
public class JsonDateTimeConverter : JsonConverter<DateTime?>
{
public override DateTime? ReadJson(JsonReader reader, Type objectType, DateTime? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var dateTimeString = reader.Value?.ToString();
if (!string.IsNullOrEmpty(dateTimeString))
{
try
{
return DateTime.ParseExact(dateTimeString, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
}
catch (FormatException)
{
throw new JsonSerializationException("Invalid date time format.");
}
}
return null;
}
public override void WriteJson(JsonWriter writer, DateTime? value, JsonSerializer serializer)
{
writer.WriteValue(value?.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
}

View File

@ -0,0 +1,164 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
using WCS.Model.ApiModel;
namespace
{
/// <summary>
/// 日志类型
/// </summary>
public enum LogsType
{
/// <summary>
/// 信息
/// </summary>
Info,
/// <summary>
/// 警告
/// </summary>
Warning,
/// <summary>
/// 错误
/// </summary>
Err,
/// <summary>
/// 数据库错误
/// </summary>
DbErr,
/// <summary>
/// 扫码枪
/// </summary>
Scanner
}
/// <summary>
/// 日志
/// </summary>
public static class Logs
{
static object obj = new object();
const string logExtension = ".log";
/// <summary>
/// 写入日志失败
/// </summary>
public static Action<IEnumerable<string>, DateTime, LogsType, Exception> WriteErr = null;
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(IEnumerable<string> content, LogsType type = LogsType.Info, DateTime? dt = null)
{
if (content == null || !content.Any())
return;
dt ??= DateTime.Now;
string hms = dt.Value.ToString("HH:mm:ss.fff");
List<string> lines = new List<string>(content.Count());
try
{
string path = Path.Combine(LocalFile.LogDir, type.ToString(), $"{(dt.Value.ToString("yyyyMMdd"))}{logExtension}");
foreach (var item in content)
lines.AddRange($"[{hms}]{item}".Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
lock (obj)
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.AppendAllLines(path, lines, Encoding.UTF8);
}
}
catch (Exception ex)
{
WriteErr?.Invoke(content, dt.Value, type, ex);
}
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容对象</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(string content, LogsType type = LogsType.Info, DateTime? dt = null)
{
Write(new string[] { content }, type, dt);
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容对象</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(object content, LogsType type = LogsType.Info, DateTime? dt = null)
{
Write(JsonConvert.SerializeObject(content), type, dt);
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容</param>
/// <param name="contentTitle">内容标题</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(object content, string contentTitle, LogsType type = LogsType.Info, DateTime? dt = null)
{
Write($"{contentTitle} {JsonConvert.SerializeObject(content)}", type, dt);
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="ex">错误</param>
/// <returns>是否写入成功</returns>
public static void Write(Exception ex, LogsType type = LogsType.Err, DateTime? dt = null)
{
Write(ex.ToString(), type, dt);
}
/// <summary>
/// 清除日志
/// </summary>
/// <param name="time">保留时间</param>
/// <returns>清理的大小(字节)</returns>
public static long Clear(TimeSpan time)
{
long size = 0;
var rs = EnumHelps.GetEnumList(typeof(LogsType));
foreach (var item in rs)
{
try
{
var path = Path.Combine(LocalFile.LogDir, item);
DirectoryInfo directoryInfo = new DirectoryInfo(path);
if (!directoryInfo.Exists)
continue;
var files = directoryInfo.GetFiles($"**{logExtension}", SearchOption.TopDirectoryOnly);
var fileDel = files.Where(o => o.CreationTime < (DateTime.Now - time));
foreach (var item2 in fileDel)
{
size += item2.Length;
item2.Delete();
}
}
catch (Exception)
{
}
}
return size;
}
}
}

View File

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace .Tool
{
public static class PrintTender
{
public static BarTender.Application Inbtapp;
static BarTender.Format InbtFormat;
//TO DO 打印机型号需要可配置
static string PKNmae = "TSC TTP-244 Pro";
static object lockll = new object();
static object lockPrint = new object();
//记录日志
public static void WriteOneLine(string msg)//写到本地记录
{
lock (lockPrint)
{
try
{
Logs.Write($"{msg}");
}
catch (Exception ex)
{
;
}
}
}
/// <summary>
/// 打印外箱条码
/// PKGip 打印机地址
/// PKNmae 打印机名字
/// </summary>
/// <param name="PKGip"></param>
/// <param name="test"></param>
public static bool PrintTag(PrintClass printtext)
{
lock (lockll)
{
try
{
if (Inbtapp == null)
{
Inbtapp = new BarTender.Application();
}
WriteOneLine($"标签开始打印");
InbtFormat = Inbtapp.Formats.Open(System.Environment.CurrentDirectory + "\\Resources\\物料条码.btw", false, "");
InbtFormat.PrintSetup.Printer = PKNmae;
InbtFormat.PrintSetup.IdenticalCopiesOfLabel = 1; //设置同序列打印的份数
InbtFormat.SetNamedSubStringValue("MatCode", printtext.MatCode);
InbtFormat.SetNamedSubStringValue("MatName", printtext.MatName);
InbtFormat.SetNamedSubStringValue("MatBatch", "批次:" + printtext.MatBatch);
InbtFormat.SetNamedSubStringValue("MatQty", "数量:" + printtext.MatQty);
InbtFormat.SetNamedSubStringValue("MatSn", printtext.MatSn);
InbtFormat.SetNamedSubStringValue("MatSpec", "规格:" + printtext.MatSpec);
InbtFormat.SetNamedSubStringValue("DateTime", DateTime.Now.ToString());
Thread.Sleep(20);
int result = InbtFormat.PrintOut(true, false); //第二个false设置打印时是否跳出打印属性
InbtFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签
DateTime datenow = DateTime.Now;
Thread.Sleep(200);
return true;
}
catch (Exception ex)
{
WriteOneLine("打标签失败" + ex.ToString());
return false;
}
}
}
}
public class PrintClass
{
public string MatQty { get; set; }
public string MatBatch { get; set; }
public string MatCode { get; set; }
public string MatName { get; set; }
public string MatSn { get; set; }
public string MatSpec { get; set; }
}
}

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace
{
/// <summary>
/// 富文本框扩展类
/// </summary>
public static class RichTextBoxTool
{
/// <summary>
/// 清空内容
/// </summary>
public static void ClearText(this RichTextBox richTextBox)
{
try
{
richTextBox.Dispatcher.Invoke((Action)delegate
{
//清空文本
richTextBox.Document.Blocks.Clear();
//滚动到开头
richTextBox.ScrollToVerticalOffset(0);
});
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 插入文本
/// </summary>
/// <param name="richTextBox"></param>
/// <param name="brush">颜色</param>
/// <param name="txt">内容</param>
private static void AppendText(this RichTextBox richTextBox, Brush brush, string txt)
{
try
{
richTextBox.Dispatcher.Invoke((Action)delegate
{
var p = new Paragraph(); //Paragraph 类似于 html 的 P 标签
var r = new Run(txt); //Run 是一个 Inline 的标签
p.Inlines.Add(r);
p.LineHeight = 8;
p.Foreground = brush;//设置字体颜色
richTextBox.Document.Blocks.Add(p);
if (richTextBox.Document.Blocks.Count > 1000)
{
richTextBox.Document.Blocks.Remove(richTextBox.Document.Blocks.FirstBlock);
}
//滚动到末尾
richTextBox.ScrollToVerticalOffset(richTextBox.Document.Blocks.Count * 200);
});
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 插入Title棕色######Title######
/// </summary>
public static void AppendTile(this RichTextBox richTextBox, string txt)
{
AppendText(richTextBox, Brushes.Brown, "#####" + txt + "#####");
}
/// <summary>
/// 插入信息(蓝色)
/// </summary>
/// <param name="addTime">是否在开头追加时间信息HH:mm:ss.fff=>txt</param>
public static void AppendInfo(this RichTextBox richTextBox, string txt, bool addTime = false)
{
if (string.IsNullOrEmpty(txt))
return;
if (addTime)
AppendText(richTextBox, Brushes.Blue, $"{DateTime.Now.ToString("HH:mm:ss.fff")}=>{txt.Replace("\r", "\\r").Replace("\n", "\\n")}");
else
AppendText(richTextBox, Brushes.Blue, txt.Replace("\r", "\\r").Replace("\n", "\\n"));
}
/// <summary>
/// 插入信息(深绿色)
/// </summary>
/// <param name="addTime">是否在开头追加时间信息HH:mm:ss.fff=>txt</param>
public static void AppendResult(this RichTextBox richTextBox, string txt, bool addTime = false)
{
if (string.IsNullOrEmpty(txt))
return;
if (addTime)
AppendText(richTextBox, Brushes.Blue, $"{DateTime.Now.ToString("HH:mm:ss.fff")}=>{txt}");
else
AppendText(richTextBox, Brushes.ForestGreen, txt);
}
/// <summary>
/// 插入错误(鲜红色)
/// </summary>
/// <param name="addTime">是否在开头追加时间信息HH:mm:ss.fff=>txt</param>
public static void AppendErr(this RichTextBox richTextBox, string txt, bool addTime = false)
{
if (string.IsNullOrEmpty(txt))
return;
if (addTime)
AppendText(richTextBox, Brushes.Blue, $"{DateTime.Now.ToString("HH:mm:ss.fff")}=>{txt}");
else
AppendText(richTextBox, Brushes.Tomato, txt);
}
}
}

View File

@ -0,0 +1,268 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 警告信息容器
/// </summary>
public class WarnInfoContainer
{
ConcurrentDictionary<WarnInfoItem, string> InfoAll = new ConcurrentDictionary<WarnInfoItem, string>();
/// <summary>
/// 有新的日志加入或移除时1当前全部2加入的3移除的
/// </summary>
public Action<IEnumerable<WarnInfoItem>, IEnumerable<WarnInfoItem>, IEnumerable<WarnInfoItem>> WarnInfoChanged;
/// <summary>
/// 添加或者更新信息
/// </summary>
public void AddOrUpdate(IEnumerable<WarnInfoItem> warnInfos)
{
if (warnInfos == null || !warnInfos.Any())
return;
List<WarnInfoItem> adds = new List<WarnInfoItem>();
List<WarnInfoItem> cles = new List<WarnInfoItem>();
var info1 = warnInfos.Where(o => o.WarnType == WarnInfoType.WhileWarn).GroupBy(o => o.Source);
var info2 = warnInfos.Where(o => o.WarnType == WarnInfoType.AlwayWarn);
DateTime dt = DateTime.Now;
foreach (var addText in info1)
{
var yuan = InfoAll.Keys.Where(o => o.WarnType == WarnInfoType.WhileWarn && o.Source == addText.Key);
var uni = yuan.Intersect(addText);
var add = addText.Except(yuan).Except(uni);
var cle = yuan.Except(addText).Except(uni);
adds.AddRange(add);
cles.AddRange(cle);
foreach (var item in cle)
{
item.TimeTo = item.TimeTo.HasValue ? item.TimeTo : dt;
if (!InfoAll.TryRemove(item, out string val))
InfoAll.TryRemove(item, out string val1);
}
foreach (var item in add)
{
item.Id = Guid.NewGuid().ToString("N");
item.TimeGo = item.TimeGo == new DateTime() ? dt : item.TimeGo;
if (!InfoAll.TryAdd(item, null))
InfoAll.TryAdd(item, null);
}
}
{
var exc = info2.Except(InfoAll.Keys);
foreach (var item in exc)
{
item.Id = Guid.NewGuid().ToString("N");
item.TimeGo = item.TimeGo == new DateTime() ? dt : item.TimeGo;
if (!InfoAll.TryAdd(item, null))
InfoAll.TryAdd(item, null);
adds.Add(item);
}
}
if (adds.Any() || cles.Any())
WarnInfoChanged?.BeginInvoke(InfoAll.Keys.ToArray(), adds, cles, null, null);
}
/// <summary>
/// 更新循环警告
/// </summary>
public void UpdateWhileWarn(IEnumerable<string> texts)
{
UpdateWhileWarn(string.Empty, texts);
}
/// <summary>
/// 更新循环警告
/// </summary>
public void UpdateWhileWarn(string source, IEnumerable<string> texts)
{
DateTime dt = DateTime.Now;
AddOrUpdate(texts.Select(o => new WarnInfoItem()
{
Source = source,
Text = o,
WarnType = WarnInfoType.WhileWarn,
TimeGo = dt,
TimeTo = null
}));
}
/// <summary>
/// 添加常驻警告
/// </summary>
public void AddAlwayWarn(string text)
{
AddAlwayWarn(string.Empty, new string[] { text });
}
/// <summary>
/// 添加常驻警告
/// </summary>
public void AddAlwayWarn(IEnumerable<string> texts)
{
AddAlwayWarn(string.Empty, texts);
}
/// <summary>
/// 添加常驻警告
/// </summary>>
public void AddAlwayWarn(string source, string text)
{
AddAlwayWarn(source, new string[] { text });
}
/// <summary>
/// 添加常驻警告
/// </summary>>
public void AddAlwayWarn(string source, IEnumerable<string> texts)
{
DateTime dt = DateTime.Now;
AddOrUpdate(texts.Select(o => new WarnInfoItem()
{
Source = source,
Text = o,
WarnType = WarnInfoType.AlwayWarn,
TimeGo = dt,
TimeTo = null
}));
}
/// <summary>
/// 移除警告信息
/// </summary>
public void RemoveAll()
{
RemoveAll(null);
}
/// <summary>
/// 移除警告信息
/// </summary>
public void RemoveAll(WarnInfoType errType)
{
RemoveAll(null, errType);
}
/// <summary>
/// 移除警告信息
/// </summary>
public void RemoveAll(string source, WarnInfoType? errType = null)
{
if (InfoAll.IsEmpty)
return;
var clear = InfoAll.Keys
.Where(o => (source == null ? true : o.Source == source) && (errType.HasValue ? o.WarnType == errType.Value : true));
if (clear == null || !clear.Any())
return;
var dt = DateTime.Now;
foreach (var item in clear)
{
item.TimeTo = item.TimeTo.HasValue ? item.TimeTo : dt;
if (!InfoAll.TryRemove(item, out string val))
InfoAll.TryRemove(item, out string val1);
}
WarnInfoChanged?.BeginInvoke(InfoAll.Keys, new List<WarnInfoItem>(), clear, null, null);
}
}
/// <summary>
/// 警告信息
/// </summary>
public class WarnInfoItem
{
/// <summary>
/// 唯一编码
/// </summary>
public string Id { get; set; }
/// <summary>
/// 来源
/// </summary>
public string Source { get; set; }
/// <summary>
/// 文本信息
/// </summary>
public string Text { get; set; }
/// <summary>
/// 级别(提示、警告、错误、致命)
/// </summary>
public string Level { get; set; }
/// <summary>
/// 解决方案
/// </summary>
public string Solution { get; set; }
/// <summary>
/// 警告类型
/// </summary>
public WarnInfoType WarnType { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime TimeGo { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime? TimeTo { get; set; }
/// <summary>
/// 自定义信息
/// </summary>
public object Tag { get; set; }
public override bool Equals(object obj)
{
if (obj is WarnInfoItem b)
return (Source == b.Source && Text == b.Text && Level == b.Level && Solution == b.Solution && WarnType == b.WarnType);
else
return false;
}
public override int GetHashCode()
{
return (Source + Text + Level + Solution + WarnType.ToString()).GetHashCode();
}
public override string ToString()
{
return $"{(string.IsNullOrEmpty(Source) ? "" : $"[{Source}]")}{(string.IsNullOrEmpty(Level) ? "" : $"[{Level}]")}{Text}{(string.IsNullOrEmpty(Solution) ? "" : $"({Solution})")}{(TimeTo.HasValue ? $"({(TimeTo.Value - TimeGo).TotalSeconds.ToString("0.00")}s)" : "")}";
}
public static bool operator ==(WarnInfoItem a, WarnInfoItem b)
{
return a.Equals(b);
}
public static bool operator !=(WarnInfoItem a, WarnInfoItem b)
{
return !a.Equals(b);
}
}
/// <summary>
/// 警告信息类型
/// </summary>
public enum WarnInfoType
{
/// <summary>
/// 常驻错误。加入一次需要手动清除
/// </summary>
AlwayWarn = 10,
/// <summary>
/// 循环错误。每次需要把全部的错误参入进来
/// </summary>
WhileWarn = 20,
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace
{
/// <summary>
/// 循环、暂停、继续、停止扩展
/// </summary>
public static class While
{
/// <summary>
/// 带条件等待并检测停止、暂停
/// </summary>
/// <param name="func">不停的执行的任务返回为true就跳出循环</param>
public static async Task Wait(Func<bool> func, CancellationToken token = default, ManualResetEvent manualReset = default)
{
while (true)
{
token.ThrowIfCancellationRequested();
manualReset?.WaitOne();
token.ThrowIfCancellationRequested();
if (func.Invoke())
break;
await Task.Delay(200, token);
}
}
/// <summary>
/// 等待并检测停止、暂停
/// </summary>
public static void Wait(CancellationToken token = default, ManualResetEvent manualReset = default)
{
token.ThrowIfCancellationRequested();
manualReset?.WaitOne();
token.ThrowIfCancellationRequested();
}
}
}

View File

@ -0,0 +1,34 @@
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace .ViewModel
{
public class AboutViewModel : BindableBase
{
public AboutViewModel()
{
var versionInfo = FileVersionInfo.GetVersionInfo(LocalFile.AppPath);
Name = versionInfo.ProductName;
Company = $"{versionInfo.CompanyName} {versionInfo.LegalCopyright}";
Ver = $"v {new string(versionInfo.FileVersion.Take(5).ToArray())}";
}
/// <summary>
/// 程序名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 公司名
/// </summary>
public string Company { get; set; }
/// <summary>
/// 版本
/// </summary>
public string Ver { get; set; }
}
}

View File

@ -0,0 +1,199 @@
using HandyControl.Controls;
using LiveCharts;
using Ping9719.WpfEx.Mvvm;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace .ViewModel
{
public class DataChartViewModel : BindableBase
{
#region
private bool isLoad;
public bool IsLoad { get => isLoad; set { SetProperty(ref isLoad, value); } }
#endregion
#region
private List<int> year = new List<int>();
/// <summary>
/// 年
/// </summary>
public List<int> Year { get => year; set { SetProperty(ref year, value); } }
private List<int> month = new List<int>();
/// <summary>
/// 月
/// </summary>
public List<int> Month { get => month; set { SetProperty(ref month, value); } }
private int yearIndex;
/// <summary>
/// 年索引
/// </summary>
public int YearIndex { get => yearIndex; set { SetProperty(ref yearIndex, value); UpdataMonth(); } }
private int monthIndex;
/// <summary>
/// 月索引
/// </summary>
public int MonthIndex { get => monthIndex; set { SetProperty(ref monthIndex, value); StatChart(); } }
#endregion
#region
public ChartValues<int> ChartValues1 { get; set; } = new ChartValues<int>();
public ChartValues<int> ChartValues2 { get; set; } = new ChartValues<int>();
public ChartValues<int> ChartValues3 { get; set; } = new ChartValues<int>();
public Func<double, string> LabelFormatterX { get; set; } = value => $"{value}号";
public Func<double, string> LabelFormatterY { get; set; } = value => $"{value}个";
private IList<string> chartLabelsX;
/// <summary>
/// X轴轴信息
/// </summary>
public IList<string> ChartLabelsX { get => chartLabelsX; set { SetProperty(ref chartLabelsX, value); } }
#endregion
#region
/// <summary>
/// 更新年
/// </summary>
public async void UpdataYear()
{
try
{
IsLoad = true;
Year = await DataDb.db.Queryable<MyTestTable>()
.GroupBy(o => o.Time.Year)
.OrderByDescending(o => o.Time.Year)
.Select(o => o.Time.Year)
.ToListAsync();
}
catch (Exception ex)
{
Year = new List<int>();
Growl.Error("刷新数据失败:" + ex.Message);
}
finally
{
YearIndex = Year.Any() ? 0 : -1;
}
}
/// <summary>
/// 更新月
/// </summary>
public async void UpdataMonth()
{
try
{
IsLoad = true;
if (!Year.Any() || YearIndex < 0)
return;
var dt1 = new DateTime(Year[YearIndex], 1, 1);
var dt2 = dt1.AddYears(1);
Month = await DataDb.db.Queryable<MyTestTable>()
.Where(o => o.Time > dt1 && o.Time < dt2)
.GroupBy(o => o.Time.Month)
.OrderBy(o => o.Time.Month)
.Select(o => o.Time.Month)
.ToListAsync();
}
catch (Exception ex)
{
Month = new List<int>();
Growl.Error("刷新数据失败:" + ex.Message);
}
finally
{
MonthIndex = Month.Any() ? Month.Count - 1 : -1;
}
}
public ICommand ButStatChartCommand { get => new DelegateCommand(ButStatChart); }
/// <summary>
/// 点击刷新
/// </summary>
public void ButStatChart()
{
if (IsLoad)
{
Growl.Info("有任务正在进行");
return;
}
if (!Year.Any() || !Month.Any() || YearIndex < 0 || MonthIndex < 0)
{
Growl.Info("没有选择年份或月份");
return;
}
StatChart();
}
/// <summary>
/// 刷新统计信息
/// </summary>
public async void StatChart()
{
try
{
if (!Year.Any() || !Month.Any() || YearIndex < 0 || MonthIndex < 0)
{
ChartValues1.Clear();
ChartValues2.Clear();
ChartValues3.Clear();
return;
}
IsLoad = true;
await Task.Delay(200);
var year = Year[YearIndex];
var month = Month[MonthIndex];
var dt1 = new DateTime(year, month, 1);
var dt2 = dt1.AddMonths(1);
//从数据库中查询、统计数量
var dbdata = await DataDb.db.Queryable<MyTestTable>()
.Where(o => o.Time > dt1 && o.Time < dt2)
.GroupBy(o => o.Time.Day)
.Select(o => new
{
day = o.Time.Day,
count = SqlFunc.AggregateCount(o.Id),
okCount = SqlFunc.AggregateCount(o.Status == "合格" ? "" : null),
notCount = SqlFunc.AggregateCount(o.Status != "合格" ? "" : null),
})
.OrderBy(o => o.day)
.ToListAsync();
ChartLabelsX = dbdata.Select(o => o.day.ToString()).ToList();
ChartValues1.Clear();
ChartValues2.Clear();
ChartValues3.Clear();
ChartValues1.AddRange(dbdata.Select(o => o.count));
ChartValues2.AddRange(dbdata.Select(o => o.okCount));
ChartValues3.AddRange(dbdata.Select(o => o.notCount));
}
catch (Exception ex)
{
Growl.Error("刷新数据失败:" + ex.Message);
}
finally
{
IsLoad = false;
}
}
#endregion
}
}

View File

@ -0,0 +1,201 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
namespace .ViewModel
{
public class DataListViewModel : BindableBase
{
private List<MyTestTable> dataList = new List<MyTestTable>();
/// <summary>
/// 列表数据
/// </summary>
public List<MyTestTable> DataList { get => dataList; set { SetProperty(ref dataList, value); } }
#region
private bool IsLoad_;
public bool IsLoad { get => IsLoad_; set { SetProperty(ref IsLoad_, value); } }
#endregion
#region
private DateTime? timeGo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
/// <summary>
/// 开始时间(默认只显示今天开始的数据)
/// </summary>
public DateTime? TimeGo { get => timeGo; set { SetProperty(ref timeGo, value); } }
private DateTime? timeTo;
/// <summary>
/// 结束时间
/// </summary>
public DateTime? TimeTo { get => timeTo; set { SetProperty(ref timeTo, value); } }
private string info1;
public string Info1 { get => info1; set { SetProperty(ref info1, value); } }
private string info2;
public string Info2 { get => info2; set { SetProperty(ref info2, value); } }
#endregion
#region
private int maxPageCount;
/// <summary>
/// 最大页数
/// </summary>
public int MaxPageCount { get => maxPageCount; set { SetProperty(ref maxPageCount, value); } }
private int pageIndex = 1;
/// <summary>
/// 当前页
/// </summary>
public int PageIndex { get => pageIndex; set { SetProperty(ref pageIndex, value); } }
private int dataCountPerPage = 20;
/// <summary>
/// 每页的数据量
/// </summary>
public int DataCountPerPage { get => dataCountPerPage; set { SetProperty(ref dataCountPerPage, value); } }
public ICommand PageUpdateCommand { get => new DelegateCommand<FunctionEventArgs<int>>(PageUpdate); }
/// <summary>
/// 页码更新
/// </summary>
public void PageUpdate(FunctionEventArgs<int> page)
{
PageIndex = page.Info;
UpdateList();
}
#endregion
public ICommand ExportExcelCommand { get => new DelegateCommand(ExportExcel); }
/// <summary>
/// 导出为excel
/// </summary>
public async void ExportExcel()
{
if (IsLoad)
{
Growl.Info("有任务正在进行,请稍等片刻。");
return;
}
IsLoad = true;
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
sfd.FileName = "XXXX记录信息";
sfd.OverwritePrompt = true;
if (sfd.ShowDialog() != true)
{
IsLoad = false;
return;
}
string path = sfd.FileName;
try
{
//1.查询数据库,加入筛选条件,并按照时间倒序排序,并导出指定列
var dbData = DataDb.db.Queryable<MyTestTable>()
.WhereIF(TimeGo != null, o => o.Time > TimeGo)
.WhereIF(TimeTo != null, o => o.Time < TimeTo)
.WhereIF(!string.IsNullOrWhiteSpace(Info1), o => o.Info1.StartsWith(Info1.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(Info2), o => o.Info2.StartsWith(Info2.Trim()))
.OrderByDescending(o => o.Id)
.Select(o => new
{
1 = o.Info1,
2 = o.Info2,
= o.Status,
= o.Time.ToString("yyyy-MM-dd HH:mm:ss"),
});
//2.导出为Excel使用内存缓存的方式防止数据量过大导致内存泄露
var sqlkv = dbData.ToSql();
var dataReader = await DataDb.db.Ado.GetDataReaderAsync(sqlkv.Key, sqlkv.Value);
await MiniExcel.SaveAsAsync(path, dataReader, overwriteFile: true);
dataReader.Close();
Growl.Success("导出成功。");
}
catch (Exception ex)
{
Growl.Error("导出失败:" + ex.Message);
}
finally
{
IsLoad = false;
}
}
public ICommand UpdateListCommand { get => new DelegateCommand(UpdateList); }
/// <summary>
/// 更新信息
/// </summary>
public async void UpdateList()
{
if (IsLoad)
{
Growl.Info("有任务正在进行,请稍等片刻。");
return;
}
IsLoad = true;
try
{
await Task.Delay(200);
//1.查询数据库,加入筛选条件,并按照时间倒序排序
var dbData = DataDb.db.Queryable<MyTestTable>()
.WhereIF(TimeGo != null, o => o.Time > TimeGo)
.WhereIF(TimeTo != null, o => o.Time < TimeTo)
.WhereIF(!string.IsNullOrWhiteSpace(Info1), o => o.Info1.StartsWith(Info1.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(Info2), o => o.Info2.StartsWith(Info2.Trim()))
.OrderByDescending(o => o.Id);
//2.开始分页(如模型不一样使用‘.Select<Model>()’来转换)
RefAsync<int> totalNumber = 0;
RefAsync<int> totalPage = 0;
DataList = await dbData.ToPageListAsync(PageIndex, DataCountPerPage, totalNumber, totalPage);
MaxPageCount = totalPage.Value;
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
IsLoad = false;
}
}
public ICommand SeeCommand { get => new DelegateCommand<MyTestTable>(See); }
/// <summary>
/// 查看详情
/// </summary>
public void See(MyTestTable obj)
{
if (IsLoad)
{
Growl.Info("有任务正在进行,请稍等片刻。");
return;
}
Growl.Info("信息:" + Newtonsoft.Json.JsonConvert.SerializeObject(obj));
}
}
}

View File

@ -0,0 +1,206 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
namespace .ViewModel
{
public class DataListWarnInfoViewModel : BindableBase
{
private List<WarnInfoItemDb> dataList = new List<WarnInfoItemDb>();
/// <summary>
/// 列表数据
/// </summary>
public List<WarnInfoItemDb> DataList { get => dataList; set { SetProperty(ref dataList, value); } }
#region
private bool isLoad1 = false;
public bool IsLoad1 { get => isLoad1; set { SetProperty(ref isLoad1, value); } }
private bool isLoad2 = false;
public bool IsLoad2 { get => isLoad2; set { SetProperty(ref isLoad2, value); } }
#endregion
#region
private DateTime? timeGo = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
/// <summary>
/// 开始时间(默认只显示今天开始的数据)
/// </summary>
public DateTime? TimeGo { get => timeGo; set { SetProperty(ref timeGo, value); } }
private DateTime? timeTo;
/// <summary>
/// 结束时间
/// </summary>
public DateTime? TimeTo { get => timeTo; set { SetProperty(ref timeTo, value); } }
private string info1;
public string Info1 { get => info1; set { SetProperty(ref info1, value); } }
private string info2;
public string Info2 { get => info2; set { SetProperty(ref info2, value); } }
#endregion
#region
private int maxPageCount;
/// <summary>
/// 最大页数
/// </summary>
public int MaxPageCount { get => maxPageCount; set { SetProperty(ref maxPageCount, value); } }
private int pageIndex = 1;
/// <summary>
/// 当前页
/// </summary>
public int PageIndex { get => pageIndex; set { SetProperty(ref pageIndex, value); } }
private int dataCountPerPage = 20;
/// <summary>
/// 每页的数据量
/// </summary>
public int DataCountPerPage { get => dataCountPerPage; set { SetProperty(ref dataCountPerPage, value); } }
public ICommand PageUpdateCommand { get => new DelegateCommand<FunctionEventArgs<int>>(PageUpdate); }
/// <summary>
/// 页码更新
/// </summary>
public void PageUpdate(FunctionEventArgs<int> page)
{
PageIndex = page.Info;
UpdateList();
}
#endregion
public ICommand ExportExcelCommand { get => new DelegateCommand(ExportExcel); }
/// <summary>
/// 导出为excel
/// </summary>
public async void ExportExcel()
{
if (IsLoad2)
{
Growl.Info("有任务正在进行,请稍等片刻。");
return;
}
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
sfd.FileName = "警告信息记录信息";
sfd.OverwritePrompt = true;
if (sfd.ShowDialog() != true)
{
IsLoad1 = false;
return;
}
string path = sfd.FileName;
try
{
//1.查询数据库,加入筛选条件,并按照时间倒序排序,并导出指定列
var dbData = WarnInfoDb.db.Queryable<WarnInfoItemDb>()
.WhereIF(TimeGo != null, o => o.TimeGo > TimeGo)
.WhereIF(TimeTo != null, o => o.TimeGo < TimeTo)
.WhereIF(!string.IsNullOrWhiteSpace(Info1), o => o.Source.StartsWith(Info1.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(Info2), o => o.Level.StartsWith(Info2.Trim()))
.OrderByDescending(o => o.TimeGo)
.Select(o => new
{
= o.Source,
= o.Text,
= o.Level,
= o.Solution,
= o.WarnType,
= o.TimeGo.ToString("yyyy-MM-dd HH:mm:ss"),
= o.TimeTo.HasValue ? o.TimeTo.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
= o.DuraTime,
});
//2.导出为Excel使用内存缓存的方式防止数据量过大导致内存泄露
var sqlkv = dbData.ToSql();
var dataReader = await DataDb.db.Ado.GetDataReaderAsync(sqlkv.Key, sqlkv.Value);
await MiniExcel.SaveAsAsync(path, dataReader, overwriteFile: true);
dataReader.Close();
Growl.Success("导出成功。");
}
catch (Exception ex)
{
Growl.Error("导出失败:" + ex.Message);
}
finally
{
IsLoad1 = false;
}
}
public ICommand UpdateListCommand { get => new DelegateCommand(UpdateList); }
/// <summary>
/// 更新信息
/// </summary>
public async void UpdateList()
{
if (IsLoad1)
{
Growl.Info("有任务正在进行,请稍等片刻。");
return;
}
try
{
await Task.Delay(200);
//1.查询数据库,加入筛选条件,并按照时间倒序排序
var dbData = WarnInfoDb.db.Queryable<WarnInfoItemDb>()
.WhereIF(TimeGo != null, o => o.TimeGo > TimeGo)
.WhereIF(TimeTo != null, o => o.TimeGo < TimeTo)
.WhereIF(!string.IsNullOrWhiteSpace(Info1), o => o.Source.StartsWith(Info1.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(Info2), o => o.Level.StartsWith(Info2.Trim()))
.OrderByDescending(o => o.TimeGo);
//2.开始分页(如模型不一样使用‘.Select<Model>()’来转换)
RefAsync<int> totalNumber = 0;
RefAsync<int> totalPage = 0;
DataList = await dbData.ToPageListAsync(PageIndex, DataCountPerPage, totalNumber, totalPage);
MaxPageCount = totalPage.Value;
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
IsLoad2 = false;
}
}
public ICommand SeeCommand { get => new DelegateCommand<MyTestTable>(See); }
/// <summary>
/// 查看详情
/// </summary>
public void See(MyTestTable obj)
{
if (IsLoad1 || IsLoad2)
{
Growl.Info("有任务正在进行,请稍等片刻。");
return;
}
Growl.Info("信息:" + Newtonsoft.Json.JsonConvert.SerializeObject(obj));
}
}
}

View File

@ -0,0 +1,677 @@
using HandyControl.Controls;
using Ping9719.WpfEx;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace .ViewModel
{
public class DeviceViewModel : BindableBase
{
//循环间隙时间
int whileSleep = 1500;
/// <summary>
/// 是否繁忙。繁忙状态下不在进行定时刷新操作。
/// </summary>
public bool IsBusy { get; set; } = false;
//public IIoTBase plc;
#region
/// <summary>
/// 监听
/// </summary>
public IEnumerable<DeviceReadModel> DataReads { get; set; }
/// <summary>
/// 控制
/// </summary>
public IEnumerable<DeviceWriteModel> DataWrites { get; set; }
/// <summary>
/// 气缸
/// </summary>
public IEnumerable<DeviceUrnModel> DataUrns { get; set; }
/// <summary>
/// 伺服
/// </summary>
public IEnumerable<DeviceServoModel> DataServos { get; set; }
private bool IsVis_ = false;
/// <summary>
/// 当前页面是否显示
/// </summary>
public bool IsVis { get => IsVis_; set { SetProperty(ref IsVis_, value); } }
#region
private bool IsVisRead_ = true;
public bool IsVisRead { get => IsVisRead_; set { SetProperty(ref IsVisRead_, value); } }
private bool IsVisWrite_ = true;
public bool IsVisWrite { get => IsVisWrite_; set { SetProperty(ref IsVisWrite_, value); } }
private bool IsVisUrn_ = true;
public bool IsVisUrn { get => IsVisUrn_; set { SetProperty(ref IsVisUrn_, value); } }
private bool IsVisServo_ = true;
public bool IsVisServo { get => IsVisServo_; set { SetProperty(ref IsVisServo_, value); } }
#endregion
#region
private bool IsVisExpRead_ = true;
public bool IsVisExpRead { get => IsVisExpRead_; set { SetProperty(ref IsVisExpRead_, value); } }
private bool IsVisExpWrite_ = true;
public bool IsVisExpWrite { get => IsVisExpWrite_; set { SetProperty(ref IsVisExpWrite_, value); } }
private bool IsVisExpUrn_ = false;
public bool IsVisExpUrn { get => IsVisExpUrn_; set { SetProperty(ref IsVisExpUrn_, value); } }
private bool IsVisExpServo_ = false;
public bool IsVisExpServo { get => IsVisExpServo_; set { SetProperty(ref IsVisExpServo_, value); } }
#endregion
#endregion
/// <summary>
/// 循环读取数据
/// </summary>
public async void WhileRead()
{
while (true)
{
try
{
if (!IsVis || IsBusy)
{
await Task.Delay(whileSleep);
continue;
}
////监控
if (DataReads != null && IsVisExpRead)
{
foreach (var item in DataReads)
{
if (!item.IsExpanded)
continue;
var plcAdd = item.ExcelTag;
if (string.IsNullOrWhiteSpace(plcAdd.))
continue;
var ts = plcAdd..Trim().ToLower();
switch (ts)
{
case "bool":
//var datab = plc?.Read<bool>(plcAdd.地址);
//item.Value = datab?.IsSucceed == true ? datab.Value : false;
break;
case "byte":
//var datay = plc?.Read<byte>(plcAdd.地址);
//item.Value = datay?.IsSucceed == true ? datay.Value : "-";
break;
case "int16":
//var datai16 = plc?.Read<Int16>(plcAdd.地址);
//item.Value = datai16?.IsSucceed == true ? datai16.Value : "-";
break;
case "int32":
//var datai32 = plc?.Read<int>(plcAdd.地址);
//item.Value = datai32?.IsSucceed == true ? datai32.Value : "-";
break;
case "uint16":
//var dataui16 = plc?.Read<UInt16>(plcAdd.地址);
//item.Value = dataui16?.IsSucceed == true ? dataui16.Value : "-";
break;
case "uint32":
//var dataui32 = plc?.Read<UInt32>(plcAdd.地址);
//item.Value = dataui32?.IsSucceed == true ? dataui32.Value : "-";
break;
case "float":
case "single":
//var datas = plc?.Read<float>(plcAdd.地址);
//item.Value = datas?.IsSucceed == true ? datas.Value : "-";
break;
case "double":
//var datad = plc?.Read<double>(plcAdd.地址);
//item.Value = datad?.IsSucceed == true ? datad.Value : "-";
break;
default:
break;
}
}
}
////控制
if (DataWrites != null && IsVisExpWrite)
{
foreach (var item in DataWrites)
{
if (!item.IsExpanded)
continue;
var plcAdd = item.ExcelTag;
if (string.IsNullOrWhiteSpace(plcAdd.))
continue;
var ts = plcAdd..Trim().ToLower();
switch (ts)
{
case "bool":
//var datab = plc?.Read<bool>(plcAdd.读地址);
//item.Value = datab?.IsSucceed == true ? datab.Value : false;
break;
case "byte":
//var datay = plc?.Read<byte>(plcAdd.读地址);
//item.Value = datay?.IsSucceed == true ? datay.Value : "-";
break;
case "int16":
//var datai16 = plc?.Read<Int16>(plcAdd.读地址);
//item.Value = datai16?.IsSucceed == true ? datai16.Value : "-";
break;
case "int32":
//var datai32 = plc?.Read<int>(plcAdd.读地址);
//item.Value = datai32?.IsSucceed == true ? datai32.Value : "-";
break;
case "uint16":
//var dataui16 = plc?.Read<UInt16>(plcAdd.读地址);
//item.Value = dataui16?.IsSucceed == true ? dataui16.Value : "-";
break;
case "uint32":
//var dataui32 = plc?.Read<UInt32>(plcAdd.读地址);
//item.Value = dataui32?.IsSucceed == true ? dataui32.Value : "-";
break;
case "float":
case "single":
//var datas = plc?.Read<float>(plcAdd.读地址);
//item.Value = datas?.IsSucceed == true ? datas.Value : "-";
break;
case "double":
//var datad = plc?.Read<double>(plcAdd.读地址);
//item.Value = datad?.IsSucceed == true ? datad.Value : "-";
break;
default:
break;
}
}
}
////气缸
if (DataUrns != null && IsVisExpUrn)
{
foreach (var item in DataUrns)
{
if (!item.IsExpanded)
continue;
var plcAdd = item.ExcelTag;
if (!string.IsNullOrWhiteSpace(plcAdd.))
{
//var data1 = plc?.Read<bool>(plcAdd.推到位地址);
//item.IsGoTo = data1?.IsSucceed == true ? data1.Value : false;
}
if (!string.IsNullOrWhiteSpace(plcAdd.))
{
//var data2 = plc?.Read<bool>(plcAdd.回到位地址);
//item.IsRetTo = data2?.IsSucceed == true ? data2.Value : false;
}
}
}
////伺服
if (DataServos != null && IsVisExpServo)
{
foreach (var item in DataServos)
{
if (!item.IsExpanded)
continue;
////读取地址信息
var plcAdd = item.ExcelTag;
if (!string.IsNullOrWhiteSpace(plcAdd.))
{
//var data1 = plc?.Read<float>(plcAdd.当前位置获取);
//item.Location = data1?.IsSucceed == true ? data1.Value : 0;
}
if (!string.IsNullOrWhiteSpace(plcAdd.) && (item.IsJog || !item.IsFold))
{
//var data2 = plc?.Read<Int16>(plcAdd.手动速度获取);
//item.JogSpeed = data2?.IsSucceed == true ? data2.Value : 0;
}
if (!string.IsNullOrWhiteSpace(plcAdd.) && (!item.IsJog || !item.IsFold))
{
//var data3 = plc?.Read<Int16>(plcAdd.自动速度设置);
//item.AutoSpeed = data3?.IsSucceed == true ? data3.Value : 0;
}
}
}
await Task.Delay(whileSleep);
}
catch (Exception)
{
}
}
}
/*一起选中【操作控制】【操作气缸】【操作伺服】可以快速解开全部注释*/
#region
////单击
public void WriteClick(object sender, RoutedEventArgs e)
{
var data = (DeviceWriteModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (dataExcel..Trim().ToLower() == "bool" && mode.StartsWith("切换"))
{
Task.Run(() =>
{
var boolval = data.Value is true;
//plc?.Write(dataExcel.写地址, !boolval);
data.Value = !boolval;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "控制", Funct = string.Empty, Val = data.Value, Mode = mode });
});
}
else
{
var ts = dataExcel..Trim().ToLower();
switch (ts)
{
case "byte":
WriteClickDialog<byte>(data);
break;
case "int16":
WriteClickDialog<Int16>(data);
break;
case "int32":
WriteClickDialog<Int32>(data);
break;
case "uint16":
WriteClickDialog<UInt16>(data);
break;
case "uint32":
WriteClickDialog<UInt32>(data);
break;
case "float":
case "single":
WriteClickDialog<float>(data);
break;
case "double":
WriteClickDialog<double>(data);
break;
default:
break;
}
}
}
////单击弹框
void WriteClickDialog<T>(DeviceWriteModel data) where T : struct
{
var dataExcel = data.ExcelTag;
var val = TipInputView.Show<T>($"请输入新的[{dataExcel.名称}]值:", "修改值", "请输入值");
if (!val.HasValue)
return;
//plc?.Write<T>(dataExcel.写地址, val.Value);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "控制", Funct = string.Empty, Val = val.Value, Mode = "" });
}
////按下左键
public void LeftDown(object sender, MouseButtonEventArgs e)
{
var data = (DeviceWriteModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (dataExcel..Trim().ToLower() == "bool" && mode.StartsWith("点动"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.写地址, true);
data.Value = true;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "控制", Funct = string.Empty, Val = data.Value, Mode = mode });
});
}
}
////放开左键
public void LeftUp(object sender, MouseButtonEventArgs e)
{
var data = (DeviceWriteModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (dataExcel..Trim().ToLower() == "bool" && mode.StartsWith("点动"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.写地址, false);
data.Value = false;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "控制", Funct = string.Empty, Val = data.Value, Mode = mode });
});
}
}
#endregion
#region
////按钮1单击
public void Button1_Click(object sender, RoutedEventArgs e)
{
var data = (DeviceUrnModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (mode.StartsWith("切换"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.推地址, true);
//plc?.Write(dataExcel.回地址, false);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "气缸", Funct = "推", Val = true, Mode = mode });
});
}
}
////按钮1按下
public void But1ClickDown(object sender, RoutedEventArgs e)
{
var data = (DeviceUrnModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (mode.StartsWith("点动"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.推地址, true);
data.IsGoTo = true;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "气缸", Funct = "推", Val = true, Mode = mode });
});
}
}
////按钮1松开
public void But1ClickUp(object sender, RoutedEventArgs e)
{
var data = (DeviceUrnModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (mode.StartsWith("点动"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.推地址, false);
data.IsGoTo = false;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "气缸", Funct = "推", Val = false, Mode = mode });
});
}
}
////按钮2单击
public void Button2_Click(object sender, RoutedEventArgs e)
{
var data = (DeviceUrnModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (mode.StartsWith("切换"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.推地址, false);
//plc?.Write(dataExcel.回地址, true);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "气缸", Funct = "回", Val = true, Mode = mode });
});
}
}
////按钮2按下
public void But2ClickDown(object sender, RoutedEventArgs e)
{
var data = (DeviceUrnModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (mode.StartsWith("点动"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.回地址, true);
data.IsRetTo = true;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "气缸", Funct = "回", Val = true, Mode = mode });
});
}
}
////按钮2松开
public void But2ClickUp(object sender, RoutedEventArgs e)
{
var data = (DeviceUrnModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = dataExcel.?.Trim() ?? "";
if (mode.StartsWith("点动"))
{
Task.Run(() =>
{
//plc?.Write(dataExcel.回地址, false);
data.IsRetTo = false;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "气缸", Funct = "回", Val = false, Mode = mode });
});
}
}
#endregion
#region
////尝试改变伺服的位置时
public void LocationChange(object sender, RoutedEventArgs e)
{
var data = (DeviceServoModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = string.Empty;
////运动方式
if (e.OriginalSource is ServoClickType servoClickType)
{
if (servoClickType == ServoClickType.StartDotAdd)
{
//plc?.Write(dataExcel.位置点动加, true);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "开始点动加", Val = true, Mode = mode });
}
else if (servoClickType == ServoClickType.EndDotAdd)
{
//plc?.Write(dataExcel.位置点动加, false);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "结束点动加", Val = false, Mode = mode });
}
else if (servoClickType == ServoClickType.StartDotSub)
{
//plc?.Write(dataExcel.位置点动减, true);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "开始点动减", Val = true, Mode = mode });
}
else if (servoClickType == ServoClickType.EndDotSub)
{
//plc?.Write(dataExcel.位置点动减, false);
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "结束点动减", Val = false, Mode = mode });
}
}
////运动到指定位置
else if (e.OriginalSource is double val)
{
//plc?.Write(dataExcel.位置移动, Convert.ToSingle(val));
data.Location = val;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "位置移动", Val = val, Mode = mode });
}
}
////尝试改变伺服的速度时
public void SpeedChange(object sender, RoutedEventArgs e)
{
var data = (DeviceServoModel)((FrameworkElement)sender).DataContext;
var dataExcel = data.ExcelTag;
var mode = string.Empty;
var data2 = (ServoSpeed)e.OriginalSource;
if (data2.Name.StartsWith("手动"))
{
//plc?.Write(dataExcel.手动速度设置, Convert.ToSingle(data2.Speed));
data.JogSpeed = data2.Speed;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "手动速度设置", Val = data2.Speed, Mode = mode });
}
else
{
//plc?.Write(dataExcel.自动速度设置, Convert.ToSingle(data2.Speed));
data.AutoSpeed = data2.Speed;
IotDevice.UserChange?.Invoke(new IotDevice() { Name = data.Name, Type = "伺服", Funct = "自动速度设置", Val = data2.Speed, Mode = mode });
}
}
#endregion
}
public class DeviceReadModel : BindableBase
{
#region
private string Name_;
/// <summary>
/// 名称
/// </summary>
public string Name { get => Name_; set { SetProperty(ref Name_, value); } }
private object Value_;
/// <summary>
/// 值
/// </summary>
public object Value { get => Value_; set { SetProperty(ref Value_, value); } }
/// <summary>
/// 是否可见
/// </summary>
public bool IsExpanded { get; set; }
/// <summary>
/// Excel原始数据
/// </summary>
public ExcelDeviceReadModel ExcelTag { get; set; }
#endregion
}
public class DeviceWriteModel : BindableBase
{
#region
private string Name_;
/// <summary>
/// 名称
/// </summary>
public string Name { get => Name_; set { SetProperty(ref Name_, value); } }
private object Value_;
/// <summary>
/// 是否合格
/// </summary>
public object Value { get => Value_; set { SetProperty(ref Value_, value); } }
/// <summary>
/// 是否可见
/// </summary>
public bool IsExpanded { get; set; }
/// <summary>
/// Excel原始数据
/// </summary>
public ExcelDeviceWriteModel ExcelTag { get; set; }
#endregion
}
public class DeviceUrnModel : BindableBase
{
#region
private string Name_;
/// <summary>
/// 名称
/// </summary>
public string Name { get => Name_; set { SetProperty(ref Name_, value); } }
private bool IsGoTo_;
/// <summary>
/// 是否推到位
/// </summary>
public bool IsGoTo { get => IsGoTo_; set { SetProperty(ref IsGoTo_, value); } }
private bool IsRetTo_;
/// <summary>
/// 是否回到位
/// </summary>
public bool IsRetTo { get => IsRetTo_; set { SetProperty(ref IsRetTo_, value); } }
/// <summary>
/// 是否可见
/// </summary>
public bool IsExpanded { get; set; }
/// <summary>
/// 自定义数据
/// </summary>
public ExcelDeviceUrnModel ExcelTag { get; set; }
#endregion
}
public class DeviceServoModel : BindableBase
{
#region
private string Name_;
/// <summary>
/// 名称
/// </summary>
public string Name { get => Name_; set { SetProperty(ref Name_, value); } }
private double JogSpeed_;
/// <summary>
/// 手动模式速度
/// </summary>
public double JogSpeed { get => JogSpeed_; set { SetProperty(ref JogSpeed_, value); } }
private double AutoSpeed_;
/// <summary>
/// 自动模式速度
/// </summary>
public double AutoSpeed { get => AutoSpeed_; set { SetProperty(ref AutoSpeed_, value); } }
private double Location_;
/// <summary>
/// 伺服当前位置
/// </summary>
public double Location { get => Location_; set { SetProperty(ref Location_, value); } }
private bool IsJog_ = true;
/// <summary>
/// 是否主页显示为手动模式
/// </summary>
public bool IsJog { get => IsJog_; set { SetProperty(ref IsJog_, value); } }
private bool IsFold_ = true;
/// <summary>
/// 是否折叠
/// </summary>
public bool IsFold { get => IsFold_; set { SetProperty(ref IsFold_, value); } }
/// <summary>
/// 是否可见
/// </summary>
public bool IsExpanded { get; set; }
private ExcelDeviceServoModel ExcelTag_;
/// <summary>
/// 自定义数据
/// </summary>
public ExcelDeviceServoModel ExcelTag { get => ExcelTag_; set { SetProperty(ref ExcelTag_, value); } }
#endregion
}
}

View File

@ -0,0 +1,109 @@
using HandyControl.Controls;
using LiveCharts;
using Ping9719.WpfEx;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using HandyControl.Tools.Extension;
using .Views.Controls;
using .Api;
using WCS.Model;
namespace .ViewModel
{
public class HomeViewModel : BindableBase
{
WarnInfoContainer WarnInfo = new WarnInfoContainer();//警告、错误等信息
#region
private string textErr;
/// <summary>
/// 错误文本
/// </summary>
public string TextErr { get => textErr; set { SetProperty(ref textErr, value); } }
public ICommand ClearTextInfoCommand { get => new DelegateCommand(ClearTextInfo); }
/// <summary>
/// 清除信息文本
/// </summary>
public void ClearTextInfo()
{
TextBoxLog.ClearLog();
}
public ICommand ClearTextErrCommand { get => new DelegateCommand(ClearTextErr); }
/// <summary>
/// 清除全部错误文本
/// </summary>
public void ClearTextErr()
{
WarnInfo.RemoveAll(WarnInfoType.AlwayWarn);
}
public ICommand AddUserControlCommand { get => new DelegateCommand(AddUserControl); }
public WrapPanel wrapPanel;
public async void AddUserControl()
{
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetShelfStatusRequest()
{
UserName = "xxx",
DeviceType = "WCS前端",
GroupNames = LocalFile.Config.GroupName,
};
var Result = await ApiHelp.Post<GetShelfStatusResponse>([LocalFile.Config.ApiIpHost, "home/getShelfStatus"], body);
if (Result != null && Result.Data?.Count > 0)
{
wrapPanel.Children.Clear();
Result.Data.ForEach(t =>
{
var shelf = new ShelfStatusControl(t.ShelfCode, t.CurentMode, t.GroupName);
wrapPanel.Children.Add(shelf);
});
}
}
catch (Exception ex)
{
}
finally
{
dia.Close();
}
}
#endregion
#region
/// <summary>
/// 页面第一次加载时执行的任务
/// </summary>
public void LoadTask()
{
//注册警告事件
WarnInfo.WarnInfoChanged += (all, add, rem) =>
{
TextErr = string.Join(Environment.NewLine, all.OrderBy(o => (o.WarnType, o.Source, o.Text)));
if (add.Any())
Logs.Write(add.Select(o => o.ToString()), LogsType.Warning);
if (rem.Any())
Logs.Write(rem.Select(o => o.ToString()), LogsType.Warning);
//警告信息保存到数据库
if (WarnInfoDb.IsEnabled)
{
WarnInfoDb.db.Insertable(WarnInfoItemDb.GetList(add)).ExecuteCommand();
WarnInfoDb.db.Updateable(WarnInfoItemDb.GetList(rem)).ExecuteCommand();
}
};
}
#endregion
}
}

View File

@ -0,0 +1,55 @@
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace .ViewModel
{
public class ImageListenerViewModel : BindableBase
{
#region MyRegion
private BitmapFrame ImageSource_;
public BitmapFrame ImageSource { get => ImageSource_; set { SetProperty(ref ImageSource_, value); } }
public double ImageWidth { get; set; }
public double ImageHeight { get; set; }
#endregion
#region
private double ScaleXY_ = 1;
public double ScaleXY { get => ScaleXY_; set { SetProperty(ref ScaleXY_, value); } }
private double CenterX_;
public double CenterX { get => CenterX_; set { SetProperty(ref CenterX_, value); } }
private double CenterY_;
public double CenterY { get => CenterY_; set { SetProperty(ref CenterY_, value); } }
private double TranslateX_;
public double TranslateX { get => TranslateX_; set { SetProperty(ref TranslateX_, value); } }
private double TranslateY_;
public double TranslateY { get => TranslateY_; set { SetProperty(ref TranslateY_, value); } }
/// <summary>
/// 自适应大小
/// </summary>
public void ImgAutoSize()
{
ScaleXY = 1;
CenterX = 0;
CenterY = 0;
TranslateX = 0;
TranslateY = 0;
}
#endregion
}
}

View File

@ -0,0 +1,207 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
using Newtonsoft.Json.Linq;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
using System.Windows.Controls;
using WCS.Model.ApiModel.InterfaceRecord;
using TouchSocket.Sockets;
using TouchSocket.Core;
using System.Text.RegularExpressions;
using System.Collections.ObjectModel;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
using System.Security.Cryptography;
namespace .ViewModel
{
public class InInventoryViewModel : BindableBase
{
public InInventoryViewModel()
{
//初始化串口接收事件
var scanners = ScannerManager.Scanners;
foreach (var scanner in scanners)
{
scanner.SerialPortClient.Received = (client, e) =>
{
//获取串口号
var COM = client.MainSerialPort.PortName;
//获取扫码枪对象
var scanner = ScannerManager.Scanners.Where(t => t.COM == COM).FirstOrDefault();
if (scanner == null)
return EasyTask.CompletedTask;
int newBytes = e.ByteBlock.Len;
if (newBytes > 0)
{
var currentScanedCode = Encoding.UTF8.GetString(e.ByteBlock, 0, e.ByteBlock.Len);
Logs.Write($"接收到扫码枪扫码数据{currentScanedCode}");
scanner.TempCode += currentScanedCode;
//校验末尾码
CheckDataCompleteness(scanner);
scanner.ScannerDisplayControl.RefreshValues(scanner.ShelfCode, scanner.MatSn);
}
return EasyTask.CompletedTask;
};
}
}
#region Property
private string shelfCode;
public string ShelfCode
{
get { return shelfCode; }
set
{
SetProperty(ref shelfCode, value);
}
}
#endregion
#region Command
public void CheckDataCompleteness(Scanner scanner)
{
if (scanner.TempCode.EndsWith("\r"))//结束符 TODO结束符是否需要自定义 现场配置
{
scanner.TempCode = scanner.TempCode.Replace("\r", string.Empty).Replace("\n", string.Empty);
try
{
//TO DO 配置项进行配置正则表达式
//数据处理
string ModuleCodePattern = "^[ABCD][0-9]{2}-R[0-9]{1,2}C[0-9]{1,2}$";
var isModuleCode = Regex.IsMatch(scanner.TempCode, ModuleCodePattern);
if (isModuleCode)
{
ModuleCodeProcess(scanner);
}
//TO DO 增加正则表达式进行判断是否扫到的是物料码
else
{
MatSnProcess(scanner);
}
}
catch (Exception ex)
{
var message = "入库扫码枪扫码发生异常:" + ex.Message;
}
finally
{
//不管入库成功与否 认为本次扫码完毕 清空暂存数据
scanner.TempCode = string.Empty;
}
}
}
/// <summary>
/// 扫到模组码的数据处理
/// </summary>
/// <param name="scanner"></param>
public void ModuleCodeProcess(Scanner scanner)
{
//如果扫码枪前一个货架未退出入库
if (scanner.IsInstoreMode)
{
//判断当前入库货架是否包含本次扫码的模组
if (scanner.ModulesStr.Contains(scanner.TempCode))
{
return;
}
else
{
#region
try
{
var body = new ShelfGoOutInStoreRequest()
{
ShelfCode = scanner.ShelfCode,
IPAdress = scanner.COM,
DeviceType = LocalFile.Config.DeviceType,
UserName = LocalStatic.CurrentUser,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase>(LocalFile.Config.ApiIpHost + "instore/shelfGoOutInStore", body, "POST");
if (Result != null && Result.Code == 200)
{
scanner.ShelfCode = string.Empty;
scanner.ModulesStr = string.Empty;
}
}
catch (Exception ex)
{
}
#endregion
}
}
//调用接口 请求进入入库模式
#region
try
{
var body = new ShelfGoInInstoreRequest()
{
ModuleCode = scanner.TempCode,
DeviceType = LocalFile.Config.DeviceType,
UserName = LocalStatic.CurrentUser,
IpAdress = scanner.COM,
};
var Result = ApiHelp.GetDataFromHttp<ShelfGoInInstoreResponse>(LocalFile.Config.ApiIpHost + "instore/shelfGoInInStore", body, "POST");
if (Result != null && Result.Code == 200)
{
scanner.ShelfCode = Result.Data.ShelfCode;
scanner.ModulesStr = Result.Data.ModulesStr;
}
}
catch (Exception ex)
{
}
#endregion
}
/// <summary>
/// 扫到物料码的数据处理
/// </summary>
public void MatSnProcess(Scanner scanner)
{
#region
try
{
var body = new QueryByMatSnRequest()
{
ShelfCode = scanner.ShelfCode,
IpAddress = scanner.COM,
DeviceType = LocalFile.Config.DeviceType,
UserName = LocalStatic.CurrentUser,
};
var Result = ApiHelp.GetDataFromHttp<QueryByMatSnResponse>(LocalFile.Config.ApiIpHost + "instore/queryByMatSn", body, "POST");
if (Result != null && Result.Code == 200)
{
scanner.MatSn = Result.Data.materialBar;
}
}
catch (Exception ex)
{
}
#endregion
}
#endregion
}
}

View File

@ -0,0 +1,288 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
using Newtonsoft.Json.Linq;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
using System.Windows.Controls;
using WCS.Model.ApiModel.InterfaceRecord;
namespace .ViewModel
{
public class InterfaceRecordViewModel : BindableBase
{
#region Property
private List<SystemApiLogModel> dataGridItemSource;
public List<SystemApiLogModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
/// <summary>
/// 接口地址
/// </summary>
private string requestUrl;
public string RequestUrl
{
get { return requestUrl; }
set
{
SetProperty(ref requestUrl, value);
}
}
/// <summary>
/// 请求参数
/// </summary>
private string requestBody;
public string RequestBody
{
get { return requestBody; }
set
{
SetProperty(ref requestBody, value);
}
}
/// <summary>
/// 请求时间的类型
/// </summary>
private TimeType timeType;
public TimeType TimeType
{
get { return timeType; }
set
{
SetProperty(ref timeType, value);
}
}
public IEnumerable<string> TimeTypes => GetEnumValues();
private IEnumerable<string> GetEnumValues()
{
return Enum.GetNames(typeof(TimeType));
}
private DateTime startTime;
public DateTime StartTime
{
get { return startTime; }
set
{
SetProperty(ref startTime, value);
}
}
private DateTime endTime;
public DateTime EndTime
{
get { return endTime; }
set
{
SetProperty(ref endTime, value);
}
}
/// <summary>
/// 调用类型 调用/被调用
/// </summary>
private string requestType;
public string RequestType
{
get { return requestType; }
set
{
SetProperty(ref requestType, value);
}
}
#endregion
#region Command
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
public void BtnReset()
{
RequestUrl = string.Empty;
RequestBody = string.Empty;
RequestType = string.Empty;
TimeType = TimeType.;
StartTime = DateTime.Now.Date;
EndTime = DateTime.Now.Date.AddDays(1);
}
public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); }
public void BtnSearchReset()
{
BtnSearch(true);
}
public void BtnSearch(bool IsPageReset = true)
{
if (CurrentPage == 0 || IsPageReset)
{
CurrentPage = 1;
return;
}
#region
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetInterfaceRecordsRequest()
{
RequestUrl = RequestUrl,
RequestBody = RequestBody,
RequestType = RequestType,
TimeType = TimeType,
StartTime = StartTime,
EndTime = EndTime,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<SystemApiLogModel>>(LocalFile.Config.ApiIpHost + "interfaceRecord/getInterfaceRecord", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists != null)
{
DataGridItemSource = Result.Data.Lists;
MaxPage = Result.Data.MaxPage;
TotalCount = Result.Data.TotalCount;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
#endregion
}
public ICommand BtnExportCommand { get => new DelegateCommand(BtnExport); }
public async void BtnExport()
{
try
{
#region
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
sfd.FileName = "接口记录" + DateTime.Now.ToString("yyyyMMddhhmmss");
sfd.OverwritePrompt = true;
if (sfd.ShowDialog() != true)
{
return;
}
string path = sfd.FileName;
#endregion
var body = new GetInterfaceRecordsRequest()
{
RequestUrl = RequestUrl,
RequestBody = RequestBody,
RequestType = RequestType,
TimeType = TimeType,
StartTime = StartTime,
EndTime = EndTime,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "interfaceRecord/exportInterfaceRecord", body);
Growl.Success("导出成功!");
}
catch (Exception ex)
{
Growl.Error("导出失败:" + ex.Message);
}
}
#endregion
#region PageOperation
private int currentPage;
public int CurrentPage
{
get { return currentPage; }
set
{
SetProperty(ref currentPage, value);
BtnSearch(false);
}
}
private int maxPage;
public int MaxPage
{
get { return maxPage; }
set { SetProperty(ref maxPage, value); }
}
//总数量
private int totalCount;
public int TotalCount
{
get { return totalCount; }
set { SetProperty(ref totalCount, value); }
}
public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); }
public void BtnFirstPage()
{
CurrentPage = 1;
}
public ICommand BtnPrePageCommand { get => new DelegateCommand(BtnPrePage); }
public void BtnPrePage()
{
if (CurrentPage > 1)
{
CurrentPage--;
}
}
public ICommand BtnNextPageCommand { get => new DelegateCommand(BtnNextPage); }
public void BtnNextPage()
{
if (CurrentPage < MaxPage)
{
CurrentPage++;
}
}
public ICommand BtnLastPageCommand { get => new DelegateCommand(BtnLastPage); }
public void BtnLastPage()
{
if (CurrentPage != MaxPage)
{
CurrentPage = MaxPage;
}
}
#endregion
}
}

View File

@ -0,0 +1,227 @@
using HandyControl.Controls;
using Newtonsoft.Json;
using Ping9719.WpfEx;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Markup;
namespace .ViewModel
{
public class MainViewModel : BindableBase
{
Mutex mutex;
private string title = string.Empty;
/// <summary>
/// 标题
/// </summary>
public string Title { get => title; set { SetProperty(ref title, value); } }
#region _MainWindow2
//隐藏式选项卡的高度
public double TabItemHeight { get; set; } = 0;
private string SelectedValue_ = "主页";
public string SelectedValue { get => SelectedValue_; set { SetProperty(ref SelectedValue_, value); } }
#endregion
private DateTime time;
/// <summary>
/// 时间
/// </summary>
public DateTime Time { get => time; set { SetProperty(ref time, value); } }
/// <summary>
/// 在初始化前的相关检查
/// </summary>
public bool InitAgo()
{
//只允许打开一个
mutex = new Mutex(true, string.Concat("MengXun货架标准上位机", Path.GetFileNameWithoutExtension(LocalFile.AppName)), out bool createdNew);
if (!createdNew)
{
MessageBox.Warning("已有实列在运行!", "提示");
return false;
}
//初始化
Tuple<string, string, Action>[] tuples = new Tuple<string, string, Action>[]
{
new Tuple<string, string, Action>("检测文件..", "缺少文件,尝试将项目[data/]中的所有文件复制到[bin/data/]中", () =>
{
if(!System.IO.File.Exists(LocalFile.ConfigPath))
throw new Exception("缺少文件,请尝试将项目[data/]中的所有文件复制到[bin/data/]中");
}),
new Tuple<string, string, Action>("检测文件..", "配置文件中没有内容,请联系管理员", () =>
{
if(string.IsNullOrWhiteSpace(System.IO.File.ReadAllText(LocalFile.ConfigPath, Encoding.UTF8)))
throw new Exception($"配置文件[{LocalFile.ConfigPath}]中没有内容");
}),
new Tuple<string, string, Action>("初始化数据中..", "初始化数据库失败,请联系管理员", () =>
{
}),
new Tuple<string, string, Action>("初始化扫码枪连接..", "初始化扫码枪连接失败,请联系管理员", () =>
{
ScannerManager.InitScanners();
}),
};
MainLoadWindow.TaskSleepTime = 200;
if (!MainLoadWindow.Show(tuples))
return false;
//清理日志
Task.Run(() =>
{
if (LocalFile.Config.Sys.SaveLogDay < 0)
return;
Logs.Clear(TimeSpan.FromDays(LocalFile.Config.Sys.SaveLogDay));
});
////不登录,直接使用最高权限
//{
// UserLoginView.NotLogin();
// return true;
//}
//登录
{
var userLoginView = new UserLoginView();
var isok = userLoginView.ShowDialog() == true;
userLoginView = null;
return isok;
}
}
/// <summary>
/// 初始化并运行时间
/// </summary>
public async void Init(System.Windows.Window window)
{
//加载 程序名称
var versionInfo = FileVersionInfo.GetVersionInfo(LocalFile.AppPath);
Title = versionInfo.ProductName;
//加载 窗体模式
if (LocalFile.Config.Sys.StartupFull)
window.WindowState = System.Windows.WindowState.Maximized;
//注册 设备
IotDevice.UserChange = ((iot) =>
{
if (string.IsNullOrEmpty(iot.Funct))
Growl.Info($"你点击了[{iot.Name}],尝试改为[{iot.Val}]");
else
Growl.Info($"你点击了[{iot.Name}][{iot.Funct}],尝试改为[{iot.Val}]");
});
//注册 信息
TextBoxLog.TextBoxLogAdd = ((info) =>
{
Logs.Write(info.Text, LogsType.Info, info.Time);
});
//加载 时钟
while (true)
{
Time = DateTime.Now;
await Task.Delay(1);
}
}
public ICommand OpenUserCommand { get => new DelegateCommand(OpenUser); }
/// <summary>
/// 打开用户
/// </summary>
public void OpenUser()
{
if (UserInfoView.viewModel.IsLogin)
{
var userInfoView = new UserInfoView();
userInfoView.ShowDialog();
if (userInfoView.IsExitLogin)
{
Growl.Info("您已退出登录。");
userInfoView = null;
}
}
else
{
var userLoginView = new UserLoginView();
//登录成功
if (userLoginView.ShowDialog() == true)
{
Growl.Success($"欢迎您:{UserInfoView.viewModel.LoginName}");
userLoginView = null;
}
}
}
public ICommand OpenLogCommand { get => new DelegateCommand(OpenLog); }
/// <summary>
/// 打开日记
/// </summary>
public void OpenLog()
{
if (!System.IO.Directory.Exists(LocalFile.LogDir))
{
Growl.Info("暂时没有日志。");
return;
}
try
{
Folder.OpenFolder(LocalFile.LogDir);
}
catch (Exception)
{
Growl.Error("打开日志目录失败。");
}
}
public ICommand OpenHelpCommand { get => new DelegateCommand(OpenHelp); }
/// <summary>
/// 打开帮助
/// </summary>
public void OpenHelp()
{
if (!System.IO.File.Exists(LocalFile.DocPath))
{
Growl.Info("帮助文档正在书写中。");
return;
}
try
{
Folder.OpenFolderAndSelectedFile(LocalFile.DocPath);
}
catch (Exception)
{
Growl.Error("打开帮助文档失败。");
}
}
public ICommand OpenWeCommand { get => new DelegateCommand(OpenWe); }
/// <summary>
/// 打开关于
/// </summary>
public void OpenWe()
{
var aboutView = new AboutView();
aboutView.ShowDialog();
aboutView = null;
}
}
}

View File

@ -0,0 +1,41 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
using Newtonsoft.Json.Linq;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
using System.Windows.Controls;
using WCS.Model.ApiModel.InterfaceRecord;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
namespace .ViewModel
{
public class MatBaseInfoAddOrUpdateViewModel : BindableBase
{
private bool isEnable;
public bool IsEnable
{
get { return isEnable; }
set
{
SetProperty(ref isEnable, value);
}
}
}
}

View File

@ -0,0 +1,470 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
using Newtonsoft.Json.Linq;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
using System.Windows.Controls;
using WCS.Model.ApiModel.InterfaceRecord;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
using System.Collections.ObjectModel;
using HandyControl.Tools.Extension;
using .Tool;
namespace .ViewModel
{
public class MatBaseInfoViewModel : BindableBase
{
#region Property
private ObservableCollection<MatBaseInfoModel> dataGridItemSource;
public ObservableCollection<MatBaseInfoModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
public MatBaseInfoModel selectedataGridItem;
public MatBaseInfoModel SelectedataGridItem
{
get { return selectedataGridItem; }
set
{
SetProperty(ref selectedataGridItem, value);
}
}
/// <summary>
/// 物料编码
/// </summary>
private string matCode;
public string MatCode
{
get { return matCode; }
set
{
SetProperty(ref matCode, value);
}
}
/// <summary>
/// 物料名称
/// </summary>
private string matName;
public string MatName
{
get { return matName; }
set
{
SetProperty(ref matName, value);
}
}
/// <summary>
/// 物料规格
/// </summary>
private string matSpec;
public string MatSpec
{
get { return matSpec; }
set
{
SetProperty(ref matSpec, value);
}
}
/// <summary>
/// 请求时间的类型
/// </summary>
private bool? isEnable;
public bool? IsEnable
{
get { return isEnable; }
set
{
SetProperty(ref isEnable, value);
}
}
#endregion
#region Command
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
public void BtnReset()
{
MatCode = string.Empty;
MatName = string.Empty;
MatSpec = string.Empty;
IsEnable = null;
}
public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); }
public void BtnSearchReset()
{
BtnSearch(true);
}
public void BtnSearch(bool IsPageReset = true)
{
if (CurrentPage == 0 || IsPageReset)
{
CurrentPage = 1;
return;
}
#region
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetMatBaseInfoRequest()
{
MatCode = MatCode,
MatName = MatName,
MatSpec = MatSpec,
IsEnable = IsEnable,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<MatBaseInfoModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/getMatBaseInfo", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists != null)
{
DataGridItemSource = new ObservableCollection<MatBaseInfoModel>(Result.Data.Lists);
//DataGridItemSource = Result.Data.Lists;
MaxPage = Result.Data.MaxPage;
TotalCount = Result.Data.TotalCount;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
#endregion
}
/// <summary>
/// 导出数据为Excel文件
/// </summary>
public ICommand BtnExportCommand { get => new DelegateCommand(BtnExport); }
public async void BtnExport()
{
try
{
#region
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.Title = "选择文件保存路径";
sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
sfd.FileName = "物料管理" + DateTime.Now.ToString("yyyyMMddhhmmss");
sfd.OverwritePrompt = true;
if (sfd.ShowDialog() != true)
{
return;
}
string path = sfd.FileName;
#endregion
var body = new GetMatBaseInfoRequest()
{
MatCode = MatCode,
MatName = MatName,
MatSpec = MatSpec,
IsEnable = IsEnable,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "matBaseInfo/exportMatBaseInfo", body);
Growl.Success("导出成功!");
}
catch (Exception ex)
{
Growl.Error("导出失败:" + ex.Message);
}
}
public ICommand BtnImportCommand { get => new DelegateCommand(BtnImport); }
public async void BtnImport()
{
try
{
#region
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
ofd.Title = "选择模板";
ofd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
ofd.FileName = "物料管理" + DateTime.Now.ToString("yyyyMMddhhmmss");
ofd.Multiselect = false;
if (ofd.ShowDialog() != true)
{
return;
}
#endregion
//已经选择文件 调用接口进行导入数据
string path = ofd.FileName;
var body = new GetMatBaseInfoRequest()
{
MatCode = MatCode,
MatName = MatName,
MatSpec = MatSpec,
IsEnable = IsEnable,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
var result = await ApiHelp.PostImportFileAsync<ResponseCommon<List<string>>>(path, System.Net.Http.HttpMethod.Post,
LocalFile.Config.ApiIpHost + "matBaseInfo/importMatBaseInfo", LocalStatic.CurrentUser, LocalFile.Config.DeviceType);
if (result.Code == 200)
{
Growl.Success("成功导入!");
CurrentPage = 0;
}
else
{
if (result.Data != null && result.Data.Count > 0)
HandyControl.Controls.MessageBox.Show(result.Message + "\t\n" + String.Join("\t\n", result.Data));
else
HandyControl.Controls.MessageBox.Show(result.Message);
}
}
catch (Exception ex)
{
Growl.Error("导入失败:" + ex.Message);
}
}
/// <summary>
/// 物料新增操作
/// </summary>
public ICommand BtnAddCommand { get => new DelegateCommand(BtnAdd); }
public async void BtnAdd()
{
var addView = new MatBaseInfoAddOrUpdateView("新增物料数据");
addView.ShowDialog();
if (addView.DialogResult == true)
{
var matBaseInfo = addView.matBaseInfo;
matBaseInfo.ModifyTime = DateTime.Now;
matBaseInfo.ModifyUser = LocalStatic.CurrentUser;
var body = new AddMatBaseInfoRequest<MatBaseInfoModel>()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
MatBaseInfo = matBaseInfo,
AddOrUpdate = AddOrUpdate.Add
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/addOrUpdateMatBaseInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("添加成功!");
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
//BtnAdd();
}
}
}
/// <summary>
/// 物料修改操作
/// </summary>
public ICommand BtnEditCommand { get => new DelegateCommand(BtnEdit); }
public async void BtnEdit()
{
//查询勾选的第一个数据
var matBaseInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault();
if (matBaseInfo == null)
{
Growl.Warning("请选择需要修改的数据!");
}
else
{
var addView = new MatBaseInfoAddOrUpdateView("修改物料数据", matBaseInfo);
addView.ShowDialog();
if (addView.DialogResult == true)
{
matBaseInfo = addView.matBaseInfo;
matBaseInfo.ModifyTime = DateTime.Now;
matBaseInfo.ModifyUser = LocalStatic.CurrentUser;
var body = new AddMatBaseInfoRequest<MatBaseInfoModel>()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
MatBaseInfo = matBaseInfo,
AddOrUpdate = AddOrUpdate.Update
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/addOrUpdateMatBaseInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("修改成功!");
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
}
/// <summary>
/// 物料删除操作
/// </summary>
public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); }
public async void BtnDelete()
{
Growl.Ask($"是否删除所有勾选得数据]!", isConfirmed =>
{
if (isConfirmed)
{
//查询勾选的第一个数据
var matBaseInfoIds = DataGridItemSource?.Where(t => t.IsSelected == true)
.Select(t => t.Id)
.ToList();
if (matBaseInfoIds == null)
{
Growl.Warning("请选择需要修改的数据!");
}
else
{
var body = new DeleteMatBaseInfosRequest()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
MatBaseInfoIds = matBaseInfoIds,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/deleteMatBaseInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("删除成功!" + Result?.Message);
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
return true;
});
}
public ICommand BtnPrintCommand { get => new DelegateCommand(BtnPrint); }
public async void BtnPrint()
{
PrintTender.PrintTag(new PrintClass()
{
MatQty = "123",
MatCode = "123",
MatBatch = "123",
MatName = "123",
MatSn = "123",
MatSpec = "123",
});
}
#endregion
#region PageOperation
private int currentPage;
public int CurrentPage
{
get { return currentPage; }
set
{
SetProperty(ref currentPage, value);
BtnSearch(false);
}
}
private int maxPage;
public int MaxPage
{
get { return maxPage; }
set { SetProperty(ref maxPage, value); }
}
//总数量
private int totalCount;
public int TotalCount
{
get { return totalCount; }
set { SetProperty(ref totalCount, value); }
}
public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); }
public void BtnFirstPage()
{
CurrentPage = 1;
}
public ICommand BtnPrePageCommand { get => new DelegateCommand(BtnPrePage); }
public void BtnPrePage()
{
if (CurrentPage > 1)
{
CurrentPage--;
}
}
public ICommand BtnNextPageCommand { get => new DelegateCommand(BtnNextPage); }
public void BtnNextPage()
{
if (CurrentPage < MaxPage)
{
CurrentPage++;
}
}
public ICommand BtnLastPageCommand { get => new DelegateCommand(BtnLastPage); }
public void BtnLastPage()
{
if (CurrentPage != MaxPage)
{
CurrentPage = MaxPage;
}
}
#endregion
}
}

View File

@ -0,0 +1,336 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
using Newtonsoft.Json.Linq;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
using System.Windows.Controls;
using WCS.Model.ApiModel.InterfaceRecord;
using HandyControl.Collections;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.MatInventoryDetail;
namespace .ViewModel
{
public class MatInventoryDetailViewModel : BindableBase
{
public MatInventoryDetailViewModel()
{
//获取物料编码列表
//matCodes = DbHelp.db.Queryable<InventoryDetail>()
// .Select(t => new DataModel()
// {
// MatCode = t.MatCode
// })
// .Distinct()
// .ToList();
}
public void InitMatCode()
{
//调用接口更新!
Task.Run(() =>
{
var body = new GetMatCodeListRequest()
{
IsFromBaseData = false,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<ResponseCommon<List<string>>>(LocalFile.Config.ApiIpHost + "matBaseInfo/getMatCodeList", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Count() > 0)
{
matCodes = Result.Data.Select(t => new DataModel()
{
MatCode = t
}).ToList();
}
});
}
#region Property
private List<MatInventoryDetailModel> dataGridItemSource;
public List<MatInventoryDetailModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
/// <summary>
/// 物料编码
/// </summary>
private string matCode;
public string MatCode
{
get { return matCode; }
set
{
SetProperty(ref matCode, value);
FilterItems(value);
}
}
public ManualObservableCollection<DataModel> Items { get; set; } = new();
private List<DataModel> matCodes = new List<DataModel>();
private void FilterItems(string key)
{
//至少输入三个字符 避免删除或输入时界面变卡
if (string.IsNullOrEmpty(key) || key.Length < 3)
{
Items.Clear();
return;
}
key = key.ToUpper();
Items.CanNotify = false;
Items.Clear();
foreach (var matCode in matCodes)
{
if (matCode.MatCode.ToUpper().Contains(key))
{
Items.Add(matCode);
}
}
Items.CanNotify = true;
}
public class DataModel()
{
public string MatCode { get; set; }
}
/// <summary>
/// 物料名称
/// </summary>
private string matName;
public string MatName
{
get { return matName; }
set
{
SetProperty(ref matName, value);
}
}
/// <summary>
/// 物料批次
/// </summary>
private string matBatch;
public string MatBatch
{
get { return matBatch; }
set
{
SetProperty(ref matBatch, value);
}
}
/// <summary>
/// 库位
/// </summary>
private string storeCode;
public string StoreCode
{
get { return storeCode; }
set
{
SetProperty(ref storeCode, value);
}
}
/// <summary>
/// 物料条码
/// </summary>
private string matSN;
public string MatSN
{
get { return matSN; }
set
{
SetProperty(ref matSN, value);
}
}
#endregion
#region Command
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
public void BtnReset()
{
MatCode = string.Empty;
MatName = string.Empty;
MatSN = string.Empty;
StoreCode = string.Empty;
}
public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); }
public void BtnSearchReset()
{
BtnSearch(true);
}
public void BtnSearch(bool IsPageReset = true)
{
if (CurrentPage == 0 || IsPageReset)
{
CurrentPage = 1;
return;
}
#region
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetMatInventoryDetailRequest()
{
MatName = MatName,
MatSN = MatSN,
MatBatch = MatBatch,
MatCode = MatCode,
StoreCode = StoreCode,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<MatInventoryDetailModel>>(LocalFile.Config.ApiIpHost + "matInventoryDetail/getMatInventoryDetail", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists != null)
{
DataGridItemSource = Result.Data.Lists;
MaxPage = Result.Data.MaxPage;
TotalCount = Result.Data.TotalCount;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
#endregion
}
public ICommand BtnExportCommand { get => new DelegateCommand(BtnExport); }
public async void BtnExport()
{
try
{
#region
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
sfd.FileName = "库存数据" + DateTime.Now.ToString("yyyyMMddhhmmss");
sfd.OverwritePrompt = true;
if (sfd.ShowDialog() != true)
{
return;
}
string path = sfd.FileName;
#endregion
#region
var body = new GetMatInventoryDetailRequest()
{
MatName = MatName,
MatSN = MatSN,
MatBatch = MatBatch,
MatCode = MatCode,
StoreCode = StoreCode,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "matInventoryDetail/exportMatInventoryDetail", body);
Growl.Success("导出成功!");
#endregion
}
catch (Exception ex)
{
Growl.Error("导出失败:" + ex.Message);
}
}
#endregion
#region PageOperation
private int currentPage;
public int CurrentPage
{
get { return currentPage; }
set
{
SetProperty(ref currentPage, value);
BtnSearch(false);
}
}
private int maxPage;
public int MaxPage
{
get { return maxPage; }
set { SetProperty(ref maxPage, value); }
}
//总数量
private int totalCount;
public int TotalCount
{
get { return totalCount; }
set { SetProperty(ref totalCount, value); }
}
public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); }
public void BtnFirstPage()
{
CurrentPage = 1;
}
public ICommand BtnPrePageCommand { get => new DelegateCommand(BtnPrePage); }
public void BtnPrePage()
{
if (CurrentPage > 1)
{
CurrentPage--;
}
}
public ICommand BtnNextPageCommand { get => new DelegateCommand(BtnNextPage); }
public void BtnNextPage()
{
if (CurrentPage < MaxPage)
{
CurrentPage++;
}
}
public ICommand BtnLastPageCommand { get => new DelegateCommand(BtnLastPage); }
public void BtnLastPage()
{
if (CurrentPage != MaxPage)
{
CurrentPage = MaxPage;
}
}
#endregion
}
}

View File

@ -0,0 +1,173 @@
using LiveCharts;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace .ViewModel
{
public class OutputStatChartViewModel : BindableBase
{
public OutputStatChartViewModel()
{
Values1.CollectionChanged += Values_CollectionChanged;
Values2.CollectionChanged += Values_CollectionChanged;
}
void Values_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
IsZero = (Values1[0] + Values2[0]) == 0;
}
//本地保存路径
public static readonly string DailyStatisticsPath = System.IO.Path.Combine(LocalFile.DataDir, "outputStat");
//文件锁
static object lockObject = new object();
#region
public ChartValues<int> Values1 { get; set; } = new ChartValues<int>() { 10 };
public ChartValues<int> Values2 { get; set; } = new ChartValues<int>() { 2 };
public Func<ChartPoint, string> PointLabel { get; set; } = value => $"{value.Y}";
#endregion
private string Title_ = "当日生产统计";
/// <summary>
/// 标题
/// </summary>
public string Title { get => Title_; set { SetProperty(ref Title_, value); } }
private bool IsZero_ = true;
/// <summary>
/// 是否为0
/// </summary>
public bool IsZero { get => IsZero_; set { SetProperty(ref IsZero_, value); } }
private DateTime? StartTime_ = null;
/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime
{
get => StartTime_;
set
{
StartTime_ = value;
Title = !value.HasValue ? "当日生产统计" : value.Value == DateTime.Now.Date ? "当日生产统计" : $"生产统计({value.Value.ToString(@"yyyy/MM/dd")})";
}
}
public void AddOkNg(int okNum, int ngNum)
{
if (okNum < 1 && ngNum < 1)
return;
if (StartTime == null)
return;
//重新计算
if (StartTime.Value.Date != DateTime.Now.Date)
Reset();
if (okNum > 0)
Values1[0] = Values1[0] + okNum;
if (ngNum > 0)
Values2[0] = Values2[0] + ngNum;
SaveData();
}
public void AddOk(int num = 1)
{
if (num < 1)
return;
if (StartTime == null)
return;
//重新计算
if (StartTime.Value.Date != DateTime.Now.Date)
Reset();
Values1[0] = Values1[0] + num;
SaveData();
}
public void AddNg(int num = 1)
{
if (num < 1)
return;
if (StartTime == null)
return;
//重新计算
if (StartTime.Value.Date != DateTime.Now.Date)
Reset();
Values2[0] = Values2[0] + num;
SaveData();
}
public void UpdataData()
{
try
{
if (!File.Exists(DailyStatisticsPath))
{
Values1[0] = 0;
Values2[0] = 0;
StartTime = DateTime.Now.Date;
}
else
{
JObject? jo;
lock (lockObject)
jo = JsonConvert.DeserializeObject<JObject>(File.ReadAllText(DailyStatisticsPath, Encoding.UTF8));
if (jo == null)
{
Values1[0] = 0;
Values2[0] = 0;
StartTime = DateTime.Now.Date;
}
else
{
Values1[0] = jo.Value<int>("ok");
Values2[0] = jo.Value<int>("ng");
StartTime = jo.Value<DateTime>("dt");
}
}
}
catch (Exception)
{
}
}
public void SaveData()
{
try
{
var data = new { ok = Values1[0], ng = Values2[0], dt = StartTime };
lock (lockObject)
File.WriteAllText(DailyStatisticsPath, JsonConvert.SerializeObject(data), Encoding.UTF8);
}
catch (Exception)
{
}
}
public void Reset()
{
Values1[0] = 0;
Values2[0] = 0;
StartTime = DateTime.Now.Date;
}
}
}

View File

@ -0,0 +1,126 @@
using HandyControl.Controls;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
namespace .ViewModel
{
//https://dandelioncloud.cn/article/details/1472765022102446082
public class RoleEditTreeViewModel : BindableBase, ITreeNode<RoleEditTreeViewModel>
{
private bool IsSelect_;
/// <summary>
/// 是否选择
/// </summary>
public bool IsSelect { get => IsSelect_; set { SetProperty(ref IsSelect_, value); Linkage(value); } }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 主键Id
/// </summary>
public object Id { get; set; }
/// <summary>
/// 父Id
/// </summary>
public object Pid { get; set; }
/// <summary>
/// 父级
/// </summary>
public RoleEditTreeViewModel Parent { get; set; }
/// <summary>
/// 子级
/// </summary>
public List<RoleEditTreeViewModel> Children { get; set; }
/// <summary>
/// 联动
/// </summary>
public void Linkage(bool newbool)
{
//父级增加联动
if (newbool && Parent != null)
Parent.IsSelect = true;
//子级联动
if (!newbool && Children != null)
foreach (var item in Children)
item.IsSelect = false;
}
/// <summary>
/// 得到数据
/// </summary>
/// <param name="select">选中的值</param>
/// <returns></returns>
public static List<RoleEditTreeViewModel> GetTreeViewModel(List<int> select)
{
//值,名称,父级,子级
List<Tuple<int, string, int?, List<int>>> quan = new List<Tuple<int, string, int?, List<int>>>();
List<RoleEditTreeViewModel> vmodel = new List<RoleEditTreeViewModel>();
//1解析枚举
{
Type type = typeof(AuthEnum);
var fields = type.GetFields(BindingFlags.Static | BindingFlags.Public) ?? new FieldInfo[] { };
foreach (var field in fields)
{
var attr = field.GetCustomAttribute<EnumTreeAttribute>(false);
var attr1 = field.GetCustomAttribute<DescriptionAttribute>(false);
var v0 = Convert.ToInt32(field.GetRawConstantValue());
var v1 = attr1 == null ? field.Name : attr1.Description;
var v2 = (int?)attr?.Parent;
var v3 = attr?.Childs?.Select(o => (int)o)?.ToList();
quan.Add(new Tuple<int, string, int?, List<int>>(v0, v1, v2, (v3 ?? new List<int>())));
}
}
//2翻译数据
{
vmodel.AddRange(quan.Select(o => new RoleEditTreeViewModel()
{
Id = o.Item1,
Name = o.Item2,
Pid = 0,
IsSelect = select?.Contains(o.Item1) ?? false,
}));
//父子
foreach (var item in vmodel)
{
var f = quan.FirstOrDefault(o => o.Item1 == (int)item.Id)?.Item3;
if (f.HasValue)
{
item.Parent = vmodel.FirstOrDefault(o => (int)o.Id == f.Value);
item.Pid = item.Parent.Id;
}
var ff = quan.FirstOrDefault(o => o.Item1 == (int)item.Id)?.Item4;
if (ff != null && ff.Any())
{
foreach (var item2 in ff)
{
vmodel.FirstOrDefault(o => (int)o.Id == item2).Parent = item;
vmodel.FirstOrDefault(o => (int)o.Id == item2).Pid = item.Id;
}
}
}
}
//3数据转为树对象
vmodel = vmodel.ToTree();
return vmodel;
}
}
}

View File

@ -0,0 +1,147 @@
using HandyControl.Controls;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using SqlSugar;
using WCS.Model.ApiModel;
using HandyControl.Tools.Extension;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
namespace .ViewModel
{
public class RoleViewModel : BindableBase
{
private List<RoleModel> dataList = new List<RoleModel>();
/// <summary>
/// 列表数据
/// </summary>
public List<RoleModel> DataList { get => dataList; set { SetProperty(ref dataList, value); } }
#region
private string info1;
public string Info1 { get => info1; set { SetProperty(ref info1, value); } }
#endregion
public ICommand UpdateListCommand { get => new DelegateCommand(UpdateList); }
/// <summary>
/// 更新信息
/// </summary>
public void UpdateList()
{
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetUsersRequest()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
Info = Info1,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<List<RoleModel>>>(LocalFile.Config.ApiIpHost + "user/getRoles", body, "POST");
if (Result != null && Result.Data != null)
{
DataList = Result.Data;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
}
public ICommand SeeCommand { get => new DelegateCommand<RoleModel>(See); }
public void See(RoleModel obj)
{
RoleEditView.Show(obj, CrudEnum.Read);
}
public ICommand AddCommand { get => new DelegateCommand(Add); }
public void Add()
{
var isUp = RoleEditView.Show(new RoleModel(), CrudEnum.Create);
if (isUp)
{
UpdateList();
Growl.Success("创建成功");
}
}
public ICommand UpdateCommand { get => new DelegateCommand<RoleModel>(Update); }
public void Update(RoleModel obj)
{
var isUp = RoleEditView.Show(obj, CrudEnum.Update);
if (isUp)
{
UpdateList();
Growl.Success("更新成功");
}
}
public ICommand DelCommand { get => new DelegateCommand<RoleModel>(Del); }
public void Del(RoleModel obj)
{
Growl.Ask($"是否删除角色[{obj.Name}]!", isConfirmed =>
{
if (isConfirmed)
{
//try
//{
// //var isContains = AuthDb1.db.Queryable<UserModel>().Select(o => o.RoleIds).ToList().SelectMany(o => o).Contains(obj.Id);
// //if (isContains)
// //{
// // Growl.Info($"此角色被用户使用中,无法删除");
// // return true;
// //}
// //AuthDb1.db.Deleteable(obj).ExecuteCommand();
//}
//catch (Exception ex)
//{
// Growl.Error($"删除失败:{ex.ToString()}");
// return true;
//}
try
{
var body = new AddRoleRequest<RoleModel>()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
Role = obj,
AddOrUpdate = AddOrUpdate.Delete,
};
var Result = ApiHelp.GetDataFromHttp<ResponseCommon<object>>(LocalFile.Config.ApiIpHost + "user/addRole", body, "POST");
if (Result.Code == 200)
{
Growl.Success("删除成功");
UpdateList();
return true;
}
else
{
Growl.Error(Result?.Message);
return true;
}
}
catch (Exception ex)
{
Growl.Error($"删除失败:{ex.ToString()}");
return true;
}
}
else
return true;
});
}
}
}

View File

@ -0,0 +1,219 @@
using HandyControl.Controls;
using Microsoft.Win32;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Input;
namespace .ViewModel
{
public class SetViewModel : BindableBase
{
private List<int> SaveLoginCountData_ = new List<int> { 3, 5, 7, 10 };
//记忆最大数量下拉框
public List<int> SaveLoginCountData { get => SaveLoginCountData_; set { SetProperty(ref SaveLoginCountData_, value); } }
private Dictionary<int, string> LogTimeData_ = new Dictionary<int, string>()
{
{ 30,"一月"},{ 91,"三月"},{ 182,"半年"},{ 365,"一年"},{ 1095,"三年"},{ -1,"永久"},
};
//日志缓存时间下拉框
public Dictionary<int, string> LogTimeData { get => LogTimeData_; set { SetProperty(ref LogTimeData_, value); } }
#region
private List<string> scannerComList;
public List<string> ScannerComList
{
get { return scannerComList; }
set
{
SetProperty(ref scannerComList, value);
}
}
private string selectedScannerCom;
public string SelectedScannerCom
{
get { return selectedScannerCom; }
set
{
SetProperty(ref selectedScannerCom, value);
}
}
private List<string> comList;
public List<string> COMList
{
get { return comList; }
set
{
SetProperty(ref comList, value);
}
}
private string selectedCOM;
public string SelectedCOM
{
get { return selectedCOM; }
set
{
SetProperty(ref selectedCOM, value);
}
}
private bool Powerboot_;
public bool Powerboot { get => Powerboot_; set { SetProperty(ref Powerboot_, value); } }
private bool StartupFull_;
public bool StartupFull { get => StartupFull_; set { SetProperty(ref StartupFull_, value); } }
private bool IsSaveLogin_;
public bool IsSaveLogin { get => IsSaveLogin_; set { SetProperty(ref IsSaveLogin_, value); } }
private int SaveLoginCount_;
public int SaveLoginCount { get => SaveLoginCount_; set { SetProperty(ref SaveLoginCount_, value); } }
private int SaveLogDay_;
public int SaveLogDay { get => SaveLogDay_; set { SetProperty(ref SaveLogDay_, value); } }
#endregion
/// <summary>
/// 刷新界面
/// </summary>
public void Update()
{
#region
try
{
LocalFile.UpdateConfig();
ScannerComList = LocalFile.Config.ScannerComList;
Powerboot = LocalFile.Config.Sys.Powerboot;
StartupFull = LocalFile.Config.Sys.StartupFull;
IsSaveLogin = LocalFile.Config.Sys.IsSaveLogin;
SaveLoginCount = LocalFile.Config.Sys.SaveLoginCount;
SaveLogDay = LocalFile.Config.Sys.SaveLogDay;
}
catch (Exception ex)
{
Growl.Info($"获取配置失败。{ex.Message}");
}
#endregion
#region
RefreshCOMList();
#endregion
}
public ICommand SaveCommand { get => new DelegateCommand(Save); }
/// <summary>
/// 保存
/// </summary>
public void Save()
{
try
{
LocalFile.Config.Sys.Powerboot = Powerboot;
LocalFile.Config.Sys.StartupFull = StartupFull;
LocalFile.Config.Sys.IsSaveLogin = IsSaveLogin;
LocalFile.Config.Sys.SaveLoginCount = SaveLoginCount;
LocalFile.Config.Sys.SaveLogDay = SaveLogDay;
LocalFile.Config.ScannerComList = ScannerComList;
LocalFile.SaveConfig();
Growl.Success($"保存成功。");
RunPowerboot(Powerboot);
}
catch (Exception ex)
{
LocalFile.UpdateConfig();
Growl.Error($"保存失败。{ex.Message}");
}
}
private void RunPowerboot(bool isPowerboot)
{
try
{
if (isPowerboot)
{
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
rgkRun.SetValue(Path.GetFileNameWithoutExtension(LocalFile.AppName), "\"" + Path.Combine(LocalFile.AppDir, LocalFile.AppName) + "\"");
}
else
{
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun == null)
rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
rgkRun.DeleteValue(Path.GetFileNameWithoutExtension(LocalFile.AppName), false);
}
}
catch (Exception ex)
{
Logs.Write(ex);
}
}
public ICommand AddCOMCommand { get => new DelegateCommand(AddCOM); }
public void AddCOM()
{
//是否已选择COM号
if (SelectedCOM == null)
{
Growl.Warning("请选择串口!");
return;
}
//列表中是否存在
var isExsist = ScannerComList.Where(t => t == SelectedCOM).Any();
if (isExsist)
{
Growl.Warning($"已存在扫码枪{SelectedCOM}");
return;
}
//添加
ScannerComList.Add(SelectedCOM);
ScannerComList = ScannerComList.ToList();
}
public ICommand DeleteCOMCommand { get => new DelegateCommand(DeleteCOM); }
public void DeleteCOM()
{
//是否已选择COM号
if (SelectedScannerCom == null)
{
Growl.Warning("请在下方选择串口!");
return;
}
ScannerComList.RemoveAll(t => t == SelectedScannerCom);
ScannerComList = ScannerComList.ToList();
}
public ICommand RefreshCOMListCommand { get => new DelegateCommand(RefreshCOMList); }
public void RefreshCOMList()
{
try
{
COMList = SerialPort.GetPortNames().ToList();
}
catch
{
}
}
}
}

View File

@ -0,0 +1,170 @@
using Ping9719.WpfEx.Mvvm;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using WCS.Model;
using WCS.Model.ApiModel.Home;
using WCS.Model.ApiModel.StoreInfo;
using .Tool;
namespace .ViewModel
{
public class ShelfInfoAddOrUpdateViewModel : BindableBase
{
#region Property
public ShelfInfoAddOrUpdateViewModel()
{
ShelfTypeItems = GetBaseData.GetShelfType();
if (ShelfTypeItems != null && ShelfTypeItems.Count > 0)
SelectedShelfTypeItem = ShelfTypeItems.First();
}
public void SetValues(ShelfInfoModel shelfInfoModel)
{
if (shelfInfoModel != null)
{
ShelfId = shelfInfoModel.Id;
SelectedShelfTypeItem = shelfTypeItems.First(t => t.Id == shelfInfoModel.ShelfTypeId);
ShelfCode = shelfInfoModel.ShelfCode;
RowCounts = shelfInfoModel.Rowcounts;
ColumnCounts = shelfInfoModel.Columncounts;
LightId = shelfInfoModel.LightId;
ClientIp = shelfInfoModel.ClientIp;
GroupName = shelfInfoModel.GroupName;
IsBind = shelfInfoModel.IsBind;
BindShelfCode = shelfInfoModel.BindShelfCode;
}
}
public ShelfInfoModel GetValues()
{
return new ShelfInfoModel()
{
Id = ShelfId,
ShelfTypeId = SelectedShelfTypeItem.Id,
ShelfTypeName = SelectedShelfTypeItem.ShelfTypeName,
ShelfCode = ShelfCode,
Rowcounts = RowCounts,
Columncounts = ColumnCounts,
LightId = LightId,
ClientIp = ClientIp,
GroupName = GroupName,
IsBind = IsBind,
BindShelfCode = BindShelfCode,
};
}
private int shelfId;
public int ShelfId
{
get { return shelfId; }
set
{
SetProperty(ref shelfId, value);
}
}
private List<ShelfTypeModel> shelfTypeItems;
public List<ShelfTypeModel> ShelfTypeItems
{
get { return shelfTypeItems; }
set
{
SetProperty(ref shelfTypeItems, value);
}
}
private ShelfTypeModel selectedShelfTypeItem;
public ShelfTypeModel SelectedShelfTypeItem
{
get { return selectedShelfTypeItem; }
set
{
SetProperty(ref selectedShelfTypeItem, value);
}
}
private string shelfCode;
public string ShelfCode
{
get { return shelfCode; }
set
{
SetProperty(ref shelfCode, value);
}
}
private int rowCounts;
public int RowCounts
{
get { return rowCounts; }
set
{
SetProperty(ref rowCounts, value);
}
}
private int columnCounts;
public int ColumnCounts
{
get { return columnCounts; }
set
{
SetProperty(ref columnCounts, value);
}
}
private int lightId;
public int LightId
{
get { return lightId; }
set
{
SetProperty(ref lightId, value);
}
}
private string clientIp;
public string ClientIp
{
get { return clientIp; }
set
{
SetProperty(ref clientIp, value);
}
}
private string groupName;
public string GroupName
{
get { return groupName; }
set
{
SetProperty(ref groupName, value);
}
}
private bool isBind;
public bool IsBind
{
get { return isBind; }
set
{
SetProperty(ref isBind, value);
}
}
private string bindShelfCode;
public string BindShelfCode
{
get { return bindShelfCode; }
set
{
SetProperty(ref bindShelfCode, value);
}
}
#endregion
}
}

View File

@ -0,0 +1,287 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using .Views.Controls;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel.Home;
using WCS.Model.ApiModel.StoreInfo;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.User;
using WCS.Model.ApiModel;
using Newtonsoft.Json.Bson;
namespace .ViewModel
{
public class ShelfInfoViewModel : BindableBase
{
public ShelfInfoViewModel()
{
}
#region Property
private List<ShelfInfoModel> dataGridItemSource;
public List<ShelfInfoModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
private ShelfInfoModel selectedataGridItem;
public ShelfInfoModel SelectedataGridItem
{
get { return selectedataGridItem; }
set
{
SetProperty(ref selectedataGridItem, value);
}
}
/// <summary>
/// 物料批次
/// </summary>
private string shelfCode;
public string ShelfCode
{
get { return shelfCode; }
set
{
SetProperty(ref shelfCode, value);
}
}
private List<ShelfTypeModel> shelfTypeItems;
public List<ShelfTypeModel> ShelfTypeItems
{
get { return shelfTypeItems; }
set
{
SetProperty(ref shelfTypeItems, value);
}
}
public void InitShelfTypeItems()
{
//调用接口更新!
Task.Run(() =>
{
var body = new RequestBase()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<ShelfTypeModel>>(LocalFile.Config.ApiIpHost + "home/getShelfTypes", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists.Count() > 0)
{
ShelfTypeItems = Result.Data.Lists;
}
});
}
private ShelfTypeModel selectedShelfTypeItem;
public ShelfTypeModel SelectedShelfTypeItem
{
get { return selectedShelfTypeItem; }
set
{
SetProperty(ref selectedShelfTypeItem, value);
}
}
#endregion
#region Command
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
public void BtnReset()
{
SelectedShelfTypeItem = null;
ShelfCode = string.Empty;
}
public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); }
public void BtnSearchReset()
{
BtnSearch(true);
}
public void BtnSearch(bool IsPageReset = true)
{
if (CurrentPage == 0 || IsPageReset)
{
CurrentPage = 1;
return;
}
#region
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetShelvesRequest()
{
ShelfTypeId = SelectedShelfTypeItem == null ? 0 : SelectedShelfTypeItem.Id,
ShelfCode = ShelfCode,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<ShelfInfoModel>>(LocalFile.Config.ApiIpHost + "storeInfo/getShelves", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists != null)
{
DataGridItemSource = Result.Data.Lists;
MaxPage = Result.Data.MaxPage;
TotalCount = Result.Data.TotalCount;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
#endregion
}
/// <summary>
/// 物料新增操作
/// </summary>
public ICommand BtnAddCommand { get => new DelegateCommand(BtnAdd); }
public async void BtnAdd()
{
var addView = new ShelfInfoAddOrUpdateView("新增货架");
addView.ShowDialog();
if (addView.DialogResult == true)
{
//添加或修改成功后重新查询
CurrentPage = 1;
}
}
public ICommand BtnEditCommand { get => new DelegateCommand(BtnEdit); }
public async void BtnEdit()
{
//查询勾选的第一个数据
var shelfInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault();
if (shelfInfo == null)
{
Growl.Warning("请选择需要修改的数据!");
}
else
{
var addView = new ShelfInfoAddOrUpdateView("修改货架", shelfInfo);
addView.ShowDialog();
if (addView.DialogResult == true)
{
CurrentPage = 1;
}
}
}
public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); }
public void BtnDelete()
{
//查询勾选的第一个数据
var shelfInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault();
if (shelfInfo == null)
{
Growl.Warning("请选择需要删除的数据!");
}
else
{
var body = new AddShelfInfoRequest<ShelfInfoModel>()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
ShelfInfo = shelfInfo,
AddOrUpdate = AddOrUpdate.Delete
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<object>>(LocalFile.Config.ApiIpHost + "storeInfo/addOrUpdateShelfInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
Growl.Success("删除成功!");
CurrentPage = 1;
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
#endregion
#region PageOperation
private int currentPage;
public int CurrentPage
{
get { return currentPage; }
set
{
SetProperty(ref currentPage, value);
BtnSearch(false);
}
}
private int maxPage;
public int MaxPage
{
get { return maxPage; }
set { SetProperty(ref maxPage, value); }
}
//总数量
private int totalCount;
public int TotalCount
{
get { return totalCount; }
set { SetProperty(ref totalCount, value); }
}
public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); }
public void BtnFirstPage()
{
CurrentPage = 1;
}
public ICommand BtnPrePageCommand { get => new DelegateCommand(BtnPrePage); }
public void BtnPrePage()
{
if (CurrentPage > 1)
{
CurrentPage--;
}
}
public ICommand BtnNextPageCommand { get => new DelegateCommand(BtnNextPage); }
public void BtnNextPage()
{
if (CurrentPage < MaxPage)
{
CurrentPage++;
}
}
public ICommand BtnLastPageCommand { get => new DelegateCommand(BtnLastPage); }
public void BtnLastPage()
{
if (CurrentPage != MaxPage)
{
CurrentPage = MaxPage;
}
}
#endregion
}
}

View File

@ -0,0 +1,44 @@
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model.ApiModel;
namespace
{
public class UserInfoViewModel : BindableBase
{
private bool isLogin = false;
/// <summary>
/// 是否登录
/// </summary>
public bool IsLogin { get => isLogin; set { SetProperty(ref isLogin, value); } }
private string LoginName_;
/// <summary>
/// 登录名
/// </summary>
public string LoginName { get => LoginName_; set { SetProperty(ref LoginName_, value); } }
private object Auth_;
/// <summary>
/// 权限变化通知
/// </summary>
public object Auth { get => Auth_; set { SetProperty(ref Auth_, value); } }
private UserModel User_;
/// <summary>
/// 用户
/// </summary>
public UserModel User { get => User_; set { SetProperty(ref User_, value); LoginName = value?.LoginName ?? null; } }
private List<RoleModel> Roles_;
/// <summary>
/// 角色
/// </summary>
public List<RoleModel> Roles { get => Roles_; set { SetProperty(ref Roles_, value); Auth = new object(); } }
}
}

View File

@ -0,0 +1,137 @@
using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using SqlSugar;
using HandyControl.Data;
using System.Windows;
using Newtonsoft.Json.Linq;
using .Views.Controls;
using WCS.Model.ApiModel.User;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
namespace .ViewModel
{
public class UserViewModel : BindableBase
{
private List<UserModel> dataList = new List<UserModel>();
/// <summary>
/// 列表数据
/// </summary>
public List<UserModel> DataList { get => dataList; set { SetProperty(ref dataList, value); } }
#region
private string info1;
public string Info1 { get => info1; set { SetProperty(ref info1, value); } }
#endregion
public ICommand UpdateListCommand { get => new DelegateCommand(UpdateList); }
/// <summary>
/// 更新信息
/// </summary>
public void UpdateList()
{
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetUsersRequest()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
Info = Info1,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<List<UserModel>>>(LocalFile.Config.ApiIpHost + "user/getUsers", body, "POST");
if (Result != null && Result.Data != null)
{
DataList = Result.Data;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
}
public ICommand SeeCommand { get => new DelegateCommand<UserModel>(See); }
public void See(UserModel obj)
{
UserEditView.Show(obj, CrudEnum.Read);
}
public ICommand AddCommand { get => new DelegateCommand(Add); }
public void Add()
{
var isUp = UserEditView.Show(new UserModel(), CrudEnum.Create);
if (isUp)
{
UpdateList();
Growl.Success("创建成功");
}
}
public ICommand UpdateCommand { get => new DelegateCommand<UserModel>(Update); }
public void Update(UserModel obj)
{
var isUp = UserEditView.Show(obj, CrudEnum.Update);
if (isUp)
{
UpdateList();
Growl.Success("更新成功");
}
}
public ICommand DelCommand { get => new DelegateCommand<UserModel>(Del); }
public void Del(UserModel obj)
{
Growl.Ask($"是否删除用户[{obj.LoginName}]!", isConfirmed =>
{
if (isConfirmed)
{
try
{
var body = new AddUserRequest<UserModel>()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
User = obj,
AddOrUpdate = AddOrUpdate.Delete
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "user/addUser", body, "POST");
if (Result != null && Result.Code == 200)
{
UpdateList();
Growl.Success("删除成功");
}
else
{
Growl.Error($"删除失败:{Result.Message.ToString()}");
}
}
catch (Exception ex)
{
Growl.Error($"删除失败:{ex.ToString()}");
return true;
}
}
return true;
});
}
}
}

View File

@ -0,0 +1,57 @@
<pi:UserControlBase x:Class="货架标准上位机.DataChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="loadFirst">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<!--筛选栏-->
<Grid Margin="5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<UniformGrid Grid.Column="0" Columns="2">
<ComboBox Margin="5" ItemsSource="{Binding Year}" SelectedIndex="{Binding YearIndex}" Style="{StaticResource ComboBoxExtend}" hc:InfoElement.Placeholder="请选择年份" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="年份"></ComboBox>
<ComboBox Margin="5" ItemsSource="{Binding Month}" SelectedIndex="{Binding MonthIndex}" Style="{StaticResource ComboBoxExtend}" hc:InfoElement.Placeholder="请选择月份" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="月份"></ComboBox>
</UniformGrid>
<hc:UniformSpacingPanel Grid.Column="1" Spacing="5">
<Button Command="{Binding ButStatChartCommand}" Style="{StaticResource ButtonDefault}" Width="70" >刷新</Button>
</hc:UniformSpacingPanel>
</Grid>
<hc:LoadingLine VerticalAlignment="Top" IsRunning="{Binding IsLoad}" Visibility="{Binding IsLoad,Converter={StaticResource Boolean2VisibilityConverter}}"/>
<!--图表栏-->
<lvc:CartesianChart Grid.Row="1" Grid.ColumnSpan="3" LegendLocation="Top" >
<!--内容-->
<lvc:CartesianChart.Series>
<lvc:LineSeries LineSmoothness="0.3" Stroke="DeepSkyBlue" Title="总数量" Values="{Binding ChartValues1}" DataLabels="True"></lvc:LineSeries>
<lvc:LineSeries LineSmoothness="0.3" Stroke="LimeGreen" Title="合格数量" Values="{Binding ChartValues2}" DataLabels="False"></lvc:LineSeries>
<lvc:LineSeries LineSmoothness="0.3" Stroke="OrangeRed" Title="不合格数量" Values="{Binding ChartValues3}" DataLabels="False"></lvc:LineSeries>
</lvc:CartesianChart.Series>
<!--x轴-->
<lvc:CartesianChart.AxisX>
<!--<lvc:Axis Title="日期" LabelFormatter="{Binding LabelFormatterX}"></lvc:Axis>-->
<lvc:Axis Title="日期" Labels="{Binding ChartLabelsX}">
<!--显示所有的列-->
<lvc:Axis.Separator>
<lvc:Separator Step="1"></lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<!--y轴-->
<lvc:CartesianChart.AxisY>
<!--<lvc:Axis Title="数量" LabelFormatter="{Binding LabelFormatterY}"></lvc:Axis>-->
<lvc:Axis Title="数量" MinValue="0"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,44 @@
using .ViewModel;
using HandyControl.Controls;
using Ping9719.WpfEx;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace
{
/// <summary>
/// 数据图表
/// </summary>
public partial class DataChartView : UserControlBase
{
DataChartViewModel viewModel = new DataChartViewModel();
public DataChartView()
{
InitializeComponent();
this.DataContext = viewModel;
}
//第一次加载
private void loadFirst(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
viewModel.UpdataYear();
}
}
}

View File

@ -0,0 +1,62 @@
<pi:UserControlBase x:Class="货架标准上位机.DataListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="loadFirst">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<!--条件区-->
<Grid Margin="5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<UniformGrid Grid.Column="0" Columns="4">
<hc:DateTimePicker SelectedDateTime="{Binding TimeGo}" Margin="5" Style="{StaticResource DateTimePickerExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="开始时间" VerticalAlignment="Center"/>
<hc:DateTimePicker SelectedDateTime="{Binding TimeTo}" Margin="5" Style="{StaticResource DateTimePickerExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="结束时间" VerticalAlignment="Center"/>
<hc:TextBox Text="{Binding Info1}" Margin="5" Style="{StaticResource TextBoxExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="信息1" hc:InfoElement.Placeholder="模糊匹配" VerticalAlignment="Center"/>
<hc:TextBox Text="{Binding Info2}" Margin="5" Style="{StaticResource TextBoxExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="信息2" hc:InfoElement.Placeholder="模糊匹配" VerticalAlignment="Center"/>
</UniformGrid>
<hc:UniformSpacingPanel Grid.Column="1" Spacing="5">
<Button Content="导出Excel" Command="{Binding ExportExcelCommand}" Style="{StaticResource ButtonSuccess}" Width="80"></Button>
<Button Content="查询" Command="{Binding UpdateListCommand}" Style="{StaticResource ButtonPrimary}" Width="70"></Button>
</hc:UniformSpacingPanel>
</Grid>
<hc:LoadingLine VerticalAlignment="Top" IsRunning="{Binding IsLoad}" Visibility="{Binding IsLoad,Converter={StaticResource Boolean2VisibilityConverter}}"/>
<!--内容区-->
<Border Grid.Row="1" Style="{StaticResource BorderRegion}" BorderThickness="1" Background="#EEEEEE" Margin="3,0,3,3" Padding="0" >
<DataGrid RowHeaderWidth="50" HeadersVisibility="All" AutoGenerateColumns="False" ItemsSource="{Binding DataList}" hc:DataGridAttach.CanUnselectAllWithBlankArea="False" hc:DataGridAttach.ShowSelectAllButton="False" hc:DataGridAttach.ShowRowNumber="True">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Info1}" Header="信息1" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Info2}" Header="信息2" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Status}" Header="状态结果" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Time,StringFormat=yyyy-MM-dd HH:mm}" Header="测试时间" CanUserSort="False"/>
<DataGridTemplateColumn CanUserResize="False" Width="auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource ButtonSuccess}" IsEnabled="True" Content="详情" Width="70" Command="{Binding DataContext.SeeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>
<!--页码区-->
<hc:Pagination Grid.Row="2" AutoHiding="True" MaxPageCount="{Binding MaxPageCount}" PageIndex="{Binding PageIndex}" DataCountPerPage="{Binding DataCountPerPage}" IsJumpEnabled="False" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,3" FontSize="16" >
<hc:Interaction.Triggers>
<hc:EventTrigger EventName="PageUpdated">
<hc:EventToCommand Command="{Binding PageUpdateCommand}" PassEventArgsToCommand="True" />
</hc:EventTrigger>
</hc:Interaction.Triggers>
</hc:Pagination>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,45 @@
using .ViewModel;
using HandyControl.Controls;
using Microsoft.Win32;
using MiniExcelLibs;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace
{
/// <summary>
/// 数据列表
/// </summary>
public partial class DataListView : UserControlBase
{
DataListViewModel viewModel = new DataListViewModel();
public DataListView()
{
InitializeComponent();
this.DataContext = viewModel;
}
//第一次加载
private void loadFirst(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
viewModel.UpdateList();
}
}
}

View File

@ -0,0 +1,64 @@
<pi:UserControlBase x:Class="货架标准上位机.DataListWarnInfoView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="loadFirst">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<!--条件区-->
<Grid Margin="5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<UniformGrid Grid.Column="0" Columns="4">
<hc:DateTimePicker SelectedDateTime="{Binding TimeGo}" Margin="5" Style="{StaticResource DateTimePickerExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="开始时间" VerticalAlignment="Center"/>
<hc:DateTimePicker SelectedDateTime="{Binding TimeTo}" Margin="5" Style="{StaticResource DateTimePickerExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="结束时间" VerticalAlignment="Center"/>
<hc:TextBox Text="{Binding Info1}" Margin="5" Style="{StaticResource TextBoxExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="来源" hc:InfoElement.Placeholder="模糊匹配" VerticalAlignment="Center"/>
<hc:TextBox Text="{Binding Info2}" Margin="5" Style="{StaticResource TextBoxExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="级别" hc:InfoElement.Placeholder="模糊匹配" VerticalAlignment="Center"/>
</UniformGrid>
<hc:UniformSpacingPanel Grid.Column="1" Spacing="5">
<ToggleButton Content="导出Excel" Command="{Binding ExportExcelCommand}" Style="{StaticResource ToggleButtonLoadingSuccess}" IsChecked="{Binding IsLoad1}" Width="80"></ToggleButton>
<ToggleButton Content="查询" Command="{Binding UpdateListCommand}" Style="{StaticResource ToggleButtonLoadingPrimary}" IsChecked="{Binding IsLoad2}" Width="70"></ToggleButton>
</hc:UniformSpacingPanel>
</Grid>
<!--内容区-->
<Border Grid.Row="1" Style="{StaticResource BorderRegion}" BorderThickness="1" Background="#EEEEEE" Margin="3,0,3,3" Padding="0" >
<DataGrid RowHeaderWidth="50" HeadersVisibility="All" AutoGenerateColumns="False" ItemsSource="{Binding DataList}" hc:DataGridAttach.CanUnselectAllWithBlankArea="False" hc:DataGridAttach.ShowSelectAllButton="False" hc:DataGridAttach.ShowRowNumber="True">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Width="100" Binding="{Binding Source}" Header="来源" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Text}" Header="信息" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="100" Binding="{Binding Level}" Header="级别" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Solution}" Header="解决方案" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="100" Binding="{Binding WarnType}" Header="警告类型" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding TimeGo,StringFormat=yyyy-MM-dd HH:mm}" Header="开始时间" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="160" Binding="{Binding DuraTime}" Header="持续时间" CanUserSort="False"/>
<!--<DataGridTemplateColumn CanUserResize="False" Width="auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource ButtonSuccess}" IsEnabled="True" Content="详情" Width="70" Command="{Binding DataContext.SeeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>-->
</DataGrid.Columns>
</DataGrid>
</Border>
<!--页码区-->
<hc:Pagination Grid.Row="2" AutoHiding="True" MaxPageCount="{Binding MaxPageCount}" PageIndex="{Binding PageIndex}" DataCountPerPage="{Binding DataCountPerPage}" IsJumpEnabled="False" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,3" FontSize="16" >
<hc:Interaction.Triggers>
<hc:EventTrigger EventName="PageUpdated">
<hc:EventToCommand Command="{Binding PageUpdateCommand}" PassEventArgsToCommand="True" />
</hc:EventTrigger>
</hc:Interaction.Triggers>
</hc:Pagination>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,45 @@
using .ViewModel;
using HandyControl.Controls;
using Microsoft.Win32;
using MiniExcelLibs;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace
{
/// <summary>
/// 数据列表
/// </summary>
public partial class DataListWarnInfoView : UserControlBase
{
DataListWarnInfoViewModel viewModel = new DataListWarnInfoViewModel();
public DataListWarnInfoView()
{
InitializeComponent();
this.DataContext = viewModel;
}
//第一次加载
private void loadFirst(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
viewModel.UpdateList();
}
}
}

View File

@ -0,0 +1,138 @@
<pi:UserControlBase x:Class="货架标准上位机.DeviceView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="visfir" IsVisibleChanged="vis">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="模式选择" Margin="3" Style="{StaticResource GroupBoxTab}">
<StackPanel Orientation="Horizontal">
<Button Margin="5,3" Padding="30,0" Content="初始化"></Button>
</StackPanel>
</GroupBox>
<hc:ScrollViewer Grid.Row="1" Margin="3,3" IsInertiaEnabled="True" hc:ScrollViewerAttach.AutoHide="True">
<StackPanel Margin="0" Orientation="Vertical">
<!--监听-->
<Border Style="{StaticResource BorderRegion}" Effect="{StaticResource EffectShadow1}" Visibility="{Binding IsVisRead,Converter={StaticResource Boolean2VisibilityConverter}}">
<Expander Style="{StaticResource BaseStyle}" Margin="0" Header="监听" IsExpanded="{Binding IsVisExpRead}">
<hc:TransitioningContentControl TransitionMode="Top2BottomWithFade">
<!--<local:IotReadListView Margin="0,10,0,0" Data="{Binding DataRead}"/>-->
<StackPanel x:Name="stackPanel1">
<StackPanel.Resources>
<ResourceDictionary>
<Style TargetType="pi:IotStateInfo" BasedOn="{StaticResource IotStateInfoStyle}">
<Setter Property="Width" Value="150"></Setter>
<Setter Property="Margin" Value="3,1"></Setter>
<!--<Setter Property="BorderThickness" Value="1"></Setter>-->
<Setter Property="Opacity" Value="0.8"></Setter>
<Setter Property="OkBrush" Value="DarkTurquoise"></Setter>
</Style>
</ResourceDictionary>
</StackPanel.Resources>
<WrapPanel>
<pi:IotStateInfo Header="传感器1" Value="false"></pi:IotStateInfo>
<pi:IotStateInfo Header="传感器2" Value="True"></pi:IotStateInfo>
</WrapPanel>
<Expander Header="分组1" IsExpanded="True" BorderThickness="0" Background="{StaticResource DefaultBrush}">
<WrapPanel>
<pi:IotStateInfo Header="温度1" Value="1.23"></pi:IotStateInfo>
</WrapPanel>
</Expander>
</StackPanel>
</hc:TransitioningContentControl>
</Expander>
</Border>
<!--控制-->
<Border Margin="0,10,0,0" Style="{StaticResource BorderRegion}" Effect="{StaticResource EffectShadow1}" Visibility="{Binding IsVisWrite,Converter={StaticResource Boolean2VisibilityConverter}}">
<Expander Style="{StaticResource BaseStyle}" Margin="0" Header="控制" IsExpanded="{Binding IsVisExpWrite}">
<hc:TransitioningContentControl TransitionMode="Top2BottomWithFade">
<!--<local:IotWriteListView Margin="0,10,0,0" Data="{Binding DataWrite}"/>-->
<StackPanel x:Name="stackPanel2">
<StackPanel.Resources>
<ResourceDictionary>
<Style TargetType="pi:IotStateInfo" BasedOn="{StaticResource IotStateInfoStyle}">
<Setter Property="Width" Value="150"></Setter>
<Setter Property="Margin" Value="3,1"></Setter>
</Style>
</ResourceDictionary>
</StackPanel.Resources>
<WrapPanel>
<pi:IotStateInfo Header="传感器1" Value="false"></pi:IotStateInfo>
<pi:IotStateInfo Header="传感器2" Value="True"></pi:IotStateInfo>
</WrapPanel>
<Expander Header="分组1" IsExpanded="True" BorderThickness="0" Background="{StaticResource DefaultBrush}">
<WrapPanel>
<pi:IotStateInfo Header="温度1" Value="1.23"></pi:IotStateInfo>
</WrapPanel>
</Expander>
</StackPanel>
</hc:TransitioningContentControl>
</Expander>
</Border>
<!--气缸-->
<Border Margin="0,10,0,0" Style="{StaticResource BorderRegion}" Effect="{StaticResource EffectShadow1}" Visibility="{Binding IsVisUrn,Converter={StaticResource Boolean2VisibilityConverter}}">
<Expander Style="{StaticResource BaseStyle}" Margin="0" Header="气缸" IsExpanded="{Binding IsVisExpUrn}">
<hc:TransitioningContentControl TransitionMode="Top2BottomWithFade">
<!--<local:IotUrnListView Margin="0,10,0,0" Data="{Binding DataUrn}"/>-->
<StackPanel x:Name="stackPanel3">
<StackPanel.Resources>
<ResourceDictionary>
<Style TargetType="pi:IotUrnMode" BasedOn="{StaticResource IotUrnModeStyle}">
<Setter Property="Margin" Value="3,1"></Setter>
</Style>
</ResourceDictionary>
</StackPanel.Resources>
<WrapPanel>
<pi:IotUrnMode Text="气缸1"></pi:IotUrnMode>
<pi:IotUrnMode Text="气缸1" IsButBadge1="True"></pi:IotUrnMode>
</WrapPanel>
<Expander Header="分组1" IsExpanded="True" BorderThickness="0" Background="{StaticResource DefaultBrush}">
<WrapPanel>
<pi:IotUrnMode Text="气缸1"></pi:IotUrnMode>
</WrapPanel>
</Expander>
</StackPanel>
</hc:TransitioningContentControl>
</Expander>
</Border>
<!--伺服-->
<Border Margin="0,10,0,0" Style="{StaticResource BorderRegion}" Effect="{StaticResource EffectShadow1}" Visibility="{Binding IsVisServo,Converter={StaticResource Boolean2VisibilityConverter}}">
<Expander Style="{StaticResource BaseStyle}" Margin="0" Header="伺服" IsExpanded="{Binding IsVisExpServo}">
<hc:TransitioningContentControl TransitionMode="Top2BottomWithFade">
<!--<local:IotServoListView Margin="0,10,0,0" Data="{Binding DataServo}"/>-->
<StackPanel x:Name="stackPanel4">
<StackPanel.Resources>
<ResourceDictionary>
<Style TargetType="pi:IotServoMode" BasedOn="{StaticResource IotServoModeStyle}">
<Setter Property="Margin" Value="3,1"></Setter>
<Setter Property="VerticalAlignment" Value="Top"></Setter>
</Style>
</ResourceDictionary>
</StackPanel.Resources>
<WrapPanel>
<pi:IotServoMode Text="伺服1"/>
<pi:IotServoMode Text="伺服1"/>
</WrapPanel>
<Expander Header="分组1" IsExpanded="True" BorderThickness="0" Background="{StaticResource DefaultBrush}">
<WrapPanel>
<pi:IotServoMode Text="伺服1"/>
<pi:IotServoMode Text="伺服1"/>
</WrapPanel>
</Expander>
</StackPanel>
</hc:TransitioningContentControl>
</Expander>
</Border>
</StackPanel>
</hc:ScrollViewer>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,390 @@
using .ViewModel;
using HandyControl.Controls;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace
{
/// <summary>
/// 设备手动信息
/// </summary>
public partial class DeviceView : UserControlBase
{
DeviceViewModel viewModel = new DeviceViewModel();
public DeviceView()
{
InitializeComponent();
//viewModel.plc = LocalStatic.Plc;
this.DataContext = viewModel;
}
//第一次显示渲染Ui
private void visfir(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
if (!System.IO.File.Exists(LocalFile.PlcDotPath))
{
Growl.Info($"没有找到文档[{LocalFile.PlcDotPath}],请联系管理员。");
return;
}
//读Excel
viewModel.DataReads = ExcelDeviceReadModel.GetDatas();
viewModel.DataWrites = ExcelDeviceWriteModel.GetDatas();
viewModel.DataUrns = ExcelDeviceUrnModel.GetDatas();
viewModel.DataServos = ExcelDeviceServoModel.GetDatas();
//加载页面
ReadUi(viewModel.DataReads);
WriteUi(viewModel.DataWrites);
UrnUi(viewModel.DataUrns);
ServoUi(viewModel.DataServos);
//展示限制
viewModel.IsVisRead = viewModel.DataReads.Any();
viewModel.IsVisWrite = viewModel.DataWrites.Any();
viewModel.IsVisUrn = viewModel.DataUrns.Any();
viewModel.IsVisServo = viewModel.DataServos.Any();
Task.Run(viewModel.WhileRead);
}
private void vis(object sender, DependencyPropertyChangedEventArgs e)
{
if (IsInDesignMode)
return;
viewModel.IsVis = (bool)e.NewValue;
}
#region
void ReadUi(IEnumerable<DeviceReadModel> data)
{
stackPanel1.Children.Clear();
if (data == null || !data.Any())
return;
var moren = data.Where(o => string.IsNullOrWhiteSpace(o.ExcelTag.));
var group = data.Where(o => !string.IsNullOrWhiteSpace(o.ExcelTag.)).GroupBy(o => o.ExcelTag.);
if (moren.Any())
{
WrapPanel wrapPanel = new WrapPanel();
foreach (var item in moren)
{
item.Value = item.ExcelTag..Trim().ToLower() == "bool" ? false : "-";
item.IsExpanded = true;
IotStateInfo iotState = new IotStateInfo();
iotState.DataContext = item;
iotState.SetBinding(IotStateInfo.HeaderProperty, nameof(item.Name));
iotState.SetBinding(IotStateInfo.ValueProperty, nameof(item.Value));
iotState.SetBinding(IotStateInfo.PostfixProperty, $"{nameof(item.ExcelTag)}.{nameof(item.ExcelTag.单位)}");
wrapPanel.Children.Add(iotState);
}
stackPanel1.Children.Add(wrapPanel);
}
if (group.Any())
{
foreach (var item in group)
{
Expander expander = new Expander();
expander.Header = item.Key;
expander.Tag = item;
expander.Expanded += (s, e) =>
{
var c = (IGrouping<string, DeviceReadModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = true;
}
};
expander.Collapsed += (s, e) =>
{
var c = (IGrouping<string, DeviceReadModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = false;
}
};
WrapPanel wrapPanel = new WrapPanel();
foreach (var item2 in item)
{
item2.Value = item2.ExcelTag..Trim().ToLower() == "bool" ? false : "-";
IotStateInfo iotState = new IotStateInfo();
iotState.DataContext = item2;
iotState.SetBinding(IotStateInfo.HeaderProperty, nameof(item2.Name));
iotState.SetBinding(IotStateInfo.ValueProperty, nameof(item2.Value));
iotState.SetBinding(IotStateInfo.PostfixProperty, $"{nameof(item2.ExcelTag)}.{nameof(item2.ExcelTag.单位)}");
wrapPanel.Children.Add(iotState);
}
expander.Content = wrapPanel;
stackPanel1.Children.Add(expander);
}
}
}
void WriteUi(IEnumerable<DeviceWriteModel> data)
{
if (true)
{
stackPanel2.Children.Clear();
if (data == null || !data.Any())
return;
var moren = data.Where(o => string.IsNullOrWhiteSpace(o.ExcelTag.));
var group = data.Where(o => !string.IsNullOrWhiteSpace(o.ExcelTag.)).GroupBy(o => o.ExcelTag.);
if (moren.Any())
{
WrapPanel wrapPanel = new WrapPanel();
foreach (var item in moren)
{
item.Value = item.ExcelTag..Trim().ToLower() == "bool" ? false : "-";
item.IsExpanded = true;
IotStateInfo iotState = new IotStateInfo();
iotState.DataContext = item;
iotState.Click += viewModel.WriteClick;
iotState.PreviewMouseLeftButtonDown += viewModel.LeftDown;
iotState.PreviewMouseLeftButtonUp += viewModel.LeftUp;
iotState.SetBinding(IotStateInfo.HeaderProperty, nameof(item.Name));
iotState.SetBinding(IotStateInfo.ValueProperty, nameof(item.Value));
iotState.SetBinding(IotStateInfo.PostfixProperty, $"{nameof(item.ExcelTag)}.{nameof(item.ExcelTag.单位)}");
wrapPanel.Children.Add(iotState);
}
stackPanel2.Children.Add(wrapPanel);
}
if (group.Any())
{
foreach (var item in group)
{
Expander expander = new Expander();
expander.Header = item.Key;
expander.Tag = item;
expander.Expanded += (s, e) =>
{
var c = (IGrouping<string, DeviceWriteModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = true;
}
};
expander.Collapsed += (s, e) =>
{
var c = (IGrouping<string, DeviceWriteModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = false;
}
};
WrapPanel wrapPanel = new WrapPanel();
foreach (var item2 in item)
{
item2.Value = item2.ExcelTag..Trim().ToLower() == "bool" ? false : "-";
IotStateInfo iotState = new IotStateInfo();
iotState.DataContext = item2;
iotState.Click += viewModel.WriteClick;
iotState.PreviewMouseLeftButtonDown += viewModel.LeftDown;
iotState.PreviewMouseLeftButtonUp += viewModel.LeftUp;
iotState.SetBinding(IotStateInfo.HeaderProperty, nameof(item2.Name));
iotState.SetBinding(IotStateInfo.ValueProperty, nameof(item2.Value));
iotState.SetBinding(IotStateInfo.PostfixProperty, $"{nameof(item2.ExcelTag)}.{nameof(item2.ExcelTag.单位)}");
wrapPanel.Children.Add(iotState);
}
expander.Content = wrapPanel;
stackPanel2.Children.Add(expander);
}
}
}
}
void UrnUi(IEnumerable<DeviceUrnModel> data)
{
if (true)
{
stackPanel3.Children.Clear();
if (data == null || !data.Any())
return;
var moren = data.Where(o => string.IsNullOrWhiteSpace(o.ExcelTag.));
var group = data.Where(o => !string.IsNullOrWhiteSpace(o.ExcelTag.)).GroupBy(o => o.ExcelTag.);
if (moren.Any())
{
WrapPanel wrapPanel = new WrapPanel();
foreach (var item in moren)
{
item.IsExpanded = true;
IotUrnMode iotUrn = new IotUrnMode();
iotUrn.DataContext = item;
iotUrn.SetBinding(IotUrnMode.TextProperty, nameof(item.Name));
iotUrn.SetBinding(IotUrnMode.IsButBadge1Property, nameof(item.IsGoTo));
iotUrn.SetBinding(IotUrnMode.IsButBadge2Property, nameof(item.IsRetTo));
iotUrn.Button1.Click += viewModel.Button1_Click;
iotUrn.Button1.PreviewMouseLeftButtonDown += viewModel.But1ClickDown;
iotUrn.Button1.PreviewMouseLeftButtonUp += viewModel.But1ClickUp;
iotUrn.Button2.Click += viewModel.Button2_Click;
iotUrn.Button2.PreviewMouseLeftButtonDown += viewModel.But2ClickDown;
iotUrn.Button2.PreviewMouseLeftButtonUp += viewModel.But2ClickUp;
wrapPanel.Children.Add(iotUrn);
}
stackPanel3.Children.Add(wrapPanel);
}
if (group.Any())
{
foreach (var item in group)
{
Expander expander = new Expander();
expander.Header = item.Key;
expander.Tag = item;
expander.Expanded += (s, e) =>
{
var c = (IGrouping<string, DeviceUrnModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = true;
}
};
expander.Collapsed += (s, e) =>
{
var c = (IGrouping<string, DeviceUrnModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = false;
}
};
WrapPanel wrapPanel = new WrapPanel();
foreach (var item2 in item)
{
IotUrnMode iotUrn = new IotUrnMode();
iotUrn.DataContext = item2;
iotUrn.SetBinding(IotUrnMode.TextProperty, nameof(item2.Name));
iotUrn.SetBinding(IotUrnMode.IsButBadge1Property, nameof(item2.IsGoTo));
iotUrn.SetBinding(IotUrnMode.IsButBadge2Property, nameof(item2.IsRetTo));
iotUrn.Button1.Click += viewModel.Button1_Click;
iotUrn.Button1.PreviewMouseLeftButtonDown += viewModel.But1ClickDown;
iotUrn.Button1.PreviewMouseLeftButtonUp += viewModel.But1ClickUp;
iotUrn.Button2.Click += viewModel.Button2_Click;
iotUrn.Button2.PreviewMouseLeftButtonDown += viewModel.But2ClickDown;
iotUrn.Button2.PreviewMouseLeftButtonUp += viewModel.But2ClickUp;
wrapPanel.Children.Add(iotUrn);
}
expander.Content = wrapPanel;
stackPanel3.Children.Add(expander);
}
}
}
}
void ServoUi(IEnumerable<DeviceServoModel> data)
{
if (true)
{
stackPanel4.Children.Clear();
if (data == null || !data.Any())
return;
var moren = data.Where(o => string.IsNullOrWhiteSpace(o.ExcelTag.));
var group = data.Where(o => !string.IsNullOrWhiteSpace(o.ExcelTag.)).GroupBy(o => o.ExcelTag.);
if (moren.Any())
{
WrapPanel wrapPanel = new WrapPanel();
foreach (var item in moren)
{
item.IsExpanded = true;
IotServoMode iotServo = new IotServoMode();
iotServo.DataContext = item;
iotServo.SetBinding(IotServoMode.TextProperty, nameof(item.Name));
iotServo.SetBinding(IotServoMode.Speed1Property, nameof(item.JogSpeed));
iotServo.SetBinding(IotServoMode.Speed2Property, nameof(item.AutoSpeed));
iotServo.SetBinding(IotServoMode.LocationProperty, nameof(item.Location));
iotServo.SetBinding(IotServoMode.IsVis1Property, new Binding(nameof(item.IsJog)) { Mode = BindingMode.TwoWay });
iotServo.SetBinding(IotServoMode.IsFoldProperty, new Binding(nameof(item.IsFold)) { Mode = BindingMode.TwoWay });
iotServo.LocationChange += viewModel.LocationChange;
iotServo.SpeedChange += viewModel.SpeedChange;
wrapPanel.Children.Add(iotServo);
}
stackPanel4.Children.Add(wrapPanel);
}
if (group.Any())
{
foreach (var item in group)
{
Expander expander = new Expander();
expander.Header = item.Key;
expander.Tag = item;
expander.Expanded += (s, e) =>
{
var c = (IGrouping<string, DeviceServoModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = true;
}
};
expander.Collapsed += (s, e) =>
{
var c = (IGrouping<string, DeviceServoModel>)((Expander)s).Tag;
foreach (var item in c)
{
item.IsExpanded = false;
}
};
WrapPanel wrapPanel = new WrapPanel();
foreach (var item2 in item)
{
IotServoMode iotServo = new IotServoMode();
iotServo.DataContext = item2;
iotServo.SetBinding(IotServoMode.TextProperty, nameof(item2.Name));
iotServo.SetBinding(IotServoMode.Speed1Property, nameof(item2.JogSpeed));
iotServo.SetBinding(IotServoMode.Speed2Property, nameof(item2.AutoSpeed));
iotServo.SetBinding(IotServoMode.LocationProperty, nameof(item2.Location));
iotServo.SetBinding(IotServoMode.IsVis1Property, new Binding(nameof(item2.IsJog)) { Mode = BindingMode.TwoWay });
iotServo.SetBinding(IotServoMode.IsFoldProperty, new Binding(nameof(item2.IsFold)) { Mode = BindingMode.TwoWay });
iotServo.LocationChange += viewModel.LocationChange;
iotServo.SpeedChange += viewModel.SpeedChange;
wrapPanel.Children.Add(iotServo);
}
expander.Content = wrapPanel;
stackPanel4.Children.Add(expander);
}
}
}
}
#endregion
}
}

View File

@ -0,0 +1,26 @@
<UserControl xmlns:hc="https://handyorg.github.io/handycontrol" x:Class="货架标准上位机.ImageListenerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Border Style="{StaticResource BorderRegion}" BorderThickness="1" Background="{DynamicResource SecondaryRegionBrush}" Padding="0" ClipToBounds="True">
<Border.Resources>
<TransformGroup x:Key="Imageview">
<ScaleTransform ScaleX="{Binding ScaleXY}" ScaleY="{Binding ScaleXY}" CenterX="{Binding CenterX}" CenterY="{Binding CenterY}"/>
<TranslateTransform X="{Binding TranslateX}" Y="{Binding TranslateY}"/>
</TransformGroup>
</Border.Resources>
<Image x:Name="img" RenderTransform="{StaticResource Imageview}" Source="{Binding ImageSource}" PreviewMouseLeftButtonDown="previewMouseDoubleClick">
<Image.ContextMenu>
<ContextMenu>
<MenuItem Header="预览图片" Click="ckyt"></MenuItem>
<MenuItem Header="适应窗口" Click="syck"></MenuItem>
<MenuItem Header="原图大小" Click="ytdx"></MenuItem>
</ContextMenu>
</Image.ContextMenu>
</Image>
</Border>
</UserControl>

View File

@ -0,0 +1,236 @@
using .ViewModel;
using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Path = System.IO.Path;
namespace
{
/// <summary>
/// 图像监听。可针对文件夹文件进行监听显示
/// </summary>
public partial class ImageListenerView : UserControl
{
ImageListenerViewModel viewModel = new ImageListenerViewModel();
public FileSystemWatcher FileWatcher = new FileSystemWatcher();
/// <summary>
/// 当前加载的图像路径
/// </summary>
public string FullPath { get; private set; }
public ImageListenerView()
{
InitializeComponent();
this.DataContext = viewModel;
//拖动
img.MouseLeftButtonDown += Img_MouseLeftButtonDown;
img.MouseLeftButtonUp += Img_MouseLeftButtonUp;
img.MouseMove += Img_MouseMove;
//鼠标滚轮
this.MouseWheel += Img_MouseWheel;
//监听
FileWatcher.Changed += FileSystemWatcher;
}
/// <summary>
/// 如果在选项卡中是否自动切换到当前变化的项来。默认为false
/// </summary>
public bool IsAutoActiveTabItem
{
get { return (bool)GetValue(IsAutoActiveTabItemProperty); }
set { SetValue(IsAutoActiveTabItemProperty, value); }
}
public static readonly DependencyProperty IsAutoActiveTabItemProperty =
DependencyProperty.Register("IsAutoActiveTabItem", typeof(bool), typeof(ImageListenerView), new PropertyMetadata(false));
/// <summary>
/// 开始监听
/// </summary>
/// <param name="path">监听的目录或文件</param>
/// <param name="filter">对目录的筛选值(文件无效)</param>
public void StartListener(string path, string filter = "*.jpg")
{
FileWatcher.EnableRaisingEvents = false;
path = (path ?? "").Trim();
if (string.IsNullOrEmpty(path))
return;
if (Path.HasExtension(path))
{
var ext = Path.GetFileName(path);
if (!string.IsNullOrEmpty(ext))
filter = ext;
path = Path.GetDirectoryName(path);
}
Directory.CreateDirectory(path);
FileWatcher.Path = path;
FileWatcher.Filter = filter;
FileWatcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.LastAccess;
FileWatcher.IncludeSubdirectories = false;
FileWatcher.EnableRaisingEvents = true;
}
/// <summary>
/// 停止监听
/// </summary>
public void StopListener()
{
FileWatcher.EnableRaisingEvents = false;
}
string FullPathTop = string.Empty;
private void FileSystemWatcher(object sender, FileSystemEventArgs e)
{
if (FullPathTop == e.FullPath)
return;
FullPathTop = e.FullPath;
Thread.Sleep(400);//确保大图片的成功
this.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
viewModel.ImageSource = null;
viewModel.ImageSource = BitmapFrame.Create(new Uri(e.FullPath), BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnLoad);
viewModel.ImageHeight = viewModel.ImageSource.Height;
viewModel.ImageWidth = viewModel.ImageSource.Width;
FullPath = e.FullPath;
viewModel.ImgAutoSize();
if (IsAutoActiveTabItem)
{
if (this.Parent is System.Windows.Controls.TabItem tabItem)
{
if (tabItem.Parent is System.Windows.Controls.TabControl tabControl)
{
tabControl.SelectedItem = tabItem;
}
}
}
}
catch (Exception)
{
}
finally
{
FullPathTop = string.Empty;
}
}));
}
#region
private bool mouseLeftDown = false;
private Point mouseLeftXY;
private void Img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
mouseLeftDown = true;
mouseLeftXY = e.GetPosition((FrameworkElement)this);
}
private void Img_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
mouseLeftDown = false;
}
private void Img_MouseMove(object sender, MouseEventArgs e)
{
if (mouseLeftDown && e.LeftButton == MouseButtonState.Pressed)
{
var position = e.GetPosition((FrameworkElement)this);
viewModel.TranslateX -= mouseLeftXY.X - position.X;
viewModel.TranslateY -= mouseLeftXY.Y - position.Y;
mouseLeftXY = position;
}
}
private void Img_MouseWheel(object sender, MouseWheelEventArgs e)
{
var delta = e.Delta * 0.001;
var scaleXY = viewModel.ScaleXY + delta;
if (scaleXY < 0.05 || scaleXY > 5)
return;
viewModel.CenterX = img.ActualWidth / 2;
viewModel.CenterY = img.ActualHeight / 2;
//校正
var point = Mouse.GetPosition(img);
//图片外
if (point.X < 0 || point.Y < 0 || point.X > img.ActualWidth || point.Y > img.ActualHeight)
{
//不需要校正
}
else
{
var lx = img.ActualWidth / 2.00 - point.X;
var ly = img.ActualHeight / 2.00 - point.Y;
var pyx = lx * scaleXY - lx * viewModel.ScaleXY;
var pyy = ly * scaleXY - ly * viewModel.ScaleXY;
viewModel.TranslateX += pyx;
viewModel.TranslateY += pyy;
}
viewModel.ScaleXY = scaleXY;
}
#endregion
#region
DateTime dtsj = DateTime.Now;
private void previewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if ((DateTime.Now - dtsj).TotalMilliseconds <= 300)
{
if (e.ChangedButton == MouseButton.Left && !string.IsNullOrEmpty(FullPath))
if (File.Exists(FullPath))
new ImageBrowser(new Uri(FullPath)).Show();
}
dtsj = DateTime.Now;
}
private void ckyt(object sender, RoutedEventArgs e)
{
if (File.Exists(FullPath))
new ImageBrowser(new Uri(FullPath)).Show();
}
private void syck(object sender, RoutedEventArgs e)
{
viewModel.ImgAutoSize();
}
private void ytdx(object sender, RoutedEventArgs e)
{
viewModel.ScaleXY = viewModel.ImageWidth / this.ActualWidth;
viewModel.CenterX = img.ActualWidth / 2;
viewModel.CenterY = img.ActualHeight / 2;
viewModel.TranslateX = 0;
viewModel.TranslateY = 0;
}
#endregion
}
}

View File

@ -0,0 +1,35 @@
<pi:UserControlBase x:Class="货架标准上位机.OutputStatChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
xmlns:pi="https://github.com/ping9719/wpfex"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="loadFir">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Title,FallbackValue=当日生产统计}" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource TextBlockDefaultSecLight}"></TextBlock>
<StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding IsZero,Converter={StaticResource Boolean2VisibilityConverter}}">
<TextBlock FontSize="40" FontFamily="{StaticResource IconFont}" Text="&#xeb91;">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1">
<GradientStop Color="White"/>
<GradientStop Color="Gray" Offset="1"/>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
<TextBlock Foreground="Gray" HorizontalAlignment="Center">无数据</TextBlock>
</StackPanel>
<lvc:PieChart Grid.Row="1" LegendLocation="Bottom">
<lvc:PieChart.Series>
<lvc:PieSeries Title="合格" Fill="LimeGreen" Values="{Binding Values1}" DataLabels="True" LabelPoint="{Binding PointLabel}"/>
<lvc:PieSeries Title="不合格" Fill="OrangeRed" Values="{Binding Values2}" DataLabels="True" LabelPoint="{Binding PointLabel}"/>
</lvc:PieChart.Series>
</lvc:PieChart>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,44 @@
using LiveCharts.Wpf;
using LiveCharts;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using .ViewModel;
using System.Runtime.InteropServices.ComTypes;
using Ping9719.WpfEx;
namespace
{
/// <summary>
/// 日产量统计扇形图
/// </summary>
public partial class OutputStatChartView : UserControlBase
{
public static OutputStatChartViewModel viewModel = new OutputStatChartViewModel();
public OutputStatChartView()
{
InitializeComponent();
this.DataContext = viewModel;
}
private void loadFir(object sender, EventArgs e)
{
if (this.IsInDesignMode)
return;
viewModel.UpdataData();
}
}
}

View File

@ -0,0 +1,52 @@
<pi:UserControlBase x:Class="货架标准上位机.RoleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="loadFirst">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--条件区-->
<Grid Margin="5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<UniformGrid Grid.Column="0" Columns="1">
<hc:TextBox Text="{Binding Info1}" Margin="5" Style="{StaticResource TextBoxExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="角色名称" hc:InfoElement.Placeholder="模糊匹配" VerticalAlignment="Center"/>
</UniformGrid>
<hc:UniformSpacingPanel Grid.Column="1" Spacing="5">
<Button Content="新增" Command="{Binding AddCommand}" Style="{StaticResource ButtonSuccess}" Width="70" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.权限},Converter={StaticResource AuthVisConverter}}"></Button>
<Button Content="查询" Command="{Binding UpdateListCommand}" Style="{StaticResource ButtonPrimary}" Width="70"></Button>
</hc:UniformSpacingPanel>
</Grid>
<!--内容区-->
<Border Grid.Row="1" Grid.Column="0" Style="{StaticResource BorderRegion}" BorderThickness="1" Background="#EEEEEE" Margin="3,0,3,3" Padding="0" >
<DataGrid RowHeaderWidth="50" HeadersVisibility="All" AutoGenerateColumns="False" ItemsSource="{Binding DataList}" hc:DataGridAttach.CanUnselectAllWithBlankArea="False" hc:DataGridAttach.ShowSelectAllButton="False" hc:DataGridAttach.ShowRowNumber="True">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Width="3*" Binding="{Binding Name}" Header="角色名称" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="7*" Binding="{Binding AuthNames,Converter={StaticResource List2StrConverter}}" Header="认证模块" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Time,StringFormat=yyyy-MM-dd HH:mm}" Header="创建时间" CanUserSort="False"/>
<DataGridTemplateColumn CanUserResize="False" Width="auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" IsEnabled="{Binding IsAdmin,Converter={StaticResource Boolean2BooleanReConverter}}">
<Button Style="{StaticResource ButtonInfo}" Margin="0,0,5,0" IsEnabled="True" Content="查看" Width="60" Command="{Binding DataContext.SeeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }"/>
<Button Style="{StaticResource ButtonWarning}" Margin="0,0,5,0" IsEnabled="True" Content="修改" Width="60" Command="{Binding DataContext.UpdateCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.权限},Converter={StaticResource AuthVisConverter}}"/>
<Button Style="{StaticResource ButtonDanger}" Margin="0,0,0,0" IsEnabled="True" Content="删除" Width="60" Command="{Binding DataContext.DelCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.权限},Converter={StaticResource AuthVisConverter}}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,42 @@
using .ViewModel;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace
{
/// <summary>
/// 角色
/// </summary>
public partial class RoleView : UserControlBase
{
RoleViewModel viewModel = new RoleViewModel();
public RoleView()
{
InitializeComponent();
this.DataContext = viewModel;
}
//第一次加载
private void loadFirst(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
viewModel.UpdateList();
}
}
}

View File

@ -0,0 +1,20 @@
<UserControl x:Class="货架标准上位机.Views.Controls.ScannerDisplayControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机.Views.Controls"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="150">
<Border Name="border" Grid.Column="0" Margin="5" BorderThickness="1" Background="LightSkyBlue" BorderBrush="Black" CornerRadius="3">
<StackPanel Margin="3">
<TextBlock HorizontalAlignment="Center">串口号</TextBlock>
<TextBlock Name="txtCom" HorizontalAlignment="Center"></TextBlock>
<TextBlock HorizontalAlignment="Center">当前入库货架</TextBlock>
<TextBlock Name="txtCurrentShelf" HorizontalAlignment="Center"></TextBlock>
<TextBlock HorizontalAlignment="Center">当前入库物料</TextBlock>
<TextBlock Name="txtCurrentMat" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
</Border>
</UserControl>

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace .Views.Controls
{
/// <summary>
/// ShelfStatusControl.xaml 的交互逻辑
/// </summary>
public partial class ScannerDisplayControl : UserControl
{
public ScannerDisplayControl(string COM)
{
InitializeComponent();
txtCom.Text = COM;
}
public void RefreshValues(string shelfCode, string matSn)
{
Dispatcher.BeginInvoke(new Action(() =>
{
txtCurrentShelf.Text = shelfCode;
txtCurrentMat.Text = matSn;
}));
}
}
}

View File

@ -0,0 +1,17 @@
<UserControl x:Class="货架标准上位机.Views.Controls.ShelfStatusControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机.Views.Controls"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="150">
<Border Name="border" Grid.Column="0" Margin="5" BorderThickness="1" Background="LightSkyBlue" BorderBrush="Black" CornerRadius="3">
<StackPanel Margin="3">
<TextBlock Name="txtShelfCode" HorizontalAlignment="Center"></TextBlock>
<TextBlock Name="txtCurrentMode" HorizontalAlignment="Center"></TextBlock>
<TextBlock Name="txtGroupName" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
</Border>
</UserControl>

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace .Views.Controls
{
/// <summary>
/// ShelfStatusControl.xaml 的交互逻辑
/// </summary>
public partial class ShelfStatusControl : UserControl
{
public ShelfStatusControl(string shelfCode, int currentMode, string groupName)
{
InitializeComponent();
txtShelfCode.Text = shelfCode;
txtGroupName.Text = groupName;
//待机模式 = 0,
//入库模式 = 1,
//出库模式 = 2,
//盘点模式 = 3
switch (currentMode)
{
case 0:
txtCurrentMode.Text = "待机模式";
border.Background = Brushes.White;
break;
case 1:
txtCurrentMode.Text = "入库模式";
border.Background = Brushes.LightSkyBlue;
break;
case 2:
txtCurrentMode.Text = "出库模式";
border.Background = Brushes.Green;
break;
case 3:
txtCurrentMode.Text = "盘点模式";
border.Background = Brushes.Pink;
break;
default:
txtCurrentMode.Text = "未知";
border.Background = Brushes.White;
break;
}
}
}
}

View File

@ -0,0 +1,16 @@
<Border x:Class="货架标准上位机.Views.Controls.TextDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
CornerRadius="10"
Width="300"
Height="186"
Background="{DynamicResource RegionBrush}">
<hc:SimplePanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<hc:LoadingCircle Height="25"/>
<TextBlock Style="{StaticResource TextBlockLargeBold}" Text="请稍候..."/>
</StackPanel>
<Button Width="22" Height="22" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource PrimaryBrush}" hc:IconElement.Geometry="{StaticResource ErrorGeometry}" Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,4,0"/>
</hc:SimplePanel>
</Border>

View File

@ -0,0 +1,28 @@
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace .Views.Controls
{
/// <summary>
/// TextDialog.xaml 的交互逻辑
/// </summary>
public partial class TextDialog
{
public TextDialog()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,52 @@
<pi:UserControlBase x:Class="货架标准上位机.UserView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="450" d:DesignWidth="800" LoadedVisibleFirst="loadFirst">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--条件区-->
<Grid Margin="5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<UniformGrid Grid.Column="0" Columns="1">
<hc:TextBox Text="{Binding Info1}" Margin="5" Style="{StaticResource TextBoxExtend}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="用户名称" hc:InfoElement.Placeholder="模糊匹配" VerticalAlignment="Center"/>
</UniformGrid>
<hc:UniformSpacingPanel Grid.Column="1" Spacing="5">
<Button Content="新增" Command="{Binding AddCommand}" Style="{StaticResource ButtonSuccess}" Width="70" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.权限},Converter={StaticResource AuthVisConverter}}"></Button>
<Button Content="查询" Command="{Binding UpdateListCommand}" Style="{StaticResource ButtonPrimary}" Width="70"></Button>
</hc:UniformSpacingPanel>
</Grid>
<!--内容区-->
<Border Grid.Row="1" Grid.Column="0" Style="{StaticResource BorderRegion}" BorderThickness="1" Background="#EEEEEE" Margin="3,0,3,3" Padding="0" >
<DataGrid RowHeaderWidth="50" HeadersVisibility="All" AutoGenerateColumns="False" ItemsSource="{Binding DataList}" hc:DataGridAttach.CanUnselectAllWithBlankArea="False" hc:DataGridAttach.ShowSelectAllButton="False" hc:DataGridAttach.ShowRowNumber="True">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Width="5*" Binding="{Binding LoginName}" Header="用户名称" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="5*" Binding="{Binding RoleNames,Converter={StaticResource List2StrConverter}}" Header="角色" CanUserSort="False"/>
<DataGridTextColumn IsReadOnly="True" Width="200" Binding="{Binding Time,StringFormat=yyyy-MM-dd HH:mm}" Header="创建时间" CanUserSort="False"/>
<DataGridTemplateColumn CanUserResize="False" Width="auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" IsEnabled="{Binding IsAdmin,Converter={StaticResource Boolean2BooleanReConverter}}">
<Button Style="{StaticResource ButtonInfo}" Margin="0,0,5,0" IsEnabled="True" Content="查看" Width="60" Command="{Binding DataContext.SeeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }"/>
<Button Style="{StaticResource ButtonWarning}" Margin="0,0,5,0" IsEnabled="True" Content="修改" Width="60" Command="{Binding DataContext.UpdateCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.权限},Converter={StaticResource AuthVisConverter}}"/>
<Button Style="{StaticResource ButtonDanger}" Margin="0,0,0,0" IsEnabled="True" Content="删除" Width="60" Command="{Binding DataContext.DelCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" CommandParameter="{Binding }" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.权限},Converter={StaticResource AuthVisConverter}}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>
</Grid>
</pi:UserControlBase>

View File

@ -0,0 +1,42 @@
using .ViewModel;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace
{
/// <summary>
/// 用户
/// </summary>
public partial class UserView : UserControlBase
{
UserViewModel viewModel = new UserViewModel();
public UserView()
{
InitializeComponent();
this.DataContext = viewModel;
}
//第一次加载
private void loadFirst(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
viewModel.UpdateList();
}
}
}

View File

@ -0,0 +1,62 @@
<pi:UserControlBase x:Class="货架标准上位机.HomeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:货架标准上位机"
xmlns:controls="clr-namespace:货架标准上位机.Views.Controls"
mc:Ignorable="d"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
d:DesignHeight="737" d:DesignWidth="1192" LoadedVisibleFirst="loadFir">
<Border Margin="0" Background="AliceBlue" CornerRadius="3" Padding="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition Height="3*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<!--内容区-->
<!--<Grid Grid.Row="0" Margin="5,5,5,0">-->
<!--货架状态显示区-->
<Border Grid.Row="0" Margin="5,5,5,0" BorderThickness="1" Background="White" BorderBrush="DodgerBlue" CornerRadius="3">
<hc:ScrollViewer IsInertiaEnabled="True" hc:ScrollViewerAttach.AutoHide="False">
<WrapPanel Name="shelfsWrapPanel">
</WrapPanel>
</hc:ScrollViewer>
</Border>
<!--</Grid>-->
<!--消息区-->
<Border Grid.Row="1" Margin="5,5,5,5" BorderThickness="1" Background="White" BorderBrush="DodgerBlue" CornerRadius="3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<!--报警-->
<GroupBox Grid.Column="0" Background="White" Padding="0" Style="{StaticResource GroupBoxTab}" Margin="5,5,5,5">
<GroupBox.Header>
<Grid Width="{Binding ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type GroupBox}}}">
<TextBlock Margin="5,0" HorizontalAlignment="Left" VerticalAlignment="Center">报警</TextBlock>
<Button HorizontalAlignment="Right" Height="25" Margin="10,0" Padding="10,0" FontFamily="{StaticResource IconFont}" Command="{Binding ClearTextErrCommand}">&#xeb45; 清除</Button>
</Grid>
</GroupBox.Header>
<TextBox Style="{StaticResource TextBoxExtend.Multi}" IsReadOnly="True" Margin="-1" Text="{Binding TextErr}" Foreground="Tomato" hc:InfoElement.Placeholder="没有报警信息"></TextBox>
</GroupBox>
<!--日志-->
<GroupBox Grid.Column="1" Background="White" Padding="0" Style="{StaticResource GroupBoxTab}" Margin="0,5,5,5" >
<GroupBox.Header>
<Grid Width="{Binding ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type GroupBox}}}">
<TextBlock Margin="5,0" HorizontalAlignment="Left" VerticalAlignment="Center">日志</TextBlock>
<Button HorizontalAlignment="Right" Height="25" Margin="10,0" Padding="10,0" FontFamily="{StaticResource IconFont}" Command="{Binding ClearTextInfoCommand}">&#xe62c; 清空</Button>
</Grid>
</GroupBox.Header>
<pi:TextBoxLog Style="{StaticResource TextBoxExtend.Multi}" Margin="-1" hc:InfoElement.Placeholder="没有日志信息" Foreground="CornflowerBlue"></pi:TextBoxLog>
</GroupBox>
</Grid>
</Border>
<Button Grid.Row="2" Command="{Binding AddUserControlCommand}" Content="点击添加控件"></Button>
</Grid>
</Border>
</pi:UserControlBase>

View File

@ -0,0 +1,44 @@
using .ViewModel;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using .Views.Controls;
namespace
{
/// <summary>
/// 主页
/// </summary>
public partial class HomeView : UserControlBase
{
HomeViewModel viewModel = new HomeViewModel();
public HomeView()
{
InitializeComponent();
this.DataContext = viewModel;
}
private void loadFir(object sender, EventArgs e)
{
viewModel.wrapPanel = shelfsWrapPanel;
if (this.IsInDesignMode)
return;
viewModel.LoadTask();
}
}
}

View File

@ -0,0 +1,140 @@
<pi:UserControlBase
xmlns:pi="https://github.com/ping9719/wpfex"
x:Class="货架标准上位机.InInventoryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:货架标准上位机"
mc:Ignorable="d"
d:DesignHeight="737" d:DesignWidth="1192" LoadedVisible="UserControlBase_LoadedVisible" Loaded="UserControlBase_Loaded" LoadedVisibleFirst="UserControlBase_LoadedVisibleFirst">
<Border Margin="0" Background="AliceBlue" CornerRadius="3" Padding="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0" Margin="0" Background="AliceBlue" CornerRadius="0" Padding="0" MouseUp="Border_MouseUp">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button Style="{StaticResource ButtonDanger}" Margin="10" hc:BorderElement.CornerRadius="15"
MinHeight="40" FontSize="20" Content="&#xe61b;结束入库" FontFamily="{StaticResource IconFont}"
Command="{Binding BtnEndCommand}">
</Button>
</StackPanel>
</Grid>
</Border>
<Border Grid.Row="1" Margin="1" Background="AliceBlue" Padding="0">
<WrapPanel Name="scannersWrapPanel">
</WrapPanel>
<!--<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="1.2*"></RowDefinition>
<RowDefinition Height="1.2*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0"
Text="最小包装条码:" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3"
Text="{Binding MatSN}" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Left"
></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0"
Text="物料编码:" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1"
Text="{Binding MatCode}" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Left"
></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0"
Text="物料名称:" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="1"
Text="{Binding MatName}" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Left"
></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="0"
Text="物料规格:" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3"
Text="{Binding MatSpec}" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Left"
>
</TextBlock>
<TextBlock Grid.Row="4" Grid.Column="0"
Text="物料批次:" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Right">
</TextBlock>
<TextBlock Grid.Row="4" Grid.Column="1"
Text="{Binding MatBatch}" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Left">
</TextBlock>
<TextBlock Grid.Row="5" Grid.Column="0"
Text="物料数量:" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Row="5" Grid.Column="1"
Text="{Binding MatQty}" FontSize="20"
VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
<TextBlock Grid.Row="4" Grid.Column="2"
Text="当前入库货架:" FontSize="20" FontWeight="Bold"
VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Row="4" Grid.Column="3" Grid.RowSpan="2"
Text="{Binding ShelfCode}" FontSize="5" FontWeight="Bold"
VerticalAlignment="Center" HorizontalAlignment="Left">
</TextBlock>
</Grid>
<DataGrid Grid.Row="1" SelectedCellsChanged="DataGrid_SelectedCellsChanged"
ItemsSource="{Binding DataGridItemSource}"
RowHeight="39" Margin="5"
AutoGenerateColumns="False" FontSize="18" CanUserSortColumns="False">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Header="物料编码" Binding="{Binding MatCode}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="物料名称" Binding="{Binding MatName}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="物料规格" Binding="{Binding MatSpec}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="批次" Binding="{Binding MatBatch}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="数量" Binding="{Binding MatQty}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="入库位置" Binding="{Binding StoreCode}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="入库人" Binding="{Binding InstoreUser}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="入库时间" Binding="{Binding InstoreTime ,StringFormat='yyyy-MM-dd HH:mm:ss'}"></DataGridTextColumn>
<DataGridTextColumn IsReadOnly="True" Header="最小包装条码" Binding="{Binding MatSN}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>-->
</Border>
</Grid>
</Border>
</pi:UserControlBase>

View File

@ -0,0 +1,69 @@
using Ping9719.WpfEx;
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.Imaging;
using System.Windows.Shapes;
using .ViewModel;
using .Views.Controls;
namespace
{
/// <summary>
/// InInventoryView.xaml 的交互逻辑
/// </summary>
public partial class InInventoryView : UserControlBase
{
public InInventoryViewModel viewModel = new InInventoryViewModel();
public InInventoryView()
{
InitializeComponent();
this.DataContext = viewModel;
var scanners = ScannerManager.Scanners.Select(t => t).ToList();
scanners.ForEach(t =>
{
var control = new ScannerDisplayControl(t.COM);
t.ScannerDisplayControl = control;
scannersWrapPanel.Children.Add(control);
});
}
private void DataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
DataGrid datagrid = sender as DataGrid;
datagrid.UnselectAllCells();
}
private void UserControlBase_Loaded(object sender, RoutedEventArgs e)
{
}
private void Border_MouseUp(object sender, MouseButtonEventArgs e)
{
}
private void UserControlBase_LoadedVisibleFirst(object sender, EventArgs e)
{
if (IsInDesignMode)
return;
//viewModel.NewMethod();
}
private void UserControlBase_LoadedVisible(object sender, EventArgs e)
{
}
}
}

View File

@ -0,0 +1,185 @@
<pi:UserControlBase
xmlns:pi="https://github.com/ping9719/wpfex"
x:Class="货架标准上位机.InterfaceRecordView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
d:DesignHeight="737" d:DesignWidth="1192" LoadedVisibleFirst="LoadedVisible">
<Border Margin="0" Background="AliceBlue" CornerRadius="3" Padding="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1.5*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0" Margin="3" Background="AliceBlue" CornerRadius="3" Padding="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.6*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="0.7*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="0.7*"></ColumnDefinition>
<ColumnDefinition Width="0.7*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Left"
Text="接口地址:" FontSize="18" ></TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding RequestUrl}"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontSize="18" MinWidth="120"></TextBox>
<TextBlock Grid.Row="0" Grid.Column="2" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Right"
Text="请求参数:" FontSize="18" ></TextBlock>
<TextBox Grid.Row="0" Grid.Column="3" Text="{Binding RequestBody}"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontSize="18" MinWidth="120"></TextBox>
<TextBlock Grid.Row="2" Grid.Column="0" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Left"
Text="调用类型:" FontSize="18" ></TextBlock>
<ComboBox Grid.Row="2" Grid.Column="1"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontSize="18" MinWidth="120" SelectedIndex="0" Text="{Binding RequestType}">
<ComboBoxItem Content="调用"></ComboBoxItem>
<ComboBoxItem Content="被调用"></ComboBoxItem>
</ComboBox>
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6" Orientation="Horizontal"
VerticalAlignment="Center" HorizontalAlignment="Left" >
<TextBlock Grid.Row="1" Grid.Column="0" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Right"
Text="时间:" FontSize="18" ></TextBlock>
<ComboBox Grid.Row="1" Grid.Column="1"
VerticalAlignment="Center" HorizontalAlignment="Left"
FontSize="18" MinWidth="120"
ItemsSource="{Binding TimeTypes}"
SelectedValue="{Binding TimeType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedIndex="0"
>
</ComboBox>
<TextBlock FontSize="18" VerticalAlignment="Center" Text=" "></TextBlock>
<hc:DateTimePicker FontSize="18" Height="24" MinWidth="180" Style="{StaticResource DateTimePickerExtend}" SelectedDateTime="{Binding StartTime}"></hc:DateTimePicker>
<TextBlock FontSize="18" VerticalAlignment="Center" Text=" 到 "></TextBlock>
<hc:DateTimePicker FontSize="18" Height="24" MinWidth="180" Style="{StaticResource DateTimePickerExtend}" SelectedDateTime="{Binding EndTime}"></hc:DateTimePicker>
</StackPanel>
<Button Style="{StaticResource ButtonSuccess}"
Command="{Binding BtnSearchCommand}"
hc:BorderElement.CornerRadius="5"
Grid.Column="5" Grid.Row="0" MinHeight="36" FontSize="16" Content="&#xe8b9; 搜索" FontFamily="{StaticResource IconFont}" Margin="0,0,0,-5" >
</Button>
<Button Style="{StaticResource ButtonWarning}"
Command="{Binding BtnResetCommand}"
hc:BorderElement.CornerRadius="5"
Grid.Column="6" Grid.Row="0" MinHeight="36" FontSize="16" Content="&#xe652; 重置" FontFamily="{StaticResource IconFont}" Margin="0,0,0,-5" >
</Button>
</Grid>
</Border>
<Border Grid.Row="1" Margin="3" Background="AliceBlue" CornerRadius="3" Padding="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="0.7*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<Button MinHeight="40" FontSize="18" Margin="5" Command="{Binding BtnExportCommand}"
Content="&#xe866; 导 出" FontFamily="{StaticResource IconFont}"
Style="{StaticResource ButtonWarning}" Background="DarkOrange">
</Button>
</StackPanel>
<DataGrid Grid.Row="1"
SelectedCellsChanged="DataGrid_SelectedCellsChanged"
ItemsSource="{Binding DataGridItemSource}"
RowHeight="39"
AutoGenerateColumns="False"
FontSize="13">
<DataGrid.Columns>
<DataGridTextColumn Header="序号" Binding="{Binding RowNumber}"></DataGridTextColumn>
<DataGridTextColumn Header="接口地址" Binding="{Binding RequestUrl}"></DataGridTextColumn>
<DataGridTextColumn Header="设备IP" Binding="{Binding DeviceIp}"></DataGridTextColumn>
<DataGridTextColumn Header="请求参数" Binding="{Binding RequestBody}" MaxWidth="100"></DataGridTextColumn>
<DataGridTextColumn Header="QueryString" Binding="{Binding QueryString}" MaxWidth="100"></DataGridTextColumn>
<DataGridTextColumn Header="请求时间" Binding="{Binding RequestTime,StringFormat='yyyy-MM-dd HH:mm:ss'}"></DataGridTextColumn>
<DataGridTextColumn Header="返回参数" Binding="{Binding ResponseJson}" MaxWidth="100"></DataGridTextColumn>
<DataGridTextColumn Header="返回时间" Binding="{Binding ResponseTime,StringFormat='yyyy-MM-dd HH:mm:ss'}"></DataGridTextColumn>
<DataGridTextColumn Header="耗时(ms)" Binding="{Binding ExecutionTime}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Row="2">
<Border CornerRadius="3" Background="Transparent" VerticalAlignment="Center" >
<Grid HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Top" Width="Auto" MinHeight="26">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"></ColumnDefinition>
<ColumnDefinition Width="5*"></ColumnDefinition>
<ColumnDefinition Width="5*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock FontSize="14" Text="共"></TextBlock>
<TextBlock FontSize="14" Text="{Binding TotalCount ,FallbackValue=0}"></TextBlock>
<TextBlock FontSize="14" Text="条记录 "></TextBlock>
<TextBlock FontSize="14" Text="第"></TextBlock>
<TextBlock FontSize="14" Text="{Binding CurrentPage,FallbackValue=0}"></TextBlock>
<TextBlock FontSize="14" Text="/"></TextBlock>
<TextBlock FontSize="14" Text="{Binding MaxPage,FallbackValue=0}"></TextBlock>
<TextBlock FontSize="14" Text="页"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Column="1">
<Grid>
<Grid.RowDefinitions >
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Button BorderBrush="Transparent" Background="Transparent" Grid.Column="0" Name="btnFirst" Content="首页" Foreground="Black" FontSize="14"
Command="{Binding BtnFirstPageCommand}"/>
<Button BorderBrush="Transparent" Background="Transparent" Grid.Column="1" Name="btnPrev" Content="上一页" FontSize="14"
Command="{Binding BtnPrePageCommand}"/>
<TextBox BorderBrush="Transparent" Grid.Column="2" FontSize="14" MinWidth="50" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="IBeam" IsEnabled="False"
Text ="{Binding CurrentPage}" TextAlignment="Center"
/>
<Button BorderBrush="Transparent" Background="Transparent" Grid.Column="3" Name="btnNext" Content="下一页" FontSize="14"
Command="{Binding BtnNextPageCommand}"/>
<Button BorderBrush="Transparent" Background="Transparent" Grid.Column="4" Name="btnLast" Content="末页" FontSize="14"
Command="{Binding BtnLastPageCommand}"/>
</Grid>
</StackPanel>
</Grid>
</Border>
</Grid>
</Grid>
</Border>
</Grid>
</Border>
</pi:UserControlBase>

View File

@ -0,0 +1,46 @@
using Ping9719.WpfEx;
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.Imaging;
using System.Windows.Shapes;
using .ViewModel;
namespace
{
public partial class InterfaceRecordView : UserControlBase
{
public InterfaceRecordViewModel viewModel { get; set; } = new InterfaceRecordViewModel();
public InterfaceRecordView()
{
InitializeComponent();
this.DataContext = viewModel;
}
private void DataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
//try
//{
// DataGrid datagrid = sender as DataGrid;
// datagrid.UnselectAllCells();
//}
//catch
//{
//}
}
private void LoadedVisible(object sender, EventArgs e)
{
viewModel.BtnReset();
}
}
}

View File

@ -0,0 +1,78 @@
<hc:Window xmlns:View="clr-namespace:货架标准上位机" x:Class="货架标准上位机.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:货架标准上位机"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="{Binding Title}" Height="800" Width="1280" Icon="/Resources/Logo.ico"
WindowStartupLocation="CenterScreen" Loaded="load">
<!--标题栏-->
<hc:Window.NonClientAreaContent>
<StackPanel HorizontalAlignment="Right">
<Menu Height="29">
<MenuItem Height="29" Command="{Binding OpenUserCommand}">
<MenuItem.Header>
<TextBlock Text="{Binding LoginName,Source={x:Static local:UserInfoView.viewModel},TargetNullValue=登录}" Foreground="DimGray" Margin="-5,0"></TextBlock>
</MenuItem.Header>
<MenuItem.Icon>
<TextBlock Text="&#xe61a;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<!--<MenuItem Height="29" Width="35" Header="">
<MenuItem.Icon>
<TextBlock Text="&#xe62b;" FontSize="15" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
<MenuItem Width="120" Header="蓝色">
<MenuItem.Icon>
<TextBlock Text="&#xe604;" Foreground="Blue" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="紫色">
<MenuItem.Icon>
<TextBlock Text="&#xe604;" Foreground="Purple" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="黑夜">
<MenuItem.Icon>
<TextBlock Text="&#xe604;" Foreground="Black" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
</MenuItem>-->
<MenuItem Height="29" Width="35" Header="">
<MenuItem.Icon>
<TextBlock Text="&#xe61b;" FontSize="15" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
<MenuItem Width="120" Header="日志" Command="{Binding OpenLogCommand}">
<MenuItem.Icon>
<TextBlock Text="&#xe61b;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="帮助" Command="{Binding OpenHelpCommand}">
<MenuItem.Icon>
<TextBlock Text="&#xe61b;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="关于" Command="{Binding OpenWeCommand}">
<MenuItem.Icon>
<TextBlock Text="&#xe61b;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</StackPanel>
</hc:Window.NonClientAreaContent>
<Grid>
<!--内容-->
<Grid>
</Grid>
<!--全局提示-->
<ScrollViewer Background="{x:Null}" Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Right" VerticalAlignment="Top">
<StackPanel Background="{x:Null}" hc:Growl.GrowlParent="True" VerticalAlignment="Top" Margin="0,10,10,10" HorizontalAlignment="Right"/>
</ScrollViewer>
</Grid>
</hc:Window>

View File

@ -0,0 +1,43 @@
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.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using .ViewModel;
namespace
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : HandyControl.Controls.Window
{
public static MainViewModel viewModel = new MainViewModel();
public MainWindow()
{
if (!viewModel.InitAgo())
this.Close();
InitializeComponent();
viewModel.Init(this);
this.DataContext = viewModel;
}
private void load(object sender, RoutedEventArgs e)
{
}
}
}

View File

@ -0,0 +1,283 @@
<hc:Window xmlns:View="clr-namespace:货架标准上位机" x:Class="货架标准上位机.MainWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:货架标准上位机"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:pi="https://github.com/ping9719/wpfex"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="{Binding Title}" NonClientAreaBackground="#FFDCEEFF" Height="800" Width="1280" Icon="/Resources/Logo.ico"
Background="#FFDCEEFF" WindowStartupLocation="CenterScreen" Loaded="load">
<!--标题栏-->
<hc:Window.NonClientAreaContent>
<StackPanel HorizontalAlignment="Right">
<Menu Height="29" Background="#FFDCEEFF">
<!--<MenuItem Height="29" Command="{Binding OpenUserCommand}" Visibility="{Binding IsLogin,Converter={StaticResource Boolean2VisibilityConverter}}">-->
<MenuItem Height="29" Command="{Binding OpenUserCommand}">
<MenuItem.Header>
<TextBlock Text="{Binding LoginName,Source={x:Static local:UserInfoView.viewModel},TargetNullValue=登录}" Foreground="DimGray" Margin="-5,0"></TextBlock>
</MenuItem.Header>
<MenuItem.Icon>
<TextBlock Text="&#xe61a;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<!--<MenuItem Height="29" Width="35" Header="">
<MenuItem.Icon>
<TextBlock Text="&#xe62b;" FontSize="15" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
<MenuItem Width="120" Header="蓝色">
<MenuItem.Icon>
<TextBlock Text="&#xe604;" Foreground="Blue" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="紫色">
<MenuItem.Icon>
<TextBlock Text="&#xe604;" Foreground="Purple" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="黑夜">
<MenuItem.Icon>
<TextBlock Text="&#xe604;" Foreground="Black" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
</MenuItem>-->
<MenuItem Height="29" Width="35">
<MenuItem.Icon>
<TextBlock Text="&#xe617;" FontSize="15" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
<MenuItem Width="120" Header="本地日志" Command="{Binding OpenLogCommand}">
<MenuItem.Icon>
<TextBlock Text="&#xe69d;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="操作说明" Command="{Binding OpenHelpCommand}">
<MenuItem.Icon>
<TextBlock Text="&#xe617;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
<MenuItem Width="120" Header="关 于" Command="{Binding OpenWeCommand}">
<MenuItem.Icon>
<TextBlock Text="&#xe6b3;" FontSize="16" FontFamily="{StaticResource IconFont}"></TextBlock>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</StackPanel>
</hc:Window.NonClientAreaContent>
<!--内容-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<!--内容-->
<TabControl Grid.Row="1" TabStripPlacement="Left" Margin="5,0,5,2" Padding="0,0,3,0" BorderThickness="0" Style="{StaticResource TabControlRectangle}" PreviewKeyDown="tabControl_PreviewKeyDown">
<TabItem Padding="10,10,40,10" IsSelected="True">
<TabItem.Header>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="&#xe603;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">主页</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:HomeView />
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe681;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">物料入库</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:InInventoryView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe67d;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">物料出库</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:MatBaseInfoView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe65f;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">物料盘点</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:MatBaseInfoView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe63a;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">库存查询</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:MatInventoryDetailView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe60b;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">出入记录</TextBlock>
</StackPanel>
</TabItem.Header>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe63a;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">库位管理</TextBlock>
</StackPanel>
</TabItem.Header>
<TabControl Style="{StaticResource TabControlBaseStyle.MouseOver}">
<TabItem Header="货架管理" >
<hc:TransitioningContentControl TransitionMode="Fade">
<View:ShelfInfoView />
</hc:TransitioningContentControl>
</TabItem>
<TabItem Header="模组管理">
<hc:TransitioningContentControl TransitionMode="Fade">
<View:RoleView />
</hc:TransitioningContentControl>
</TabItem>
<TabItem Header="库位管理">
<hc:TransitioningContentControl TransitionMode="Fade">
<View:RoleView />
</hc:TransitioningContentControl>
</TabItem>
</TabControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe662;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">物料管理</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:MatBaseInfoView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe662;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">条码打印</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:MatBaseInfoView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.查询},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe600;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">接口记录</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:InterfaceRecordView/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Padding="10,10,40,10" >
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xe63f;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">权限</TextBlock>
</StackPanel>
</TabItem.Header>
<TabControl Margin="5" Style="{StaticResource TabControlBaseStyle.MouseOver}">
<TabItem Header="用户管理" >
<hc:TransitioningContentControl TransitionMode="Fade">
<View:UserView Margin="0,5"/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Header="角色管理">
<hc:TransitioningContentControl TransitionMode="Fade">
<View:RoleView Margin="0,5"/>
</hc:TransitioningContentControl>
</TabItem>
</TabControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.调试},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="&#xe601;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">调试</TextBlock>
</StackPanel>
</TabItem.Header>
<TabControl Margin="5" Style="{StaticResource TabControlBaseStyle.MouseOver}">
<TabItem Header="PLC">
<hc:TransitioningContentControl TransitionMode="Fade">
<View:DeviceView Margin="0,5"/>
</hc:TransitioningContentControl>
</TabItem>
<TabItem Header="扫码枪">
<hc:TransitioningContentControl TransitionMode="Fade">
<pi:TextBoxScanner Style="{StaticResource TextBoxExtend.Multi}" hc:InfoElement.Placeholder="鼠标点击此处激活" hc:InfoElement.Title="码信息" hc:InfoElement.TitlePlacement="Top" AutoClear="NextClear" IsAutoFocus="True"></pi:TextBoxScanner>
</hc:TransitioningContentControl>
</TabItem>
</TabControl>
</TabItem>
<TabItem Padding="10,10,40,10" Visibility="{Binding Auth,Source={x:Static local:UserInfoView.viewModel},ConverterParameter={x:Static local:AuthEnum.设置},Converter={StaticResource AuthVisConverter}}">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xeb8d;" FontSize="20" FontFamily="{StaticResource IconFont}"></TextBlock>
<TextBlock Margin="10,0,0,0" FontSize="16">设置</TextBlock>
</StackPanel>
</TabItem.Header>
<hc:TransitioningContentControl TransitionMode="Fade">
<View:SetView />
</hc:TransitioningContentControl>
</TabItem>
</TabControl>
<!--状态栏-->
<Border Margin="5,3" Grid.Row="2" Grid.ColumnSpan="2" Background="AliceBlue" CornerRadius="3">
<Grid>
<StackPanel Margin="5" Orientation="Horizontal" HorizontalAlignment="Left">
<pi:IotState Content="状态内容待定" IsOk="False" Height="auto" Width="auto" InteriorHeight="13" Foreground="Gray" Background="{x:Null}"></pi:IotState>
</StackPanel>
<StackPanel Margin="5" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Margin="0,0" Text="{Binding Time,StringFormat=yyyy-MM-dd HH:mm:ss,FallbackValue=2000-01-01 00:00:00}" Foreground="#FF3A90C1" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</Grid>
</Border>
<!--全局提示-->
<ScrollViewer Background="{x:Null}" Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Right" VerticalAlignment="Bottom">
<StackPanel Background="{x:Null}" hc:Growl.GrowlParent="True" VerticalAlignment="Top" Margin="0,10,10,10" HorizontalAlignment="Right"/>
</ScrollViewer>
</Grid>
</hc:Window>

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using .ViewModel;
using HandyControl.Controls;
namespace
{
/// <summary>
/// MainWindow1.xaml 的交互逻辑
/// </summary>
public partial class MainWindow1 : HandyControl.Controls.Window
{
public static MainViewModel viewModel = MainWindow.viewModel;
public MainWindow1()
{
if (!viewModel.InitAgo())
this.Close();
InitializeComponent();
this.DataContext = viewModel;
}
private void load(object sender, RoutedEventArgs e)
{
viewModel.Init(this);
}
private void tabControl_PreviewKeyDown(object sender, KeyEventArgs e)
{
//取消tabControl快捷键切换
if (e.Key == Key.LeftCtrl || e.Key == Key.LeftCtrl || e.Key == Key.Tab)
e.Handled = true;
}
}
}

View File

@ -0,0 +1,92 @@
<Window
xmlns:pi="https://github.com/ping9719/wpfex"
x:Class="货架标准上位机.MatBaseInfoAddOrUpdateView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
Height="320" Width="320" WindowStyle="None" BorderThickness="0" Background="{x:Null}" AllowsTransparency="True" WindowStartupLocation="CenterScreen" Opacity="1">
<Border BorderBrush="Gray" Background="WhiteSmoke" CornerRadius="5" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="18" Name="Title" Text="{Binding Title, FallbackValue=新增物料}" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Button Margin="-5,-1"
Visibility="{Binding IsClose,Converter={StaticResource Boolean2VisibilityConverter}}"
Style="{StaticResource ButtonIcon}"
hc:IconElement.Geometry="{StaticResource CloseGeometry}" HorizontalAlignment="Right"
VerticalAlignment="Top" Click="closeClick"/>
<StackPanel Margin="5,0" Grid.Row="1" >
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="物料编码:" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBox Name="MatCode" MinWidth="200" Grid.Row="0" Grid.Column="1" FontSize="15"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
Style="{StaticResource TextBoxExtend}"
hc:InfoElement.Placeholder="此项必填"
></TextBox>
<TextBlock Text="*" Foreground="Red" VerticalAlignment="Center">
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="物料名称:" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBox Name="MatName" MinWidth="200" Grid.Row="0" Grid.Column="1" FontSize="15"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
Style="{StaticResource TextBoxExtend}"
hc:InfoElement.Placeholder="此项必填"
></TextBox>
<TextBlock Text="*" Foreground="Red" VerticalAlignment="Center">
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="物料规格:" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBox Name="MatSpec" MinWidth="200" Grid.Row="0" Grid.Column="1" FontSize="15"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
Style="{StaticResource TextBoxExtend}">
</TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="物料单位:" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBox Name="MatUnit" MinWidth="200" Grid.Row="0" Grid.Column="1" FontSize="15"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
Style="{StaticResource TextBoxExtend}">
</TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="物料客户:" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<TextBox Name="MatCustomer" MinWidth="200" Grid.Row="0" Grid.Column="1" FontSize="15"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
Style="{StaticResource TextBoxExtend}">
</TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="状 态:" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>
<ComboBox Name="IsEnable" MinWidth="100" Grid.Row="0" Grid.Column="1" FontSize="15"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
SelectedValuePath="Tag" SelectedValue="{Binding IsEnable}">
<ComboBoxItem IsSelected="True" Tag="True">启用</ComboBoxItem>
<ComboBoxItem Tag="False">禁用</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
<StackPanel Margin="5" x:Name="spacingPanel" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Margin="5" MinHeight="30" FontSize="15" Content="确认" Name="btnOk" Click="btnOk_Click"/>
<Button Margin="5" MinHeight="30" FontSize="15" Content="取消" Click="closeClick"/>
</StackPanel>
</Grid>
</Border>
</Window>

View File

@ -0,0 +1,94 @@
using HandyControl.Controls;
using SqlSugar;
using System;
using System.Windows;
using WCS.BLL.DbModels;
using .ViewModel;
namespace
{
public partial class MatBaseInfoAddOrUpdateView : System.Windows.Window
{
public MatBaseInfoAddOrUpdateViewModel ViewModel = new MatBaseInfoAddOrUpdateViewModel();
public MatBaseInfoModel matBaseInfo = null;
public MatBaseInfoAddOrUpdateView(string _titleText, MatBaseInfoModel _matBaseInfo = null)
{
InitializeComponent();
this.DataContext = ViewModel;
if (_matBaseInfo != null)
{
matBaseInfo = _matBaseInfo;
//绑定数据
MatCode.Text = matBaseInfo.MatCode;
MatName.Text = matBaseInfo.MatName;
MatSpec.Text = matBaseInfo.MatSpec;
MatUnit.Text = matBaseInfo.MatUnit;
MatCustomer.Text = matBaseInfo.MatCustomer;
ViewModel.IsEnable = matBaseInfo.IsEnable;
MatCode.IsEnabled = false;
}
else
{
matBaseInfo = new MatBaseInfoModel();
ViewModel.IsEnable = true;
}
//绑定标题
if (!string.IsNullOrEmpty(_titleText))
{
Title.Text = _titleText;
}
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(MatCode.Text))
{
Growl.Warning($"物料编码必填!");
MatCode.Focus();
return;
}
else if (string.IsNullOrEmpty(MatName.Text))
{
Growl.Warning($"物料名称必填!");
MatName.Focus();
return;
}
try
{
matBaseInfo.MatCode = MatCode.Text;
matBaseInfo.MatName = MatName.Text;
matBaseInfo.MatSpec = MatSpec.Text;
matBaseInfo.MatUnit = MatUnit.Text;
matBaseInfo.MatCustomer = MatCustomer.Text;
matBaseInfo.IsEnable = ViewModel.IsEnable;
}
//绑定数据
catch (Exception ex)
{
Growl.Error($"发生异常:{ex.Message}");
return;
}
this.DialogResult = true;
this.Close();
}
private void closeClick(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
}
}

Some files were not shown because too many files have changed in this diff Show More