You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
395 lines
14 KiB
395 lines
14 KiB
using Platform.Infrastructure;
|
|
using Platform.Infrastructure.SignalRLayer.Entity;
|
|
using Platform.Infrastructure.SignalRLayer.Service;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Web;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// OaLeaveHandler 的摘要说明
|
|
/// </summary>
|
|
public class OaNoticeHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.OA.OA_NOTICE bll = new BLL.OA.OA_NOTICE();
|
|
|
|
ISignalRMessage<Notice> message = new SignalRMessage();
|
|
SendMessageBySignalR sendMessage = new SendMessageBySignalR();
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/plain";
|
|
string action = context.Request.Params["Action"];
|
|
string returnstr = "";
|
|
|
|
if (action == "List")
|
|
{
|
|
returnstr = List(context);
|
|
}
|
|
if (action == "Add")
|
|
{
|
|
returnstr = Add(context);
|
|
}
|
|
if (action == "Edit")
|
|
{
|
|
returnstr = Edit(context);
|
|
}
|
|
if (action == "Del")
|
|
{
|
|
returnstr = Del(context);
|
|
}
|
|
else if (action == "getDicdetail")
|
|
{
|
|
returnstr = getDicdetail(context);
|
|
}
|
|
//else if (action == "OrgDeptTree")
|
|
//{
|
|
// returnstr = OrgDeptTree(context);
|
|
//}
|
|
|
|
context.Response.Write(returnstr);
|
|
}
|
|
|
|
//查询
|
|
private string List(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string orgId = context.Request.Params["orgId"];
|
|
string cls = context.Request.Params["cls"];
|
|
|
|
string keyword = context.Request.Params["keywords"];
|
|
string page = context.Request.Params["page"];
|
|
string limit = context.Request.Params["limit"];
|
|
|
|
int pageIndex = 1;
|
|
int pageSize = 10;//
|
|
if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); }
|
|
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
|
|
int endIndex = pageIndex * pageSize;
|
|
int startIndex = (pageIndex - 1) * pageSize;
|
|
|
|
string where = null;
|
|
where = " ORG_ID = '" + orgId + "' ";
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
{
|
|
where += " and ART_TITLE like '%" + keyword + "%' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(cls))
|
|
{
|
|
where += " and CLS = '" + cls + "' ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.GetRecordCount(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
|
|
DataTable dt = bll.GetListByPage(where, "", startIndex, endIndex).Tables[0];
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch
|
|
{
|
|
returnstr = "{\"code\":-1,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
}
|
|
return returnstr;
|
|
}
|
|
private string getDicdetail(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string mod_code = context.Request.Params["mod_code"];
|
|
|
|
string where = " mod_code = '" + mod_code + "' ";
|
|
FangYar.BLL.TBL.SysDicdetailBLL dicbll = new BLL.TBL.SysDicdetailBLL();
|
|
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
returnstr += "\"count\":-1,\"data\":";
|
|
|
|
DataTable dt = dicbll.GetList(where).Tables[0];
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
|
|
returnstr += "}";
|
|
}
|
|
catch
|
|
{
|
|
returnstr = "{\"code\":-1,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
}
|
|
return returnstr;
|
|
|
|
}
|
|
|
|
//添加
|
|
private string Add(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = Guid.NewGuid().ToString("N");
|
|
string userId = "";
|
|
string title = "";
|
|
string contents = "";
|
|
SendMessageBySignalR.SiganalR(userId, id, title, contents);
|
|
|
|
string cls = context.Request.Params["cls"];
|
|
string art_title = context.Request.Params["art_title"];
|
|
string orgids = context.Request.Params["orgids"];
|
|
string art_is = context.Request.Params["art_is"];
|
|
string artst_time = context.Request.Params["artst_time"];
|
|
string arten_time = context.Request.Params["arten_time"];
|
|
|
|
string art_come = context.Request.Params["art_come"];
|
|
string art_pic = context.Request.Params["art_pic"];
|
|
string art_short = context.Request.Params["art_short"];
|
|
string art_cont = context.Request.Params["art_cont"];
|
|
|
|
string org_id = context.Request.Params["org_id"];
|
|
string org_name = context.Request.Params["org_name"];
|
|
string uid = context.Request.Params["uid"];
|
|
string uname = context.Request.Params["uname"];
|
|
|
|
byte[] outputb = Convert.FromBase64String(art_cont);
|
|
string orgStr = Encoding.Default.GetString(outputb);
|
|
|
|
string text = System.Web.HttpUtility.UrlDecode(orgStr);//将Url中的编码转换为简体汉字 , System.Text.Encoding.GetEncoding("GB2312")
|
|
|
|
////存储图片
|
|
string picture = GetUploadImg(context);
|
|
|
|
//巡查计划表
|
|
FangYar.Model.OA.OA_NOTICE model = new Model.OA.OA_NOTICE ();
|
|
model.ID = id;
|
|
model.RECORDSNUM = 0;
|
|
model.USERS_UID = uid;
|
|
model.USERS_NAME = uname;
|
|
model.ORG_ID = org_id;
|
|
model.ORG_NAME = org_name;
|
|
model.CREATE_TIME = DateTime.Now;
|
|
model.UPDATE_TIME = DateTime.Now; ;
|
|
model.ARTST_TIME = DateTime.Parse(artst_time);
|
|
model.ARTEN_TIME = DateTime.Parse(arten_time);
|
|
model.ART_IS = art_is;
|
|
model.ART_ORGS = orgids;
|
|
model.CLS = cls;
|
|
model.ART_TITLE = art_title;
|
|
|
|
model.ART_COME = art_come;
|
|
model.ART_PIC = picture;
|
|
model.ART_SHORT = art_short;
|
|
model.ART_CONT = art_cont;
|
|
|
|
if (bll.Add(model))
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else { msg = "添加失败!"; }
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
msg = "添加失败!";
|
|
}
|
|
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
|
|
return returnstr;
|
|
}
|
|
//图片上传
|
|
private string GetUploadImg(HttpContext context)
|
|
{
|
|
string returnStr = "";
|
|
|
|
try
|
|
{
|
|
string serverPath = "Upload/OA/Kon/";
|
|
string base64Str = context.Request.Params["art_pic"];
|
|
base64Str = base64Str.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "")
|
|
.Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""); //将base64头部信息替换
|
|
|
|
|
|
byte[] imageBytes = Convert.FromBase64String(base64Str);
|
|
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
|
|
{
|
|
ms.Write(imageBytes, 0, imageBytes.Length);
|
|
|
|
System.Drawing.Image img = Image.FromStream(ms, true);//将流中的图片转换为Image图片对象
|
|
|
|
Random ran = new Random((int)DateTime.Now.Ticks);//利用时间种子解决伪随机数短时间重复问题
|
|
if (!Directory.Exists(context.Server.MapPath("~/" + serverPath)))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(context.Server.MapPath("~/" + serverPath));
|
|
directoryInfo.Create();
|
|
}
|
|
|
|
//文件保存位置及命名,精确到毫秒并附带一组随机数,防止文件重名,数据库保存路径为此变量
|
|
//string serverPath = "Upload/Device/";
|
|
string filename = serverPath + DateTime.Now.ToString("yyyyMMddhhmmssms") + ran.Next(99999) + ".jpg";
|
|
//路径映射为绝对路径
|
|
string path = context.Server.MapPath("~/") + filename;
|
|
|
|
img.Save(path);//图片保存,JPEG格式图片较小
|
|
returnStr = filename;
|
|
}
|
|
}
|
|
catch (Exception ex) { }
|
|
return returnStr;
|
|
}
|
|
|
|
//修改
|
|
private string Edit(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = context.Request.Params["ID"];
|
|
string cls = context.Request.Params["cls"];
|
|
string art_title = context.Request.Params["art_title"];
|
|
string orgids = context.Request.Params["orgids"];
|
|
string art_is = context.Request.Params["art_is"];
|
|
string artst_time = context.Request.Params["artst_time"];
|
|
string arten_time = context.Request.Params["arten_time"];
|
|
|
|
string art_come = context.Request.Params["art_come"];
|
|
string art_pic = context.Request.Params["art_pic"];
|
|
string art_pictype = context.Request.Params["art_pictype"];
|
|
string art_short = context.Request.Params["art_short"];
|
|
string art_cont = context.Request.Params["art_cont"];
|
|
|
|
string org_id = context.Request.Params["org_id"];
|
|
string org_name = context.Request.Params["org_name"];
|
|
string uid = context.Request.Params["uid"];
|
|
string uname = context.Request.Params["uname"];
|
|
|
|
byte[] outputb = Convert.FromBase64String(art_cont);
|
|
string orgStr = Encoding.Default.GetString(outputb);
|
|
|
|
string text = System.Web.HttpUtility.UrlDecode(orgStr);//将Url中的编码转换为简体汉字 , System.Text.Encoding.GetEncoding("GB2312")
|
|
|
|
//存储图片
|
|
string picture = "";
|
|
if (art_pictype == "0")
|
|
{
|
|
picture = GetUploadImg(context);
|
|
}
|
|
else
|
|
{
|
|
picture = art_pic;
|
|
}
|
|
|
|
//巡查计划表
|
|
FangYar.Model.OA.OA_NOTICE model = bll.GetModel(id);
|
|
if (model != null)
|
|
{
|
|
model.ID = id;
|
|
model.RECORDSNUM = 0;
|
|
model.UPDATE_TIME =DateTime.Now ;
|
|
model.ARTST_TIME = DateTime.Parse(artst_time);
|
|
model.ARTEN_TIME = DateTime.Parse(arten_time);
|
|
model.ART_IS = art_is;
|
|
model.ART_ORGS = orgids;
|
|
model.CLS = cls;
|
|
model.ART_TITLE = art_title;
|
|
|
|
model.ART_COME = art_come;
|
|
model.ART_PIC = picture;
|
|
model.ART_SHORT = art_short;
|
|
model.ART_CONT = art_cont;
|
|
|
|
if (bll.Update(model))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else { msg = "修改失败!"; }
|
|
}
|
|
else {
|
|
msg = "修改失败!";
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
|
|
return returnstr;
|
|
}
|
|
|
|
//删除
|
|
private string Del(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = context.Request.Params["id"];
|
|
if (bll.Delete(id))
|
|
{
|
|
msg = "删除成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
/// </summary>
|
|
/// 文件上传
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string UploadImage(HttpContext context)
|
|
{
|
|
|
|
var imgFile = context.Request.Files[0];
|
|
if (imgFile != null && !string.IsNullOrEmpty(imgFile.FileName))
|
|
{
|
|
long size = imgFile.ContentLength;
|
|
string filename = imgFile.FileName;
|
|
string extname = filename.Substring(filename.LastIndexOf("."));
|
|
string filenewname = System.Guid.NewGuid().ToString() + extname;
|
|
string filepath = "Upload/NoticePage/" +DateTime.Now.ToString("yyyy-MM-dd")+"/"+ filenewname;
|
|
string Dirpath = context.Server.MapPath(@"/Upload/NoticePage/" + DateTime.Now.ToString("yyyy-MM-dd") + "/");
|
|
CreateDir(Dirpath);
|
|
imgFile.SaveAs(Dirpath + "/" + filenewname);
|
|
return filepath;
|
|
}
|
|
return "false";
|
|
}
|
|
//根据文件夹全路径创建文件夹
|
|
public static void CreateDir(string subdir)
|
|
{
|
|
if (!Directory.Exists(subdir))
|
|
{
|
|
Directory.CreateDirectory(subdir);
|
|
}
|
|
}
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|