public string GetWaterUserHasQuotasById(string loginIdentifer, string waterUserId) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("Result", false); obj2.Add("Message", ""); obj2.Add("WaterUser", new JavaScriptObject()); try { ResMsg msg = CommonUtil.CheckLoginState(loginIdentifer, true); if (!msg.Result) { obj2["Message"] = msg.Message; return(JavaScriptConvert.SerializeObject(obj2)); } if ((waterUserId == null) || (waterUserId.Trim() == "")) { obj2["Message"] = "用水户ID不能为空"; return(JavaScriptConvert.SerializeObject(obj2)); } WaterUser wui = WaterUserModule.GetWaterUserById(long.Parse(waterUserId)); if (wui == null) { obj2["Message"] = "ID为" + waterUserId + "用水户不存在"; return(JavaScriptConvert.SerializeObject(obj2)); } obj2["Result"] = true; obj2["WaterUser"] = WaterUserModule.WaterUserToJson(wui); } catch (Exception exception) { obj2["Message"] = exception.Message; } return(JavaScriptConvert.SerializeObject(obj2)); }
public static void LoadWaterUsers() { string strSql = "select * from WaterUser"; try { DataTable table = DbHelperSQL.Query(strSql).Tables[0]; if (table.Rows.Count != 0) { ModelHandler <WaterUser> modelHandler = new ModelHandler <WaterUser>(); lock (waterUserLockFlag) { dicWaterUsersById.Clear(); for (int i = 0; i < table.Rows.Count; i++) { DataRow dataRow = table.Rows[i]; WaterUser user = modelHandler.FillModel(dataRow); if (!dicWaterUsersById.ContainsKey(user.id)) { dicWaterUsersById.Add(user.id, user); } } } } } catch { } }
public static JavaScriptObject WaterUserToJson(WaterUser waterUser) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("ID", waterUser.id); obj2.Add("名称", waterUser.UserName); //obj2.Add("户号", waterUser.UserNum); obj2.Add("状态", waterUser.State); District node = DistrictModule.ReturnDistrictInfo(waterUser.DistrictId); District node2 = DistrictModule.ReturnDistrictInfo(node.ParentId); District node3 = DistrictModule.ReturnDistrictInfo(node2.ParentId); District node4 = DistrictModule.ReturnDistrictInfo(node3.ParentId); District node5 = DistrictModule.ReturnDistrictInfo(node4.ParentId); obj2.Add("省ID", node5.Id); obj2.Add("市ID", node4.Id); obj2.Add("区县ID", node3.Id); obj2.Add("乡镇ID", node2.Id); obj2.Add("村庄ID", node.Id); obj2.Add("水价ID", waterUser.水价ID); obj2.Add("电价ID", waterUser.电价ID); obj2.Add("电话", waterUser.Telephone); obj2.Add("身份证号", waterUser.IdentityNumber); obj2.Add("地址", waterUser.Address); obj2.Add("用水定额", waterUser.WaterQuota); obj2.Add("用电定额", waterUser.ElectricQuota); /* * obj2.Add("累计购水金额", waterUser.TotalMoneyOfBuyWater); * obj2.Add("累计购电金额", waterUser.TotalMoneyOfBuyPower); * obj2.Add("累计购水量", waterUser.TotalAmountOfBuyWater); * obj2.Add("累计购电量", waterUser.TotalAmountOfBuyPower); * obj2.Add("累计用水量", waterUser.TotalAmountOfUseWater); * obj2.Add("累计用电量", waterUser.TotalAmountOfUsePower); * obj2.Add("年累计购水量", waterUser.YearAmountOfBuyWater); * obj2.Add("年累计购电量", waterUser.YearAmountOfBuyPower); * obj2.Add("最后用水时间", waterUser.LastUseWaterTime); * obj2.Add("详细信息", waterUser.Details); * string id = ""; * string str2 = "未分配"; * if (waterUser.WaterUserQuota != null) * { * str2 = waterUser.WaterUserQuota.Quota.ToString(); * id = waterUser.WaterUserQuota.Id; * } * obj2.Add("用水定额ID", id); * obj2.Add("用水定额", str2); * obj2.Add("卡序列号", waterUser.CardSerialNumber); * */ return(obj2); }
public static JavaScriptObject CardUserToJson(CardUser cardUser) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("ID", cardUser.Id); obj2.Add("WaterUserId", cardUser.WaterUserId); obj2.Add("SerialNumber", cardUser.SerialNumber); obj2.Add("UserNo", cardUser.UserNo.Trim().TrimStart('0')); obj2.Add("ResidualWater", cardUser.ResidualWater); obj2.Add("ResidualElectric", cardUser.ResidualElectric); obj2.Add("TotalWater", cardUser.TotalWater); obj2.Add("TotalElectric", cardUser.TotalElectric); obj2.Add("TotallMoney", cardUser.TotallMoney); obj2.Add("DeviceList", cardUser.DeviceList); obj2.Add("IsCountermand", cardUser.IsCountermand == 0 ? "否" : "是"); obj2.Add("OpenTime", cardUser.OpenTime.ToString("yyyy-MM-dd HH:mm:ss")); obj2.Add("LastChargeTime", cardUser.LastChargeTime > DateTime.Parse("2010-1-1") ? cardUser.LastChargeTime.ToString("yyyy-MM-dd HH:mm:ss") : ""); WaterUser waterUser = WaterUserModule.GetWaterUserById(cardUser.WaterUserId); if (waterUser != null) { obj2.Add("UserName", waterUser.UserName); obj2.Add("IdentityNumber", waterUser.IdentityNumber); obj2.Add("Telephone", waterUser.Telephone); District node = DistrictModule.ReturnDistrictInfo(waterUser.DistrictId); District node2 = DistrictModule.ReturnDistrictInfo(node.ParentId); District node3 = DistrictModule.ReturnDistrictInfo(node2.ParentId); District node4 = DistrictModule.ReturnDistrictInfo(node3.ParentId); District node5 = DistrictModule.ReturnDistrictInfo(node4.ParentId); obj2.Add("省ID", node5.Id); obj2.Add("市ID", node4.Id); obj2.Add("区县ID", node3.Id); obj2.Add("乡镇ID", node2.Id); obj2.Add("村庄ID", node.Id); } else { obj2.Add("UserName", "未知"); obj2.Add("IdentityNumber", "未知"); obj2.Add("Telephone", "未知"); obj2.Add("省ID", "未知"); obj2.Add("市ID", "未知"); obj2.Add("区县ID", "未知"); obj2.Add("乡镇ID", "未知"); obj2.Add("村庄ID", "未知"); } return(obj2); }
private static ResMsg WriteOffWaterUserById(long waterUserId, bool checkWaterUserExist) { try { WaterUser wui = GetWaterUserById(waterUserId); if (checkWaterUserExist && wui == null) { return(new ResMsg(false, "用水户不存在")); } wui.State = "已注销"; return(ModifyWaterUser(wui)); } catch { return(new ResMsg(false, " 注销失败")); } }
public string GetCardUsersByWaterUserIds(string loginIdentifer, string waterUserIds) { JavaScriptObject obj2 = new JavaScriptObject(); JavaScriptArray array = new JavaScriptArray(); obj2.Add("Result", false); obj2.Add("Message", ""); obj2.Add("CardUsers", array); try { ResMsg msg = CommonUtil.CheckLoginState(loginIdentifer, true); if (!msg.Result) { obj2["Message"] = msg.Message; return(JavaScriptConvert.SerializeObject(obj2)); } if ((waterUserIds == null) || (waterUserIds.Trim() == "")) { obj2["Message"] = "用水户ID不能为空"; return(JavaScriptConvert.SerializeObject(obj2)); } foreach (string str in waterUserIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { WaterUser wui = WaterUserModule.GetWaterUserById(long.Parse(str)); if (wui == null) { obj2["Message"] = "ID为" + str + "的用水户不存在"; return(JavaScriptConvert.SerializeObject(obj2)); } List <CardUser> liCardUsers = CardUserModule.GetCardUsersByWaterUserId(wui.id, true); foreach (CardUser info in liCardUsers) { array.Add(CardUserModule.CardUserToJson(info)); } } obj2["Result"] = true; } catch (Exception exception) { obj2["Message"] = exception.Message; } return(JavaScriptConvert.SerializeObject(obj2)); }
public static List <CardUser> GetCardUsersByDistrictId(long DistrictId, bool IsCountermand) { List <CardUser> list = new List <CardUser>(); lock (dicCardUsersById) { foreach (KeyValuePair <long, CardUser> pair in dicCardUsersById) { WaterUser wu = WaterUserModule.GetWaterUserById(pair.Value.WaterUserId); if (wu.DistrictId == DistrictId) { if (!IsCountermand && pair.Value.IsCountermand == 0 || IsCountermand) { list.Add(Tools.Copy <CardUser>(pair.Value)); } } } } return(list); }
public string WriteOffWaterUserByUserSerialNumber(string loginIdentifer, string userSerialNumber) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("Result", false); obj2.Add("Message", ""); try { ResMsg msg = CommonUtil.CheckLoginState(loginIdentifer, true); if (!msg.Result) { obj2["Message"] = msg.Message; return(JavaScriptConvert.SerializeObject(obj2)); } LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); if ((userSerialNumber == null) || (userSerialNumber.Trim() == "")) { obj2["Message"] = "用户卡号不能为空"; return(JavaScriptConvert.SerializeObject(obj2)); } CardUser cu = CardUserModule.GetCardUserBySerialNumber(userSerialNumber); if (cu == null) { obj2["Message"] = "卡号为" + userSerialNumber + "的用户卡不存在"; return(JavaScriptConvert.SerializeObject(obj2)); } WaterUser wui = WaterUserModule.GetWaterUserById(cu.WaterUserId); if (wui == null) { obj2["Message"] = "卡号为" + userSerialNumber + "的用水户不存在"; return(JavaScriptConvert.SerializeObject(obj2)); } ResMsg msg1 = WaterUserModule.WriteOffWaterUserById(cu.WaterUserId); if (msg1.Result)//msg.Result { obj2["Result"] = true; } else { obj2["Message"] = msg.Message; } try { //添加日志 WaterUserLog log = new WaterUserLog(); log.WaterUserId = wui.id; log.LogUserId = loginUser.UserId; log.LogUserName = loginUser.LoginName; log.LogAddress = ToolsWeb.GetIP(context.Request); log.LogTime = loginUser.LastOperateTime; log.LogType = "注销"; log.LogContent = msg.Message; log.UserName = wui.UserName; log.Password = wui.Password; log.DistrictId = wui.DistrictId; log.TrueName = wui.TrueName; log.IdentityNumber = wui.IdentityNumber; log.Telephone = wui.Telephone; log.Address = wui.Address; log.WaterQuota = wui.WaterQuota; log.ElectricQuota = wui.ElectricQuota; log.Remark = wui.Remark; log.水价ID = wui.水价ID; log.电价ID = wui.电价ID; log.State = wui.State; WaterUserLogModule.Add(log); } catch { } } catch (Exception exception) { obj2["Message"] = exception.Message; } return(JavaScriptConvert.SerializeObject(obj2)); }
public string AddWaterUser(string loginIdentifer, string waterUserJson) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("Result", false); obj2.Add("Message", ""); try { ResMsg msg = CommonUtil.CheckLoginState(loginIdentifer, true); if (!msg.Result) { obj2["Message"] = msg.Message; return(JavaScriptConvert.SerializeObject(obj2)); } LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); string message = msg.Message; JavaScriptObject obj3 = (JavaScriptObject)JavaScriptConvert.DeserializeObject(waterUserJson); if (obj3 == null) { obj2["Message"] = "参数waterUserJson格式不正确"; return(JavaScriptConvert.SerializeObject(obj2)); } WaterUser wui = new WaterUser(); wui.UserName = obj3["名称"].ToString(); wui.Password = ""; wui.TrueName = ""; wui.DistrictId = long.Parse(obj3["管理ID"].ToString()); wui.IdentityNumber = obj3["身份证号"].ToString(); wui.Telephone = obj3["电话"].ToString(); wui.Address = obj3["地址"].ToString(); wui.State = "正常"; wui.WaterQuota = decimal.Parse(obj3["用水定额"].ToString()); wui.ElectricQuota = decimal.Parse(obj3["用电定额"].ToString()); wui.水价ID = int.Parse(obj3["水价ID"].ToString()); wui.电价ID = int.Parse(obj3["电价ID"].ToString()); if (WaterUserModule.ExistsUserName(wui.DistrictId, wui.UserName)) { obj2["Message"] = "存在相同户名"; return(JavaScriptConvert.SerializeObject(obj2)); } if (WaterUserModule.ExistsIdentityNumber(wui.IdentityNumber)) { obj2["Message"] = "存在相同身份证号"; return(JavaScriptConvert.SerializeObject(obj2)); } if (WaterUserModule.ExistsTelephone(wui.Telephone)) { obj2["Message"] = "存在相同身份证号"; return(JavaScriptConvert.SerializeObject(obj2)); } msg = WaterUserModule.AddWaterUser(wui); if (msg.Result) { obj2["Result"] = true; } else { obj2["Message"] = msg.Message; } try { //添加日志 WaterUserLog log = new WaterUserLog(); log.WaterUserId = wui.id; log.LogUserId = loginUser.UserId; log.LogUserName = loginUser.LoginName; log.LogAddress = ToolsWeb.GetIP(context.Request); log.LogTime = loginUser.LastOperateTime; log.LogType = "添加"; log.LogContent = msg.Message; log.UserName = wui.UserName; log.Password = wui.Password; log.DistrictId = wui.DistrictId; log.TrueName = wui.TrueName; log.IdentityNumber = wui.IdentityNumber; log.Telephone = wui.Telephone; log.Address = wui.Address; log.WaterQuota = wui.WaterQuota; log.ElectricQuota = wui.ElectricQuota; log.Remark = wui.Remark; log.水价ID = wui.水价ID; log.电价ID = wui.电价ID; log.State = wui.State; WaterUserLogModule.Add(log); } catch { } } catch (Exception exception) { obj2["Message"] = exception.Message; } return(JavaScriptConvert.SerializeObject(obj2)); }
public static ResMsg ModifyWaterUser(WaterUser wui) { if (wui == null) { return(new ResMsg(false, "用水户对象为空")); } if (!Exists(wui.id)) { return(new ResMsg(false, "用水户不存在")); } if (ExistsIdentityNumber(wui.IdentityNumber, wui.id)) { return(new ResMsg(false, "用水户身份证号重复")); } if (ExistsTelephone(wui.Telephone, wui.id)) { return(new ResMsg(false, "用水户电话号码重复")); } StringBuilder strSql = new StringBuilder(); strSql.Append("update WaterUser set "); strSql.Append("UserName=@UserName,"); strSql.Append("Password=@Password,"); strSql.Append("DistrictId=@DistrictId,"); strSql.Append("TrueName=@TrueName,"); strSql.Append("IdentityNumber=@IdentityNumber,"); strSql.Append("Telephone=@Telephone,"); strSql.Append("Address=@Address,"); strSql.Append("WaterQuota=@WaterQuota,"); strSql.Append("ElectricQuota=@ElectricQuota,"); strSql.Append("Remark=@Remark,"); strSql.Append("水价ID=@水价ID,"); strSql.Append("电价ID=@电价ID,"); strSql.Append("State=@State"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.NVarChar, 50), new SqlParameter("@Password", SqlDbType.NVarChar, 50), new SqlParameter("@DistrictId", SqlDbType.BigInt, 8), new SqlParameter("@TrueName", SqlDbType.NVarChar, 50), new SqlParameter("@IdentityNumber", SqlDbType.NVarChar, 20), new SqlParameter("@Telephone", SqlDbType.NVarChar, 50), new SqlParameter("@Address", SqlDbType.NVarChar, 200), new SqlParameter("@WaterQuota", SqlDbType.Decimal, 9), new SqlParameter("@ElectricQuota", SqlDbType.Decimal, 9), new SqlParameter("@Remark", SqlDbType.NVarChar, -1), new SqlParameter("@水价ID", SqlDbType.Int, 4), new SqlParameter("@电价ID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.BigInt, 8) }; parameters[0].Value = wui.UserName; parameters[1].Value = wui.Password; parameters[2].Value = wui.DistrictId; parameters[3].Value = wui.TrueName; parameters[4].Value = wui.IdentityNumber; parameters[5].Value = wui.Telephone; parameters[6].Value = wui.Address; parameters[7].Value = wui.WaterQuota; parameters[8].Value = wui.ElectricQuota; parameters[9].Value = wui.Remark; parameters[10].Value = wui.水价ID; parameters[11].Value = wui.电价ID; parameters[12].Value = wui.State; parameters[13].Value = wui.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { if (!dicWaterUsersById.ContainsKey(wui.id)) { dicWaterUsersById.Add(wui.id, wui); } else { dicWaterUsersById[wui.id] = wui; } return(new ResMsg(true, "修改成功")); } else { return(new ResMsg(false, "修改失败")); } }
public static ResMsg AddWaterUser(WaterUser wui) { if (wui == null) { return(new ResMsg(false, "用水户对象为空")); } if (ExistsIdentityNumber(wui.IdentityNumber)) { return(new ResMsg(false, "用水户身份证号重复")); } if (ExistsTelephone(wui.Telephone)) { return(new ResMsg(false, "用水户电话号码重复")); } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into WaterUser("); strSql.Append("UserName,Password,DistrictId,TrueName,IdentityNumber,Telephone,Address,WaterQuota,ElectricQuota,Remark,水价ID,电价ID,State)"); strSql.Append(" values ("); strSql.Append("@UserName,@Password,@DistrictId,@TrueName,@IdentityNumber,@Telephone,@Address,@WaterQuota,@ElectricQuota,@Remark,@水价ID,@电价ID,@State)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.NVarChar, 50), new SqlParameter("@Password", SqlDbType.NVarChar, 50), new SqlParameter("@DistrictId", SqlDbType.BigInt, 8), new SqlParameter("@TrueName", SqlDbType.NVarChar, 50), new SqlParameter("@IdentityNumber", SqlDbType.NVarChar, 20), new SqlParameter("@Telephone", SqlDbType.NVarChar, 50), new SqlParameter("@Address", SqlDbType.NVarChar, 200), new SqlParameter("@WaterQuota", SqlDbType.Decimal, 9), new SqlParameter("@ElectricQuota", SqlDbType.Decimal, 9), new SqlParameter("@Remark", SqlDbType.NVarChar, -1), new SqlParameter("@水价ID", SqlDbType.Int, 4), new SqlParameter("@电价ID", SqlDbType.Int, 4), new SqlParameter("@State", SqlDbType.NVarChar, 50) }; parameters[0].Value = wui.UserName; parameters[1].Value = wui.Password; parameters[2].Value = wui.DistrictId; parameters[3].Value = wui.TrueName; parameters[4].Value = wui.IdentityNumber; parameters[5].Value = wui.Telephone; parameters[6].Value = wui.Address; parameters[7].Value = wui.WaterQuota; parameters[8].Value = wui.ElectricQuota; parameters[9].Value = wui.Remark; parameters[10].Value = wui.水价ID; parameters[11].Value = wui.电价ID; parameters[12].Value = wui.State; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(new ResMsg(false, "添加失败")); } else { wui.id = Convert.ToInt64(obj); if (!dicWaterUsersById.ContainsKey(wui.id)) { dicWaterUsersById.Add(wui.id, wui); } return(new ResMsg(true, Convert.ToInt64(obj).ToString())); } }
public string Recharge(string loginIdentifer, string userid1, string userid2, string n) { JavaScriptObject obj2 = new JavaScriptObject(); obj2.Add("Result", false); obj2.Add("Message", ""); LoginUser loginUser = GlobalAppModule.GetLoginUser(loginIdentifer); if (loginUser == null) { obj2["Message"] = "未登录"; return(JavaScriptConvert.SerializeObject(obj2)); } if (loginUser.LoginTimeout) { obj2["Message"] = "登录超时"; return(JavaScriptConvert.SerializeObject(obj2)); } loginUser.LastOperateTime = DateTime.Now; CommonUtil.WaitMainLibInit(); string msg = "交易失败!"; long nl = 0; try { nl = long.Parse(n); } catch { } if (nl <= 0) { msg = "交易失败!水量非法!"; } else { try { WaterUser wu1 = WaterUserModule.GetWaterUserById(long.Parse(userid1)); if (wu1.WaterQuota - nl > 0) { WaterUser wu2 = WaterUserModule.GetWaterUserById(long.Parse(userid2)); wu2.WaterQuota = wu2.WaterQuota + nl; ResMsg r2 = WaterUserModule.ModifyWaterUser(wu2); if (r2.Result) { wu1.WaterQuota = wu1.WaterQuota - nl; ResMsg r1 = WaterUserModule.ModifyWaterUser(wu1); if (r1.Result) { obj2["Result"] = true; msg = "交易成功!"; } else { wu2 = WaterUserModule.GetWaterUserById(long.Parse(userid2)); wu2.WaterQuota = wu2.WaterQuota - nl; WaterUserModule.ModifyWaterUser(wu2); msg = "交易失败!出卖方异常!"; } } else { msg = "交易失败!买受方异常!"; } } else { msg = "交易失败!水量不足!"; } } catch (Exception ex) { msg = "交易失败!" + ex.Message; } } obj2["Message"] = msg; try { SysLog log = new SysLog(); log.LogUserId = loginUser.UserId; log.LogUserName = loginUser.LoginName; log.LogAddress = ToolsWeb.GetIP(context.Request); log.LogTime = DateTime.Now; log.LogType = "水权交易"; log.LogContent = msg + "|" + userid1 + "|" + userid2 + "|" + nl; SysLogModule.Add(log); } catch { } return(JavaScriptConvert.SerializeObject(obj2)); }