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"; /// /// 获取数据表名 /// public override string TableName { get { return _tableName; } set { this._tableName = value; } } /// /// 获取当前新的数据表模型对象 /// public override object ObjModel { get { return this.CurrentModel; } } /// /// 获取当前新的MOdel /// public LoginModel.app_authorization CurrentModel { get { return new LoginModel.app_authorization(); } } string _tableFieldNameString = ""; /// /// 数据表字段名数组 /// public override string TableFieldNameString { get { return this._tableFieldNameString; } set { this._tableFieldNameString = value; } } #endregion #region 检查记录 //基类已经实现 #endregion #region 增加数据 /// /// 增加一条数据, 返回Id /// /// Model对象 /// 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 删除数据 /// /// 删除数据 /// /// /// public bool Delete(LoginModel.app_authorization model) { return base.Delete(model.id); } #endregion #region 更新数据 /// /// 更新一条数据 /// public bool Update(LoginModel.app_authorization model) { return base.Update(model); } /// /// 根据筛选字段和SQL筛选运算符号更新数据 /// /// Model对象 /// 筛选字段名称 /// SQL筛选运算符号 /// 忽略字段名列表 字段名之间用“,”号分隔 /// public bool Update(LoginModel.app_authorization model, string filterFieldName = "ID", string operators = "=", string overlookFieldList = "ID") { return base.Update(model, filterFieldName, operators, overlookFieldList); } #endregion #region 查询数据 /// /// 得到一个对象实体 /// public LoginModel.app_authorization GetModel(int ID) { return DataRowToModel(GetDataRow(ID)); } /// /// 得到一个对象实体 /// /// /// public LoginModel.app_authorization DataRowToModel(DataRow row) { return DataRowToModelObject(row) as LoginModel.app_authorization; } #endregion #region 数据分页 //基类已实现相关方法 #endregion public app_authorization() { this.TableFieldNameString = ""; } /// /// 删除一条数据 /// 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; } } /// /// 更新一条数据 /// 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; } } }