internal ReturnObj BuildXml(IList<XmlHelper.ParamList> paramLists, string channelId) { ReturnObj obj = new ReturnObj(); obj.State = 1; obj.Msg = "操作成功完成。"; obj.Content = ""; StringBuilder sb = new StringBuilder(); IDao idao=new Dao.Impl.Dao(); IList<PriceLog> list = idao.GetList(channelId); if (list.Count == 0) { obj.State = -1; obj.Msg = "操作成功完成。"; obj.Content = "没有今天的价格记录!"; return obj; } foreach (var p in paramLists) { if (p.Name.Equals("pricelog") && p.Value.Equals("1")) { sb.Append(BuildPriceLogXml(list)); } } obj.Content = sb.ToString(); return obj; }
internal ReturnObj BuildEntity(IList<XmlHelper.ParamList> paramLists, System.Xml.XmlDocument xmlDoc) { ReturnObj returnObj = new ReturnObj(); returnObj.Content = ""; returnObj.Msg = ""; returnObj.State = 0; IList<DataBean> list = new List<DataBean>(); foreach (var p in paramLists) { if (p.Name.Equals("xsjls") && p.Value.Equals("1")) { list = BuildDataBeanEntity(xmlDoc.SelectSingleNode("/cpXML/xsjls")); } } IDao iDao = new Dao.Impl.Dao(); int i = iDao.Save(list); if (i > 0) { returnObj.State = 1; returnObj.Content = "成功提交" + i.ToString() + "条数据!"; returnObj.Msg = "操作成功!"; } else { returnObj.State = -1; returnObj.Msg = "添加失败请再次尝试!"; } return returnObj; }
private static ReturnObj BuildSubmitResponse(string subPackage, IList<ParamList> paramLists) { ReturnObj obj = null; try { StringBuilder sb = new StringBuilder(); XmlDocument xmlDoc = new XmlDocument(); sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.Append("<cpXML cName=\"销售记录提交应答\" name=\"lsj_submit_response\" version=\"CP2013\">"); xmlDoc.LoadXml(subPackage); //note:the subPackage is not defined with explicit namespace //so XPath does not need a XmlNameSpaceManager LsjHelper lsjHelper = new LsjHelper(); obj = lsjHelper.BuildEntity(paramLists, xmlDoc); sb.Append("<xsjls>").Append(obj.Content).Append("</xsjls></cpXML>"); obj.Content = sb.ToString(); } catch (Exception ex) { obj = new ReturnObj { State = -1, Msg = "服务程序错误:" + ex.Message, Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cpXML cName=\"销售记录提交应答\" name=\"lsj_submit_response\" version=\"CP2013\"></cpXML>" }; } return obj; }
private static ReturnObj BuildQueryResponse(string subPackage, IList<ParamList> paramLists, string channelId) { ReturnObj obj = null; try { XmlDocument xmlDoc = new XmlDocument(); StringBuilder sb = new StringBuilder(); //sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //sb.Append("<cpXML cName=\"lsj价格查询应答\" name=\"lsj_query_response\" version=\"CP2013\">"); //xmlDoc.LoadXml(subPackage); LsjHelper pisHelper = new LsjHelper(); obj = pisHelper.BuildXml(paramLists, channelId); if (obj.State == 1) { sb.Append(obj.Content).Append(""); obj.Content = sb.ToString(); } else //可能有各种错误 { obj.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cpXML cName=\"lsj价格查询应答\" name=\"lsj_query_response\" version=\"CP2013\"></cpXML>"; } } catch (Exception ex) { obj = new ReturnObj { State = -1, Msg = "服务程序错误:" + ex.Message, Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cpXML cName=\"lsj价格查询应答\" name=\"lsj_query_response\" version=\"CP2013\"></cpXML>" }; } return obj; }