app_authorization.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using LYFZ.Helper;
  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. namespace LoginDal
  10. {
  11. public class app_authorization : BaseDataOperate
  12. {
  13. #region 属性和字段
  14. string _tableName = "app_authorization";
  15. /// <summary>
  16. /// 获取数据表名
  17. /// </summary>
  18. public override string TableName
  19. {
  20. get { return _tableName; }
  21. set { this._tableName = value; }
  22. }
  23. /// <summary>
  24. /// 获取当前新的数据表模型对象
  25. /// </summary>
  26. public override object ObjModel
  27. {
  28. get
  29. {
  30. return this.CurrentModel;
  31. }
  32. }
  33. /// <summary>
  34. /// 获取当前新的MOdel
  35. /// </summary>
  36. public LoginModel.app_authorization CurrentModel
  37. {
  38. get { return new LoginModel.app_authorization(); }
  39. }
  40. string _tableFieldNameString = "";
  41. /// <summary>
  42. /// 数据表字段名数组
  43. /// </summary>
  44. public override string TableFieldNameString
  45. {
  46. get { return this._tableFieldNameString; }
  47. set { this._tableFieldNameString = value; }
  48. }
  49. #endregion
  50. #region 检查记录
  51. //基类已经实现
  52. #endregion
  53. #region 增加数据
  54. /// <summary>
  55. /// 增加一条数据, 返回Id
  56. /// </summary>
  57. /// <param name="model">Model对象</param>
  58. /// <returns></returns>
  59. public int Add(LoginModel.app_authorization model)
  60. {
  61. LYFZ.Helper.CommandInfo comdInfo = this.GetAddCommandInfo(model, "");
  62. object result = SQLHelper.GetSingle(comdInfo.CommandText, (SqlParameter[])comdInfo.Parameters);
  63. return Convert.ToInt32(result);
  64. }
  65. #endregion
  66. #region 删除数据
  67. /// <summary>
  68. /// 删除数据
  69. /// </summary>
  70. /// <param name="model"></param>
  71. /// <returns></returns>
  72. public bool Delete(LoginModel.app_authorization model)
  73. {
  74. return base.Delete(model.id);
  75. }
  76. #endregion
  77. #region 更新数据
  78. /// <summary>
  79. /// 更新一条数据
  80. /// </summary>
  81. public bool Update(LoginModel.app_authorization model)
  82. {
  83. return base.Update(model);
  84. }
  85. /// <summary>
  86. /// 根据筛选字段和SQL筛选运算符号更新数据
  87. /// </summary>
  88. /// <param name="model">Model对象</param>
  89. /// <param name="filterFieldName">筛选字段名称</param>
  90. /// <param name="operators">SQL筛选运算符号</param>
  91. /// <param name="overlookFieldList">忽略字段名列表 字段名之间用“,”号分隔</param>
  92. /// <returns></returns>
  93. public bool Update(LoginModel.app_authorization model, string filterFieldName = "ID", string operators = "=", string overlookFieldList = "ID")
  94. {
  95. return base.Update(model, filterFieldName, operators, overlookFieldList);
  96. }
  97. #endregion
  98. #region 查询数据
  99. /// <summary>
  100. /// 得到一个对象实体
  101. /// </summary>
  102. public LoginModel.app_authorization GetModel(int ID)
  103. {
  104. return DataRowToModel(GetDataRow(ID));
  105. }
  106. /// <summary>
  107. /// 得到一个对象实体
  108. /// </summary>
  109. /// <param name="row"></param>
  110. /// <returns></returns>
  111. public LoginModel.app_authorization DataRowToModel(DataRow row)
  112. {
  113. return DataRowToModelObject(row) as LoginModel.app_authorization;
  114. }
  115. #endregion
  116. #region 数据分页
  117. //基类已实现相关方法
  118. #endregion
  119. public app_authorization()
  120. {
  121. this.TableFieldNameString = "";
  122. }
  123. /// <summary>
  124. /// 删除一条数据
  125. /// </summary>
  126. public bool DeleteEx(string ent_id, string app_id)
  127. {
  128. StringBuilder strSql = new StringBuilder();
  129. strSql.Append("delete from app_authorization ");
  130. strSql.Append(" where app_id=@app_id and ent_id=@ent_id");
  131. SqlParameter[] parameters = {
  132. new SqlParameter("@app_id", app_id),
  133. new SqlParameter("@ent_id", ent_id)
  134. };
  135. int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
  136. return rows > 0 ? true : false;
  137. }
  138. public LoginModel.app_authorization GetModel(string ent_id, string app_id)
  139. {
  140. StringBuilder strSql = new StringBuilder();
  141. strSql.Append("select id, create_time, update_time, refresh_token_time, app_type_name, ent_id, app_id, authorization_info, authorize_status, authorizer_access_token, expires_in, authorizer_refresh_token, account_aasic_info");
  142. strSql.Append(" from app_authorization");
  143. strSql.Append(" where ent_id=@ent_id and app_id=@app_id");
  144. SqlParameter[] parameters =
  145. {
  146. new SqlParameter("@ent_id", ent_id),
  147. new SqlParameter("@app_id", app_id)
  148. };
  149. LoginModel.app_authorization model = new LoginModel.app_authorization();
  150. DataSet ds = SQLHelper.Query(strSql.ToString(), parameters);
  151. if ( ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  152. {
  153. if (ds.Tables[0].Rows[0]["id"].ToString() != "")
  154. {
  155. model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
  156. }
  157. if (ds.Tables[0].Rows[0]["create_time"].ToString() != "")
  158. {
  159. model.create_time = DateTime.Parse(ds.Tables[0].Rows[0]["create_time"].ToString());
  160. }
  161. if (ds.Tables[0].Rows[0]["update_time"].ToString() != "")
  162. {
  163. model.update_time = DateTime.Parse(ds.Tables[0].Rows[0]["update_time"].ToString());
  164. }
  165. if (ds.Tables[0].Rows[0]["refresh_token_time"].ToString() != "")
  166. {
  167. model.refresh_token_time = DateTime.Parse(ds.Tables[0].Rows[0]["refresh_token_time"].ToString());
  168. }
  169. model.app_type_name = ds.Tables[0].Rows[0]["app_type_name"].ToString();
  170. model.ent_id = ds.Tables[0].Rows[0]["ent_id"].ToString();
  171. model.app_id = ds.Tables[0].Rows[0]["app_id"].ToString();
  172. model.authorization_info = ds.Tables[0].Rows[0]["authorization_info"].ToString();
  173. if (ds.Tables[0].Rows[0]["authorize_status"].ToString() != "")
  174. {
  175. model.authorize_status = int.Parse(ds.Tables[0].Rows[0]["authorize_status"].ToString());
  176. }
  177. model.authorizer_access_token = ds.Tables[0].Rows[0]["authorizer_access_token"].ToString();
  178. if (ds.Tables[0].Rows[0]["expires_in"].ToString() != "")
  179. {
  180. model.expires_in = int.Parse(ds.Tables[0].Rows[0]["expires_in"].ToString());
  181. }
  182. model.authorizer_refresh_token = ds.Tables[0].Rows[0]["authorizer_refresh_token"].ToString();
  183. model.account_aasic_info = ds.Tables[0].Rows[0]["account_aasic_info"].ToString();
  184. return model;
  185. }
  186. else
  187. {
  188. return null;
  189. }
  190. }
  191. /// <summary>
  192. /// 更新一条数据
  193. /// </summary>
  194. public bool UpdateEx(int id, string auth_code, int expires_in, int auth_status)
  195. {
  196. StringBuilder strSql = new StringBuilder();
  197. strSql.Append("update app_authorization set ");
  198. strSql.Append(" authorize_status = @authorize_status , ");
  199. strSql.Append(" refresh_token_time = @refresh_token_time , ");
  200. strSql.Append(" update_time = @update_time , ");
  201. strSql.Append(" authorizer_access_token = @authorizer_access_token , ");
  202. strSql.Append(" expires_in = @expires_in ");
  203. strSql.Append(" where id=@id ");
  204. SqlParameter[] parameters = {
  205. new SqlParameter("@id", id) ,
  206. new SqlParameter("@authorize_status", auth_status) ,
  207. new SqlParameter("@refresh_token_time", DateTime.Now.AddMilliseconds(expires_in)) ,
  208. new SqlParameter("@update_time", DateTime.Now) ,
  209. new SqlParameter("@authorizer_access_token", auth_code) ,
  210. new SqlParameter("@expires_in", expires_in)
  211. };
  212. return SQLHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
  213. }
  214. }
  215. }