forked from kenve/PAMSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanceDAL.cs
More file actions
90 lines (89 loc) · 2.86 KB
/
Copy pathBalanceDAL.cs
File metadata and controls
90 lines (89 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using PAMSystem.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PAMSystem.DAL
{
public class BalanceDAL
{
/// <summary>
/// 通过用户Id获得余额
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Balance GetByOperatorId(Guid operatorid)
{
DataTable table = SqlHelper.ExecuteDataTable(@"select * from T_Balance where OperatorId=@OperatorId and IsDeleted=0",
new SqlParameter("@OperatorId", operatorid));
if (table.Rows.Count <= 0)
{
return null;
}
else if (table.Rows.Count > 1)
{
throw new Exception("数据库出现重复!");
}
else
{
return ToBalance(table.Rows[0]);
}
}
//添加新用户的余额为0
public void AddNew(Guid operatorId)
{
SqlHelper.ExecuteNonQuery(
"insert into T_Balance(Id,OperatorId,Balance) values (newid(),@OperatorId,0)",
new SqlParameter("@OperatorId", operatorId));
}
//更新账户余额
public bool Update(Guid operatorId,decimal balances)
{
int i= SqlHelper.ExecuteNonQuery(@"update T_Balance set Balance=Balance+@Balances where OperatorId=@OperatorId",
new SqlParameter("@Balances",balances),
new SqlParameter("@OperatorId", operatorId));
if (i>0)
{
return true;
}
else
{
return false;
}
}
//为属性赋值
private Balance ToBalance(DataRow row)
{
Balance balance = new Balance();
balance.Id = (Guid)row["Id"];
balance.OperatorId = (Guid)row["OperatorId"];
balance.Balances = (decimal)row["Balance"];
return balance;
}
//删除账户余额
public bool DeleteByOperatorId(Guid operatorId)
{
int i = SqlHelper.ExecuteNonQuery("Update T_Balance Set IsDeleted=1 where OperatorId=@OperatorId",
new SqlParameter("@OperatorId", operatorId));
if (i > 0)
{
return true;
}
else { return false; };
}
//恢复删除账号
public bool ReuseByOperatorId(Guid operatorId)
{
int i = SqlHelper.ExecuteNonQuery("Update T_Balance Set IsDeleted=0 where OperatorId=@OperatorId",
new SqlParameter("@OperatorId", operatorId));
if (i > 0)
{
return true;
}
else { return false; };
}
}
}