public String AnalysisXml(string ReqXml) { string ResXml = string.Empty; string ReqCode = string.Empty; try { System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument(); xmldoc.LoadXml(ReqXml); //请求指令 ReqCode = xmldoc.SelectSingleNode("JTW91G/MsgData/ReqHeader/ReqCode").InnerText; Trade.CTrade trade = new Trade.CTrade(); int NType = Convert.ToInt32(xmldoc.SelectSingleNode("JTW91G/MsgData/DataBody/Lqc/NewsType").InnerText); NewsLqc Lqc = new NewsLqc(); Lqc.LoginID = xmldoc.SelectSingleNode("JTW91G/MsgData/DataBody/LoginId").InnerText; Lqc.StartTime = Convert.ToDateTime(xmldoc.SelectSingleNode("JTW91G/MsgData/DataBody/Lqc/StartTime").InnerText); Lqc.EndTime = Convert.ToDateTime(xmldoc.SelectSingleNode("JTW91G/MsgData/DataBody/Lqc/EndTime").InnerText); Lqc.NType = (NewsType)NType; int pageindex = Convert.ToInt32(xmldoc.SelectSingleNode("JTW91G/MsgData/DataBody/Lqc/PageIndex").InnerText); int pagesize = Convert.ToInt32(xmldoc.SelectSingleNode("JTW91G/MsgData/DataBody/Lqc/PageSize").InnerText); int page = 0; TradeNewsInfo newsinfo = trade.GetTradeNewsInfoWithPage(Lqc, pageindex, pagesize, ref page); StringBuilder strb = new StringBuilder(); foreach (TradeNews tn in newsinfo.TradeNewsInfoList) { strb.Append("<News>"); strb.AppendFormat("<NewsId>{0}</NewsId>", tn.ID); strb.AppendFormat("<Title>{0}</Title>", tn.NewsTitle); strb.AppendFormat("<NewsType>{0}</NewsType>", (int)tn.NType); strb.AppendFormat("<Detail>{0}</Detail>", tn.NewsContent.Replace("src=\"/", string.Format("src=\"http://{0}/", ComFunction.NewsHostAddr))); strb.AppendFormat("<Time>{0}</Time>", tn.PubTime.ToString(Const.dateformat)); strb.AppendFormat("<Publisher>{0}</Publisher>", tn.PubPerson); strb.AppendFormat("<Status>{0}</Status>", (int)tn.Status); strb.Append("</News>"); } if (strb.Length > 0) { //响应消息体 string DataBody = string.Format("<DataBody><PageCount>{0}</PageCount><AllNews>{1}</AllNews></DataBody>", page, strb); ResXml = GssResXml.GetResXml(ReqCode, ResCode.UL004, ResCode.UL004Desc, DataBody); } else { ResXml = GssResXml.GetResXml(ReqCode, ResCode.UL034, ResCode.UL034Desc, string.Format("<DataBody></DataBody>")); } } catch (Exception ex) { com.individual.helper.LogNet4.WriteErr(ex); //业务处理失败 ResXml = GssResXml.GetResXml(ReqCode, ResCode.UL005, ResCode.UL005Desc, string.Format("<DataBody></DataBody>")); } return ResXml; }
/// <summary> /// 新闻公告查询 /// </summary> /// <param name="lqc">新闻查询条件</param> /// <param name="pageindex">第几页,从1开始</param> /// <param name="pagesize">每页多少条</param> /// <param name="page">输出参数(总页数)</param> /// <returns>新闻信息</returns> public TradeNewsInfo GetTradeNewsInfoWithPage(NewsLqc lqc, int pageindex, int pagesize, ref int page) { TradeNewsInfo tradeNewsInfo = new TradeNewsInfo(); SqlConnection sqlconn = null; SqlCommand sqlcmd = null; SqlDataReader sqldr = null; tradeNewsInfo.TradeNewsInfoList = new List<TradeNews>(); try { TradeUser TdUser = new TradeUser(); #region 判断登陆标识是否过期 if (!ComFunction.ExistUserLoginID(lqc.LoginID, ref TdUser)) { tradeNewsInfo.Result = false; tradeNewsInfo.ReturnCode = ResCode.UL003; tradeNewsInfo.Desc = ResCode.UL003Desc; return tradeNewsInfo; } #endregion string newsType = string.Empty; if (lqc.NType != NewsType.ALL) { newsType = string.Format(" and NewsType={0}", (int)lqc.NType); } string status = string.Empty; if (UserType.NormalType == TdUser.UType) //客户端只返回启用的新闻 { status = string.Format(" and Status=1"); } string sqlcondition = string.Format("where PubTime>='{0}' and PubTime<='{1}' {2} {3}", lqc.StartTime.ToString("yyyy-MM-dd"), lqc.EndTime.ToString("yyyy-MM-dd"), newsType, status); sqlconn = new SqlConnection(ComFunction.SqlConnectionString); sqlconn.Open(); sqlcmd = sqlconn.CreateCommand(); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.CommandText = "GetRecordFromPage"; sqlcmd.Parameters.Add("@selectlist", SqlDbType.VarChar);//选择字段列表 sqlcmd.Parameters.Add("@SubSelectList", SqlDbType.VarChar); //内部子查询字段列表 sqlcmd.Parameters.Add("@TableSource", SqlDbType.VarChar); //表名或视图表 sqlcmd.Parameters.Add("@TableOrder", SqlDbType.VarChar); //排序后的表名称 即子查询结果集的别名 sqlcmd.Parameters.Add("@SearchCondition", SqlDbType.VarChar); //查询条件 sqlcmd.Parameters.Add("@OrderExpression", SqlDbType.VarChar); //排序 表达式 sqlcmd.Parameters.Add("@PageIndex", SqlDbType.Int); sqlcmd.Parameters.Add("@PageSize", SqlDbType.Int); sqlcmd.Parameters.Add("@PageCount", SqlDbType.Int); sqlcmd.Parameters["@SubSelectList"].Value = "ID,NewsTitle,NewsContent,PubPerson,PubTime,Status,NewsType,OverView "; sqlcmd.Parameters["@selectlist"].Value = "ID,NewsTitle,NewsContent,PubPerson,PubTime,Status,NewsType,OverView "; sqlcmd.Parameters["@TableSource"].Value = "Trade_News"; sqlcmd.Parameters["@TableOrder"].Value = "a";//取L_Trade_Order的别名 sqlcmd.Parameters["@SearchCondition"].Value = sqlcondition; sqlcmd.Parameters["@OrderExpression"].Value = "order by PubTime desc"; sqlcmd.Parameters["@PageIndex"].Value = pageindex; sqlcmd.Parameters["@PageSize"].Value = pagesize; sqlcmd.Parameters["@PageCount"].Direction = ParameterDirection.Output; sqldr = sqlcmd.ExecuteReader(); while (sqldr.Read()) { TradeNews TdNews = new TradeNews(); TdNews.ID = sqldr["ID"].ToString(); TdNews.NewsTitle = sqldr["NewsTitle"].ToString(); TdNews.NewsContent = sqldr["NewsContent"].ToString(); TdNews.PubPerson = sqldr["PubPerson"].ToString(); TdNews.PubTime = Convert.ToDateTime(sqldr["PubTime"]); TdNews.Status = (NewsStatus)sqldr["Status"]; TdNews.NType = (NewsType)sqldr["NewsType"]; TdNews.OverView = System.DBNull.Value != sqldr["OverView"] ? sqldr["OverView"].ToString() : string.Empty; tradeNewsInfo.TradeNewsInfoList.Add(TdNews); } sqlconn.Close(); page = Convert.ToInt32(sqlcmd.Parameters["@PageCount"].Value); tradeNewsInfo.Result = true; tradeNewsInfo.Desc = "查询成功"; } catch (Exception ex) { ComFunction.WriteErr(ex); if (null != tradeNewsInfo.TradeNewsInfoList && tradeNewsInfo.TradeNewsInfoList.Count > 0) { tradeNewsInfo.TradeNewsInfoList.Clear(); } tradeNewsInfo.Result = false; tradeNewsInfo.Desc = "查询失败"; } finally { if (null != sqlconn) { sqlconn.Close(); } if (null != sqldr) { sqldr.Close(); } } return tradeNewsInfo; }