using CallCenter.Utility; using CallCenterApi.Interface.Controllers.Base; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Mvc; namespace CallCenterApi.Interface.Controllers.Wiki { [Authority] public class FunctionsController : BaseController { // GET: Policy /// /// 上传附件 /// /// public ActionResult UploadFile() { HttpFileCollection files = RequestString.GetFiles(); if (files.Count > 0) { List acs = new List(); string path = "/Upload/Wiki/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/"; for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; FileUp fu = new FileUp(); string name = fu.Upload(file, path); Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories(); model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间 model_T_Sys_Accessories.F_FileName = name;//附件名称 model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型 model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址 model_T_Sys_Accessories.F_Size = file.ContentLength; model_T_Sys_Accessories.F_UserCode = User.F_UserCode;//上传人 int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories); model_T_Sys_Accessories.F_FileId = id; acs.Add(model_T_Sys_Accessories); } return Success("成功", acs); } else { return Error("请选择要上传的文件"); } } /// /// 列表 /// /// /// /// /// public ActionResult GetList(string keyvalue, string stime, string etime, int key = 0, int page = 1, int pagesize = 10, int isdc = 0) { DataTable dt = new DataTable(); string sql = " and F_IsDelete=0 "; string sqldt = ""; if (stime.Trim() != "" && stime != "undefined") { sql += " and F_FaBuShiJian >= '" + stime + " 00:00:00" + "' "; } if (etime.Trim() != "" && etime != "undefined") { sql += " and F_FaBuShiJian <= '" + etime + " 23:59:59" + "' "; } if (key > 0) { //sql += " and F_Key = " + key; sqldt = " INNER JOIN [GetValueId]('" + key + "') Value on a.F_Key = Value.F_ValueId"; } if (!string.IsNullOrEmpty(keyvalue)) { sql += " and (F_FaWenWenHao like '%" + keyvalue + "%' or F_FaWenDanWei like '%" + keyvalue + "%' orF_BiaoShiBianMa like '%" + keyvalue + "%' or F_ZhiNengBuMen like '%" + keyvalue + "%' or F_WenJianMingCheng like '%" + keyvalue + "%' or F_WenJianNeiRong like '%" + keyvalue + "%')"; } if (isdc > 0) { string cols = "(case when a.F_Id <100 then RIGHT ('00'+CONVERT (varchar(10),a.F_Id),3) else CONVERT(varchar(10), a.F_Id) end) as 序号,F_HangYe as 所属行业 ,F_ZhiNengBuMen as 职能部门,F_WenJianNeiRong as 文件内容,F_WenJianMingCheng as 文件名称,F_FaWenWenHao as 发文文号,F_FaWenDanWei as 发文单位,dbo.GetKeyNames(F_Key) as 四级关键词,F_FaBuShiJian as 发布时间,F_FaBuRen as 发布人,F_FaBuDanWei as 发布单位,F_BiaoShiBianMa as 标识编码,(select stuff((select ',' + F_FileName from T_Sys_Accessories where F_FileId in (a.F_File) for xml path('')),1,1,'')) as 附件,地区 as F_DiQu"; var dtdc = DB.DbHelperSQL.Query(" select " + cols + " from T_Wiki_Functions a with(nolock) " + sqldt + " where 1=1 " + sql).Tables[0]; var msg = new NPOIHelper().ExportToExcel("部门职能", dtdc); if (msg == "") { return Success("导出成功"); } else { return Error("导出失败"); } } int recordCount = 0; dt = BLL.PagerBLL.GetListPager( "T_Wiki_Functions a with(nolock) " + sqldt, "F_Id", "a.*,dbo.GetDictionaryName(F_Key) as KeyName", sql, "ORDER BY F_DianJiLiang,F_CreateTime DESC", pagesize, page, true, out recordCount); var obj = new { state = "success", message = "成功", rows = dt, total = recordCount }; return Content(obj.ToJson()); } /// /// 获取 /// /// /// public ActionResult GetModel(int id = 0) { if (id != 0) { var model = new BLL.T_Wiki_Functions().GetModel(id); if (model != null) { DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Functions set F_DianJiLiang=F_DianJiLiang+1 where F_Id=" + id); DataTable dtkey = new DataTable(); if (model.F_Key > 0) { dtkey = DB.DbHelperSQL.Query(" select * from View_KeysSplit where id=" + model.F_Key).Tables[0]; } DataTable dtfile = new DataTable(); var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault(); if (!string.IsNullOrEmpty(model.F_File) && configfj != null) { dtfile = DB.DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + model.F_File + ")").Tables[0]; foreach (DataRow dr in dtfile.Rows) { dr["F_FileUrl"] = configfj.F_ParamValue + dr["F_FileUrl"].ToString(); } } var obj = new { model, dtkey, dtfile }; return Success("成功", obj); } return Error("参数错误"); } else { return Error("参数错误"); } } /// /// 添加 /// /// /// [HttpPost] public ActionResult AddModel(int id = 0, int key = 0) { string fabudanwei = RequestString.GetFormString("fabudanwei"); string faburen = RequestString.GetFormString("faburen"); string hangye = RequestString.GetFormString("hangye"); string diqu = RequestString.GetFormString("diqu"); string shengxiaoshijian = RequestString.GetFormString("shengxiaoshijian"); string shixiaoshijian = RequestString.GetFormString("shixiaoshijian"); string fabushijian = RequestString.GetFormString("fabushijian"); string fawenwenhao = RequestString.GetFormString("fawenwenhao"); string fawendanwei = RequestString.GetFormString("fawendanwei"); string biaoshibianma = RequestString.GetFormString("biaoshibianma"); string zhinengbumen = RequestString.GetFormString("zhinengbumen"); string file = RequestString.GetFormString("file"); string wenjianmingcheng = RequestString.GetFormString("wenjianmingcheng"); string wenjianneirong = RequestString.GetFormString("wenjianneirong"); Model.T_Wiki_Functions dModel = new Model.T_Wiki_Functions(); if (id == 0) { //var list = new BLL.T_Wiki_Functions().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 ").Tables[0]; //if (list.Rows.Count > 0) //{ // return Error("已经存在"); //} //else //{ dModel.F_FaBuRen = User.F_UserName; dModel.F_FaBuDanWei = fabudanwei; dModel.F_HangYe = hangye; dModel.F_DiQu = diqu; try { dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian); } catch { }; try { dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian); } catch { }; dModel.F_FaBuShiJian = DateTime.Now; dModel.F_Key = key; dModel.F_FaWenWenHao = DateTime.Now.ToString("yyyyMMddHHmmssff"); dModel.F_FaWenDanWei = fawendanwei; // dModel.F_BiaoShiBianMa = biaoshibianma; dModel.F_ZhiNengBuMen = zhinengbumen; dModel.F_File = file; dModel.F_WenJianMingCheng = wenjianmingcheng; dModel.F_WenJianNeiRong = wenjianneirong; dModel.F_DianJiLiang = 0; dModel.F_IsDelete = 0; dModel.F_CreateUser = User.F_UserCode; dModel.F_CreateTime = DateTime.Now; int n = new BLL.T_Wiki_Functions().Add(dModel); if (n > 0) { DB.DbHelperSQL.ExecuteSql("update T_Wiki_Functions set F_BiaoShiBianMa =right('00000'+'" + User.F_DeptId + "' ,5)+right('0000000'+'" + n + "' ,8) where F_Id=" + n); return Success("添加成功", n); } else return Error("添加失败"); //} } else { dModel = new BLL.T_Wiki_Functions().GetModel(id); if (dModel != null) { //var list = new BLL.T_Wiki_Functions().GetList(" F_FaBuDanWei='" + fabudanwei + "' and F_IsDelete=0 and F_Id!='" + id + "' ").Tables[0]; //if (list.Rows.Count > 0) //{ // return Error("已经存在"); //} //else //{ dModel.F_FaBuRen = faburen; dModel.F_FaBuDanWei = fabudanwei; dModel.F_HangYe = hangye; dModel.F_DiQu = diqu; try { dModel.F_ShengXiaoShiJian = DateTime.Parse(shengxiaoshijian); } catch { }; try { dModel.F_ShiXiaoShiJian = DateTime.Parse(shixiaoshijian); } catch { }; try { dModel.F_FaBuShiJian = DateTime.Parse(fabushijian); } catch { }; dModel.F_Key = key; dModel.F_FaWenWenHao = fawenwenhao; dModel.F_FaWenDanWei = fawendanwei; dModel.F_BiaoShiBianMa = biaoshibianma; dModel.F_ZhiNengBuMen = zhinengbumen; dModel.F_File = file; dModel.F_WenJianMingCheng = wenjianmingcheng; dModel.F_WenJianNeiRong = wenjianneirong; if (new BLL.T_Wiki_Functions().Update(dModel)) return Success("修改成功"); else return Error("修改失败"); //} } else { return Error("修改失败"); } } } /// /// 删除 /// /// /// public ActionResult DelModel(string[] ids) { if (ids == null || ids.Length <= 0) { return Error("请选择要删除的选项"); } var idStr = string.Join(",", ids); if (string.IsNullOrEmpty(idStr.Trim())) { return Error("请选择要删除的选项"); } int n = DB.DbHelperSQL.ExecuteSql(" update T_Wiki_Functions set F_IsDelete=1,F_DeleteUser='" + User.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")"); if (n > 0) { return Success("删除成功"); } return Error("删除失败"); } /// /// 导出word /// /// public ActionResult ExportWord(int id) { var aw = new AsposeWord(); aw.OpenWithTemplate(Server.MapPath("/Upload/Word/政策法规模板.doc")); var dt = DB.DbHelperSQL.Query("select a.*,(select stuff((select ',' + F_FileName from T_Sys_Accessories where F_FileId in (a.F_File) for xml path('')),1,1,'')) as fileurl from T_Wiki_Policy a with(nolock) where a.F_Id=" + id).Tables[0]; string F_key = dt.Rows[0]["F_key"].ToString(); var dt2 = DB.DbHelperSQL.Query("SELECT * FROM View_KeysSplit WHERE id=" + F_key).Tables[0]; aw.Builder(); aw.CreateDepartmentFunctionsWord(dt, dt2); var bt = aw.ExportAs(); Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition"); return File(bt, "application/msword", DateTime.Now.Ticks.ToString() + ".doc"); } } }