using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using QMFrameWork.Common.Encrypt; using QMFrameWork.Data; using QMAPP.FJC.DAL.SendPlan; using QMAPP.FJC.Entity.SendPlan; using QMAPP.BLL; using QMAPP.Entity; using QMAPP.FJC.BLL.Dict; using QMFrameWork.Log; using QMAPP.FJC.Entity; namespace QMAPP.FJC.BLL.SendPlan { /// /// 模块编号:M14-1 /// 作 用:贴车单 /// 作 者:王庆男 /// 编写日期:2015年06月04日 /// public class SendPlanInfoBLL : BaseBLL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public SendPlanInfo Get(SendPlanInfo model) { try { return new SendPlanInfoDAL().Get(model); } catch (Exception ex) { throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(SendPlanInfo condition, DataPage page) { try { return new SendPlanInfoDAL().GetList(condition, page); } catch (Exception ex) { throw ex; } } #endregion #region 信息是否重复 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsSendPlanInfo(SendPlanInfo model) { try { return new SendPlanInfoDAL().ExistsSendPlanInfo(model); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public int Insert(SendPlanInfo model) { try { //基本信息 model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; SendPlanInfoDAL cmdDAL = new SendPlanInfoDAL(); if (ExistsSendPlanInfo(model) == true) return -1; return new SendPlanInfoDAL().Insert(model); } catch (Exception ex) { throw ex; } } /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult InsertAndUpdateMain(SendPlanInfo model) { DataResult result = new DataResult(); result.IsSuccess = true; try { //基本信息 model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; foreach (var item in model.mainList) { item.SPID = model.PID; item.SENDCODE = model.SENDCODE; item.OUTFLAG = EnumGeter.OUTFLAG.OUTWAREHOUSE.GetHashCode().ToString(); } SendPlanInfoDAL cmdDAL = new SendPlanInfoDAL(); result.Result = new SendPlanInfoDAL().InsertAndUpdateMain(model); result.Msg = "操作成功!"; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "发运单插入异常!" }); result.IsSuccess = false; result.Ex = ex; } return result; } /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult UpdateMain(SendPlanInfo model) { DataResult result = new DataResult(); result.IsSuccess = true; try { //基本信息 //model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; foreach (var item in model.mainList) { item.SPID = model.PID; item.SENDCODE = model.SENDCODE; item.OUTFLAG = EnumGeter.OUTFLAG.OUTWAREHOUSE.GetHashCode().ToString(); } SendPlanInfoDAL cmdDAL = new SendPlanInfoDAL(); result.Result = new SendPlanInfoDAL().UpdateMain(model); result.Msg = "操作成功!"; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "发运单插入异常!" }); result.IsSuccess = false; result.Ex = ex; } return result; } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(SendPlanInfo model) { try { //if (ExistsSendPlanInfo(Model) == true) //return -1; //基本信息 model.UPDATEUSER = this.LoginUser.UserID; return new SendPlanInfoDAL().Update(model); } catch (Exception ex) { throw ex; } } #endregion #region 删除 /// /// 删除信息 /// /// /// 删除个数 public int Delete(string strs) { int count = 0; string[] list = strs.Split(":".ToCharArray()); try { foreach (string str in list) { count += this.DeleteSendPlanInfo(new SendPlanInfo { PID = str }); } return count; } catch (Exception ex) { throw ex; } } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteSendPlanInfo(SendPlanInfo model) { int count = 0; try { count = new SendPlanInfoDAL().Delete(model); return count; } catch (Exception ex) { throw ex; } } #endregion #region 导出数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(SendPlanInfo model) { try { return new SendPlanInfoDAL().GetExportData(model); } catch (Exception ex) { throw ex; } } #endregion #region 导入数据 public DataResult GetImportData(List list) { DataResult result = new DataResult(); SendPlanInfoDAL cmDal = new SendPlanInfoDAL(); List List = new List(); int index = 0; try { result.Result = new ImportMessage(); result.Result.Errors = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { //状态判断 foreach (SendPlanInfo ma in list) { index++; if (string.IsNullOrEmpty(ma.InfoError) == false) { ma.PID = null; result.Result.failureNum += 1; continue; } //修改改时根据主键等信息获取详细内容信息 SendPlanInfo oldInfo = cmDal.Get(ma); if (oldInfo != null) { //更新 ma.PID = oldInfo.PID; ma.CREATEUSER = oldInfo.CREATEUSER; ma.CREATEDATE = oldInfo.CREATEDATE; ma.UPDATEUSER = this.LoginUser.UserID; ma.UPDATEDATE = oldInfo.UPDATEDATE; ma.IsNewInfo = false; result.Result.updateNum += 1; } else { //新增 oldInfo = new SendPlanInfo(); ma.PID = Guid.NewGuid().ToString(); ma.CREATEUSER = this.LoginUser.UserID; ma.CREATEDATE = DateTime.Now; ma.UPDATEUSER = ma.CREATEUSER; ma.UPDATEDATE = ma.CREATEDATE; ma.IsNewInfo = true; result.Result.insertNum += 1; } List.Add(ma); } } //导入 cmDal.GetImportData(List); result.Msg = "导入成功"; result.IsSuccess = true; return result; } catch (Exception ex) { result.IsSuccess = false; result.Ex = ex; return result; } } #endregion #region 获取列表(发车统计分析) /// /// 获取列表(发车统计分析) /// /// 条件 /// 信息集合 public DataResult> GetSendStatisticsList(SendPlanInfo condition) { DataResult> result = new DataResult>(); try { result.Result = new SendPlanInfoDAL().GetListGroupBy(condition); #region 转换颜色、高低配显示类型 DictManageBLL dictColorBll = new DictManageBLL(DictKind.COLOR); DictManageBLL dictHAandLBll = new DictManageBLL(DictKind.HAndL); foreach (SendPlanInfo m in result.Result) { //颜色 m.COLORCODE = dictColorBll.GetDictValue(m.COLORCODE); //高低配 m.VERSION = dictHAandLBll.GetDictValue(m.VERSION); } #endregion } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "贴车单-获取列表(发车统计分析)!" }); result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #region 导出数据(发车统计分析) /// /// 获取导出的数据(发车统计分析) /// /// 查询条件 /// 数据 public DataResult GetSendStatisticsExportData(SendPlanInfo model) { DataResult result = new DataResult(); try { result.Result = new SendPlanInfoDAL().GetSendStatisticsExportData(model); #region 转换颜色、高低配显示类型 DictManageBLL dictColorBll = new DictManageBLL(DictKind.COLOR); DictManageBLL dictHAandLBll = new DictManageBLL(DictKind.HAndL); foreach (DataRow item in result.Result.Rows) { //颜色 item["COLORCODE"] = dictColorBll.GetDictValue(item["COLORCODE"].ToString()); //高低配 item["VERSION"] = dictHAandLBll.GetDictValue(item["VERSION"].ToString()); } #endregion } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "贴车单-导出数据(发车统计分析)!" }); result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #endregion #endregion } }