/// <summary> /// 添加数据输出管理信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public int AddOutPutInfo(OutPutInfo info) { string sql = ""; try { sql = "INSERT INTO OutPutInfo(Address,UserId,UserPwd,Contact,Email,Phone,QQ,Pattern,Destination,EstablishTime)VALUES(@Address,@UserId,@UserPwd,@Contact,@Email,@Phone,@QQ,@Pattern,@Destination,GETDATE())"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Address", info.Address), new SqlParameter("@UserId", info.UserId), new SqlParameter("@UserPwd", info.UserPwd), new SqlParameter("@Contact", info.Contact), new SqlParameter("@Email", info.Email), new SqlParameter("@Phone", info.Phone), new SqlParameter("@QQ", info.QQ), new SqlParameter("@Pattern", info.Pattern), new SqlParameter("@Destination", info.Destination) }; return(SqlHelper.ExecuteNonQuery(SqlHelper.DBConnStr, CommandType.Text, sql, param)); } catch (Exception ex) { Logger.ErrorLog(ex, new Dictionary <string, string>() { { "Function", "HBHtmlDAL.AddOutPutInfo(OutPutInfo info)" }, { "SQL", sql } }); throw ex; } }
/// <summary> /// 模拟支出 /// </summary> /// <param name="user">用户信息</param> /// <param name="date">日期</param> /// <returns></returns> private IEnumerable <OutPutInfo> SimulateOutPut(LoginInfo user, DateTime date) { //条数 int num = 6; //最大金额 decimal maxAmount = 2000; //年份偏移量 var offset = (date.Year - 2019) * 300; maxAmount += offset; //查询账户列表 var lstAmountAccount = this.QueryAmountAccount(user); //查询支出类型列表 var lstOutType = this.QueryOutType(user); for (int i = 0; i < num; i++) { var item = new OutPutInfo(); item.OutDate = date.Date; item.OutTypeID = lstOutType[random.Next(0, lstOutType.Count)].ID; item.AmountAccountID = lstAmountAccount[random.Next(0, lstAmountAccount.Count)].ID; item.Amount = (Convert.ToDecimal(random.NextDouble()) * maxAmount) + 1; item.Remark = "模拟支出"; //随机出来的支出太高了,控制下... if (Convert.ToInt32(item.Amount) % 25 != 1) { item.Amount = item.Amount / 30; } yield return(item); } }
/// <summary> /// 修改数据输出管理信息 /// </summary> /// <param name="info"></param> /// <returns></returns> public int UpadteOutPut(OutPutInfo info) { string sql = ""; try { sql = "UPDATE OutPutInfo SET Address = @Address,Contact = @Contact,UserId = @UserId,UserPwd = @UserPwd,Email = @Email,Phone = @Phone ,QQ = @QQ,Pattern = @Pattern,Destination = @Destination WHERE ID = @Id "; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@Address", info.Address), new SqlParameter("@Contact", info.Contact), new SqlParameter("@UserId", info.UserId), new SqlParameter("@UserPwd", info.UserPwd), new SqlParameter("@Email", info.Email), new SqlParameter("@Phone", info.Phone), new SqlParameter("@QQ", info.QQ), new SqlParameter("@Pattern", info.Pattern), new SqlParameter("@Destination", info.Destination), new SqlParameter("@Id", info.ID) }; return(SqlHelper.ExecuteNonQuery(SqlHelper.DBConnStr, CommandType.Text, sql, param)); } catch (Exception ex) { Logger.ErrorLog(ex, new Dictionary <string, string>() { { "Function", "HBHtmlDAL.UpadteOutPut(OutPutInfo info)" }, { "SQL", sql } }); throw ex; } }
/// <summary> /// 保存支出信息 /// </summary> /// <param name="user">用户信息</param> /// <param name="info">支出信息</param> /// <returns>主键ID</returns> private int SaveOutPut(LoginInfo user, OutPutInfo info) { //token var dicHeader = new Dictionary <string, string>(); dicHeader["Authorization"] = user.Token; //条件 var req = new LoginReq(); req.LoginName = AppConfig.Inst.App.IOLoginName; req.Password = AppConfig.Inst.App.IOLoginPwd; //请求接口 var client = new TdbHttpClient(AppConfig.Inst.App.IOApiUrl); var res = client.ExecPost <ResultInfo <int> >("api/InOut/SaveOutPut", info, dicHeader); return(res.Result.Info); }
/// <summary> /// 保存支出信息 /// </summary> /// <param name="info">支出信息</param> /// <returns>主键ID</returns> public async Task <ResultInfo <int> > SaveOutPutAsync(OutPutInfo info) { //判断支出类型是否存在 var modelOutType = await BasicDAL.Inst.GetOutTypeAsync(this.LoginInfo.FamilyID, info.OutTypeID); if (modelOutType == null) { return(new ResultInfo <int>(false, this.Res.Bas.OutTypeUnexist, -1)); } //判断账户是否存在 var modelAmountAccount = await BasicDAL.Inst.GetAmountAccountAsync(this.LoginInfo.FamilyID, info.AmountAccountID); if (modelAmountAccount == null) { return(new ResultInfo <int>(false, this.Res.Bas.AmountAccountUnexist, -1)); } //转成model var model = new OutPut(); model.ID = info.ID; model.FamilyID = this.LoginInfo.FamilyID; model.OutDate = info.OutDate; model.OutTypeID = info.OutTypeID; model.AmountAccountID = info.AmountAccountID; model.Amount = info.Amount; model.Remark = info.Remark; //设置创建者/更新者字段值 this.SetCreateUpdateFields(model); //保存到数据库 var ret = await CacheLock.DoByLockFamilyAsync(this.LoginInfo.FamilyID, () => InOutDAL.Inst.SaveOutPutAsync(model)); if (!ret.IsDone) { return(new ResultInfo <int>(false, Res.Gen.WaiteTimeOut, model.ID)); } return(new ResultInfo <int>(true, Res.Gen.OK, model.ID)); }
/// <summary> /// 获取支出信息 /// </summary> /// <param name="id">主键ID</param> /// <returns></returns> public async Task <OutPutInfo> GetOutPutAsync(int id) { //获取数据库信息 var model = await InOutDAL.Inst.GetOutPutAsync(this.LoginInfo.FamilyID, id); if (model == null) { return(null); } //结果 var info = new OutPutInfo(); info.ID = model.ID; info.OutDate = model.OutDate; info.OutTypeID = model.OutTypeID; info.AmountAccountID = model.AmountAccountID; info.Amount = model.Amount; info.Remark = model.Remark; return(info); }
public async Task <ResultInfo <int> > SaveOutPutAsync([FromBody] OutPutInfo info) { var result = await this.bll.SaveOutPutAsync(info); return(result); }