using SysBaseLibs; using SysDataLibs; using SysDataLibs.TableClass; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Services; using System.Xml.Serialization; namespace GSMarketSys.WS { /// /// WSInformationExchange 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class WSInformationExchange : System.Web.Services.WebService { public WSInformationExchange() { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } /* InfoGuid 信息的主键编号(平台所记录的主键编号,在回复接口中需要使用到) InfoTitle 信息标题 InfoContent 信息内容 SendDate 信息发送时间 SendBy 信息发送人 Attachments 可选,信息的附件信息 Guid 用户令牌 */ [XmlInclude(typeof(InfoAttachEntity))] [WebMethod] public InfoExchgResult InfoSend(string InfoGuid, string InfoTitle, string InfoContent, DateTime SendDate, string SendBy, InfoAttachEntity[] Attachments, string Guid) { InfoExchgResult result = new InfoExchgResult(); result.Flag = false; result.Message = ""; DBConnSql loDBConn = null; try { // 检查是否有效guid if (LoginGUID.Instance.GetOne(Guid) == null) { string strMsg = "Invalid guid " + Guid; result.Message = strMsg; throw new Exception(strMsg); } FSInformationExchange_info info = new FSInformationExchange_info(); info.InfoGuid = SysBaseLibs.Utils.AreaToSQL(InfoGuid); info.InfoTitle = SysBaseLibs.Utils.AreaToSQL(InfoTitle); info.InfoContent = SysBaseLibs.Utils.AreaToSQL(InfoContent); info.SendDate = SendDate.ToString(); info.SendBy = SysBaseLibs.Utils.AreaToSQL(SendBy); info.Recipient = "工商"; info.IsRoot = "1"; info.IsDeleted = "0"; info.IsFromPlat = "1"; // 数据库操作 loDBConn = new DBConnSql(); if (loDBConn.Open()) { // 查询指定信息是否通过InfoSend收到过 if (IsInfoSendExist(InfoGuid, loDBConn) == false) { // 流水号 info.MsgID = System.Guid.NewGuid().ToString("N"); string lcSql = info.InsertSql(); if (loDBConn.ExcuteSqlTran(lcSql)) { // 保存附件信息 SaveAttachments(info.MsgID, Attachments, loDBConn); result.Flag = true; } } else { result.Flag = false; result.Message = "InfoGuid already exist"; } } } catch (Exception err) { result.Flag = false; result.Message = err.Message; string strTemp = "WSInformationExchange::InfoSend失败," + err.Message; ThreadLog.LogInfo(strTemp); } finally { if (loDBConn != null && loDBConn.IsOpened) loDBConn.Close(); } return result; } /* InfoGuid 信息的主键编号(平台所记录的主键编号,在回复接口中需要使用到) InfoTitle 信息标题 InfoContent 信息内容 SendDate 信息发送时间 SendBy 信息发送人 Recipient 信息接收人 Attachments 可选,信息的附件信息 Guid 用户令牌*/ [XmlInclude(typeof(InfoAttachEntity))] [WebMethod] public InfoExchgResult InfoReply(string InfoGuid, string InfoTitle, string InfoContent, DateTime SendDate, string SendBy, string Recipient, InfoAttachEntity[] Attachments, string Guid) { InfoExchgResult result = new InfoExchgResult(); result.Flag = false; result.Message = ""; DBConnSql loDBConn = null; try { // 检查是否有效guid if (LoginGUID.Instance.GetOne(Guid) == null) { string strMsg = "Invalid guid " + Guid; result.Message = strMsg; throw new Exception(strMsg); } FSInformationExchange_info info = new FSInformationExchange_info(); info.InfoGuid = SysBaseLibs.Utils.AreaToSQL(InfoGuid); info.InfoTitle = SysBaseLibs.Utils.AreaToSQL(InfoTitle); info.InfoContent = SysBaseLibs.Utils.AreaToSQL(InfoContent); info.SendDate = SendDate.ToString(); info.SendBy = SysBaseLibs.Utils.AreaToSQL(SendBy); info.Recipient = SysBaseLibs.Utils.AreaToSQL(Recipient); info.IsRoot = "0"; info.IsDeleted = "0"; info.IsFromPlat = "1"; // 数据库操作 loDBConn = new DBConnSql(); if (loDBConn.Open()) { // 流水号 info.MsgID = System.Guid.NewGuid().ToString("N"); string lcSql = info.InsertSql(); if (loDBConn.ExcuteSqlTran(lcSql)) { // 保存附件信息 SaveAttachments(info.MsgID, Attachments, loDBConn); result.Flag = true; } } } catch (Exception err) { result.Flag = false; result.Message = err.Message; string strTemp = "WSInformationExchange::InfoReply失败," + err.Message; ThreadLog.LogInfo(strTemp); } finally { if (loDBConn != null && loDBConn.IsOpened) loDBConn.Close(); } return result; } // 查询指定信息是否通过InfoSend收到过 private bool IsInfoSendExist(string lcInfoGuid, DBConnSql loConn) { bool bRet = false; string lcSql = "select count(*) as totalcount from " + Tn.FSInformationExchange + " where " + FSInformationExchange_info.cInfoGuid + "='" + lcInfoGuid + "' and " + FSInformationExchange_info.cIsRoot + "=1"; SysBaseLibs.rsQuery loQuery = loConn.OpenQuery(lcSql); if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0) { int nCount = loQuery.GetInt("totalcount"); if (nCount > 0) bRet = true; } return bRet; } // 保存附件文件 private void SaveAttachments(string MsgID, InfoAttachEntity[] Attachments, DBConnSql loDBConn) { if (Attachments == null) return; foreach (InfoAttachEntity attachFile in Attachments) { if (string.IsNullOrEmpty(attachFile.AttachmentName) || string.IsNullOrEmpty(attachFile.AttachmentFormat) || attachFile.AttachmentContent == null) { continue; } try { // 相对路径路径 string strFilePath = SysDataLibs.AppEnv.SysSetObj.GetString("DOWNLOADPATH") + "/" + SysDataLibs.AppEnv.SysSetObj.GetString("ATTACHFILES") + "/" + Tn.FSOnlineComplaints.ToUpper(); // 物理路径 string strPhysicalDir = HttpContext.Current.Request.PhysicalApplicationPath; strPhysicalDir += strFilePath; if (!Directory.Exists(strPhysicalDir)) { Directory.CreateDirectory(strPhysicalDir); } string strFileExt = attachFile.AttachmentFormat.Replace("'", ""); strFileExt = strFileExt.Replace(".", ""); // 扩展名不需要"."符号 string strFileTitle = attachFile.AttachmentName.Replace("'", ""); string lcDateRd = strFileTitle + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "." + strFileExt; string strFileName = lcDateRd.Replace(" ", ""); // 写入文件 System.IO.File.WriteAllBytes(strPhysicalDir + "/" + strFileName, attachFile.AttachmentContent); // 附件信息写入数据库 Sys_AttachFiles_info loAttachFile = new Sys_AttachFiles_info(); loAttachFile.TableId = Tn.FSInformationExchange; loAttachFile.ColumnId = FSInformationExchange_info.cMsgID; loAttachFile.SourceKey = MsgID; loAttachFile.FileTitle = strFileTitle; loAttachFile.FileName = strFileName; loAttachFile.FilePath = strFilePath; loAttachFile.FileExt = strFileExt; loAttachFile.TimeCreated = DateTime.Now.ToString(); loAttachFile.TimeLastMod = DateTime.Now.ToString(); loAttachFile.UserIDLastMod = "platuser"; loAttachFile.Description = ""; string strSql = loAttachFile.InsertSql(); bool bRet = loDBConn.ExcuteSqlTran(strSql); } catch (Exception err) { string strMsg = "WSComplaints.SaveAttachments exception," + err.Message; ThreadLog.LogErr(strMsg); } }//foreach } } // 附件信息 [Serializable] public class InfoAttachEntity { public string AttachmentName; // 附件名称 public byte[] AttachmentContent; // 附件内容 public string AttachmentFormat; // 附件格式 } // 调用返回结果 [Serializable] public class InfoExchgResult { public bool Flag; // 是否执行成功 public string Message; // 失败原因 } }