/// <summary> /// 授权经销商产品线 /// </summary> /// <param name="dto"></param> /// <returns></returns> public bool DistributorProductLineAuthority(DistributorAuthorityOperateDTO dto) { bool blResult = false; using (var tcdmse = new Entities.TCDMS_MasterDataEntities()) { var pp = tcdmse.master_DistributorInfo.Where(p => p.DistributorID == dto.DistributorID).FirstOrDefault(); if (pp == null) { throw new Exception("该经销商已不存在"); } foreach (var line in dto.ProductLineRegion) { master_DistributorProductLineInfo displine = new master_DistributorProductLineInfo(); displine.DistributorID = pp.DistributorID; displine.ProductLineID = line.ProductLineID; tcdmse.master_DistributorProductLineInfo.Add(displine); var qq = tcdmse.master_ProductLine.Where(q => q.ProductLineID == line.ProductLineID).Select(s => s.ProductLineName).FirstOrDefault(); // 记录日志 this.AddLog(tcdmse, new LogData { CurrentLogType = LogType.ADD, LogDetails = "经销商授权 经销商:" + pp.DistributorName + "授权产品线:" + qq, OpratorName = dto.CreateUser }); } blResult = tcdmse.SaveChanges() > 0; } return(blResult); }
/// <summary> /// 导入数据 /// </summary> /// <param name="impdto"></param> /// <returns></returns> public bool ImportData(List <ExcelImportDataDTO> impdtolst) { bool blResult = false; using (var tcdmse = new Entities.TCDMS_MasterDataEntities()) { foreach (var p in impdtolst) { if (p is ExcelDistributorDTO) // 判断是否为经销商信息 { ExcelDistributorDTO exrdt = p as ExcelDistributorDTO; if (exrdt.UpLogic == 2) { var pp = tcdmse.master_DistributorInfo.Where(m => m.DistributorID == exrdt.DistributorID).FirstOrDefault(); pp.IsActive = exrdt.IsActiveStr == "是" ? true : false; pp.DistributorCode = exrdt.DistributorCode; pp.DistributorTypeID = exrdt.DistributorTypeID; pp.DistributorServiceTypeID = exrdt.DistributorServiceTypeID; pp.RegionID = exrdt.RegionID; pp.InvoiceCode = exrdt.InvoiceCode; pp.DeliverCode = exrdt.DeliverCode; pp.CSRNameReagent = exrdt.CSRNameReagent; pp.CSRNameD = exrdt.CSRNameD; pp.CSRNameB = exrdt.CSRNameB; pp.Office = exrdt.Office; pp.ModifyUser = exrdt.Importer; pp.ModifyTime = DateTime.Now; } else { master_DistributorInfo mprd = new master_DistributorInfo(); mprd.DistributorID = Guid.NewGuid(); mprd.IsActive = exrdt.IsActiveStr == "启用" ? true : false; mprd.DistributorCode = exrdt.DistributorCode; mprd.DistributorName = exrdt.DistributorName; mprd.DistributorTypeID = exrdt.DistributorTypeID; mprd.DistributorServiceTypeID = exrdt.DistributorServiceTypeID; mprd.RegionID = exrdt.RegionID; mprd.InvoiceCode = exrdt.InvoiceCode; mprd.DeliverCode = exrdt.DeliverCode; mprd.CSRNameReagent = exrdt.CSRNameReagent; mprd.CSRNameD = exrdt.CSRNameD; mprd.CSRNameB = exrdt.CSRNameB; mprd.Office = exrdt.Office; mprd.CreateUser = exrdt.Importer; mprd.CreateTime = DateTime.Now; tcdmse.master_DistributorInfo.Add(mprd); // 记录日志 this.AddLog(tcdmse, new LogData { CurrentLogType = LogType.IMPORT, LogDetails = "导入经销商" + exrdt.DistributorName, OpratorName = exrdt.Importer }); } } if (p is ExcelDistributorADAuthorityDTO) // 判断是否为经销商公告授权 { ExcelDistributorADAuthorityDTO exrdt = p as ExcelDistributorADAuthorityDTO; tcdmse.master_DistributorADInfo.RemoveRange(tcdmse.master_DistributorADInfo.Where(m => m.DistributorID == exrdt.DistributorID)); if (exrdt.ProductLineIDList != null && exrdt.ProductLineIDList.Count() > 0) { foreach (var productlineid in exrdt.ProductLineIDList) { master_DistributorADInfo mprd = new master_DistributorADInfo(); mprd.DistributorID = exrdt.DistributorID; mprd.ProductLineID = productlineid; mprd.CreateUser = exrdt.Importer; mprd.CreateTime = DateTime.Now; tcdmse.master_DistributorADInfo.Add(mprd); } // 记录日志 this.AddLog(tcdmse, new LogData { CurrentLogType = LogType.IMPORT, LogDetails = "导入经销商公告授权,经销商:" + exrdt.DistributorName + ",产品线:" + exrdt.ProductLineName, OpratorName = exrdt.Importer }); } } if (p is ExcelDistributorAuthorityDTO) // 判断是否为经销商授权 { ExcelDistributorAuthorityDTO exrdt = p as ExcelDistributorAuthorityDTO; var pp = tcdmse.master_DistributorInfo.FirstOrDefault(g => g.DistributorName == exrdt.DistributorName); if (pp != null) { pp.IsOrderGoods = exrdt.IsOrderGoodsstr == "是" ? true : false; //付款条款 pp.master_DistributorPayInfo.Clear(); tcdmse.master_PaymentInfo.Where(w => exrdt.PayNamelist.Contains(w.PayName)).ToList().ForEach(f => { pp.master_DistributorPayInfo.Add(new master_DistributorPayInfo { PayID = f.PayID, DistributorID = pp.DistributorID }); }); //运输方式 pp.master_DistributorTransport.Clear(); tcdmse.master_TransportInfo.Where(w => exrdt.TransportNamelist.Contains(w.TransportName)).ToList().ForEach(f => { pp.master_DistributorTransport.Add(new master_DistributorTransport { TransportID = f.TransportID, DistributorID = pp.DistributorID }); }); //产品线 var productline = tcdmse.master_ProductLine.Where(w => exrdt.ProductLineNamelist.Contains(w.ProductLineName)).ToList(); //取得省份到部门 pp.master_DistributorProductLineInfo.Clear(); var prolineregin = tcdmse.vw_DepartToRegion.Where(w => exrdt.RegionNamelist.Contains(w.RegionName)).ToList(); productline.ForEach(f => { master_DistributorProductLineInfo proline = new master_DistributorProductLineInfo(); pp.master_DistributorProductLineInfo.Add(proline); proline.ProductLineID = f.ProductLineID; proline.DistributorID = pp.DistributorID; //产品线区域 List <master_DistributorRegionInfo> disregionlist = new List <master_DistributorRegionInfo>(); proline.master_DistributorRegionInfo = disregionlist; prolineregin.ForEach(pf => { master_DistributorRegionInfo disregion = new master_DistributorRegionInfo(); disregionlist.Add(disregion); disregion.RegionID = pf.RegionID; disregion.DistrictID = pf.districtid; disregion.AreaID = pf.AreaID; disregion.DepartID = pf.DepartID; }); }); // 记录日志 this.AddLog(tcdmse, new LogData { CurrentLogType = LogType.IMPORT, LogDetails = "导入经销商授权:经销商:" + exrdt.DistributorName + ";授权付款条款:" + exrdt.PayNamestr + ";授权运输方式:" + exrdt.TransportNamestr + ";授权产品线" + exrdt.ProductLineNamestr + ";授权区域" + exrdt.RegionNamestr, OpratorName = exrdt.Importer }); } } } blResult = tcdmse.SaveChanges() > 0; } return(blResult); }