BulletinInfoController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using SysBaseLibs;
  2. using SysDataLibs.TableClass;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace GSMarketSys.Controllers
  10. {
  11. public class BulletinInfoController : BaseController
  12. {
  13. public ActionResult BulletinInfoList()
  14. {
  15. ViewBag.SelBulletinType = GetData.Instance.GetSelStr(BulletinType_info.cBulletinTypeID, BulletinType_info.cNames, Tn.BulletinType, "", UserSessionInfo.DBConn);
  16. ViewBag.IsAdd = UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsAdd) ? "Y" : "N";
  17. ViewBag.IsUpdate = UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsUpdate) ? "Y" : "N";
  18. ViewBag.IsDelete = UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsDelete) ? "Y" : "N";
  19. ViewBag.IsAudit = (UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsAudit)&&!UserSessionInfo.IsMarketSysAccount) ? "Y" : "N";
  20. return View();
  21. }
  22. public ActionResult GetBulletinInfoList()
  23. {
  24. string lcSql = " select * from " + Tn.BulletinInfo + " where 1=1 ";
  25. if (UserSessionInfo.IsMarketSysAccount)
  26. {
  27. lcSql += " and MarketID = '" + UserSessionInfo.MarketId + "' ";
  28. }
  29. lcSql += " order by " + BulletinInfo_info.cUpdateTime + " desc ";
  30. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);//
  31. StringBuilder sb = new StringBuilder();
  32. sb.Append("{\"total\":" + loQuery.RecCount + ",\"rows\":");
  33. if (loQuery.IsOpened && loQuery.RecCount > 0)
  34. {
  35. loQuery.CurrentTable.Columns.Add("BulletinType", typeof(string));
  36. loQuery.CurrentTable.Columns.Add("AuditFlagName", typeof(string));
  37. Dictionary<string, string> BulletinTypeDic = SysDataLibs.AppEnv.GetKeyValueByTable(Tn.BulletinType, BulletinType_info.cNames, BulletinType_info.cBulletinTypeID, UserSessionInfo.DBConn);
  38. loQuery.MoveFirst();
  39. for (int i = 0; i < loQuery.RecCount; i++)
  40. {
  41. loQuery.SetField("BulletinType", BulletinTypeDic[loQuery.GetString(BulletinInfo_info.cBulletinTypeID)]);
  42. loQuery.SetField("AuditFlagName", loQuery.GetInt(BulletinInfo_info.cAuditFlag) == 1 ? "是" : "否");
  43. loQuery.MoveNext();
  44. }
  45. sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd"));
  46. }
  47. else
  48. {
  49. sb.Append("[]");
  50. }
  51. sb.Append("}");
  52. return Content(sb.ToString());
  53. }
  54. public ActionResult GetBulletinInfoAttachFileInfo()
  55. {
  56. string ID = Request["ID"];
  57. Sys_AttachFiles_info lTbl = new Sys_AttachFiles_info(Tn.BulletinInfo, BulletinInfo_info.cID, ID, UserSessionInfo.DBConn);
  58. StringBuilder sb = new StringBuilder();
  59. if (lTbl!=null&&!string.IsNullOrEmpty(lTbl.AttachID))
  60. {
  61. sb.Append(lTbl.ToJson("yyyy-MM-dd"));
  62. }
  63. else
  64. {
  65. sb.Append("[]");
  66. }
  67. return Content(sb.ToString());
  68. }
  69. //[ValidateInput(false)]
  70. [CheckPowerFilter]
  71. public ActionResult BulletinInfoListOper()
  72. {
  73. string lcRetval = "false";
  74. string Type = Request["Type"];
  75. string ID = Request["ID"];
  76. BulletinInfo_info lTbl = Type == "Add" ? new BulletinInfo_info() : new BulletinInfo_info(ID, UserSessionInfo.DBConn);
  77. string ReFileBackMsg = "";
  78. try
  79. {
  80. HttpFileCollection attachFile = System.Web.HttpContext.Current.Request.Files;
  81. if (attachFile.Count > 0)
  82. {
  83. string lcFileAllName = attachFile[0].FileName;
  84. if (!string.IsNullOrEmpty(lcFileAllName)&&!CheckFileType(lcFileAllName, "DOC,DOCS,DOCX,XLS,XLSX,TXT,PDF"))
  85. {
  86. return Content(ErrorRebackInfo.GetErrorBackInfo(false, "0", "只支持Word,Excel,TXT文件上传!"));
  87. }
  88. }
  89. }
  90. catch (Exception err)
  91. {
  92. ThreadLog.LogException(err);
  93. return Content(SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_IsUploadFileError"));
  94. }
  95. if (Type == "Del")
  96. {
  97. if (UserSessionInfo.DBConn.ExecuteSql(lTbl.DeleteSql()))
  98. {
  99. Sys_AttachFiles_info loDelAttacthFile = new Sys_AttachFiles_info(Tn.BulletinInfo, BulletinInfo_info.cID, ID, UserSessionInfo.DBConn);
  100. GetData.Instance.AttachFileUpdate(Type, loDelAttacthFile, UserSessionInfo, ref ReFileBackMsg);
  101. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success");
  102. }
  103. else
  104. {
  105. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError");
  106. }
  107. return Content(lcRetval);
  108. }
  109. if (Type == "Aud")
  110. {
  111. lTbl.AuditFlag = "1";
  112. if (UserSessionInfo.DBConn.ExecuteSql(lTbl.UpdateSql()))
  113. {
  114. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success");
  115. }
  116. else
  117. {
  118. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError");
  119. }
  120. return Content(lcRetval);
  121. }
  122. string BulletinTypeID = Utils.AreaToSQLcs(Request["BulletinTypeID"]).Trim();
  123. string Title = Utils.AreaToSQLcs(Request["Title"]).Trim();
  124. string content = Utils.AreaToSQLcs(Request["content"]).Trim();
  125. string UpdateTime = Utils.AreaToSQLcs(Request["UpdateTime"]).Trim();
  126. if (string.IsNullOrEmpty(Title))
  127. {
  128. return Content(ErrorRebackInfo.GetErrorBackInfo(false, "0", "标题名称不能为空!"));
  129. }
  130. if (string.IsNullOrEmpty(UpdateTime))
  131. {
  132. return Content(ErrorRebackInfo.GetErrorBackInfo(false, "0", "发布日期不能为空!"));
  133. }
  134. lTbl.BulletinTypeID = BulletinTypeID;
  135. lTbl.Title = Title;
  136. byte[] inArray = Convert.FromBase64String(content);//Encoding.UTF8.GetBytes(content);
  137. lTbl.content = Encoding.UTF8.GetString(inArray);//HttpUtility.UrlDecode(HttpUtility.UrlDecode(content));
  138. lTbl.UpdateTime = UpdateTime;
  139. if (UserSessionInfo.IsMarketSysAccount)
  140. {
  141. lTbl.MarketID = UserSessionInfo.MarketId;
  142. lTbl.AuditFlag = "0";
  143. }
  144. else
  145. {
  146. lTbl.MarketID = "";
  147. lTbl.AuditFlag = "1";
  148. }
  149. Sys_AttachFiles_info loAttacthFile = null;
  150. string lcSql = "";
  151. try
  152. {
  153. if (Type == "Edit")
  154. {
  155. lcSql = lTbl.UpdateSql();
  156. loAttacthFile = new Sys_AttachFiles_info(Tn.BulletinInfo, BulletinInfo_info.cID, ID, UserSessionInfo.DBConn);
  157. if (UserSessionInfo.DBConn.ExecuteSql(lcSql))
  158. {
  159. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success");
  160. Type = string.IsNullOrEmpty(loAttacthFile.SourceKey) ? "Add" : Type;
  161. loAttacthFile.TableId = Tn.BulletinInfo;
  162. loAttacthFile.ColumnId = BulletinInfo_info.cID;
  163. loAttacthFile.FileTitle = Title;
  164. loAttacthFile.SourceKey = ID;
  165. loAttacthFile.TimeCreated = DateTime.Now.ToShortDateString();
  166. loAttacthFile.TimeLastMod = DateTime.Now.ToShortDateString();
  167. loAttacthFile.UserIDLastMod = UserSessionInfo.UserInfo.UserID;
  168. GetData.Instance.AttachFileUpdate(Type, loAttacthFile, UserSessionInfo, ref ReFileBackMsg);
  169. return Content(lcRetval);
  170. }
  171. else
  172. {
  173. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError");
  174. }
  175. }
  176. else
  177. {
  178. lTbl.UserID = UserSessionInfo.UserInfo.UserID;
  179. //lTbl.AuditFlag = "0";
  180. lcSql = lTbl.InsertSql();
  181. lcSql += " select @@IDENTITY as ident ";
  182. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);
  183. string identity = loQuery.GetString("ident");
  184. loAttacthFile = new Sys_AttachFiles_info();
  185. loAttacthFile.SourceKey = identity;
  186. lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success");
  187. loAttacthFile.TableId = Tn.BulletinInfo;
  188. loAttacthFile.ColumnId = BulletinInfo_info.cID;
  189. loAttacthFile.FileTitle = Title;
  190. loAttacthFile.TimeCreated = DateTime.Now.ToShortDateString();
  191. loAttacthFile.TimeLastMod = DateTime.Now.ToShortDateString();
  192. loAttacthFile.UserIDLastMod = UserSessionInfo.UserInfo.UserID;
  193. GetData.Instance.AttachFileUpdate(Type, loAttacthFile, UserSessionInfo, ref ReFileBackMsg);
  194. return Content(lcRetval);
  195. }
  196. }
  197. catch (Exception err)
  198. {
  199. ThreadLog.LogException(err);
  200. return Content(SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError"));
  201. }
  202. return Content(lcRetval);
  203. }
  204. private bool CheckFileType(string FileName, string pcType)
  205. {
  206. bool lbRetval = false;
  207. if (!string.IsNullOrEmpty(pcType))
  208. {
  209. string[] strArr = pcType.Split(',');
  210. FileName = FileName.Substring(FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1);
  211. string FileExt = FileName.Substring(FileName.LastIndexOf(".") + 1, FileName.Length - FileName.LastIndexOf(".") - 1);
  212. FileExt = UtilStr.UAndT(FileExt);
  213. if (strArr.Contains(FileExt))
  214. {
  215. lbRetval = true;
  216. }
  217. }
  218. return lbRetval;
  219. }
  220. }
  221. }