using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.BLL; using QMAPP.FJC.Entity.Basic; using QMAPP.FJC.DAL.Basic; using QMFrameWork.Data; using QMAPP.KB.Entity; using QMAPP.FJC.Entity; namespace QMAPP.FJC.BLL.Basic { /// /// 单色搪塑操作类 /// 2016-6-15 闫永刚 /// /// public class MoldConfigBLL : BaseBLL { /// /// 获取所有的配置信息 /// /// /// public DataPage GetList(MoldConfig condition) { try { DataPage page = new DataPage(); //获取物料信息列表 List list = new MoldConfigDAL().GetList(condition); page.Result = list; return page; } catch (Exception ex) { throw ex; } } /// /// 获取最大的模架号和模腔号 /// /// public MoldConfig GetMaxMold() { try { //获取物料信息列表 MoldConfig mold = new MoldConfigDAL().GetMaxMold(); return mold; } catch (Exception ex) { throw ex; } } /// /// 获取单个实体 /// /// /// public DataResult Get(MoldConfig condition) { DataResult result=new DataResult(); condition = new MoldConfigDAL().Get(condition); result.Result = condition; return result; } /// /// 删除 /// /// /// public DataResult Delete(MoldConfig condition) { DataResult result = new DataResult(); try { new MoldConfigDAL().Delete(condition); result.IsSuccess = true; result.Msg = "删除成功!"; } catch (Exception ex) { result.IsSuccess = false; result.Msg = "删除失败!"; } return result; } /// /// 新增模腔号配置信息 /// /// /// public DataResult Insert(MoldConfig entity) { DataResult result = new DataResult(); entity.PID = Guid.NewGuid().ToString(); MoldConfigDAL dal = new MoldConfigDAL(); using (IDataSession session = AppDataFactory.CreateMainSession()) { dal.BaseSession = session; session.OpenTs(); dal.Insert(entity); if (entity.USED == 1) { dal.UpdateOtherUsed(entity); } session.CommitTs(); } result.Msg = "保存成功!"; result.IsSuccess = true; return result; } /// /// 修改模腔号配置信息 /// /// /// public DataResult Update(MoldConfig entity) { DataResult result = new DataResult(); MoldConfigDAL dal = new MoldConfigDAL(); using (IDataSession session = AppDataFactory.CreateMainSession()) { dal.BaseSession = session; session.OpenTs(); dal.Update(entity); if (entity.USED == 1) { dal.UpdateOtherUsed(entity); } session.CommitTs(); } result.Msg = "保存成功!"; result.IsSuccess = true; return result; } public DataResult UpdateNextUsed(MoldConfig entity) { DataResult result = new DataResult(); MoldConfigDAL dal = new MoldConfigDAL(); List list = new MoldConfigDAL().GetList(new MoldConfig() { STATUS=1 }); MoldConfig original = new MoldConfig(); MoldConfig nextEntity = new MoldConfig(); if (list.Count(o => o.MOLDSTATION == entity.MOLDSTATION) > 0) { original = list.First(o => o.MOLDSTATION == entity.MOLDSTATION); //original.USED = 0; List restList = list.Where(o => o.INDEXVALUE > original.INDEXVALUE) .OrderBy(o => o.INDEXVALUE).ToList(); if (restList.Count > 0) { nextEntity = restList[0]; } else { nextEntity = list[0]; } nextEntity.USED = 1; } using (IDataSession session = AppDataFactory.CreateMainSession()) { dal.BaseSession = session; session.OpenTs(); if (string.IsNullOrEmpty(nextEntity.PID) == false) { dal.Update(nextEntity); } dal.UpdateOtherUsed(nextEntity); session.CommitTs(); } result.Msg = "保存成功!"; result.IsSuccess = true; return result; } } }