/// <summary> /// ��¼�Ѷ���ʾ /// </summary> /// <param name="id">��¼Id</param> private void MarkRead(int id) { LMessageReadedData messageReadedData = new LMessageReadedData(); LMessageReadedBB messageReadedBB = new LMessageReadedBB(); try { //�����Ϣδ�� if (!messageReadedBB.IsReaded(id, this.currentUser.empId)) { messageReadedData.messageId = id; messageReadedData.empId = this.currentUser.empId; messageReadedData.isReaded = true; messageReadedData.readDt = DateTime.Now.ToString(); messageReadedBB.AddRecord(messageReadedData); } } finally { messageReadedBB.Dispose(); } }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LMessageReadedData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into LMessageReaded("); strSql.Append(@"messageId,empId,isReaded,readDt)"); strSql.Append(" values ("); strSql.Append(@"@messageId,@empId,@isReaded,@readDt)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@messageId", SqlDbType.Int), new SqlParameter("@empId", SqlDbType.Int), new SqlParameter("@isReaded", SqlDbType.Bit), new SqlParameter("@readDt", SqlDbType.DateTime) }; parameters[0].Value = model.messageId; parameters[1].Value = model.empId; parameters[2].Value = model.isReaded; parameters[3].Value = model.readDt == string.Empty ? null : model.readDt; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LMessageReadedData model) { return this.messageReadedDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LMessageReadedData model) { return this.messageReadedDB.AddRecord(model); }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LMessageReadedData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update LMessageReaded set "); strSql.Append("messageId=@messageId,"); strSql.Append("empId=@empId,"); strSql.Append("isReaded=@isReaded,"); strSql.Append("readDt=@readDt"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@messageId", SqlDbType.Int), new SqlParameter("@empId", SqlDbType.Int), new SqlParameter("@isReaded", SqlDbType.Bit), new SqlParameter("@readDt", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.messageId; parameters[2].Value = model.empId; parameters[3].Value = model.isReaded; parameters[4].Value = model.readDt == string.Empty ? null : model.readDt; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public LMessageReadedData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,messageId,empId,isReaded,readDt from LMessageReaded"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; LMessageReadedData model = new LMessageReadedData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["messageId"] != DBNull.Value) { model.messageId = Convert.ToInt32(row["messageId"]); } if (row["empId"] != DBNull.Value) { model.empId = Convert.ToInt32(row["empId"]); } if (row["isReaded"] != DBNull.Value) { model.isReaded = Convert.ToBoolean(row["isReaded"]); } if (row["readDt"] != DBNull.Value) { model.readDt = Convert.ToString(row["readDt"]); } return model; } else { return null; } }