wenjy 1 year ago
commit 276a0dca6e

1
.gitignore vendored

@ -35,3 +35,4 @@ bld/
/*/*/obj/
/.vs/Admin.Core/v17/.futdcache.v2
/Admin.Core.Repository/Repository_New/SysUserInfoRepository.cs
/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs

@ -36,6 +36,14 @@ namespace Admin.Core.Repository
}
}
//输入最终SQL语句...
//_db.Aop.OnLogExecuting = (sql, pars) =>
//{
// //var s1 = sql;//断点打在这里看内部生成的sql语句...
// Console.Write(sql);
//};
return _dbBase;
}
}
@ -83,7 +91,7 @@ namespace Admin.Core.Repository
public async Task<TEntity> QueryByIdAsync(object objId)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().In(objId).SingleAsync();
return await _db.CopyNew().Queryable<TEntity>().In(objId).SingleAsync();
}
/// <summary>
/// 功能描述:根据ID查询一条数据
@ -95,7 +103,7 @@ namespace Admin.Core.Repository
public async Task<TEntity> QueryByIdAsync(object objId, bool blnUseCache = false)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().WithCacheIF(blnUseCache).In(objId).SingleAsync();
return await _db.CopyNew().Queryable<TEntity>().WithCacheIF(blnUseCache).In(objId).SingleAsync();
}
/// <summary>
@ -107,7 +115,7 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QueryByIDsAsync(object[] lstIds)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().In(lstIds).ToListAsync();
return await _db.CopyNew().Queryable<TEntity>().In(lstIds).ToListAsync();
}
/// <summary>
@ -117,11 +125,11 @@ namespace Admin.Core.Repository
/// <returns></returns>
public async Task<int> AddAsync(TEntity entity)
{
//var i = await Task.Run(() => _db.Insertable(entity).ExecuteReturnBigIdentity());
//var i = await Task.Run(() => _db.CopyNew().Insertable(entity).ExecuteReturnBigIdentity());
////返回的i是long类型,这里你可以根据你的业务需要进行处理
//return (int)i;
var insert = _db.Insertable(entity);
var insert = _db.CopyNew().Insertable(entity);
//这里你可以返回TEntity这样的话就可以获取id值无论主键是什么类型
//var return3 = await insert.ExecuteReturnEntityAsync();
@ -138,7 +146,7 @@ namespace Admin.Core.Repository
/// <returns>返回自增量列</returns>
public async Task<int> AddAsync(TEntity entity, Expression<Func<TEntity, object>> insertColumns = null)
{
var insert = _db.Insertable(entity);
var insert = _db.CopyNew().Insertable(entity);
if (insertColumns == null)
{
return await insert.ExecuteReturnIdentityAsync();
@ -156,7 +164,7 @@ namespace Admin.Core.Repository
/// <returns>影响行数</returns>
public async Task<int> AddAsync(List<TEntity> listEntity)
{
return await _db.Insertable(listEntity.ToArray()).ExecuteCommandAsync();
return await _db.CopyNew().Insertable(listEntity.ToArray()).ExecuteCommandAsync();
}
/// <summary>
@ -167,27 +175,27 @@ namespace Admin.Core.Repository
public async Task<bool> UpdateAsync(TEntity entity)
{
////这种方式会以主键为条件
//var i = await Task.Run(() => _db.Updateable(entity).ExecuteCommand());
//var i = await Task.Run(() => _db.CopyNew().Updateable(entity).ExecuteCommand());
//return i > 0;
//这种方式会以主键为条件
return await _db.Updateable(entity).ExecuteCommandHasChangeAsync();
return await _db.CopyNew().Updateable(entity).ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateAsync(TEntity entity, string strWhere)
{
//return await Task.Run(() => _db.Updateable(entity).Where(strWhere).ExecuteCommand() > 0);
return await _db.Updateable(entity).Where(strWhere).ExecuteCommandHasChangeAsync();
//return await Task.Run(() => _db.CopyNew().Updateable(entity).Where(strWhere).ExecuteCommand() > 0);
return await _db.CopyNew().Updateable(entity).Where(strWhere).ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateAsync(string strSql, SugarParameter[] parameters = null)
{
//return await Task.Run(() => _db.Ado.ExecuteCommand(strSql, parameters) > 0);
return await _db.Ado.ExecuteCommandAsync(strSql, parameters) > 0;
//return await Task.Run(() => _db.CopyNew().Ado.ExecuteCommand(strSql, parameters) > 0);
return await _db.CopyNew().Ado.ExecuteCommandAsync(strSql, parameters) > 0;
}
public async Task<bool> UpdateAsync(object operateAnonymousObjects)
{
return await _db.Updateable<TEntity>(operateAnonymousObjects).ExecuteCommandAsync() > 0;
return await _db.CopyNew().Updateable<TEntity>(operateAnonymousObjects).ExecuteCommandAsync() > 0;
}
public async Task<bool> UpdateAsync(
@ -197,7 +205,7 @@ namespace Admin.Core.Repository
string strWhere = ""
)
{
//IUpdateable<TEntity> up = await Task.Run(() => _db.Updateable(entity));
//IUpdateable<TEntity> up = await Task.Run(() => _db.CopyNew().Updateable(entity));
//if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
//{
// up = await Task.Run(() => up.IgnoreColumns(it => lstIgnoreColumns.Contains(it)));
@ -212,7 +220,7 @@ namespace Admin.Core.Repository
//}
//return await Task.Run(() => up.ExecuteCommand()) > 0;
IUpdateable<TEntity> up = _db.Updateable(entity);
IUpdateable<TEntity> up = _db.CopyNew().Updateable(entity);
if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
{
up = up.IgnoreColumns(lstIgnoreColumns.ToArray());
@ -234,7 +242,7 @@ namespace Admin.Core.Repository
public async Task<TEntity> FirstAsync()
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().FirstAsync();
return await _db.CopyNew().Queryable<TEntity>().FirstAsync();
}
/// <summary>
/// 查询第一条数据
@ -244,7 +252,7 @@ namespace Admin.Core.Repository
public async Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> whereExpression)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).FirstAsync();
return await _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).FirstAsync();
}
/// <summary>
/// 根据实体删除一条数据
@ -253,9 +261,9 @@ namespace Admin.Core.Repository
/// <returns></returns>
public async Task<bool> DeleteAsync(TEntity entity)
{
//var i = await Task.Run(() => _db.Deleteable(entity).ExecuteCommand());
//var i = await Task.Run(() => _db.CopyNew().Deleteable(entity).ExecuteCommand());
//return i > 0;
return await _db.Deleteable(entity).ExecuteCommandHasChangeAsync();
return await _db.CopyNew().Deleteable(entity).ExecuteCommandHasChangeAsync();
}
/// <summary>
@ -265,9 +273,9 @@ namespace Admin.Core.Repository
/// <returns></returns>
public async Task<bool> DeleteByIdAsync(object id)
{
//var i = await Task.Run(() => _db.Deleteable<TEntity>(id).ExecuteCommand());
//var i = await Task.Run(() => _db.CopyNew().Deleteable<TEntity>(id).ExecuteCommand());
//return i > 0;
return await _db.Deleteable<TEntity>(id).ExecuteCommandHasChangeAsync();
return await _db.CopyNew().Deleteable<TEntity>(id).ExecuteCommandHasChangeAsync();
}
/// <summary>
@ -277,9 +285,9 @@ namespace Admin.Core.Repository
/// <returns></returns>
public async Task<bool> DeletesAsync(List<TEntity> entitys)
{
//var i = await Task.Run(() => _db.Deleteable<TEntity>().In(ids).ExecuteCommand());
//var i = await Task.Run(() => _db.CopyNew().Deleteable<TEntity>().In(ids).ExecuteCommand());
//return i > 0;
return await _db.Deleteable<TEntity>(entitys).ExecuteCommandHasChangeAsync();
return await _db.CopyNew().Deleteable<TEntity>(entitys).ExecuteCommandHasChangeAsync();
}
/// <summary>
@ -292,7 +300,7 @@ namespace Admin.Core.Repository
try
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().ToListAsync();
return await _db.CopyNew().Queryable<TEntity>().ToListAsync();
}catch(Exception ex)
{
Console.WriteLine($"QueryAsync执行异常:{ex.Message}");
@ -309,8 +317,8 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QueryAsync(string strWhere)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return await _db.Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToListAsync();
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return await _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToListAsync();
}
/// <summary>
@ -322,7 +330,7 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> whereExpression)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToListAsync();
return await _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToListAsync();
}
/// <summary>
@ -335,7 +343,7 @@ namespace Admin.Core.Repository
public async Task<List<TResult>> QueryAsync<TResult>(Expression<Func<TEntity, TResult>> expression)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().Select(expression).ToListAsync();
return await _db.CopyNew().Queryable<TEntity>().Select(expression).ToListAsync();
}
/// <summary>
@ -350,7 +358,7 @@ namespace Admin.Core.Repository
public async Task<List<TResult>> QueryAsync<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Select(expression).ToListAsync();
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Select(expression).ToListAsync();
}
/// <summary>
@ -363,8 +371,8 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> whereExpression, string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToList());
return await _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(strOrderByFileds != null, strOrderByFileds).ToListAsync();
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToList());
return await _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(strOrderByFileds != null, strOrderByFileds).ToListAsync();
}
/// <summary>
/// 功能描述:查询一个列表
@ -376,8 +384,8 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList());
return await _db.Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToListAsync();
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList());
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToListAsync();
}
/// <summary>
@ -390,8 +398,8 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QueryAsync(string strWhere, string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToListAsync();
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToListAsync();
}
@ -409,8 +417,8 @@ namespace Admin.Core.Repository
string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList());
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToListAsync();
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList());
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToListAsync();
}
/// <summary>
@ -427,8 +435,8 @@ namespace Admin.Core.Repository
string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList());
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToListAsync();
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList());
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToListAsync();
}
/// <summary>
@ -440,7 +448,7 @@ namespace Admin.Core.Repository
public async Task<List<TEntity>> QuerySqlAsync(string strSql, SugarParameter[] parameters = null)
{
if (GetConnectionState() == false) return null;
return await _db.Ado.SqlQueryAsync<TEntity>(strSql, parameters);
return await _db.CopyNew().Ado.SqlQueryAsync<TEntity>(strSql, parameters);
}
/// <summary>
@ -451,7 +459,7 @@ namespace Admin.Core.Repository
/// <returns>泛型集合</returns>
public async Task<int> ExecSqlAsync(string strSql, SugarParameter[] parameters = null)
{
return await _db.Ado.ExecuteCommandAsync(strSql, parameters);
return await _db.CopyNew().Ado.ExecuteCommandAsync(strSql, parameters);
}
/// <summary>
@ -463,7 +471,7 @@ namespace Admin.Core.Repository
public async Task<DataTable> QueryTableAsync(string strSql, SugarParameter[] parameters = null)
{
if (GetConnectionState() == false) return null;
return await _db.Ado.GetDataTableAsync(strSql, parameters);
return await _db.CopyNew().Ado.GetDataTableAsync(strSql, parameters);
}
/// <summary>
@ -482,8 +490,8 @@ namespace Admin.Core.Repository
string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize));
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageListAsync(intPageIndex, intPageSize);
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize));
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageListAsync(intPageIndex, intPageSize);
}
/// <summary>
@ -503,8 +511,8 @@ namespace Admin.Core.Repository
string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return await Task.Run(() => _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize));
return await _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageListAsync(intPageIndex, intPageSize);
//return await Task.Run(() => _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize));
return await _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageListAsync(intPageIndex, intPageSize);
}
@ -522,7 +530,7 @@ namespace Admin.Core.Repository
if (GetConnectionState() == false) return null;
RefAsync<int> totalCount = 0;
var list = await _db.Queryable<TEntity>()
var list = await _db.CopyNew().Queryable<TEntity>()
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
.WhereIF(whereExpression != null, whereExpression)
.ToPageListAsync(intPageIndex, intPageSize, totalCount);
@ -551,9 +559,9 @@ namespace Admin.Core.Repository
if (GetConnectionState() == false) return null;
if (whereLambda == null)
{
return await _db.Queryable(joinExpression).Select(selectExpression).ToListAsync();
return await _db.CopyNew().Queryable(joinExpression).Select(selectExpression).ToListAsync();
}
return await _db.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).ToListAsync();
return await _db.CopyNew().Queryable(joinExpression).Where(whereLambda).Select(selectExpression).ToListAsync();
}
@ -580,7 +588,7 @@ namespace Admin.Core.Repository
{
if (GetConnectionState() == false) return null;
RefAsync<int> totalCount = 0;
var list = await _db.Queryable<T, T2>(joinExpression)
var list = await _db.CopyNew().Queryable<T, T2>(joinExpression)
.Select(selectExpression)
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
.WhereIF(whereExpression != null, whereExpression)
@ -614,7 +622,7 @@ namespace Admin.Core.Repository
if (GetConnectionState() == false) return null;
RefAsync<int> totalCount = 0;
var list = await _db.Queryable<T, T2>(joinExpression).GroupBy(groupExpression)
var list = await _db.CopyNew().Queryable<T, T2>(joinExpression).GroupBy(groupExpression)
.Select(selectExpression)
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
.WhereIF(whereExpression != null, whereExpression)
@ -629,7 +637,7 @@ namespace Admin.Core.Repository
public TEntity QueryById(object objId)
{
return _db.Queryable<TEntity>().In(objId).Single();
return _db.CopyNew().Queryable<TEntity>().In(objId).Single();
}
/// <summary
/// 功能描述:根据ID查询一条数据
@ -640,7 +648,7 @@ namespace Admin.Core.Repository
/// <returns数据实体</returns
public TEntity QueryById(object objId, bool blnUseCache = false)
{
return _db.Queryable<TEntity>().WithCacheIF(blnUseCache).In(objId).Single();
return _db.CopyNew().Queryable<TEntity>().WithCacheIF(blnUseCache).In(objId).Single();
}
/// <summary
@ -651,7 +659,7 @@ namespace Admin.Core.Repository
/// <returns数据实体列表</returns
public List<TEntity> QueryByIDs(object[] lstIds)
{
return _db.Queryable<TEntity>().In(lstIds).ToList();
return _db.CopyNew().Queryable<TEntity>().In(lstIds).ToList();
}
/// <summary
@ -663,8 +671,8 @@ namespace Admin.Core.Repository
{
if (GetConnectionState() == false)
{
_db.Open();
var insert = _db.Insertable(entity);
_db.CopyNew().Open();
var insert = _db.CopyNew().Insertable(entity);
if (insert == null)
{
@ -688,7 +696,7 @@ namespace Admin.Core.Repository
/// <returns返回自增量列</returns
public int Add(TEntity entity, Expression<Func<TEntity, object>> insertColumns = null)
{
var insert = _db.Insertable(entity);
var insert = _db.CopyNew().Insertable(entity);
if (insertColumns == null)
{
return insert.ExecuteReturnIdentity();
@ -706,7 +714,7 @@ namespace Admin.Core.Repository
/// <returns影响行数</returns
public int Add(List<TEntity> listEntity)
{
return _db.Insertable(listEntity.ToArray()).ExecuteCommand();
return _db.CopyNew().Insertable(listEntity.ToArray()).ExecuteCommand();
}
/// <summary
@ -717,27 +725,27 @@ namespace Admin.Core.Repository
public bool Update(TEntity entity)
{
////这种方式会以主键为条件
//var i = Task.Run(() = _db.Updateable(entity).ExecuteCommand());
//var i = Task.Run(() = _db.CopyNew().Updateable(entity).ExecuteCommand());
//return i 0;
//这种方式会以主键为条件
return _db.Updateable(entity).ExecuteCommandHasChange();
return _db.CopyNew().Updateable(entity).ExecuteCommandHasChange();
}
public bool Update(TEntity entity, string strWhere)
{
//return Task.Run(() = _db.Updateable(entity).Where(strWhere).ExecuteCommand() 0);
return _db.Updateable(entity).Where(strWhere).ExecuteCommandHasChange();
//return Task.Run(() = _db.CopyNew().Updateable(entity).Where(strWhere).ExecuteCommand() 0);
return _db.CopyNew().Updateable(entity).Where(strWhere).ExecuteCommandHasChange();
}
public bool Update(string strSql, SugarParameter[] parameters = null)
{
//return Task.Run(() = _db.Ado.ExecuteCommand(strSql, parameters) 0);
return _db.Ado.ExecuteCommand(strSql, parameters) > 0;
//return Task.Run(() = _db.CopyNew().Ado.ExecuteCommand(strSql, parameters) 0);
return _db.CopyNew().Ado.ExecuteCommand(strSql, parameters) > 0;
}
public bool Update(object operateAnonymousObjects)
{
return _db.Updateable<TEntity>(operateAnonymousObjects).ExecuteCommand() > 0;
return _db.CopyNew().Updateable<TEntity>(operateAnonymousObjects).ExecuteCommand() > 0;
}
public bool Update(
@ -748,7 +756,7 @@ namespace Admin.Core.Repository
)
{
IUpdateable<TEntity> up = _db.Updateable(entity);
IUpdateable<TEntity> up = _db.CopyNew().Updateable(entity);
if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0)
{
up = up.IgnoreColumns(lstIgnoreColumns.ToArray());
@ -771,9 +779,9 @@ namespace Admin.Core.Repository
/// <returns</returns
public bool Delete(TEntity entity)
{
//var i = Task.Run(() = _db.Deleteable(entity).ExecuteCommand());
//var i = Task.Run(() = _db.CopyNew().Deleteable(entity).ExecuteCommand());
//return i 0;
return _db.Deleteable(entity).ExecuteCommandHasChange();
return _db.CopyNew().Deleteable(entity).ExecuteCommandHasChange();
}
/// <summary
@ -783,9 +791,9 @@ namespace Admin.Core.Repository
/// <returns</returns
public bool DeleteById(object id)
{
//var i = Task.Run(() = _db.Deleteable<TEntity(id).ExecuteCommand());
//var i = Task.Run(() = _db.CopyNew().Deleteable<TEntity(id).ExecuteCommand());
//return i 0;
return _db.Deleteable<TEntity>(id).ExecuteCommandHasChange();
return _db.CopyNew().Deleteable<TEntity>(id).ExecuteCommandHasChange();
}
/// <summary
@ -795,9 +803,9 @@ namespace Admin.Core.Repository
/// <returns</returns
public bool Deletes(List<TEntity> entitys)
{
//var i = Task.Run(() = _db.Deleteable<TEntity().In(ids).ExecuteCommand());
//var i = Task.Run(() = _db.CopyNew().Deleteable<TEntity().In(ids).ExecuteCommand());
//return i 0;
return _db.Deleteable<TEntity>(entitys).ExecuteCommandHasChange();
return _db.CopyNew().Deleteable<TEntity>(entitys).ExecuteCommandHasChange();
}
@ -810,7 +818,7 @@ namespace Admin.Core.Repository
public List<TEntity> Query()
{
if (GetConnectionState() == false) return null;
return _db.Queryable<TEntity>().ToList();
return _db.CopyNew().Queryable<TEntity>().ToList();
}
/// <summary
@ -822,8 +830,8 @@ namespace Admin.Core.Repository
public List<TEntity> Query(string strWhere)
{
if (GetConnectionState() == false) return null;
//return Task.Run(() = _db.Queryable<TEntity().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return _db.Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList();
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList();
}
/// <summary
@ -835,7 +843,7 @@ namespace Admin.Core.Repository
public List<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression)
{
if (GetConnectionState() == false) return null;
return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToList();
return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToList();
}
/// <summary
@ -848,7 +856,7 @@ namespace Admin.Core.Repository
public List<TResult> Query<TResult>(Expression<Func<TEntity, TResult>> expression)
{
if (GetConnectionState() == false) return null;
return _db.Queryable<TEntity>().Select(expression).ToList();
return _db.CopyNew().Queryable<TEntity>().Select(expression).ToList();
}
/// <summary
@ -863,7 +871,7 @@ namespace Admin.Core.Repository
public List<TResult> Query<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Select(expression).ToList();
return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Select(expression).ToList();
}
/// <summary
@ -876,8 +884,8 @@ namespace Admin.Core.Repository
public List<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression, string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToList());
return _db.Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(strOrderByFileds != null, strOrderByFileds).ToList();
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToList());
return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(strOrderByFileds != null, strOrderByFileds).ToList();
}
/// <summary
/// 功能描述:查询一个列表
@ -889,8 +897,8 @@ namespace Admin.Core.Repository
public List<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true)
{
if (GetConnectionState() == false) return null;
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList());
return _db.Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList();
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList());
return _db.CopyNew().Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList();
}
/// <summary
@ -903,8 +911,8 @@ namespace Admin.Core.Repository
public List<TEntity> Query(string strWhere, string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList();
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList());
return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList();
}
@ -922,8 +930,8 @@ namespace Admin.Core.Repository
string strOrderByFileds)
{
if (GetConnectionState() == false) return null;
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList());
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList();
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList());
return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList();
}
/// <summary
@ -939,8 +947,8 @@ namespace Admin.Core.Repository
int intTop,
string strOrderByFileds)
{
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList());
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList();
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList());
return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList();
}
/// <summary
@ -951,7 +959,7 @@ namespace Admin.Core.Repository
/// <returns泛型集合</returns
public List<TEntity> QuerySql(string strSql, SugarParameter[] parameters = null)
{
return _db.Ado.SqlQuery<TEntity>(strSql, parameters);
return _db.CopyNew().Ado.SqlQuery<TEntity>(strSql, parameters);
}
/// <summary
@ -962,7 +970,7 @@ namespace Admin.Core.Repository
/// <returns泛型集合</returns
public int ExecSql(string strSql, SugarParameter[] parameters = null)
{
return _db.Ado.ExecuteCommand(strSql, parameters);
return _db.CopyNew().Ado.ExecuteCommand(strSql, parameters);
}
/// <summary
@ -973,7 +981,7 @@ namespace Admin.Core.Repository
/// <returnsDataTable</returns
public DataTable QueryTable(string strSql, SugarParameter[] parameters = null)
{
return _db.Ado.GetDataTable(strSql, parameters);
return _db.CopyNew().Ado.GetDataTable(strSql, parameters);
}
/// <summary
@ -991,8 +999,8 @@ namespace Admin.Core.Repository
int intPageSize,
string strOrderByFileds)
{
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize));
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize);
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize));
return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize);
}
/// <summary
@ -1011,8 +1019,8 @@ namespace Admin.Core.Repository
string strOrderByFileds)
{
//return Task.Run(() = _db.Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize));
return _db.Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize);
//return Task.Run(() = _db.CopyNew().Queryable<TEntity().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize));
return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize);
}
@ -1029,7 +1037,7 @@ namespace Admin.Core.Repository
{
int totalCount = 0;
var list = _db.Queryable<TEntity>()
var list = _db.CopyNew().Queryable<TEntity>()
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
.WhereIF(whereExpression != null, whereExpression)
.ToPageList(intPageIndex, intPageSize, ref totalCount);
@ -1057,9 +1065,9 @@ namespace Admin.Core.Repository
{
if (whereLambda == null)
{
return _db.Queryable(joinExpression).Select(selectExpression).ToList();
return _db.CopyNew().Queryable(joinExpression).Select(selectExpression).ToList();
}
return _db.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).ToList();
return _db.CopyNew().Queryable(joinExpression).Where(whereLambda).Select(selectExpression).ToList();
}
@ -1086,7 +1094,7 @@ namespace Admin.Core.Repository
{
int totalCount = 0;
var list = _db.Queryable<T, T2>(joinExpression)
var list = _db.CopyNew().Queryable<T, T2>(joinExpression)
.Select(selectExpression)
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
.WhereIF(whereExpression != null, whereExpression)
@ -1119,7 +1127,7 @@ namespace Admin.Core.Repository
{
int totalCount = 0;
var list = _db.Queryable<T, T2>(joinExpression).GroupBy(groupExpression)
var list = _db.CopyNew().Queryable<T, T2>(joinExpression).GroupBy(groupExpression)
.Select(selectExpression)
.OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds)
.WhereIF(whereExpression != null, whereExpression)

@ -104,30 +104,20 @@ namespace Aucma.Core.BoxFoam.Business
public void init()
{
//allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
//foreach (var space in allSpaces)
//{
// spaceAddresses.Add(spaceConfig.GetSpaceAddress(storeCode, space.SpaceCode));
//}
//// 模拟入库
////Task.Run(() =>
////{
//// Thread.Sleep(2000);
//// InStore("B24010181060282920011");
////});
////实时监测入库任务下发和入库任务完成
//StartPassDownAndRealInstoreFinish();
Task.Run(() =>
allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
foreach (var space in allSpaces)
{
while (true)
{
var allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
Console.WriteLine(allSpaces.ToJson());
}
});
spaceAddresses.Add(spaceConfig.GetSpaceAddress(storeCode, space.SpaceCode));
}
// 模拟入库
//Task.Run(() =>
//{
// Thread.Sleep(2000);
// InStore("B24010181060282920011");
//});
//实时监测入库任务下发和入库任务完成
StartPassDownAndRealInstoreFinish();
}
/// <summary>

@ -302,21 +302,25 @@ namespace Aucma.Core.ProductOffLine.ViewModels
}
tempInfo.MsgAlarmFlag = false;
});
}
}
#endregion
private async void InitEveryDayMethod()
{
LoadData();
List<WorkTime> listTime = await _baseBomInfoServices.getWorkTime();
if (listTime == null) return;
List<Admin.Core.Model.ViewModels.ChartsByTime> list = await _offLineInfoServices.QueryCharts(listTime[0].startTime, listTime[11].startTime);
// var aa =_offLineInfoServices.Query(x=>x.ProductScanTime>= listTime[0].startTime && x.ProductScanTime<= listTime[11].startTime);
List<Admin.Core.Model.ViewModels.ChartsByTime> list = await _offLineInfoServices.QueryCharts(listTime[0].startTime, listTime[11].startTime);
if (list == null) return;
List<string> xList =new List<string>();
List<string> xList = new List<string>();
ChartValues<double> achievement2 = new ChartValues<double>();
for (int i = 0; i < 12; i++)
{
xList.Add(list[i].time.Substring(11, 2)+":00");
xList.Add(list[i].time.Substring(11, 2) + ":00");
achievement2.Add(list[i].Amount);
}
var column2 = new ColumnSeries();
@ -351,6 +355,54 @@ namespace Aucma.Core.ProductOffLine.ViewModels
"SC-439VAM,元气森林,C",
};
}
//private async void InitEveryDayMethod()
//{
// LoadData();
// List<WorkTime> listTime = await _baseBomInfoServices.getWorkTime();
// if (listTime == null) return;
// List<Admin.Core.Model.ViewModels.ChartsByTime> list = await _offLineInfoServices.QueryCharts(listTime[0].startTime, listTime[11].startTime);
// if (list == null) return;
// List<string> xList =new List<string>();
// ChartValues<double> achievement2 = new ChartValues<double>();
// for (int i = 0; i < 12; i++)
// {
// xList.Add(list[i].time.Substring(11, 2)+":00");
// achievement2.Add(list[i].Amount);
// }
// var column2 = new ColumnSeries();
// column2.DataLabels = true;
// column2.Title = "产量";
// column2.Values = achievement2;
// column2.Foreground = Brushes.White;
// Achievement.Add(column2);
// ProductionHourList = xList;
// ChartValues<double> achievement = new ChartValues<double>();
// Random random = new Random();
// for (int i = 0; i < 5; i++)
// {
// achievement.Add(random.Next(60, 100));
// }
// var column = new ColumnSeries();
// column.DataLabels = true;
// column.Title = "型号";
// column.Values = achievement;
// column.Foreground = Brushes.White;
// ModelStatistics.Add(column);
// MaterialNameList = new List<string>()
// {
// "SC-230,11W/H成品",
// "SC-439箱体",
// "SC-439U壳",
// "SC-439背板",
// "SC-439VAM,元气森林,C",
// };
//}
public async void LoadData()
{
List<OffLineInfo> list = await _offLineInfoServices.QueryAsync(x => x.ProductScanTime >= System.DateTime.Now.AddDays(-1), "PRODUCT_SCANTIME desc");

@ -1,788 +0,0 @@
using Aucma.Core.SheetMetal.Models;
using Aucma.Core.SheetMetal.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Linq;
using System.Threading.Tasks;
using Admin.Core.IService;
using Microsoft.Extensions.DependencyInjection;
using Aucma.Core.SheetMetal.Common;
using LiveCharts;
using LiveCharts.Wpf;
using Admin.Core.Model;
using System.Windows.Media;
using Admin.Core.Common;
using LiveCharts.Defaults;
using Aucma.Core.SheetMetal.Business;
using Admin.Core.Service;
using NPOI.SS.Formula.Functions;
using Admin.Core.Model.ViewModels;
/*
*
*/
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
protected readonly IExecutePlanInfoServices? _taskExecutionPlanInfoServices;
protected readonly IRecordBackPanelComplateServices _recordBackPanelComplateServices;
protected readonly IRecordSidePanelComplateServices _recordSidePanelComplateServices;
protected readonly IBaseBomInfoServices _baseBomInfoServices;
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly IRecordInStoreServices _recordInstoreServices;
private AppConfigHelper appConfig = new AppConfigHelper();
List<SelectModel> list = new List<SelectModel>() { new SelectModel()
{
ID=1,
TypeName="手动"
},
new SelectModel()
{
ID=2,
TypeName="自动"
}};
public Func<double, string> Formatter { get; set; }
public HwPLc.PlcModel obj = null;
#region 构造函数
public IndexPageViewModel()
{
_stationName = Appsettings.app("StationInfo", "StationName");//工位名称
_taskExecutionPlanInfoServices = App.ServiceProvider.GetService<IExecutePlanInfoServices>();
_recordBackPanelComplateServices = App.ServiceProvider.GetService<IRecordBackPanelComplateServices>();
_recordSidePanelComplateServices = App.ServiceProvider.GetService<IRecordSidePanelComplateServices>();
_baseBomInfoServices = App.ServiceProvider.GetService<IBaseBomInfoServices>();
_sysUserInfoServices = App.ServiceProvider.GetService<ISysUserInfoServices>();
_recordInstoreServices = App.ServiceProvider.GetService<IRecordInStoreServices>();
//Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod;
//Job_SheetMetalTask_Quartz.SmTaskDelegateEvent += UpdatePlanSHow;//计划内容展示
//WeakReferenceMessenger.Default.Register<string>(this, Recive);
Task.WaitAll(LoadData());
AddSelectData();//添加下拉菜单
RefreshHourAmount();//小时产量
// InitEveryDayMethod();
RefreshMaterialStats();//型号产量
SheetMetalPlanTaskHandle.RefreshCurrentPlanInfoEvent += RefreshCurrentPlanInfo;
QuantityIssuedViewModel.RefreshCretaePlanInfoEvent += LoadData;
}
#endregion
#region 下拉
public void AddSelectData()
{
foreach (var item in list)
{
LocationSource.Add(item);
}
SelectLocation = ReadFile();
}
#endregion
#region 订单统计
private async Task InitExecMethod()
{
string station = Appsettings.app("StoreInfo", "StationCode");
ExecutePlanInfo info = await _taskExecutionPlanInfoServices.FirstAsync(d => d.ProductLineCode.Equals(station) && d.ExecuteStatus == 2);
if (info == null) return;
PlanNum = info.PlanAmount;
RealQuantity = info.CompleteAmount;
DiffQuantity = Math.Abs(info.CompleteAmount - info.PlanAmount);
CompletionRate = info.CompleteAmount / info.PlanAmount;
}
#endregion
#region 日产量
/// <summary>
/// 每日生产
/// </summary>
/// <returns></returns>
private Task InitEveryDayMethod()
{
#region 按时间统计
ChartValues<ObservablePoint> achievement = new ChartValues<ObservablePoint>
{
new ObservablePoint(0, 8),
new ObservablePoint(1, 14),
new ObservablePoint(2, 10),
new ObservablePoint(3, 5),
new ObservablePoint(4, 11),
new ObservablePoint(5, 15),
new ObservablePoint(6, 7),
new ObservablePoint(7, 3),
new ObservablePoint(8, 13),
new ObservablePoint(9, 11),
new ObservablePoint(10, 8),
new ObservablePoint(11, 5)
};
var column = new ColumnSeries();
column.DataLabels = true;
column.Title = "前板";
column.Values = achievement;
column.Foreground = Brushes.White;
column.FontSize = 18;
//柱子宽度
//column.Width = 30;
//column.MaxColumnWidth = 30;
//column.LabelsPosition = BarLabelPosition.Perpendicular;
//column.Fill = new SolidColorBrush(Color.FromRgb(34, 139, 34)); //柱状图颜色填充
//column.LabelPoint = p => p.Y.ToString(); //柱状图数据显示位置
ProductionHourList = new List<string>()
{
"8:00", "9:00", "9:30", "10:30", "11:30", "12:30", "13:30", "14:30", "15:30", "16:30", "17:30", "18:30"
};
//Formatter = value => value.ToString("N");
Achievement.Add(column);
Achievement.Add(new ColumnSeries
{
DataLabels = true,
Title = "后板",
Values = achievement,
Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)),
Foreground = Brushes.CadetBlue,
FontSize = 18
});
#endregion
#region 按类型统计
//ChartValues<double> achievement2 = new ChartValues<double>();
//Random random2 = new Random();
//for (int i = 0; i < 2; i++)
//{
// achievement2.Add(random2.Next(60, 100));
//}
//var column2 = new ColumnSeries();
//column2.DataLabels = true;
//column2.Title = "前板";
//column2.Values = achievement2;
//column2.Foreground = Brushes.White;
//column2.FontSize = 18;
//ModelStatistics.Add(column2);
//ModelStatistics.Add(new ColumnSeries()
//{
// DataLabels = true,
// Title = "后板",
// Values = achievement2,
// Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)),
// Foreground = Brushes.White,
// FontSize = 18
//});
//MaterialNameList = new List<string>()
//{
// "玻璃门,SC-439", "玻璃门,SC-439,AC"
//};
#endregion
//await InitExecMethod();
return Task.CompletedTask;
}
#endregion
#region 计划列表
#region 加载DataGrid数据
private Task LoadData()
{
string stationCode = Appsettings.app("StationInfo", "StationCode");
CurrentTeamTimeView view = GetTeamHour();
var list = _taskExecutionPlanInfoServices.QueryAsync(x => x.ProductLineCode == stationCode&& x.CreatedTime> view.StartTime && x.CreatedTime <view.EndTime&& x.ExecuteStatus==2).Result;
if (list == null) return Task.CompletedTask;
var execList = list.OrderByDescending(d => d.ExecuteOrder);
int i = 1;
string planType = string.Empty;
PlanInfoDataGrid.Clear();
foreach (var item in execList)
{
TaskExecModel task = new TaskExecModel();
task.No = i;
task.ID = item.ObjId.ToString();
task.OrderCode = item.OrderCode;
task.MaterialCode = item.MaterialCode;
task.MaterialName = item.MaterialName;
task.TaskAmount = item.PlanAmount;
task.CompleteAmount = item.CompleteAmount;
task.BeginTime = item.BeginTime;
task.IsExec = item.ExecuteStatus;//执行状态
if (item.PlanType == 1)
{
planType = "前后板联动";
}
if (item.PlanType == 2)
{
planType = "前板计划";
}
if (item.PlanType == 3)
{
planType = "后板计划";
}
task.PlanType = planType;
task.TaskCode = item.TaskCode;
task.ExecuteStatus = item.ExecuteStatus;//执行状态
PlanInfoDataGrid.Add(task);
i++;
}
//更新首页显示信息
ExecutePlanInfo execPlan = execList.SingleOrDefault(d => d.ExecuteStatus == 2);
if (execPlan != null)
{
_orderCode = execPlan.OrderCode;
_mesMOrderCode = execPlan.ProductPlanCode;
_productModel = execPlan.MaterialName;
_beginTime = execPlan.BeginTime.ToString();
_planMaxNum = _planNum = execPlan.PlanAmount;
_realQuantity = execPlan.CompleteAmount;
_diffQuantity = _planMaxNum - _realQuantity;
_completionRate = _realQuantity / _planMaxNum;
}
return Task.CompletedTask;
}
#endregion
#region 向上
/// <summary>
/// 向上
/// </summary>
[RelayCommand]
private async Task MoveUp(string Id)
{
string stationCode = Appsettings.app("StoreInfo", "StationCode");
bool result = await _taskExecutionPlanInfoServices.PlanMoveUp(Id, stationCode);
if (result)
{
PlanInfoDataGrid.Clear();
await LoadData();
}
}
#endregion
#region 向下
/// <summary>
/// 向下
/// </summary>
[RelayCommand]
private async Task MoveDown(string Id)
{
string stationCode = Appsettings.app("StoreInfo", "StationCode");
bool result = await _taskExecutionPlanInfoServices.PlanMoveDown(Id, stationCode);
if (result)
{
PlanInfoDataGrid.Clear();
LoadData();
}
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
[RelayCommand]
private async Task DeletePlan(string Id)
{
MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (MessageBoxResult.Yes == msg)
{
bool result = await _taskExecutionPlanInfoServices.ExecPlanDelete(Id);
if (result)
{
PlanInfoDataGrid.Clear();
LoadData();
MessageBox.Show("执行计划删除成功", "系统信息");
}
else
{
MessageBox.Show("执行计划删除失败", "系统信息");
}
}
}
#endregion
#region 下传计划
/// <summary>
/// 下传计划
/// </summary>
[RelayCommand]
private async Task NextPass(string Id)
{
MessageBoxResult msg = MessageBox.Show("确定要下发计划吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (MessageBoxResult.Yes != msg) return;
var model = await _taskExecutionPlanInfoServices.FirstAsync(d => d.ObjId == int.Parse(Id));
if (model.ExecuteStatus == 2)
{
MessageBox.Show("该计划正在执行中,请勿重复下传", "系统信息");
}
else
{
var result = _taskExecutionPlanInfoServices.PlanNextPass(model);
if (result != null)
{
//刷新列表
MessageBox.Show("执行计划已下达", "系统信息");
}
else
{
MessageBox.Show("执行计划下达失败", "系统信息");
}
}
}
#endregion
#region 初始化datagrid
private ObservableCollection<TaskExecModel> planInfoDataGrid = new ObservableCollection<TaskExecModel>();
public ObservableCollection<TaskExecModel> PlanInfoDataGrid
{
get { return planInfoDataGrid; }
set
{
planInfoDataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 计划拆分执行
/// <summary>
/// 计划拆分执行
/// </summary>
[RelayCommand]
private void SplitPlan()
{
SplitPlanView split = new SplitPlanView();
split.ShowDialog();
}
#endregion
#region 物料库存
/// <summary>
/// 物料库存
/// </summary>
[RelayCommand]
private void InventoryStatistics()
{
MaterialStatisticsView model = new MaterialStatisticsView();
model.ShowDialog();
}
#endregion
#endregion
#region 执行计划
#region 工位名称
private string _stationName;
public string StationName
{
get => _stationName;
set => SetProperty(ref _stationName, value);
}
#endregion
#region 订单编号
private string _orderCode;
public string OrderCode
{
get => _orderCode;
set => SetProperty(ref _orderCode, value);
}
#endregion
#region 计划编号
private string _mesMOrderCode;
public string MesMOrderCode
{
get => _mesMOrderCode;
set => SetProperty(ref _mesMOrderCode, value);
}
#endregion
#region 成品型号
private string _productModel;
public string ProductModel
{
get => _productModel;
set => SetProperty(ref _productModel, value);
}
#endregion
#region 开始时间
private string _beginTime;
public string BeginTime
{
get => _beginTime;
set => SetProperty(ref _beginTime, value);
}
#endregion
#region 计划数量
private int _planNum;
public int PlanNum
{
get => _planNum;
set => SetProperty(ref _planNum, value);
}
/// <summary>
/// 计划最大值
/// </summary>
private int _planMaxNum;
public int PlanMaxNum
{
get => _planMaxNum;
set => SetProperty(ref _planMaxNum, value);
}
#endregion
#region 实际数量
private int _realQuantity;
public int RealQuantity
{
get => _realQuantity;
set => SetProperty(ref _realQuantity, value);
}
#endregion
#region 差异数量
private int _diffQuantity;
public int DiffQuantity
{
get => _diffQuantity;
set => SetProperty(ref _diffQuantity, value);
}
#endregion
#region 完成率
private double _completionRate;
public double CompletionRate
{
get => _completionRate;
set => SetProperty(ref _completionRate, value);
}
#endregion
#endregion
#region 当日产量
#region 日产量柱状图X轴日期
/// <summary>
/// 日产量柱状图X轴日期
/// </summary>
private List<string> productionHourList;
public List<string> ProductionHourList
{
get { return productionHourList; }
set { productionHourList = value; }
}
#endregion
/// <summary>
/// 日产量柱状图
/// </summary>
private SeriesCollection achievement = new SeriesCollection();
public SeriesCollection Achievement
{
get { return achievement; }
set { achievement = value; }
}
#endregion
#region 型号统计
#region 型号统计柱状图x轴物料类型
/// <summary>
/// 型号统计柱状图x轴物料类型
/// </summary>
private List<string> materialNameList;
public List<string> MaterialNameList
{
get { return materialNameList; }
set { materialNameList = value; }
}
#endregion
#region 型号统计柱状图
/// <summary>
/// 型号统计柱状图
/// </summary>
private SeriesCollection modelStatistics = new SeriesCollection();
public SeriesCollection ModelStatistics
{
get { return modelStatistics; }
set { modelStatistics = value; }
}
#endregion
#endregion
#region 下拉框 选择执行状态
/// <summary>
/// 下拉框 选择执行状态
/// </summary>
private string materialTypeCombox;
public string MaterialTypeCombox
{
get { return materialTypeCombox; }
set
{
materialTypeCombox = value;
SetProperty(ref materialTypeCombox, value);
}
}
/// <summary>
/// 当ComboBox选中项更改时发生
/// </summary>
private SelectModel _selectLocation;
public SelectModel SelectLocation
{
get
{
return this._selectLocation;
}
set
{
this._selectLocation = value;
//这里操作更改变化的值
//MessageBox.Show(_selectLocation.ID);
if (_selectLocation != null)
{
WriteFile(_selectLocation.ID);
}
SetProperty(ref _selectLocation, value);
}
}
private ObservableCollection<SelectModel> _locationRoad = new ObservableCollection<SelectModel>();
/// <summary>
/// 集合数据
/// </summary>
public ObservableCollection<SelectModel> LocationSource
{
get
{
return this._locationRoad;
}
set
{
SetProperty(ref _locationRoad, value);
}
}
#endregion
#region 刷新列表-其他界面刷新该方法
/// <summary>
/// 刷新列表
/// </summary>
/// <param name="recipient"></param>
/// <param name="message"></param>
private async void Recive(object recipient, string message)
{
if (message == "Refresh")
{
PlanInfoDataGrid.Clear();
await LoadData();
}
}
#endregion
#region 刷新界面显示数据
/// <summary>
/// 刷新界面显示数据
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public async Task UpdatePlanSHow()
{
string stationCode = Appsettings.app("StoreInfo", "StationCode");
var info = await _taskExecutionPlanInfoServices.FirstAsync(d => d.ExecuteStatus == 3 && d.ProductLineCode == stationCode);
if (info == null) return;
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
{
PlanMaxNum = info.PlanAmount;
OrderCode = info.OrderCode;
MesMOrderCode = info.ProductPlanCode;
ProductModel = info.MaterialName;
BeginTime = info.BeginTime.ToString();
}));
}
#endregion
#region 读写文件
public void WriteFile(int obj)
{
//写入到配置文件中
appConfig.queryExec = obj.ToString();
}
public SelectModel ReadFile()
{
//读取入到配置文件中
var queryExec = appConfig.queryExec;
var model = list.FirstOrDefault(d => d.ID == int.Parse(queryExec));
return model;
}
#endregion
#region 刷新当前执行的计划进度
/// <summary>
/// 刷新当前执行的计划进度
/// </summary>
/// <param name="planInfo"></param>
private void RefreshCurrentPlanInfo(ExecutePlanInfo planInfo)
{
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
PlanInfoDataGrid.Clear();
LoadData();
}));
}
#endregion
#region 刷新小时产量统计
/// <summary>
/// 刷新小时产量统计
/// </summary>
private void RefreshHourAmount()
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
//获取小时产量
string stationCode = Appsettings.app("StationInfo", "StationCode");
var hourAmount = _sysUserInfoServices.GetSheetMetaHourData(stationCode).Result;
if (hourAmount != null)
{
Achievement.Clear();
ProductionHourList = new List<string>();
ChartValues<ObservablePoint> hourAchievement1 = new ChartValues<ObservablePoint>();
ChartValues<ObservablePoint> hourAchievement2 = new ChartValues<ObservablePoint>();
int hour = 0;
foreach (var item in hourAmount)
{
hourAchievement1.Add(new ObservablePoint(hour,Convert.ToDouble(item.FrontPlateAmount)));
hourAchievement2.Add(new ObservablePoint(hour,Convert.ToDouble(item.RearPanelAmount)));
ProductionHourList.Add(item.HourTime);
hour++;
}
#region 按时间统计
var column = new ColumnSeries();
column.DataLabels = true;
column.Title = "前板";
column.Values = hourAchievement1;
column.Foreground = Brushes.White;
column.FontSize = 18;
Achievement.Add(column);
Achievement.Add(new ColumnSeries
{
DataLabels = true,
Title = "后板",
Values = hourAchievement2,
Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)),
Foreground = Brushes.CadetBlue,
FontSize = 18
});
#endregion
}
}));
}
#endregion
#region 刷新物料型号统计
/// <summary>
/// 刷新物料型号统计
/// </summary>
private void RefreshMaterialStats()
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
//获取物料型号统计
string stationCode = Appsettings.app("StationInfo", "StationCode");
var sheetMetalTypeList = _sysUserInfoServices.GetSheetMetalTypeData(stationCode).Result;
if (sheetMetalTypeList != null)
{
#region 按类型统计
ChartValues<double> achievement1 = new ChartValues<double>();
ChartValues<double> achievement2 = new ChartValues<double>();
MaterialNameList = new List<string>();
foreach (var item in sheetMetalTypeList)
{
achievement1.Add(Convert.ToInt32(item.FrontPlateAmount));
achievement2.Add(Convert.ToInt32(item.RearPanelAmount));
MaterialNameList.Add(item.MaterialName);
}
var column2 = new ColumnSeries();
column2.DataLabels = true;
column2.Title = "前板";
column2.Values = achievement1;
column2.Foreground = Brushes.White;
column2.FontSize = 18;
ModelStatistics.Add(column2);
ModelStatistics.Add(new ColumnSeries()
{
DataLabels = true,
Title = "后板",
Values = achievement2,
Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)),
Foreground = Brushes.White,
FontSize = 18
});
#endregion
}
}));
}
#endregion
public CurrentTeamTimeView GetTeamHour()
{
List<CurrentTeamTimeView> obj = _sysUserInfoServices.GetTeamData().Result;
if (obj != null)
{
CurrentTeamTimeView view = new CurrentTeamTimeView();
view.TeamName = obj.FirstOrDefault(d=>d.Seq==1).TeamName;
view.StartTime = obj.Min(d => d.StartTime);
view.EndTime = obj.Max(d => d.EndTime);
return view;
}
return null;
}
}
}
Loading…
Cancel
Save