| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using LYFZ.Helper;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LoginDal
- {
- public class app_authorization : BaseDataOperate
- {
- #region 属性和字段
- string _tableName = "app_authorization";
- /// <summary>
- /// 获取数据表名
- /// </summary>
- public override string TableName
- {
- get { return _tableName; }
- set { this._tableName = value; }
- }
- /// <summary>
- /// 获取当前新的数据表模型对象
- /// </summary>
- public override object ObjModel
- {
- get
- {
- return this.CurrentModel;
- }
- }
- /// <summary>
- /// 获取当前新的MOdel
- /// </summary>
- public LoginModel.app_authorization CurrentModel
- {
- get { return new LoginModel.app_authorization(); }
- }
- string _tableFieldNameString = "";
- /// <summary>
- /// 数据表字段名数组
- /// </summary>
- public override string TableFieldNameString
- {
- get { return this._tableFieldNameString; }
- set { this._tableFieldNameString = value; }
- }
- #endregion
- #region 检查记录
- //基类已经实现
- #endregion
- #region 增加数据
- /// <summary>
- /// 增加一条数据, 返回Id
- /// </summary>
- /// <param name="model">Model对象</param>
- /// <returns></returns>
- public int Add(LoginModel.app_authorization model)
- {
- LYFZ.Helper.CommandInfo comdInfo = this.GetAddCommandInfo(model, "");
- object result = SQLHelper.GetSingle(comdInfo.CommandText, (SqlParameter[])comdInfo.Parameters);
- return Convert.ToInt32(result);
- }
- #endregion
- #region 删除数据
- /// <summary>
- /// 删除数据
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool Delete(LoginModel.app_authorization model)
- {
- return base.Delete(model.id);
- }
- #endregion
- #region 更新数据
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public bool Update(LoginModel.app_authorization model)
- {
- return base.Update(model);
- }
- /// <summary>
- /// 根据筛选字段和SQL筛选运算符号更新数据
- /// </summary>
- /// <param name="model">Model对象</param>
- /// <param name="filterFieldName">筛选字段名称</param>
- /// <param name="operators">SQL筛选运算符号</param>
- /// <param name="overlookFieldList">忽略字段名列表 字段名之间用“,”号分隔</param>
- /// <returns></returns>
- public bool Update(LoginModel.app_authorization model, string filterFieldName = "ID", string operators = "=", string overlookFieldList = "ID")
- {
- return base.Update(model, filterFieldName, operators, overlookFieldList);
- }
- #endregion
- #region 查询数据
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- public LoginModel.app_authorization GetModel(int ID)
- {
- return DataRowToModel(GetDataRow(ID));
- }
- /// <summary>
- /// 得到一个对象实体
- /// </summary>
- /// <param name="row"></param>
- /// <returns></returns>
- public LoginModel.app_authorization DataRowToModel(DataRow row)
- {
- return DataRowToModelObject(row) as LoginModel.app_authorization;
- }
- #endregion
- #region 数据分页
- //基类已实现相关方法
- #endregion
- public app_authorization()
- {
- this.TableFieldNameString = "";
- }
- /// <summary>
- /// 删除一条数据
- /// </summary>
- public bool DeleteEx(string ent_id, string app_id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("delete from app_authorization ");
- strSql.Append(" where app_id=@app_id and ent_id=@ent_id");
- SqlParameter[] parameters = {
- new SqlParameter("@app_id", app_id),
- new SqlParameter("@ent_id", ent_id)
- };
- int rows = SQLHelper.ExecuteSql(strSql.ToString(), parameters);
- return rows > 0 ? true : false;
- }
- public LoginModel.app_authorization GetModel(string ent_id, string app_id)
- {
- StringBuilder strSql = new StringBuilder();
- 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");
- strSql.Append(" from app_authorization");
- strSql.Append(" where ent_id=@ent_id and app_id=@app_id");
- SqlParameter[] parameters =
- {
- new SqlParameter("@ent_id", ent_id),
- new SqlParameter("@app_id", app_id)
- };
- LoginModel.app_authorization model = new LoginModel.app_authorization();
- DataSet ds = SQLHelper.Query(strSql.ToString(), parameters);
- if ( ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
- {
- if (ds.Tables[0].Rows[0]["id"].ToString() != "")
- {
- model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
- }
- if (ds.Tables[0].Rows[0]["create_time"].ToString() != "")
- {
- model.create_time = DateTime.Parse(ds.Tables[0].Rows[0]["create_time"].ToString());
- }
- if (ds.Tables[0].Rows[0]["update_time"].ToString() != "")
- {
- model.update_time = DateTime.Parse(ds.Tables[0].Rows[0]["update_time"].ToString());
- }
- if (ds.Tables[0].Rows[0]["refresh_token_time"].ToString() != "")
- {
- model.refresh_token_time = DateTime.Parse(ds.Tables[0].Rows[0]["refresh_token_time"].ToString());
- }
- model.app_type_name = ds.Tables[0].Rows[0]["app_type_name"].ToString();
- model.ent_id = ds.Tables[0].Rows[0]["ent_id"].ToString();
- model.app_id = ds.Tables[0].Rows[0]["app_id"].ToString();
- model.authorization_info = ds.Tables[0].Rows[0]["authorization_info"].ToString();
- if (ds.Tables[0].Rows[0]["authorize_status"].ToString() != "")
- {
- model.authorize_status = int.Parse(ds.Tables[0].Rows[0]["authorize_status"].ToString());
- }
- model.authorizer_access_token = ds.Tables[0].Rows[0]["authorizer_access_token"].ToString();
- if (ds.Tables[0].Rows[0]["expires_in"].ToString() != "")
- {
- model.expires_in = int.Parse(ds.Tables[0].Rows[0]["expires_in"].ToString());
- }
- model.authorizer_refresh_token = ds.Tables[0].Rows[0]["authorizer_refresh_token"].ToString();
- model.account_aasic_info = ds.Tables[0].Rows[0]["account_aasic_info"].ToString();
- return model;
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 更新一条数据
- /// </summary>
- public bool UpdateEx(int id, string auth_code, int expires_in, int auth_status)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update app_authorization set ");
- strSql.Append(" authorize_status = @authorize_status , ");
- strSql.Append(" refresh_token_time = @refresh_token_time , ");
- strSql.Append(" update_time = @update_time , ");
- strSql.Append(" authorizer_access_token = @authorizer_access_token , ");
- strSql.Append(" expires_in = @expires_in ");
- strSql.Append(" where id=@id ");
- SqlParameter[] parameters = {
- new SqlParameter("@id", id) ,
- new SqlParameter("@authorize_status", auth_status) ,
- new SqlParameter("@refresh_token_time", DateTime.Now.AddMilliseconds(expires_in)) ,
- new SqlParameter("@update_time", DateTime.Now) ,
- new SqlParameter("@authorizer_access_token", auth_code) ,
- new SqlParameter("@expires_in", expires_in)
- };
- return SQLHelper.ExecuteSql(strSql.ToString(), parameters) > 0 ? true : false;
- }
- }
- }
|