三元财务API

telloc_users.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using CallCenterApi.DB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using CallCenterApi.Model;
  10. namespace CallCenterApi.DAL
  11. {
  12. public class telloc_users
  13. {
  14. public Model.telloc_users GetModel(int id)
  15. {
  16. StringBuilder strSql = new StringBuilder();
  17. strSql.Append("select top 1 * from telloc_users ");
  18. strSql.Append(" where id=@id");
  19. SqlParameter[] parameters = {
  20. new SqlParameter("@id", SqlDbType.Int,4)
  21. };
  22. parameters[0].Value = id;
  23. Model.telloc_users model = new Model.telloc_users();
  24. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  25. if (ds.Tables[0].Rows.Count > 0)
  26. {
  27. return DataRowToModel(ds.Tables[0].Rows[0]);
  28. }
  29. else
  30. {
  31. return null;
  32. }
  33. }
  34. public Model.telloc_users GetModel(int userid, int telid)
  35. {
  36. StringBuilder strSql = new StringBuilder();
  37. strSql.Append("select top 1 * from telloc_users ");
  38. strSql.Append(" where tellocid=@tellocid and userid=@userid and isdelete=0");
  39. SqlParameter[] parameters = {
  40. new SqlParameter("@tellocid", SqlDbType.Int,4),
  41. new SqlParameter("@userid", SqlDbType.Int,4)
  42. };
  43. parameters[0].Value = telid;
  44. parameters[1].Value = userid;
  45. Model.telloc_users model = new Model.telloc_users();
  46. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  47. if (ds.Tables[0].Rows.Count > 0)
  48. {
  49. return DataRowToModel(ds.Tables[0].Rows[0]);
  50. }
  51. else
  52. {
  53. return null;
  54. }
  55. }
  56. public DataSet GetList(string strWhere)
  57. {
  58. StringBuilder strSql = new StringBuilder();
  59. strSql.Append("select * ");
  60. strSql.Append(" FROM telloc_users ");
  61. if (strWhere.Trim() != "")
  62. {
  63. strSql.Append(" where " + strWhere);
  64. }
  65. return DbHelperSQL.Query(strSql.ToString());
  66. }
  67. public int Add(Model.telloc_users model)
  68. {
  69. StringBuilder strSql = new StringBuilder();
  70. strSql.Append("insert into telloc_users(");
  71. strSql.Append("tellocid,userid,isdelete)");
  72. strSql.Append(" values (");
  73. strSql.Append("@tellocid,@userid,@isdelete)");
  74. strSql.Append(";select @@IDENTITY");
  75. SqlParameter[] parameters = {
  76. new SqlParameter("@tellocid", SqlDbType.Int,4),
  77. new SqlParameter("@userid", SqlDbType.Int,4),
  78. new SqlParameter("@isdelete", SqlDbType.Int,4)};
  79. parameters[0].Value = model.tellocid;
  80. parameters[1].Value = model.userid;
  81. parameters[2].Value = model.isdelete;
  82. object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
  83. if (obj == null)
  84. {
  85. return 0;
  86. }
  87. else
  88. {
  89. return Convert.ToInt32(obj);
  90. }
  91. }
  92. public bool Update(Model.telloc_users model)
  93. {
  94. StringBuilder strSql = new StringBuilder();
  95. strSql.Append("update telloc_users set ");
  96. strSql.Append("tellocid=@tellocid,");
  97. strSql.Append("userid=@userid,");
  98. strSql.Append("isdelete=@isdelete");
  99. strSql.Append(" where id=@id");
  100. SqlParameter[] parameters = {
  101. new SqlParameter("@tellocid", SqlDbType.Int,4),
  102. new SqlParameter("@userid", SqlDbType.Int,4),
  103. new SqlParameter("@isdelete", SqlDbType.Int,4),
  104. new SqlParameter("@id", SqlDbType.Int,4)};
  105. parameters[0].Value = model.tellocid;
  106. parameters[1].Value = model.userid;
  107. parameters[2].Value = model.isdelete;
  108. parameters[3].Value = model.id;
  109. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  110. if (rows > 0)
  111. {
  112. return true;
  113. }
  114. else
  115. {
  116. return false;
  117. }
  118. }
  119. /// <summary>
  120. /// 得到一个对象实体
  121. /// </summary>
  122. public Model.telloc_users DataRowToModel(DataRow row)
  123. {
  124. Model.telloc_users model = new Model.telloc_users();
  125. if (row != null)
  126. {
  127. if (row["id"] != null && row["id"].ToString() != "")
  128. {
  129. model.id = int.Parse(row["id"].ToString());
  130. }
  131. if (row["tellocid"] != null && row["tellocid"].ToString() != "")
  132. {
  133. model.tellocid = int.Parse(row["tellocid"].ToString());
  134. }
  135. if (row["userid"] != null && row["userid"].ToString() != "")
  136. {
  137. model.userid = int.Parse(row["userid"].ToString());
  138. }
  139. if (row["isdelete"] != null && row["isdelete"].ToString() != "")
  140. {
  141. model.isdelete = int.Parse(row["isdelete"].ToString());
  142. }
  143. }
  144. return model;
  145. }
  146. }
  147. }