WSInformationExchange.asmx.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using SysBaseLibs;
  2. using SysDataLibs;
  3. using SysDataLibs.TableClass;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Services;
  10. using System.Xml.Serialization;
  11. namespace GSMarketSys.WS
  12. {
  13. /// <summary>
  14. /// WSInformationExchange 的摘要说明
  15. /// </summary>
  16. [WebService(Namespace = "http://tempuri.org/")]
  17. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  18. [System.ComponentModel.ToolboxItem(false)]
  19. // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
  20. // [System.Web.Script.Services.ScriptService]
  21. public class WSInformationExchange : System.Web.Services.WebService
  22. {
  23. public WSInformationExchange()
  24. {
  25. //如果使用设计的组件,请取消注释以下行
  26. //InitializeComponent();
  27. }
  28. /* InfoGuid 信息的主键编号(平台所记录的主键编号,在回复接口中需要使用到)
  29. InfoTitle 信息标题
  30. InfoContent 信息内容
  31. SendDate 信息发送时间
  32. SendBy 信息发送人
  33. Attachments 可选,信息的附件信息
  34. Guid 用户令牌 */
  35. [XmlInclude(typeof(InfoAttachEntity))]
  36. [WebMethod]
  37. public InfoExchgResult InfoSend(string InfoGuid, string InfoTitle, string InfoContent,
  38. DateTime SendDate, string SendBy, InfoAttachEntity[] Attachments, string Guid)
  39. {
  40. InfoExchgResult result = new InfoExchgResult();
  41. result.Flag = false;
  42. result.Message = "";
  43. DBConnSql loDBConn = null;
  44. try
  45. {
  46. // 检查是否有效guid
  47. if (LoginGUID.Instance.GetOne(Guid) == null)
  48. {
  49. string strMsg = "Invalid guid " + Guid;
  50. result.Message = strMsg;
  51. throw new Exception(strMsg);
  52. }
  53. FSInformationExchange_info info = new FSInformationExchange_info();
  54. info.InfoGuid = SysBaseLibs.Utils.AreaToSQL(InfoGuid);
  55. info.InfoTitle = SysBaseLibs.Utils.AreaToSQL(InfoTitle);
  56. info.InfoContent = SysBaseLibs.Utils.AreaToSQL(InfoContent);
  57. info.SendDate = SendDate.ToString();
  58. info.SendBy = SysBaseLibs.Utils.AreaToSQL(SendBy);
  59. info.Recipient = "工商";
  60. info.IsRoot = "1";
  61. info.IsDeleted = "0";
  62. info.IsFromPlat = "1";
  63. // 数据库操作
  64. loDBConn = new DBConnSql();
  65. if (loDBConn.Open())
  66. {
  67. // 查询指定信息是否通过InfoSend收到过
  68. if (IsInfoSendExist(InfoGuid, loDBConn) == false)
  69. {
  70. // 流水号
  71. info.MsgID = System.Guid.NewGuid().ToString("N");
  72. string lcSql = info.InsertSql();
  73. if (loDBConn.ExcuteSqlTran(lcSql))
  74. {
  75. // 保存附件信息
  76. SaveAttachments(info.MsgID, Attachments, loDBConn);
  77. result.Flag = true;
  78. }
  79. }
  80. else
  81. {
  82. result.Flag = false;
  83. result.Message = "InfoGuid already exist";
  84. }
  85. }
  86. }
  87. catch (Exception err)
  88. {
  89. result.Flag = false;
  90. result.Message = err.Message;
  91. string strTemp = "WSInformationExchange::InfoSend失败," + err.Message;
  92. ThreadLog.LogInfo(strTemp);
  93. }
  94. finally
  95. {
  96. if (loDBConn != null && loDBConn.IsOpened)
  97. loDBConn.Close();
  98. }
  99. return result;
  100. }
  101. /* InfoGuid 信息的主键编号(平台所记录的主键编号,在回复接口中需要使用到)
  102. InfoTitle 信息标题
  103. InfoContent 信息内容
  104. SendDate 信息发送时间
  105. SendBy 信息发送人
  106. Recipient 信息接收人
  107. Attachments 可选,信息的附件信息
  108. Guid 用户令牌*/
  109. [XmlInclude(typeof(InfoAttachEntity))]
  110. [WebMethod]
  111. public InfoExchgResult InfoReply(string InfoGuid, string InfoTitle, string InfoContent,
  112. DateTime SendDate, string SendBy, string Recipient, InfoAttachEntity[] Attachments, string Guid)
  113. {
  114. InfoExchgResult result = new InfoExchgResult();
  115. result.Flag = false;
  116. result.Message = "";
  117. DBConnSql loDBConn = null;
  118. try
  119. {
  120. // 检查是否有效guid
  121. if (LoginGUID.Instance.GetOne(Guid) == null)
  122. {
  123. string strMsg = "Invalid guid " + Guid;
  124. result.Message = strMsg;
  125. throw new Exception(strMsg);
  126. }
  127. FSInformationExchange_info info = new FSInformationExchange_info();
  128. info.InfoGuid = SysBaseLibs.Utils.AreaToSQL(InfoGuid);
  129. info.InfoTitle = SysBaseLibs.Utils.AreaToSQL(InfoTitle);
  130. info.InfoContent = SysBaseLibs.Utils.AreaToSQL(InfoContent);
  131. info.SendDate = SendDate.ToString();
  132. info.SendBy = SysBaseLibs.Utils.AreaToSQL(SendBy);
  133. info.Recipient = SysBaseLibs.Utils.AreaToSQL(Recipient);
  134. info.IsRoot = "0";
  135. info.IsDeleted = "0";
  136. info.IsFromPlat = "1";
  137. // 数据库操作
  138. loDBConn = new DBConnSql();
  139. if (loDBConn.Open())
  140. {
  141. // 流水号
  142. info.MsgID = System.Guid.NewGuid().ToString("N");
  143. string lcSql = info.InsertSql();
  144. if (loDBConn.ExcuteSqlTran(lcSql))
  145. {
  146. // 保存附件信息
  147. SaveAttachments(info.MsgID, Attachments, loDBConn);
  148. result.Flag = true;
  149. }
  150. }
  151. }
  152. catch (Exception err)
  153. {
  154. result.Flag = false;
  155. result.Message = err.Message;
  156. string strTemp = "WSInformationExchange::InfoReply失败," + err.Message;
  157. ThreadLog.LogInfo(strTemp);
  158. }
  159. finally
  160. {
  161. if (loDBConn != null && loDBConn.IsOpened)
  162. loDBConn.Close();
  163. }
  164. return result;
  165. }
  166. // 查询指定信息是否通过InfoSend收到过
  167. private bool IsInfoSendExist(string lcInfoGuid, DBConnSql loConn)
  168. {
  169. bool bRet = false;
  170. string lcSql = "select count(*) as totalcount from " + Tn.FSInformationExchange +
  171. " where " + FSInformationExchange_info.cInfoGuid + "='" + lcInfoGuid + "' and " +
  172. FSInformationExchange_info.cIsRoot + "=1";
  173. SysBaseLibs.rsQuery loQuery = loConn.OpenQuery(lcSql);
  174. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
  175. {
  176. int nCount = loQuery.GetInt("totalcount");
  177. if (nCount > 0)
  178. bRet = true;
  179. }
  180. return bRet;
  181. }
  182. // 保存附件文件
  183. private void SaveAttachments(string MsgID, InfoAttachEntity[] Attachments, DBConnSql loDBConn)
  184. {
  185. if (Attachments == null)
  186. return;
  187. foreach (InfoAttachEntity attachFile in Attachments)
  188. {
  189. if (string.IsNullOrEmpty(attachFile.AttachmentName) || string.IsNullOrEmpty(attachFile.AttachmentFormat) || attachFile.AttachmentContent == null)
  190. {
  191. continue;
  192. }
  193. try
  194. {
  195. // 相对路径路径
  196. string strFilePath = SysDataLibs.AppEnv.SysSetObj.GetString("DOWNLOADPATH") + "/" +
  197. SysDataLibs.AppEnv.SysSetObj.GetString("ATTACHFILES") + "/" + Tn.FSOnlineComplaints.ToUpper();
  198. // 物理路径
  199. string strPhysicalDir = HttpContext.Current.Request.PhysicalApplicationPath;
  200. strPhysicalDir += strFilePath;
  201. if (!Directory.Exists(strPhysicalDir))
  202. {
  203. Directory.CreateDirectory(strPhysicalDir);
  204. }
  205. string strFileExt = attachFile.AttachmentFormat.Replace("'", "");
  206. strFileExt = strFileExt.Replace(".", ""); // 扩展名不需要"."符号
  207. string strFileTitle = attachFile.AttachmentName.Replace("'", "");
  208. string lcDateRd = strFileTitle + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "." + strFileExt;
  209. string strFileName = lcDateRd.Replace(" ", "");
  210. // 写入文件
  211. System.IO.File.WriteAllBytes(strPhysicalDir + "/" + strFileName, attachFile.AttachmentContent);
  212. // 附件信息写入数据库
  213. Sys_AttachFiles_info loAttachFile = new Sys_AttachFiles_info();
  214. loAttachFile.TableId = Tn.FSInformationExchange;
  215. loAttachFile.ColumnId = FSInformationExchange_info.cMsgID;
  216. loAttachFile.SourceKey = MsgID;
  217. loAttachFile.FileTitle = strFileTitle;
  218. loAttachFile.FileName = strFileName;
  219. loAttachFile.FilePath = strFilePath;
  220. loAttachFile.FileExt = strFileExt;
  221. loAttachFile.TimeCreated = DateTime.Now.ToString();
  222. loAttachFile.TimeLastMod = DateTime.Now.ToString();
  223. loAttachFile.UserIDLastMod = "platuser";
  224. loAttachFile.Description = "";
  225. string strSql = loAttachFile.InsertSql();
  226. bool bRet = loDBConn.ExcuteSqlTran(strSql);
  227. }
  228. catch (Exception err)
  229. {
  230. string strMsg = "WSComplaints.SaveAttachments exception," + err.Message;
  231. ThreadLog.LogErr(strMsg);
  232. }
  233. }//foreach
  234. }
  235. }
  236. // 附件信息
  237. [Serializable]
  238. public class InfoAttachEntity
  239. {
  240. public string AttachmentName; // 附件名称
  241. public byte[] AttachmentContent; // 附件内容
  242. public string AttachmentFormat; // 附件格式
  243. }
  244. // 调用返回结果
  245. [Serializable]
  246. public class InfoExchgResult
  247. {
  248. public bool Flag; // 是否执行成功
  249. public string Message; // 失败原因
  250. }
  251. }