You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/DAL/MsAnnounce/MsAnnounceDAL.cs

130 lines
5.3 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsAnnounce;
using DSWeb.MvcShipping.Models.MsTemplet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsAnnounce
{
public class MsAnnounceDAL
{
#region Inquery DataList
static public List<Announce> GetDataList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,NAME,DESCRIPTION,ANNOUNCECONTENT,CREATETIME,CREATEUSER,");
strSql.Append("MODIFIEDUSER,MODIFIEDTIME,BEGINTIME,ENDTIME,ISDELETE,DELETEUSER,DELETETIME,INTERVAL,TYPE,ISISSUE");
strSql.Append(",(select showname from [user] where gid=sys_announce.CREATEUSER) CREATEUSERREF");
strSql.Append(",(CASE TYPE WHEN 1 THEN '内部公告' ELSE '外部公告' END) TYPEREF");
strSql.Append(" from sys_announce where ISDELETE<>1 and ISISSUE=1 and ENDTIME>='" + DateTime.Now.ToString("yyyy-MM-dd") + "' and BEGINTIME<='" + DateTime.Now.ToString("yyyy-MM-dd") + "' ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by MODIFIEDTIME DESC");
}
return SetData(strSql);
}
static public Announce GetData(string condition, string companyid)
{
Announce data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new Announce();
}
return data;
}
private static List<Announce> SetData(StringBuilder strSql)
{
var headList = new List<Announce>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Announce data = new Announce();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.ANNOUNCECONTENT = Convert.ToString(reader["ANNOUNCECONTENT"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);
if (reader["BEGINTIME"] != DBNull.Value)
data.BEGINTIME = Convert.ToDateTime(reader["BEGINTIME"]).ToString("yyyy-MM-dd");
if (reader["ENDTIME"] != DBNull.Value)
data.ENDTIME = Convert.ToDateTime(reader["ENDTIME"]).ToString("yyyy-MM-dd");
if (reader["TYPE"] != DBNull.Value)
data.TYPE = Convert.ToInt16(reader["TYPE"]);
data.TYPEREF = Convert.ToString(reader["TYPEREF"]);
if (reader["ISISSUE"] != DBNull.Value)
data.ISISSUE = Convert.ToBoolean(reader["ISISSUE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 查询模板地址
public static List<MsTempletStructure> GetTempletURL(string gid, string userid, string companyid)
{
List<MsTempletStructure> list = new List<MsTempletStructure>();
StringBuilder sql = new StringBuilder();
//sql.AppendLine("select top 1 TEMPLETURL from templet where TEMPLETID='" + gid + "'");
sql.AppendLine("select distinct B.GID,A.TEMPLETURL ");
sql.AppendLine("from templet as A ");
sql.AppendLine("left join user_templet as B on A.TEMPLETID=B.TEMPLETID ");
sql.AppendLine("where A.TEMPLETID='" + gid + "' and B.LINKURL='#' and B.COMPANYID='" + companyid + "' and A.USERID='" + userid + "' ");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString()))
{
while (reader.Read())
{
MsTempletStructure data=new MsTempletStructure();
data.GID=Convert.ToString(reader["GID"]);
data.LINKURL = Convert.ToString(reader["TEMPLETURL"]);
list.Add(data);
}
reader.Close();
}
return list;
}
#endregion
#region 参照部分
#endregion
}
}