public Dictionary <string, object> delete(int id) { if (db.Properties.Count(w => w.ConfigId == id) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用"); } else if (db.Parkings.Count(w => w.ConfigId == id) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用"); } else if (db.WaterAndElectricities.Count(w => w.ConfigId == id) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用"); } else if (db.ElseCosts.Count(w => w.ConfigId == id) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用"); } if (result["code"].ToString() == "success") { CostConfig config = db.CostConfigs.FirstOrDefault(w => w.ConfigId == id); db.CostConfigs.Remove(config); db.SaveChanges(); } result["message"] = message; return(result); }
public Dictionary <string, object> modify([FromBody] CostConfig config) { if (db.Properties.Count(w => w.ConfigId == config.ConfigId) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用,只能禁用"); } else if (db.Parkings.Count(w => w.ConfigId == config.ConfigId) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用,只能禁用"); } else if (db.WaterAndElectricities.Count(w => w.ConfigId == config.ConfigId) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用,只能禁用"); } else if (db.ElseCosts.Count(w => w.ConfigId == config.ConfigId) > 0) { result["code"] = "failed"; message.Add("此配置已有缴费使用,只能禁用"); } else if (string.IsNullOrEmpty(config.ConfigType)) { result["code"] = "failed"; message.Add("配置类型必选"); } else if (string.IsNullOrEmpty(config.ConfigVersion)) { result["code"] = "failed"; message.Add("配置版本必填"); } else if (string.IsNullOrEmpty(config.Category)) { result["code"] = "failed"; message.Add("配置分类必填"); } if (result["code"].ToString() == "success") { config.UserId = user.UserId; config.ModifyDate = Ricky.Common.NowDate; CostConfig newConfig = db.CostConfigs.FirstOrDefault(w => w.ConfigId == config.ConfigId); Ricky.ObjectCopy.Copy <CostConfig>(config, newConfig); db.SaveChanges(); if (config.IsDefault) { var a = from b in db.CostConfigs where b.ConfigType == config.ConfigType && b.EstateId == config.EstateId && b.ConfigId != config.ConfigId select b; foreach (var item in a) { item.IsDefault = false; } db.SaveChanges(); } } result["message"] = message; return(result); }
/// <summary> /// 是否有某cost的所需 /// </summary> public bool hasCost(int costID, int num) { CostConfig config = CostConfig.get(costID); if (!me.role.hasCurrencies(config.currency, num)) { return(false); } if (!containsItems(config.items, num)) { return(false); } return(true); }
/// <summary> /// 执行某id的消耗 /// </summary> public bool doCost(int costID, int num, int way) { CostConfig config = CostConfig.get(costID); if (!me.role.hasCurrencies(config.currency, num)) { return(false); } if (!removeItems(config.items, num, way)) { return(false); } if (!me.role.costCurrencies(config.currency, num, way)) { Ctrl.errorLog("出严重错误,此时不该消耗不掉"); addItems(config.items, num, way); return(false); } return(true); }
public Dictionary <string, object> add([FromBody] CostConfig config) { if (string.IsNullOrEmpty(config.ConfigType)) { result["code"] = "failed"; message.Add("配置类型必选"); } else if (string.IsNullOrEmpty(config.ConfigVersion)) { result["code"] = "failed"; message.Add("配置版本必填"); } else if (string.IsNullOrEmpty(config.Category)) { result["code"] = "failed"; message.Add("配置分类必填"); } if (result["code"].ToString() == "success") { config.UserId = user.UserId; config.ModifyDate = Ricky.Common.NowDate; db.CostConfigs.Add(config); db.SaveChanges(); if (config.IsDefault) { var a = from b in db.CostConfigs where b.ConfigType == config.ConfigType && b.EstateId == config.EstateId && b.ConfigId != config.ConfigId select b; foreach (var item in a) { item.IsDefault = false; } db.SaveChanges(); } db.SaveChanges(); } result["message"] = message; return(result); }
public async Task <HttpResponseMessage> Import() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } MultipartMemoryStreamProvider provider = await Request.Content.ReadAsMultipartAsync(); HttpContent content = provider.Contents.First(); Stream stream = await content.ReadAsStreamAsync(); string fileName = content.Headers.ContentDisposition.FileName.Trim('"'); DataTable dt = Excel.ExcelToDataTable(fileName, stream); dt.Columns.Add("导入状态"); dt.Columns.Add("导入备注"); foreach (DataRow dr in dt.Rows) { string EstateName = dr[0].ToString(); if (!string.IsNullOrEmpty(EstateName)) { Estate estate = db.Estates.FirstOrDefault(w => w.EstateName == EstateName); if (estate != null) { string HouseNo = dr[1].ToString(); House house = db.Houses.FirstOrDefault(w => w.EstateId == estate.EstateId && w.HouseNo == HouseNo); if (house != null) { Owner owner = db.Owners.FirstOrDefault(w => w.HouseId == house.HouseId); if (owner != null) { try { Property property = new Property(); property.OwnerId = owner.OwnerId; property.PayerName = owner.CheckInName; property.UnitPrice = decimal.Parse(dr[2].ToString()); string UnitName = dr[3].ToString(); CostConfig config = db.CostConfigs.FirstOrDefault(w => w.EstateId == estate.EstateId && w.ConfigType == "property" && w.UnitPrice == property.UnitPrice && w.UnitName == UnitName); if (config != null) { property.ConfigId = config.ConfigId; } property.MonthCount = int.Parse(dr[4].ToString()); property.Amount = decimal.Parse(dr[5].ToString()); property.CreateTime = DateTime.Now; DateTime PayTime = DateTime.MinValue; if (DateTime.TryParse(dr[6].ToString(), out PayTime)) { property.PayTime = PayTime; } DateTime StartDate = DateTime.MinValue; if (DateTime.TryParse(dr[7].ToString(), out StartDate)) { property.StartDate = StartDate; } DateTime EndDate = DateTime.MinValue; if (DateTime.TryParse(dr[8].ToString(), out EndDate)) { property.EndDate = EndDate; } property.ReceiptNo = dr[9].ToString(); property.VoucherNo = dr[10].ToString(); property.OprationName = dr[11].ToString(); property.PayWay = dr[12].ToString(); property.Remark = dr[13].ToString(); if (property.PayTime != null) { property.Status = 1; } if (db.Properties.Count(w => w.OwnerId == property.OwnerId && w.Amount == property.Amount && w.MonthCount == property.MonthCount && w.StartDate == property.StartDate && w.EndDate == property.EndDate) == 0) { db.Properties.Add(property); db.SaveChanges(); dr[14] = "成功"; dr[15] = "新增"; } else { Property newProperty = db.Properties.First(w => w.OwnerId == property.OwnerId && w.Amount == property.Amount && w.MonthCount == property.MonthCount && w.StartDate == property.StartDate && w.EndDate == property.EndDate); Ricky.ObjectCopy.Copy <Property>(property, newProperty, new string[] { "PropertyId", "PayerName", "UserId" }); db.SaveChanges(); dr[14] = "成功"; dr[15] = "修改"; } } catch (Exception e) { dr[14] = "失败"; dr[15] = e.Message; } } else { dr[14] = "失败"; dr[15] = "没有找到业主"; } } else { dr[14] = "失败"; dr[15] = "沒有找到此房产"; } } else { dr[14] = "失败"; dr[15] = "沒有找到此小区"; } } else { dr[14] = "失败"; dr[15] = "缺少所属小区名称"; } } db.Database.ExecuteSqlCommand("update [Owner] set PropertyExpireDate=t.EndDate from (select OwnerId,MAX(EndDate) EndDate from [Property] group by OwnerId)t where [Owner].OwnerId=t.OwnerId and ([Owner].PropertyExpireDate is null or [Owner].PropertyExpireDate<t.EndDate)"); string fileSaveLocation = HttpContext.Current.Server.MapPath("~/upload/property"); if (!Directory.Exists(fileSaveLocation)) { Directory.CreateDirectory(fileSaveLocation); } string Name = fileName.Substring(0, fileName.LastIndexOf('.')); Excel excel = new Excel(dt); string saveFileName = string.Format("{1}{2}.xlsx", fileSaveLocation, Name, DateTime.Now.ToString("yyyyMMddHHmmssfff")); excel.Save(fileSaveLocation + "\\" + saveFileName); return(Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, filename = saveFileName })); }
public async Task <HttpResponseMessage> Import() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } MultipartMemoryStreamProvider provider = await Request.Content.ReadAsMultipartAsync(); HttpContent content = provider.Contents.First(); Stream stream = await content.ReadAsStreamAsync(); string fileName = content.Headers.ContentDisposition.FileName.Trim('"'); DataTable dt = Excel.ExcelToDataTable(fileName, stream); dt.Columns.Add("导入状态"); dt.Columns.Add("导入备注"); foreach (DataRow dr in dt.Rows) { string EstateName = dr[0].ToString(); if (!string.IsNullOrEmpty(EstateName)) { Estate estate = db.Estates.FirstOrDefault(w => w.EstateName == EstateName); if (estate != null) { string HouseNo = dr[1].ToString(); House house = db.Houses.FirstOrDefault(w => w.EstateId == estate.EstateId && w.HouseNo == HouseNo); if (house != null) { Owner owner = db.Owners.FirstOrDefault(w => w.HouseId == house.HouseId); if (owner != null) { try { WaterAndElectricity waterE = new WaterAndElectricity(); waterE.OwnerId = owner.OwnerId; waterE.PayerName = owner.CheckInName; waterE.UnitPrice = decimal.Parse(dr[5].ToString()); waterE.FeeName = dr[2].ToString(); waterE.FeeType = waterE.FeeName.Equals("水费") ? "water" : waterE.FeeName.Equals("电费") ? "electricity" : ""; if (!string.IsNullOrEmpty(waterE.FeeType)) { CostConfig config = db.CostConfigs.FirstOrDefault(w => w.EstateId == estate.EstateId && w.ConfigType == waterE.FeeType && w.UnitPrice == waterE.UnitPrice); if (config != null) { waterE.ConfigId = config.ConfigId; } waterE.CreateTime = DateTime.Now; DateTime PayTime = DateTime.MinValue; if (DateTime.TryParse(dr[3].ToString(), out PayTime)) { waterE.PayTime = PayTime; } DateTime FeeDate = DateTime.MinValue; if (DateTime.TryParse(dr[4].ToString(), out PayTime)) { waterE.FeeDate = PayTime; } waterE.UnitName = dr[6].ToString(); waterE.LastQuantity = double.Parse(dr[7].ToString()); waterE.Quantity = double.Parse(dr[8].ToString()); waterE.Amount = decimal.Parse(dr[9].ToString()); waterE.ReceiptNo = dr[10].ToString(); waterE.VoucherNo = dr[11].ToString(); waterE.OprationName = dr[12].ToString(); waterE.PayWay = dr[13].ToString(); waterE.Remark = dr[14].ToString(); waterE.Status = dr[15].ToString().Equals("是") ? 1 : 0; if (db.WaterAndElectricities.Count(w => w.OwnerId == owner.OwnerId && w.LastQuantity == waterE.LastQuantity && w.Quantity == waterE.Quantity && w.FeeDate == waterE.FeeDate) == 0) { db.WaterAndElectricities.Add(waterE); db.SaveChanges(); dr[16] = "成功"; dr[17] = "新增"; } else { WaterAndElectricity newWateE = db.WaterAndElectricities.First(w => w.OwnerId == owner.OwnerId && w.LastQuantity == waterE.LastQuantity && w.Quantity == waterE.Quantity && w.FeeDate == waterE.FeeDate); Ricky.ObjectCopy.Copy <WaterAndElectricity>(waterE, newWateE, new string[] { "FeeId", "PayerName", "UserId" }); db.SaveChanges(); dr[16] = "成功"; dr[17] = "修改"; } } else { dr[16] = "失败"; dr[17] = "无法识别费用类型"; } } catch (Exception e) { dr[16] = "失败"; dr[17] = e.Message; } } else { dr[16] = "失败"; dr[17] = "没有找到业主"; } } else { dr[16] = "失败"; dr[17] = "沒有找到此房产"; } } else { dr[16] = "失败"; dr[17] = "沒有找到此小区"; } } else { dr[16] = "失败"; dr[17] = "缺少所属小区名称"; } } string fileSaveLocation = HttpContext.Current.Server.MapPath("~/upload/water-electricity"); if (!Directory.Exists(fileSaveLocation)) { Directory.CreateDirectory(fileSaveLocation); } string Name = fileName.Substring(0, fileName.LastIndexOf('.')); Excel excel = new Excel(dt); string saveFileName = string.Format("{1}{2}.xlsx", fileSaveLocation, Name, DateTime.Now.ToString("yyyyMMddHHmmssfff")); excel.Save(fileSaveLocation + "\\" + saveFileName); return(Request.CreateResponse(HttpStatusCode.OK, new { Status = 1, filename = saveFileName })); }