public void InsertTestMeter(string meterCode) { var meterEntity = new MeterEntity { F_MeterType = "WaterMeter", F_Factor = "贝林电子", F_MeterRate = 1, F_MeterCode = meterCode, F_OwnerId = "b566c9fd-cc74-4280-95e5-b513b86f365b", F_UserCard = meterCode }; var meterChargingEntity = new MeterChargingEntity { F_PriceModel = "95a3d254-af0b-4424-894c-3de53c85bdfb", F_MeterModel = "1", F_Balance = 0, F_StartValue = 0, F_CloseAmount = 0, F_AlarmAmount = 0, F_EnableAlarm = false, F_EnableClose = false, F_State = true }; SubmitForm(meterEntity, meterChargingEntity, ""); }
public async Task Seed() { _ctx.Database.EnsureCreated(); var user = await _userManager.FindByNameAsync("Admin"); if (user == null) { user = new UserEntity() { UserName = "******" }; var result = await _userManager.CreateAsync(user, "P@ssw0rd!"); if (result != IdentityResult.Success) { throw new InvalidOperationException("Failed to create the admin user"); } } if (!_ctx.Meters.Any()) { MeterEntity[] meters = new MeterEntity[5]; var metersfilepath = Path.Combine(hosting.ContentRootPath, @"Services\metersentity.json"); meters = JsonConvert.DeserializeObject <MeterEntity[]>(File.ReadAllText(metersfilepath)); _ctx.Meters.AddRange(meters); _ctx.SaveChanges(); } }
public ActionResult SubmitForm(MeterEntity meterEntity, MeterChargingEntity meterChargingEntity, string keyValue) { var companyId = OperatorProvider.Provider.GetCurrent().CompanyId; meterEntity.F_OwnerId = companyId; _meterApp.SubmitForm(meterEntity, meterChargingEntity, keyValue); return(Success("操作成功。")); }
public void SubmitForm(MeterEntity meterEntity, MeterChargingEntity meterChargingEntity, string keyValue) { CheckEntity(meterEntity, keyValue); meterEntity.F_MeterNumber = meterEntity.F_MeterNumber ?? BitConverter.ToUInt16(Guid.Parse(meterEntity.F_OwnerId).ToByteArray().Take(2).ToArray(), 0) + "|" + (_service.IQueryable().Count() + 1); meterChargingEntity.F_CloseAmount = meterChargingEntity.F_CloseAmount ?? 0; meterChargingEntity.F_AlarmAmount = meterChargingEntity.F_AlarmAmount ?? 0; meterChargingEntity.F_Balance = meterChargingEntity.F_Balance ?? 0; meterChargingEntity.F_EnableAlarm = meterChargingEntity.F_EnableAlarm ?? false; meterChargingEntity.F_EnableClose = meterChargingEntity.F_EnableClose ?? false; meterChargingEntity.F_StartValue = meterChargingEntity.F_StartValue ?? 0; meterChargingEntity.F_State = meterChargingEntity.F_State ?? true; _service.SubmitForm(meterEntity, meterChargingEntity, keyValue); }
public void SubmitForm(ChangeMeterEntity changeMeterEntity, MeterEntity meterEntity, MeterChargingEntity meterChargingEntity, string meterCode, ReadTaskEntity readTaskEntity) { using (var db = new RepositoryBase().BeginTrans()) { try { changeMeterEntity.Create(); db.Insert(changeMeterEntity); meterEntity.Remove(); db.Update(meterEntity); db.Insert(new MeterEntity { F_CreatorTime = meterEntity.F_CreatorTime, F_DeleteMark = false, F_IDNumber = meterEntity.F_IDNumber, F_DeleteTime = null, F_DeleteUserId = null, F_MeterCode = meterCode, F_Id = changeMeterEntity.F_ArchiveId, F_UserCard = meterEntity.F_UserCard, F_OwnerId = meterEntity.F_OwnerId, F_MobilePhone = meterEntity.F_MobilePhone, F_CreatorUserId = meterEntity.F_CreatorUserId, F_CustomerAddress = meterEntity.F_CustomerAddress, F_CustomerName = meterEntity.F_CustomerName, F_Description = meterEntity.F_Description, F_Factor = meterEntity.F_Factor, F_LastModifyTime = meterEntity.F_LastModifyTime, F_LastModifyUserId = meterEntity.F_LastModifyUserId, F_MeterName = meterEntity.F_MeterName, F_MeterNumber = meterEntity.F_MeterNumber, F_MeterRate = meterEntity.F_MeterRate, F_MeterType = meterEntity.F_MeterType }); var newMeterChargingEntity = meterChargingEntity; newMeterChargingEntity.F_StartValue = changeMeterEntity.F_BaseDosage; newMeterChargingEntity.F_ArchiveId = changeMeterEntity.F_ArchiveId; db.Insert(newMeterChargingEntity); if (readTaskEntity != null) { readTaskEntity.F_WorkId = changeMeterEntity.F_Id; db.Insert(readTaskEntity); } db.Commit(); } catch (Exception ex) { } } }
public void CheckEntity(MeterEntity meterEntity, string keyValue) { var ownerId = meterEntity.F_OwnerId; if (string.IsNullOrEmpty(meterEntity.F_MeterCode)) { throw new Exception("表计编码不允许为空"); } if (string.IsNullOrEmpty(meterEntity.F_UserCard)) { throw new Exception("用户卡号不允许为空"); } if (_service.IQueryable(x => x.F_MeterCode == meterEntity.F_MeterCode && x.F_Id != keyValue && x.F_DeleteMark != true).Any()) { throw new Exception("表计编码" + meterEntity.F_MeterCode + "已存在"); } if (_service.IQueryable(x => x.F_UserCard == meterEntity.F_UserCard && x.F_OwnerId == ownerId && x.F_Id != keyValue && x.F_DeleteMark != true).Any()) { throw new Exception("用户卡号" + meterEntity.F_UserCard + "已存在"); } }
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); }