using SysBaseLibs; using SysDataLibs.TableClass; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace GSMarketSys.Controllers { public class BulletinInfoController : BaseController { public ActionResult BulletinInfoList() { ViewBag.SelBulletinType = GetData.Instance.GetSelStr(BulletinType_info.cBulletinTypeID, BulletinType_info.cNames, Tn.BulletinType, "", UserSessionInfo.DBConn); ViewBag.IsAdd = UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsAdd) ? "Y" : "N"; ViewBag.IsUpdate = UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsUpdate) ? "Y" : "N"; ViewBag.IsDelete = UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsDelete) ? "Y" : "N"; ViewBag.IsAudit = (UserSessionInfo.CheckPowerNotRe(SysDataLibs.PowerType.IsAudit)&&!UserSessionInfo.IsMarketSysAccount) ? "Y" : "N"; return View(); } public ActionResult GetBulletinInfoList() { string lcSql = " select * from " + Tn.BulletinInfo + " where 1=1 "; if (UserSessionInfo.IsMarketSysAccount) { lcSql += " and MarketID = '" + UserSessionInfo.MarketId + "' "; } lcSql += " order by " + BulletinInfo_info.cUpdateTime + " desc "; rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);// StringBuilder sb = new StringBuilder(); sb.Append("{\"total\":" + loQuery.RecCount + ",\"rows\":"); if (loQuery.IsOpened && loQuery.RecCount > 0) { loQuery.CurrentTable.Columns.Add("BulletinType", typeof(string)); loQuery.CurrentTable.Columns.Add("AuditFlagName", typeof(string)); Dictionary BulletinTypeDic = SysDataLibs.AppEnv.GetKeyValueByTable(Tn.BulletinType, BulletinType_info.cNames, BulletinType_info.cBulletinTypeID, UserSessionInfo.DBConn); loQuery.MoveFirst(); for (int i = 0; i < loQuery.RecCount; i++) { loQuery.SetField("BulletinType", BulletinTypeDic[loQuery.GetString(BulletinInfo_info.cBulletinTypeID)]); loQuery.SetField("AuditFlagName", loQuery.GetInt(BulletinInfo_info.cAuditFlag) == 1 ? "是" : "否"); loQuery.MoveNext(); } sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd")); } else { sb.Append("[]"); } sb.Append("}"); return Content(sb.ToString()); } public ActionResult GetBulletinInfoAttachFileInfo() { string ID = Request["ID"]; Sys_AttachFiles_info lTbl = new Sys_AttachFiles_info(Tn.BulletinInfo, BulletinInfo_info.cID, ID, UserSessionInfo.DBConn); StringBuilder sb = new StringBuilder(); if (lTbl!=null&&!string.IsNullOrEmpty(lTbl.AttachID)) { sb.Append(lTbl.ToJson("yyyy-MM-dd")); } else { sb.Append("[]"); } return Content(sb.ToString()); } //[ValidateInput(false)] [CheckPowerFilter] public ActionResult BulletinInfoListOper() { string lcRetval = "false"; string Type = Request["Type"]; string ID = Request["ID"]; BulletinInfo_info lTbl = Type == "Add" ? new BulletinInfo_info() : new BulletinInfo_info(ID, UserSessionInfo.DBConn); string ReFileBackMsg = ""; try { HttpFileCollection attachFile = System.Web.HttpContext.Current.Request.Files; if (attachFile.Count > 0) { string lcFileAllName = attachFile[0].FileName; if (!string.IsNullOrEmpty(lcFileAllName)&&!CheckFileType(lcFileAllName, "DOC,DOCS,DOCX,XLS,XLSX,TXT,PDF")) { return Content(ErrorRebackInfo.GetErrorBackInfo(false, "0", "只支持Word,Excel,TXT文件上传!")); } } } catch (Exception err) { ThreadLog.LogException(err); return Content(SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_IsUploadFileError")); } if (Type == "Del") { if (UserSessionInfo.DBConn.ExecuteSql(lTbl.DeleteSql())) { Sys_AttachFiles_info loDelAttacthFile = new Sys_AttachFiles_info(Tn.BulletinInfo, BulletinInfo_info.cID, ID, UserSessionInfo.DBConn); GetData.Instance.AttachFileUpdate(Type, loDelAttacthFile, UserSessionInfo, ref ReFileBackMsg); lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success"); } else { lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError"); } return Content(lcRetval); } if (Type == "Aud") { lTbl.AuditFlag = "1"; if (UserSessionInfo.DBConn.ExecuteSql(lTbl.UpdateSql())) { lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success"); } else { lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError"); } return Content(lcRetval); } string BulletinTypeID = Utils.AreaToSQLcs(Request["BulletinTypeID"]).Trim(); string Title = Utils.AreaToSQLcs(Request["Title"]).Trim(); string content = Utils.AreaToSQLcs(Request["content"]).Trim(); string UpdateTime = Utils.AreaToSQLcs(Request["UpdateTime"]).Trim(); if (string.IsNullOrEmpty(Title)) { return Content(ErrorRebackInfo.GetErrorBackInfo(false, "0", "标题名称不能为空!")); } if (string.IsNullOrEmpty(UpdateTime)) { return Content(ErrorRebackInfo.GetErrorBackInfo(false, "0", "发布日期不能为空!")); } lTbl.BulletinTypeID = BulletinTypeID; lTbl.Title = Title; byte[] inArray = Convert.FromBase64String(content);//Encoding.UTF8.GetBytes(content); lTbl.content = Encoding.UTF8.GetString(inArray);//HttpUtility.UrlDecode(HttpUtility.UrlDecode(content)); lTbl.UpdateTime = UpdateTime; if (UserSessionInfo.IsMarketSysAccount) { lTbl.MarketID = UserSessionInfo.MarketId; lTbl.AuditFlag = "0"; } else { lTbl.MarketID = ""; lTbl.AuditFlag = "1"; } Sys_AttachFiles_info loAttacthFile = null; string lcSql = ""; try { if (Type == "Edit") { lcSql = lTbl.UpdateSql(); loAttacthFile = new Sys_AttachFiles_info(Tn.BulletinInfo, BulletinInfo_info.cID, ID, UserSessionInfo.DBConn); if (UserSessionInfo.DBConn.ExecuteSql(lcSql)) { lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success"); Type = string.IsNullOrEmpty(loAttacthFile.SourceKey) ? "Add" : Type; loAttacthFile.TableId = Tn.BulletinInfo; loAttacthFile.ColumnId = BulletinInfo_info.cID; loAttacthFile.FileTitle = Title; loAttacthFile.SourceKey = ID; loAttacthFile.TimeCreated = DateTime.Now.ToShortDateString(); loAttacthFile.TimeLastMod = DateTime.Now.ToShortDateString(); loAttacthFile.UserIDLastMod = UserSessionInfo.UserInfo.UserID; GetData.Instance.AttachFileUpdate(Type, loAttacthFile, UserSessionInfo, ref ReFileBackMsg); return Content(lcRetval); } else { lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError"); } } else { lTbl.UserID = UserSessionInfo.UserInfo.UserID; //lTbl.AuditFlag = "0"; lcSql = lTbl.InsertSql(); lcSql += " select @@IDENTITY as ident "; rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql); string identity = loQuery.GetString("ident"); loAttacthFile = new Sys_AttachFiles_info(); loAttacthFile.SourceKey = identity; lcRetval = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Success"); loAttacthFile.TableId = Tn.BulletinInfo; loAttacthFile.ColumnId = BulletinInfo_info.cID; loAttacthFile.FileTitle = Title; loAttacthFile.TimeCreated = DateTime.Now.ToShortDateString(); loAttacthFile.TimeLastMod = DateTime.Now.ToShortDateString(); loAttacthFile.UserIDLastMod = UserSessionInfo.UserInfo.UserID; GetData.Instance.AttachFileUpdate(Type, loAttacthFile, UserSessionInfo, ref ReFileBackMsg); return Content(lcRetval); } } catch (Exception err) { ThreadLog.LogException(err); return Content(SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_DBError")); } return Content(lcRetval); } private bool CheckFileType(string FileName, string pcType) { bool lbRetval = false; if (!string.IsNullOrEmpty(pcType)) { string[] strArr = pcType.Split(','); FileName = FileName.Substring(FileName.LastIndexOf("\\", StringComparison.Ordinal) + 1); string FileExt = FileName.Substring(FileName.LastIndexOf(".") + 1, FileName.Length - FileName.LastIndexOf(".") - 1); FileExt = UtilStr.UAndT(FileExt); if (strArr.Contains(FileExt)) { lbRetval = true; } } return lbRetval; } } }