using MaterialTraceability.Business;
using MaterialTraceability.Entity.DAO;
using MaterialTraceability.Entity.DTO;
using MaterialTraceability.SqlSugar;
using MaterialTraceability.SqlSugar.ServiceImpl;
using MaterialTraceabilityUI.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
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 MaterialTraceabilityUI
{
///
/// SysConfigPage.xaml 的交互逻辑
///
public partial class SysConfigPage : UserControl
{
private IBaseServices baseServices = new BaseServices();
private AppConfigDto appConfig = AppConfigDto.Instance;
///
/// 系统配置页面
///
public SysConfigPage()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
List info = getList();
this.SysCientDataGrid.ItemsSource = info;
var paramTypeInfo = info.GroupBy(x => x.paramType).Distinct().Select(a => a.Key).ToList();
paramTypeInfo.Add("");
this.paramType.ItemsSource = paramTypeInfo;
}
///
/// 查询
///
///
///
private void Seach_Click(object sender, RoutedEventArgs e)
{
this.SysCientDataGrid.ItemsSource = getList();
}
///
/// 保存
///
///
///
private void Save_Click(object sender, RoutedEventArgs e)
{
try
{
List sysClients = getList();
List clients = (List)this.SysCientDataGrid.ItemsSource;
foreach(var x in clients)
{
var info = sysClients.Where(z => z.paramType == x.paramType && z.paramKey == x.paramKey).FirstOrDefault();
if (info == null)
{
baseServices.Add(new SysClient()
{
paramKey = x.paramKey,
paramType = x.paramType,
paramValue = x.paramValue,
remark = x.remark,
processId = appConfig.processId,
});
}
else
{
x.processId = appConfig.processId;
baseServices.Update(x);
}
}
}catch(Exception ex)
{
LogHelperBusiness.LogError("参数配置保存异常",ex);
}
}
private List getList()
{
Expression> exp = s1 => true;
if (StringExtension.IsNotBlank(this.paramKey.Text))
{
exp = exp.And(x => x.paramKey == this.paramKey.Text);
}
if (StringExtension.IsNotBlank(Convert.ToString(this.paramType.SelectedItem)))
{
exp = exp.And(x => x.paramType == this.paramType.SelectedItem.ToString());
}
exp = exp.And(x => x.processId == appConfig.processId);
List info = baseServices.Query(exp).Result;
return info;
}
///
/// 编辑Sys_Client表
///
///
///
private void Edit_Click(object sender, RoutedEventArgs e)
{
try
{
if (!"1".Equals(ConfigHelper.GetConfig("roleId")) && !"2".Equals(ConfigHelper.GetConfig("roleId")))
{
System.Windows.MessageBox.Show("请登录系统管理账号进行操作");
}
else
{
string deleteStr = @"delete from Sys_Client";
baseServices.QueryBySql(deleteStr, null);
string sqlStr = @"ALTER TABLE Sys_Client ADD processId VARCHAR(64) ";
var info = baseServices.QueryBySql(sqlStr, null);
List clients = baseServices.Query().Result;
clients.ForEach(x => x.processId = appConfig.processId);
baseServices.Update(clients);
}
}catch(Exception ex)
{
LogHelperBusiness.LogError("编辑Sys_Client表异常", ex);
}
}
}
}