public bool UpLoad(Stream stream, string companyId) { var dataItems = (Dictionary <string, object>) new ItemsDetailApp().GetDataItemList(); var count = 2; var ds = NPOIExcel.ImportExceltoDs(stream); if (ds == null) { return(false); } var dt = ds.Tables[0]; if (dt == null || dt.Rows.Count <= 0) { return(false); } foreach (DataRow item in dt.Rows) { try { var row = item; if (string.IsNullOrEmpty(row[0] as string) || string.IsNullOrEmpty(row[1] as string)) { continue; } var channel = new ChannelApp().GetFormByName((string)row[0]); if (channel == null) { throw new Exception("当前设备不存在"); } var meter = _meterApp.GetFormByMeterCode((string)row[1], companyId); if (meter == null) { throw new Exception("当前表计不存在"); } var channeMeterEntity = new ChannelMeterEntity { F_ArchiveId = meter.F_Id, F_ChannelId = channel.F_Id, }; var channelMeter = _viewService.FindEntity(x => x.F_ArchiveId == meter.F_Id && x.F_DeleteMark != true); SubmitForm(channeMeterEntity, channelMeter == null ? "" : channelMeter.F_Id); count++; } catch (Exception ex) { throw new Exception("表格行" + count + "数据不正确," + ex.Message); } } return(count > 2); }
public bool UpLoad(Stream stream) { var count = 0; var list = new List <IOTEntity>(); var ds = NPOIExcel.ImportExceltoDs(stream); if (ds == null) { return(false); } var dt = ds.Tables[0]; if (dt == null || dt.Rows.Count <= 0) { return(false); } foreach (DataRow item in dt.Rows) { DateTime?purchaseTime = null; DateTime?openAccountTime = null; var row = item; if (!string.IsNullOrEmpty(row[2] == null ? "" : row[2].ToString())) { purchaseTime = DateTime.FromOADate(double.Parse(row[2] == null ? "" : row[2].ToString())); } if (!string.IsNullOrEmpty(row[2] == null ? "" : row[8].ToString())) { openAccountTime = DateTime.FromOADate(double.Parse(row[8] == null ? "" : row[8].ToString())); } ; var iccid = (string)row[6]; var en = _service.FindEntity(t => t.M_ICCID == iccid); if (en == null) { list.Add(new IOTEntity { M_IMEI = row[3] == null ? "" : row[3].ToString(), M_SN = row[4] == null ? "" : row[4].ToString(), M_IMSI = row[5] == null ? "" : row[5].ToString(), M_ICCID = row[6] == null ? "" : row[6].ToString(), M_CardID = row[7] == null ? "" : row[7].ToString(), M_HardwareName = row[10] == null ? "" : row[10].ToString(), M_ArtNo = row[11] == null ? "" : row[11].ToString(), M_MeterTypeName = row[12] == null ? "" : row[12].ToString(), M_CustomerName = row[13] == null ? "" : row[13].ToString(), M_Location = row[14] == null ? "" : row[14].ToString(), M_Balance = row[15] == null ? "" : row[15].ToString(), M_Remarks = row[16] == null ? "" : row[16].ToString(), M_Batch = row[1] == null ? "" : row[1].ToString(), M_PurchaseTime = purchaseTime, M_OpenAccountTime = openAccountTime, M_OpenAccountUserName = row[9] == null ? "" : row[9].ToString(), }); } else { en.M_IMEI = row[3] == null ? "" : row[3].ToString(); en.M_SN = row[4] == null ? "" : row[4].ToString(); en.M_IMSI = row[5] == null ? "" : row[5].ToString(); en.M_ICCID = row[6] == null ? "" : row[6].ToString(); en.M_CardID = row[7] == null ? "" : row[7].ToString(); en.M_HardwareName = row[10] == null ? "" : row[10].ToString(); en.M_ArtNo = row[11] == null ? "" : row[11].ToString(); en.M_MeterTypeName = row[12] == null ? "" : row[12].ToString(); en.M_CustomerName = row[13] == null ? "" : row[13].ToString(); en.M_Location = row[14] == null ? "" : row[14].ToString(); en.M_Balance = row[15] == null ? "" : row[15].ToString(); en.M_Remarks = row[16] == null ? "" : row[16].ToString(); en.M_Batch = row[1] == null ? "" : row[1].ToString(); en.M_PurchaseTime = purchaseTime; en.M_OpenAccountTime = openAccountTime; en.M_OpenAccountUserName = row[9] == null ? "" : row[9].ToString(); count += _service.Update(en); } } count += _service.Insert(list); return(count > 0); }
public bool UpLoad(Stream stream, string companyId) { var dataItems = (Dictionary <string, object>) new ItemsDetailApp().GetDataItemList(); var count = 2; var ds = NPOIExcel.ImportExceltoDs(stream); if (ds == null) { return(false); } var dt = ds.Tables[0]; if (dt == null || dt.Rows.Count <= 0) { return(false); } foreach (DataRow item in dt.Rows) { try { var row = item; var price = new PriceEntity(); if (companyId == "030eca51-483a-47b6-ad46-b6164278ebcb") { var metercode = row[4] as string; if (string.IsNullOrEmpty(metercode)) { continue; } price = _priceApp.GetDefault(companyId); var customPara = new MeterCustomParameter { LINENO = "", BusinessID = row[5] as string, AreaID = row[6] as string, BookID = row[7] as string, InTabManIDs = row[8] as string, }; var meterEntity = new MeterEntity(); var meterChargingEntity = new MeterChargingEntity(); var meter = _service.FindEntity(x => x.F_MeterCode == metercode && x.F_DeleteMark != true && x.F_OwnerId == companyId); if (meter != null) { var meterCharging = new MeterChargingApp().GetForm(meter.F_Id); meterEntity = meter; meterChargingEntity = meterCharging; } meterEntity.F_MeterType = "WaterMeter"; meterEntity.F_Factor = "贝林电子"; meterEntity.F_MeterName = row[1] as string; meterEntity.F_MeterRate = 1; meterEntity.F_UserCard = (string)row[0]; meterEntity.F_MeterCode = (string)row[4]; meterEntity.F_CustomerName = (string)row[1]; meterEntity.F_IDNumber = row[0] as string; meterEntity.F_MobilePhone = row[3] as string; meterEntity.F_CustomerAddress = row[2] as string; meterEntity.F_Description = customPara.ToJson(); meterEntity.F_OwnerId = companyId; meterChargingEntity.F_PriceModel = price.F_Id; meterChargingEntity.F_MeterModel = "1"; SubmitForm(meterEntity, meterChargingEntity, meter == null ? "" : meter.F_Id); count++; } else { var metercode = row[7] as string; if (string.IsNullOrEmpty(metercode)) { continue; } var priceName = row[2] as string; price = _priceApp.GetForm(companyId, priceName); if (price == null) { throw new Exception("当前执行价格不存在"); } double rate; var meterEntity = new MeterEntity(); var meterChargingEntity = new MeterChargingEntity(); var meter = _service.FindEntity(x => x.F_MeterCode == metercode && x.F_DeleteMark != true && x.F_OwnerId == companyId); if (meter != null) { var meterCharging = new MeterChargingApp().GetForm(meter.F_Id); meterEntity = meter; meterChargingEntity = meterCharging; } meterEntity.F_MeterType = ((Dictionary <string, string>)dataItems["DeviceType"]).First(x => x.Value == (string)row[0]).Key; meterEntity.F_Factor = (string)row[3]; meterEntity.F_MeterName = row[4] as string; meterEntity.F_MeterRate = double.TryParse(row[5] as string, out rate) ? rate : 1; meterEntity.F_UserCard = (string)row[6]; meterEntity.F_MeterCode = (string)row[7]; meterEntity.F_CustomerName = (string)row[8]; meterEntity.F_IDNumber = row[9] as string; meterEntity.F_MobilePhone = (string)row[10]; meterEntity.F_CustomerAddress = row[11] as string; meterEntity.F_Description = row[12] as string; meterEntity.F_OwnerId = companyId; meterChargingEntity.F_PriceModel = price.F_Id; meterChargingEntity.F_MeterModel = ((Dictionary <string, string>)dataItems["MeterModel"]).First(x => x.Value == (string)row[1]).Key; SubmitForm(meterEntity, meterChargingEntity, meter == null ? "" : meter.F_Id); count++; } } catch (Exception ex) { throw new Exception("表格行" + count + "数据不正确," + ex.Message); } } return(count > 2); }