天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

400 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.MD.Entity;
using QMFrameWork.Log;
using QMFrameWork.Data;
using QMAPP.MD.DAL;
namespace QMAPP.MD.BLL
{
/// <summary>
/// 模块名称:班次
/// 作 者:郭兆福
/// 编写日期:2017年05月17日
/// </summary>
public class ShiftBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<Shift__> Get(Shift__ model)
{
DataResult<Shift__> result = new DataResult<Shift__>();
try
{
result.Result = new ShiftDAL().Get(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表(分页)
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(Shift__ condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取物料信息列表
DataPage dataPage = new ShiftDAL().GetList(condition, page);
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public IList<Shift__> GetAllList(Shift__ condition)
{
try
{
//获取物料信息列表
return new ShiftDAL().GetList(condition);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
// <summary>
/// 获取全部用户
/// </summary>
/// <param name="condition">获取条件</param>
/// <returns>用户信息列表</returns>
public List<Shift__> GetAllShift(Shift__ condition)
{
return new ShiftDAL().GetAllShift(condition);
}
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsShift(Shift__ model)
{
try
{
return new ShiftDAL().ExistsShift(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> Insert(Shift__ model)
{
DataResult<int> result = new DataResult<int>();
ShiftDAL cmdDAL = new ShiftDAL();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.UPDATEUSER = model.CREATEUSER;
model.FLGDEL = "0";
try
{
if (ExistsShift(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProduceShiftCodeIsHave;
return result;
}
result.Result = new ShiftDAL().Insert(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> Update(Shift__ model)
{
DataResult<int> result = new DataResult<int>();
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsShift(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProduceShiftCodeIsHave;
return result;
}
result.Result = new ShiftDAL().Update(model);
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public DataResult<int> Delete(string strs)
{
DataResult<int> result = new DataResult<int>();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
result.Result += this.DeleteShift(new Shift__ { PID = str });
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteShift(Shift__ model)
{
int count = 0;
try
{
count = new ShiftDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 校验时间
/// <summary>
/// 校验时间
/// </summary>
/// <param name="model">班次信息</param>
/// <returns>true:不存在通过;false:已存在不存在。</returns>
public DataResult<bool> ExistsShiftTime(Shift__ model)
{
ShiftDAL psDal = new ShiftDAL();
Shift__ condition = new Shift__();
// 工厂
condition.FACTORY_CODE = model.FACTORY_CODE;
IList<Shift__> psList = new List<Shift__>();
// 既存开始时间
DateTime psDbStart = new DateTime();
// 既存结束时间
DateTime psDbEnd = new DateTime();
//前台班次时间值
DateTime startTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + model.WORK_START_TIME.ToLongTimeString());
DateTime endTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + model.WORK_END_TIME.ToLongTimeString());
DataResult<bool> result = new DataResult<bool>();
try
{
//得到相同工厂班次信息
psList = psDal.GetList(condition);
//遍历所有班次信息,校验输入班次信息时间在数据库中是否已存在
if (psList != null || psList.Count() != 0)
{
foreach (var item in psList)
{
// 修改的情况下,去掉本身
if (item.SHIFT_CODE.Equals(model.SHIFT_CODE))
{
continue;
}
//数据库DB班次时间值
psDbStart = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + item.WORK_START_TIME.ToLongTimeString());
psDbEnd = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + item.WORK_END_TIME.ToLongTimeString());
#region 时间校验
if (psDbStart < psDbEnd)
{
// 前台输入时间开始时间 < 结束时间
if (startTime < endTime)
{
return IsDuplicateShift(startTime, endTime, psDbStart, psDbEnd);
}
else
{
//输入时间零点分割零点分割
//后一天的零点
DateTime tempInputEndTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " " + "00:00:00");
//当天的零点
DateTime tempInputStartTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + "00:00:00");
// 输入的开始时间到后一天的零点
result = IsDuplicateShift(startTime, tempInputEndTime, psDbStart, psDbEnd);
if (result.IsSuccess == true)
{
// 当天的零点到输入的结束时间
result = IsDuplicateShift(tempInputStartTime, endTime, psDbStart, psDbEnd);
}
if (result.IsSuccess == false)
{
return result;
}
}
}
else
{
// DB 时间跨天分割
//后一天的零点
DateTime tempDbEndTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " " + "00:00:00");
//当天的零点
DateTime tempDbStartTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + "00:00:00");
// 前台输入时间开始时间 < 结束时间
if (startTime < endTime)
{
// 输入的开始时间到后一天的零点
result = IsDuplicateShift(startTime, endTime, psDbStart, tempDbEndTime);
if (result.IsSuccess == true)
{
// 当天的零点到输入的结束时间
result = IsDuplicateShift(startTime, endTime, tempDbStartTime, psDbEnd);
}
if (result.IsSuccess == false)
{
return result;
}
}
else
{
// 输入时间和DB时间都有跨天,班次时间上就重复了
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
}
#endregion
}
}
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 班次时间是否重复
/// </summary>
/// <param name="inputStart">输入开始时间</param>
/// <param name="inputEnd">输入结束时间</param>
/// <param name="dbStart">既存开始时间</param>
/// <param name="dbEnd">既存结束时间</param>
/// <returns>true:通过 false:未通过</returns>
private DataResult<bool> IsDuplicateShift(DateTime inputStart, DateTime inputEnd, DateTime dbStart, DateTime dbEnd)
{
DataResult<bool> result = new DataResult<bool>();
// 前台输入的开始时间 大于等于 数据库的开时间 并且小于等于数据
if ((dbStart <= inputStart && inputStart < dbEnd)
|| (dbStart < inputEnd && inputEnd <= dbEnd)
|| (inputStart < dbStart && dbStart < inputEnd)
)
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取班次信息列表(下拉列表使用)
/// <summary>
///
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<Shift__> GetShiftList(Shift__ condition)
{
List<Shift__> result = new List<Shift__>();
try
{
result = new ShiftDAL().GetShiftList(condition);
}
catch (Exception ex)
{
throw ex;
}
return result;
}
#endregion
}
}