public TcpRow(IpHelper.TcpRow tcpRow) { this.state = tcpRow.state; this.processId = tcpRow.owningPid; int localPort = (tcpRow.localPort1 << 8) + (tcpRow.localPort2) + (tcpRow.localPort3 << 24) + (tcpRow.localPort4 << 16); long localAddress = tcpRow.localAddr; this.localEndPoint = new IPEndPoint(localAddress, localPort); int remotePort = (tcpRow.remotePort1 << 8) + (tcpRow.remotePort2) + (tcpRow.remotePort3 << 24) + (tcpRow.remotePort4 << 16); long remoteAddress = tcpRow.remoteAddr; this.remoteEndPoint = new IPEndPoint(remoteAddress, remotePort); }
public UdpRow(IpHelper.UdpRow udpRow) { try { _processId = udpRow.owningPid; int localPort = (udpRow.localPort1 << 8) + (udpRow.localPort2) + (udpRow.localPort3 << 24) + (udpRow.localPort4 << 16); long localAddress = udpRow.localAddr; _localEndPoint = new IPEndPoint(localAddress, localPort); } catch (Exception) { } }
/// <returns>上传成功返回"",并填充 Model.UploadFile</returns> /// <param name="vid">上传配置模块id,即UploadConfig_Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="remotePicUrl">远程图片的url地址</param> /// <param name="m_r">Model.UploadFile</param> /// <returns>上传成功返回"",并填充 Model.UploadFile</returns> public string Upload_RemotePic(int vid, string key, int userId, string userName, string remotePicUrl, UploadFile m_r) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return("缺少参数:key或sid"); } //--------------------------------------------------- #region 检查登陆 m_r.UserId = userId; m_r.UserName = userName; if (m_r.UserId == 0) { return("您的权限不足!"); } #endregion //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC.Id != vid) { return("缺少参数:UploadConfig_Id!"); } if (mC.IsPost != 1) { return("系统暂时禁止上传文件2!"); } if (mC.IsEditor != 1) { return("非编辑器类别!"); } mC.UploadType_TypeKey = "image"; #endregion //---------------------------------------------- #region 生成暂时目录 string sCfgSavePath = new Uploader().SavePath; string sSavePath = DirFileHelper.FixDirPath(sCfgSavePath + mC.SaveDir) + DateTime.Now.ToString("yyMM") + "/"; if (!DirFileHelper.CheckSaveDir(sSavePath)) { return("SavePath设置不当:" + sSavePath + ", 或权限不足!"); } string sServerDir = sCfgSavePath + "remote/"; if (!DirFileHelper.CheckSaveDir(sServerDir)) { return("ServerDir设置不当:" + sServerDir + ", 或权限不足!"); } //---------------------------------------------- string sSrcName = StringHelper.Left(DirFileHelper.GetFileName(remotePicUrl), 90); string sFileExt = DirFileHelper.GetFileExtension(sSrcName); //因部部分网站不是标准的jpg、gif扩展名,所以修改下面代码 if (sFileExt.Length > 0) { string sAllowed = ",jpg,gif,png,bmp,"; string sExt = "," + sFileExt.ToLower() + ","; if (sAllowed.IndexOf(sExt) == -1) { sFileExt = "jpg"; } } else { sFileExt = "jpg"; } //---------------------------------------------- string sNewFile = FileOperateHelper.GetRndFileName("." + sFileExt); if (sServerDir.IndexOf(":") < 0) { sServerDir = DirFileHelper.FixDirPath(DirFileHelper.GetMapPath(sServerDir)); } string sNewRoot = System.IO.Path.Combine(sServerDir, sNewFile); #endregion //---------------------------------------------- #region 到暂时目录 try { var wc = new System.Net.WebClient(); wc.DownloadFile(remotePicUrl, sNewRoot); } catch (Exception ex) { //throw ex; return(ex.Message.ToLower()); } if (!DirFileHelper.IsExistFile(sNewRoot)) { return("上传失败"); } #endregion //---------------------------------------------- #region 判断是否真实图片格式,并取得图片宽高 int ww = 0, hh = 0; if (!Uploader.Get_Pic_WW_HH(sNewRoot, out ww, out hh)) { DirFileHelper.DeleteFile(sNewRoot); return("非法格式!不是图片文件。"); } int iMaxSize = mC.PicSize; long iFileSize = DirFileHelper.GetFileSize(sNewRoot); /* * if (iFileSize > iMaxSize) * { * return "上传文件大小超过了限制.最多上传(" + DirFileHelper.FmtFileSize2(iMaxSize) + ")."; * } */ #endregion #region 把上传的暂时文件复制到相关模块目录中 string sNewPath = sSavePath + sNewFile; string orgImg = DirFileHelper.GetFilePathPostfix(sNewPath, "o"); //复制到原始图 DirFileHelper.CopyFile(sNewRoot, orgImg); //删除暂时上传的图片 DirFileHelper.DeleteFile(sNewRoot); //生成相关缩略图 OneMakeThumbImage(sNewPath, mC); #endregion //---------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = sNewFile; m_r.Path = sNewPath; m_r.Src = sSrcName; m_r.Ext = sFileExt; m_r.Size = ConvertHelper.Cint0(iFileSize); m_r.PicWidth = ww; m_r.PicHeight = hh; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return(""); }
/// <returns>上传成功返回"",并填充 UploadFile(AspNet上传控件专用)</returns> /// <param name="oFile">System.Web.HttpPostedFile</param> /// <param name="vid">上传配置模块id,即Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="m_r">UploadFile</param> /// <param name="userType">0=未知,1=后台管理员上传,2=前台会员上传</param> /// <returns>上传成功返回"",并填充 UploadFile</returns> public string Upload_AspNet(System.Web.HttpPostedFile oFile, int vid, string key, int userId, string userName, UploadFile m_r, int userType = 1) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return("缺少参数:key或sid"); } //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC.Id != vid) { return("缺少参数:Id!"); } if (mC.IsPost != 1) { return("系统暂时禁止上传文件2!"); } if (mC.IsEditor == 1) { return("非编辑器类别!"); } #endregion //--------------------------------------------------- #region 检查登陆 m_r.UserId = 0; if (mC.UserType == 1)//管理员 { if (userType == 1) { m_r.UserId = userId; m_r.UserName = userName; } } else { if (userType == 2)//一般会员 { m_r.UserId = userId; m_r.UserName = userName; } } if (m_r.UserId == 0) { return("您的权限不足!"); } #endregion //------------------------------------------------ #region 设置上传参数 var oUp = new Uploader(); oUp.IsEnabled = true; oUp.IsChkSrcPost = true; oUp.CutType = ConvertHelper.Cint0(mC.CutType); oUp.AllowedExt = Get_Ext(mC.UploadType_TypeKey); oUp.MaxSize = (mC.UploadType_TypeKey == "image") ? ConvertHelper.Cint0(mC.PicSize) : ConvertHelper.Cint0(mC.FileSize); oUp.SavePath = mC.SaveDir; oUp.SetPic((mC.IsFixPic == 1), ConvertHelper.Cint0(mC.PicWidth), ConvertHelper.Cint0(mC.PicHeight), ConvertHelper.Cint0(mC.PicQuality)); oUp.SetBig((mC.IsBigPic == 1), ConvertHelper.Cint0(mC.BigWidth), ConvertHelper.Cint0(mC.BigHeight), ConvertHelper.Cint0(mC.BigQuality)); oUp.SetMid((mC.IsMidPic == 1), ConvertHelper.Cint0(mC.MidWidth), ConvertHelper.Cint0(mC.MidHeight), ConvertHelper.Cint0(mC.MidQuality)); oUp.SetMin((mC.IsMinPic == 1), ConvertHelper.Cint0(mC.MinWidth), ConvertHelper.Cint0(mC.MinHeight), ConvertHelper.Cint0(mC.MinQuality)); oUp.SetHot((mC.IsHotPic == 1), ConvertHelper.Cint0(mC.HotWidth), ConvertHelper.Cint0(mC.HotHeight), ConvertHelper.Cint0(mC.HotQuality)); oUp.IsWaterPic = (mC.IsWaterPic == 1); #endregion #region //------------------------------------------------ bool isOk = oUp.UploadFile(oFile); if (!isOk) { //上传出错 return(StringHelper.XssTextClear(oUp.GetErrMsg() + mC.Id)); } #endregion //---------------------------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = oUp.NewFile; m_r.Path = oUp.NewPath; m_r.Src = StringHelper.Left(oUp.SrcName, 90, false); m_r.Ext = oUp.FileExt; m_r.Size = oUp.GetFileSize(); m_r.PicWidth = oUp.NewWidth; m_r.PicHeight = oUp.NewHeight; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return(""); }
/// <returns>上传成功返回"",并填充 UploadFile</returns> /// <param name="vid">上传配置模块id,即Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="m_r">UploadFile</param> /// <param name="filePostName">上传文件框控件的名称,默认"imgFile",uploadify 默认 "Filedata"</param> /// <param name="userType">0=未知,1=后台管理员上传,2=前台会员上传</param> /// <param name="isEditor">从GetAction返回判断是否为编辑器</param> /// <param name="isSwf">是否通过flash上传</param> /// <returns>上传成功返回"",并填充 UploadFile</returns> public string Upload_Web(int vid, string key, int userId, string userName, UploadFile m_r, string filePostName = "imgFile", int userType = 1, bool isEditor = false, bool isSwf = false) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return("缺少参数:key或sid"); } string dir = RequestHelper.GetKeyChar("dir");//编辑器专用:image,flash,media,file if (dir.Length > 0) { if (Array.IndexOf("image,flash,media,file".Split(','), dir) == -1) { return("缺少参数:dir"); } } //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC.Id != vid) { return("缺少参数:Id!"); } if (mC.IsPost != 1) { return("系统暂时禁止上传文件2!"); } if (mC.IsEditor == 1 && isEditor == false) { return("非编辑器类别!"); } if (mC.IsSwf == 0 && isSwf == true) { return("不能从flash中上传!"); } #endregion //--------------------------------------------------- #region 检查登陆 m_r.UserId = 0; if (mC.UserType == 1)//管理员 { if (userType == 1) { m_r.UserId = userId; m_r.UserName = userName; } } else { if (userType == 2)//一般会员 { m_r.UserId = userId; m_r.UserName = userName; } } if (m_r.UserId == 0) { return("您的权限不足!"); } #endregion //------------------------------------------------ #region 设置上传参数 var oUp = new Uploader(); oUp.IsEnabled = true; if (isSwf) { oUp.IsChkSrcPost = false; //如果swf提交,必须设置为 o_up.isChkSrcPost = false; } else { //o_up.isChkSrcPost = (m_c.isChkSrcPost == "1"); //如果swf提交,必须设置为 o_up.isChkSrcPost = false; oUp.IsChkSrcPost = true; } oUp.CutType = ConvertHelper.Cint0(mC.CutType); oUp.FilePostName = filePostName; if (isEditor && mC.UploadType_TypeKey == "editor") { mC.UploadType_TypeKey = dir; } oUp.AllowedExt = Get_Ext(mC.UploadType_TypeKey); oUp.MaxSize = (mC.UploadType_TypeKey == "image") ? ConvertHelper.Cint0(mC.PicSize) : ConvertHelper.Cint0(mC.FileSize); oUp.SavePath = mC.SaveDir; oUp.SetPic((mC.IsFixPic == 1), ConvertHelper.Cint0(mC.PicWidth), ConvertHelper.Cint0(mC.PicHeight), ConvertHelper.Cint0(mC.PicQuality)); oUp.SetBig((mC.IsBigPic == 1), ConvertHelper.Cint0(mC.BigWidth), ConvertHelper.Cint0(mC.BigHeight), ConvertHelper.Cint0(mC.BigQuality)); oUp.SetMid((mC.IsMidPic == 1), ConvertHelper.Cint0(mC.MidWidth), ConvertHelper.Cint0(mC.MidHeight), ConvertHelper.Cint0(mC.MidQuality)); oUp.SetMin((mC.IsMinPic == 1), ConvertHelper.Cint0(mC.MinWidth), ConvertHelper.Cint0(mC.MinHeight), ConvertHelper.Cint0(mC.MinQuality)); oUp.SetHot((mC.IsHotPic == 1), ConvertHelper.Cint0(mC.HotWidth), ConvertHelper.Cint0(mC.HotHeight), ConvertHelper.Cint0(mC.HotQuality)); oUp.IsWaterPic = (mC.IsWaterPic == 1); #endregion #region //------------------------------------------------ bool isOk = oUp.UploadFile(); if (!isOk) { //上传出错 return(StringHelper.XssTextClear(oUp.GetErrMsg() + mC.Id)); } #endregion //---------------------------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = oUp.NewFile; m_r.Path = oUp.NewPath; m_r.Src = StringHelper.Left(oUp.SrcName, 90); m_r.Ext = oUp.FileExt; m_r.Size = oUp.GetFileSize(); m_r.PicWidth = oUp.NewWidth; m_r.PicHeight = oUp.NewHeight; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return(""); }
public ActionResult CreateSave() { if (Session["last_user_id"] == null) { return(RedirectToAction("Index", "Login")); } string user_id0 = (string)Session["last_user_id"]; if (!p_helper.hasPermission("0110", user_id0)) { return(RedirectToAction("Index", "Login")); } IUSERROLE rp_bll = Bll_Utilitity.GetUserRole(); IROLE p_bll = Bll_Utilitity.GetRole(); IEnumerable <TB_ROLE> list_role = p_bll.ListAll(); Dictionary <string, bool> checkState = new Dictionary <string, bool>(); foreach (TB_ROLE bean in list_role) { checkState.Add(bean.ROLE_ID, false); } IUSER bll = Bll_Utilitity.GetUser(); string user_id = Request["user.USER_ID"]; string real_name = Request["user.REAL_NAME"]; string sex = Request["sex"]; string password = Request["user.PASSWORD"]; string re_password = Request["user.RE_PASSWORD"]; string email = Request["user.EMAIL"]; string account_status = Request["account_status"]; string image_file = Request["image_file"]; string title = Request["user.TITLE"]; TB_USER user = new TB_USER(); user.USER_ID = user_id; user.REAL_NAME = real_name; user.SEX = sex; user.PASSWORD = password; user.EMAIL = email; user.ACCOUNT_STATUS = account_status; user.TITLE = title; string roles = Request["role"]; string[] ps = null; if (!String.IsNullOrEmpty(roles)) { ps = roles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (ps != null && ps.Length > 0) { for (int ii = 0; ii < ps.Length; ii++) { if (checkState.ContainsKey(ps[ii])) { checkState[ps[ii]] = true; } } } } user.ROLE_LIST = list_role; string file_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads/" + image_file); if (System.IO.File.Exists(file_path)) { byte[] b = System.IO.File.ReadAllBytes(file_path); user.USER_IMAGE = b; user.USER_IMAGE_PATH = image_file; } bool isError = false; if (string.IsNullOrEmpty(user_id)) { ModelState.AddModelError("user.USER_ID", "用户ID不能为空"); isError = true; } if (string.IsNullOrEmpty(real_name)) { ModelState.AddModelError("user.REAL_NAME", "姓名不能为空"); isError = true; } if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("user.PASSWORD", "密码不能为空"); isError = true; } if (password != re_password) { ModelState.AddModelError("user.RE_PASSWORD", "确认密码与输入密码不一致"); isError = true; } if (string.IsNullOrEmpty(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱不能为空"); isError = true; } if (isError) { ViewData["user"] = user; ViewData["check_state"] = checkState; List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); List <SelectListItem> account_status_list = new List <SelectListItem>(); bool selected_account_status_y = false; bool selected_account_status_n = false; if (user.ACCOUNT_STATUS == "Y") { selected_account_status_y = true; } else if (user.ACCOUNT_STATUS == "N") { selected_account_status_n = true; } account_status_list.Add(new SelectListItem() { Text = "启用", Value = "Y", Selected = selected_account_status_y }); account_status_list.Add(new SelectListItem() { Text = "禁用", Value = "N", Selected = selected_account_status_n }); ViewData["sex"] = sex_list.AsEnumerable(); ViewData["account_status"] = account_status_list.AsEnumerable(); return(View("Create")); } bll.Insert(user); bll.SetPassword(user.USER_ID, user.PASSWORD); string change_content = "用户ID:" + user.USER_ID + ",用户姓名:" + user.REAL_NAME; IOPLOG op_bll = Bll_Utilitity.GetOpLog(); TB_OP_LOG log = new TB_OP_LOG(); log.OP_USER_ID = (string)Session["last_user_id"]; log.OPER_NAME = "用户添加"; log.OPER_IP = IpHelper.GetClientIP(); log.OPER_TIME = DateTime.Now; log.OPER_DESC = "用户添加(" + change_content + ")"; op_bll.AddLog(log); IList <String> list = new List <String>(); if (ps != null) { foreach (string role_id in ps) { list.Add(role_id); } } rp_bll.Save(user.USER_ID, list); return(RedirectToAction("Index", "User")); }
public ActionResult EditSave() { if (Session["last_user_id"] == null) { return(RedirectToAction("Index", "Login")); } string user_id0 = (string)Session["last_user_id"]; if (!p_helper.hasPermission("0111", user_id0)) { return(RedirectToAction("Index", "Login")); } if (CommonConfig.isForDemo && user_id0.ToLower() == "admin") { TempData["ErrMsg"] = "演示版本,admin用户无法编辑"; return(RedirectToAction("Index", "USER")); } IUSERROLE rp_bll = Bll_Utilitity.GetUserRole(); IROLE p_bll = Bll_Utilitity.GetRole(); IEnumerable <TB_ROLE> list_role = p_bll.ListAll(); Dictionary <string, bool> checkState = new Dictionary <string, bool>(); foreach (TB_ROLE bean in list_role) { checkState.Add(bean.ROLE_ID, false); } IUSER bll = Bll_Utilitity.GetUser(); string user_id = Request["user.USER_ID"]; string real_name = Request["user.REAL_NAME"]; string sex = Request["sex"]; string old_password = Request["user.OLD_PASSWORD"]; string new_password = Request["user.NEW_PASSWORD"]; string re_password = Request["user.RE_PASSWORD"]; string email = Request["user.EMAIL"]; string account_status = Request["account_status"]; string image_file = Request["image_file"]; string title = Request["user.TITLE"]; TB_USER user = new TB_USER(); user.USER_ID = user_id; user.REAL_NAME = real_name; user.SEX = sex; user.EMAIL = email; user.ACCOUNT_STATUS = account_status; user.TITLE = title; string file_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Uploads/" + image_file); if (System.IO.File.Exists(file_path)) { byte[] b = System.IO.File.ReadAllBytes(file_path); user.USER_IMAGE = b; user.USER_IMAGE_PATH = image_file; } string roles = Request["role"]; string[] ps = null; if (!String.IsNullOrEmpty(roles)) { ps = roles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (ps != null && ps.Length > 0) { for (int ii = 0; ii < ps.Length; ii++) { if (checkState.ContainsKey(ps[ii])) { checkState[ps[ii]] = true; } } } } user.ROLE_LIST = list_role; bool isError = false; bool change_password = false; if (string.IsNullOrEmpty(user_id)) { ModelState.AddModelError("user.USER_ID", "用户ID不能为空"); isError = true; } if (string.IsNullOrEmpty(real_name)) { ModelState.AddModelError("user.REAL_NAME", "姓名不能为空"); isError = true; } if (new_password == "" && re_password == "") { } else if (new_password != re_password) { ModelState.AddModelError("user.RE_PASSWORD", "确认密码与输入密码不一致"); isError = true; } else { bool passowrd_collect = bll.isPasswordCorrect(user_id, old_password); if (!passowrd_collect) { ModelState.AddModelError("user.OLD_PASSWORD", "原密码错误"); isError = true; } else { user.PASSWORD = new_password; change_password = true; } } if (string.IsNullOrEmpty(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱不能为空"); isError = true; } if (!Validator.IsEmail(email)) { ModelState.AddModelError("user.EMAIL", "电子邮箱格式错误"); isError = true; } if (isError) { ViewData["user"] = user; ViewData["check_state"] = checkState; List <SelectListItem> sex_list = new List <SelectListItem>(); bool selected_man = false; bool selected_woman = false; if (user.SEX == "男") { selected_man = true; } else if (user.SEX == "女") { selected_woman = true; } sex_list.Add(new SelectListItem() { Text = "男", Value = "男", Selected = selected_man }); sex_list.Add(new SelectListItem() { Text = "女", Value = "女", Selected = selected_woman }); List <SelectListItem> account_status_list = new List <SelectListItem>(); bool selected_account_status_y = false; bool selected_account_status_n = false; if (user.ACCOUNT_STATUS == "Y") { selected_account_status_y = true; } else if (user.ACCOUNT_STATUS == "N") { selected_account_status_n = true; } account_status_list.Add(new SelectListItem() { Text = "启用", Value = "Y", Selected = selected_account_status_y }); account_status_list.Add(new SelectListItem() { Text = "禁用", Value = "N", Selected = selected_account_status_n }); ViewData["sex"] = sex_list.AsEnumerable(); ViewData["account_status"] = account_status_list.AsEnumerable(); return(View("Edit")); } TB_USER old_user = bll.Get(user.USER_ID); bll.Update(user); if (change_password) { bll.SetPassword(user_id, new_password); } string change_content = ""; if (old_user.REAL_NAME != user.REAL_NAME) { change_content += string.Format("姓名({0}->{1})", old_user.REAL_NAME, user.REAL_NAME); } if (old_user.SEX != user.SEX) { if (change_content != "") { change_content += ","; } change_content += string.Format("性别({0}->{1})", old_user.SEX, user.SEX); } if (old_user.TITLE != user.TITLE) { if (change_content != "") { change_content += ","; } change_content += string.Format("称呼({0}->{1})", old_user.TITLE, user.TITLE); } if (old_user.USER_IMAGE_PATH != user.USER_IMAGE_PATH) { if (change_content != "") { change_content += ","; } change_content += string.Format("图片({0}->{1})", old_user.USER_IMAGE_PATH, user.USER_IMAGE_PATH); } IEnumerable <string> old_role_ids = rp_bll.GetRoleIds(user.USER_ID); IList <String> list = new List <String>(); if (ps != null) { foreach (string role_id in ps) { list.Add(role_id); } } rp_bll.Save(user.USER_ID, list); IList <string> old_role_id_list = old_role_ids.ToList <string>(); string result = CollectionUtilitity.compare("原包含角色", "现包含角色", old_role_id_list, list); if (result != "") { if (change_content != "") { change_content += ","; } change_content += result; } IOPLOG op_bll = Bll_Utilitity.GetOpLog(); TB_OP_LOG log = new TB_OP_LOG(); log.OP_USER_ID = (string)Session["last_user_id"]; log.OPER_NAME = "用户编辑"; log.OPER_IP = IpHelper.GetClientIP(); log.OPER_TIME = DateTime.Now; log.OPER_DESC = "用户编辑(" + change_content + ")"; op_bll.AddLog(log); return(RedirectToAction("Index", "User")); }
// GET: ApplyManager/Delete/5 public JsonResult Delete(string number) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_code = "nologin"; goto next; } if (number == null) { json.msg_code = "errorNumber"; json.msg_text = "报销单号获取失败。"; goto next; } //查询订单状态,如果已批复,不能撤销。如果没有,删除流程。 Reimbursement bill = db.Reimbursement.Find(number); if (bill == null) { json.msg_code = "nodate"; json.msg_text = "报销单不存在或被删除。"; goto next; } int user = Common.PageValidate.FilterParam(User.Identity.Name); if (user != bill.r_add_user_id) { json.msg_code = "forbidden"; json.msg_text = "没有权限操作他人申请的报销单。"; goto next; } if (bill.r_bill_state == 1) { json.msg_code = "forbidden"; json.msg_text = "已批复同意的报销单不允许删除。"; goto next; } var cs = db.Reimbursement_Content.Where(x => x.c_reimbursement_code == bill.reimbursement_code); //删除报销内容 if (cs.Count() > 0) { foreach (Reimbursement_Content citem in cs) { //删除报销细节 db.Reimbursement_Detail.RemoveRange(db.Reimbursement_Detail.Where(x => x.detail_content_id == citem.content_id)); db.Reimbursement_Content.Remove(citem); } } //删除附件 db.Reimbursement_Attachment.RemoveRange(db.Reimbursement_Attachment.Where(x => x.atta_reimbursement_code == bill.reimbursement_code)); //删除批复 db.Process_Respond.RemoveRange(db.Process_Respond.Where(x => x.pr_reimbursement_code == bill.reimbursement_code)); //删除总单 db.Reimbursement.Remove(bill); try { db.SaveChanges(); SysLog.WriteLog(user, string.Format("删除报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db); } catch (DbEntityValidationException ex) { StringBuilder errors = new StringBuilder(); IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors; foreach (DbEntityValidationResult result in validationResult) { ICollection <DbValidationError> validationError = result.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n"); } } ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name); json.msg_code = "error"; json.msg_text = "报销单删除失败。"; goto next; } json.state = 1; json.msg_code = "success"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public async Task <MessageModel <string> > Deregister() { var data = new MessageModel <string>(); await NacosNamingService.DeregisterInstance(JsonConfigSettings.NacosServiceName, Nacos.V2.Common.Constants.DEFAULT_GROUP, IpHelper.GetCurrentIp(null), JsonConfigSettings.NacosPort); data.Success = true; data.Message = "Success"; return(data); }
public JsonResult Create(ApplyListModel _sbill) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_code = "nologin"; goto next; } int user = Common.PageValidate.FilterParam(User.Identity.Name); SetSelect(0); if (ModelState.IsValid) { var funds = (from fs in db.Funds where fs.f_id == _sbill.Fid select fs).FirstOrDefault(); if (funds.f_amount == 0) { json.msg_code = "error"; json.msg_text = string.Format("报销单提交失败,id为{0}的经费没有设置总额。", _sbill.Fid); goto next; } //if (funds.f_manager == user) //{ // json.msg_code = "forbidden"; // json.msg_text = "不允许申请自己的经费。"; // goto next; //} if (funds.f_balance < _sbill.amount) { json.msg_code = "error"; json.msg_text = string.Format("报销单提交失败,id为{0}的经费不足。", _sbill.Fid); goto next; } Reimbursement bill = new Reimbursement(); bill.r_bill_amount = _sbill.amount; bill.r_bill_state = 0; bill.r_add_date = DateTime.Now; bill.r_add_user_id = user; bill.reimbursement_info = _sbill.info; bill.r_funds_id = _sbill.Fid; var maxfa = db.Reimbursement.OrderByDescending(x => x.reimbursement_code).FirstOrDefault(); //apply_number:年份+10001自增 if (maxfa == null) { bill.reimbursement_code = DateTime.Now.Year.ToString() + "10001"; } else { bill.reimbursement_code = DateTime.Now.Year.ToString() + (int.Parse(maxfa.reimbursement_code.Substring(4)) + 1); } db.Reimbursement.Add(bill); try { db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); json.msg_code = "error"; json.msg_text = "报销单提交失败。"; goto next; } StringBuilder sbErr = new StringBuilder(); //添加报销内容 foreach (ViewContentModel citem in _sbill.contents) { Reimbursement_Content content = new Reimbursement_Content(); content.c_reimbursement_code = bill.reimbursement_code; content.c_amount = citem.amount; content.c_dic_id = citem.selectId; db.Reimbursement_Content.Add(content); try { //必需先提交更改,因为下面添加明细需要用到自动生成的ID。 db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); Delete(bill.reimbursement_code); json.msg_code = "error"; json.msg_text = "报销单提交失败。"; goto next; } //添加明细 if (citem.details != null && citem.details.Count() > 0) { foreach (ViewDetailContent viewDetail in citem.details) { Reimbursement_Detail detail = new Reimbursement_Detail() { detail_amount = viewDetail.amount, detail_content_id = content.content_id, detail_date = DateTime.Parse(viewDetail.strDate + " 00:00"), detail_info = viewDetail.detailInfo }; db.Reimbursement_Detail.Add(detail); } } //添加附件 if (citem.attachments != null && citem.attachments.Count() > 0) { string attachment_path = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd")); string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();; if (!Directory.Exists(attachment_path)) { Directory.CreateDirectory(attachment_path); } string filePath, tempFile, saveFileName = "", storeFileName; foreach (ViewAttachment item in citem.attachments) { try { saveFileName = Path.GetFileName(item.fileName); storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName); tempFile = attachment_temp_path + item.fileName; filePath = string.Format("{0}{1}", attachment_path, saveFileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } System.IO.File.Move(tempFile, filePath); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), GetType().ToString()); sbErr.Append("文件【").Append(saveFileName).Append("】保存失败,请重新上传。\r\n"); continue; } Reimbursement_Attachment attachment = new Reimbursement_Attachment { attachment_path = storeFileName, atta_detail_id = content.content_id, atta_reimbursement_code = bill.reimbursement_code }; db.Reimbursement_Attachment.Add(attachment); } } try { db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); Delete(bill.reimbursement_code); json.msg_code = "error"; json.msg_text = "报销单提交失败。"; goto next; } } //添加其他附件 if (_sbill.attachments != null && _sbill.attachments.Count() > 0) { string attachment_path = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd")); string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();; if (!Directory.Exists(attachment_path)) { Directory.CreateDirectory(attachment_path); } string filePath, tempFile, saveFileName = "", storeFileName; foreach (ViewAttachment item in _sbill.attachments) { try { saveFileName = Path.GetFileName(item.fileName); storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName); tempFile = attachment_temp_path + item.fileName; filePath = string.Format("{0}{1}", attachment_path, saveFileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } System.IO.File.Move(tempFile, filePath); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), GetType().ToString()); sbErr.Append("文件【").Append(saveFileName).Append("】保存失败,请重新上传。\r\n"); continue; } Reimbursement_Attachment attachment = new Reimbursement_Attachment { attachment_path = storeFileName, atta_detail_id = 0, atta_reimbursement_code = bill.reimbursement_code }; db.Reimbursement_Attachment.Add(attachment); } try { db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); Delete(bill.reimbursement_code); json.msg_code = "error"; json.msg_text = "报销单提交失败。"; goto next; } } //添加批复人 Process_Respond pr = new Process_Respond(); pr.pr_reimbursement_code = bill.reimbursement_code; pr.pr_user_id = _sbill.next; pr.pr_number = 1; db.Process_Respond.Add(pr); try { db.SaveChanges(); SysLog.WriteLog(user, string.Format("添加报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); Delete(bill.reimbursement_code); json.msg_code = "error"; json.msg_text = "报销单提交失败。"; goto next; } json.state = 1; json.msg_code = bill.reimbursement_code; json.msg_text = sbErr.ToString(); } next: return(Json(json, JsonRequestBehavior.AllowGet)); }
public JsonResult LogReceive(string id, decimal amount) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_code = "nologin"; goto next; } int user = Common.PageValidate.FilterParam(User.Identity.Name); var bill = db.Reimbursement.Find(id); if (bill == null) { json.msg_text = "没有找到该报销单。"; json.msg_code = "noData"; goto next; } if (bill.r_bill_state != 1) { json.msg_text = "不能操作未批复报销单。"; json.msg_code = "noData"; goto next; } bool isManager = RoleCheck.CheckHasAuthority(user, db, "系统管理"); if (!isManager && bill.c_has_log) { json.msg_text = "已操作录入实际信用金额。"; json.msg_code = "noData"; goto next; } if (user != bill.r_add_user_id && !isManager) { json.msg_text = "不能操作他人报销单。"; json.msg_code = "noData"; goto next; } bill.r_fact_amount = amount; bill.c_has_log = true; db.Entry(bill).State = EntityState.Modified; Funds funds = db.Funds.Find(bill.r_funds_id); if (funds != null) { decimal m = bill.r_bill_amount - bill.r_fact_amount; funds.f_balance = funds.f_balance + m; db.Entry(funds).State = EntityState.Modified; } try { db.SaveChanges(); SysLog.WriteLog(user, string.Format("录入报销单[{0}]实领金额{1}元", bill.reimbursement_code, amount), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().Name); json.msg_code = "error"; json.msg_text = "录入失败。"; goto next; } json.state = 1; json.msg_code = "success"; next: return(Json(json, JsonRequestBehavior.AllowGet)); }
private void DoSignIn(IAcDomain acDomain, Dictionary <string, object> args) { if (EmptyAcDomain.SingleInstance.Equals(acDomain)) { return; } var loginName = args.ContainsKey("loginName") ? (args["loginName"] ?? string.Empty).ToString() : string.Empty; var password = args.ContainsKey("password") ? (args["password"] ?? string.Empty).ToString() : string.Empty; var rememberMe = args.ContainsKey("rememberMe") ? (args["rememberMe"] ?? string.Empty).ToString() : string.Empty; var passwordEncryptionService = acDomain.GetRequiredService <IPasswordEncryptionService>(); if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password)) { throw new ValidationException("用户名和密码不能为空"); } var addVisitingLogCommand = new AddVisitingLogCommand(AcSessionState.Empty) { IpAddress = IpHelper.GetClientIp(), LoginName = loginName, VisitedOn = null, VisitOn = DateTime.Now, Description = "登录成功", ReasonPhrase = VisitState.LogOnFail.ToName(), StateCode = (int)VisitState.LogOnFail }; password = passwordEncryptionService.Encrypt(password); IAccount account = null; try { account = AcSessionState.AcMethod.GetAccountByLoginName(acDomain, loginName); } catch (SqlException ex) { throw new GeneralException("请转到Anycmd数据库,使用SqlServer管理工具修改Anycmd.dbo.RDatabase表中的密码项。切记:修改密码后重启一下应用程序站点,因为目前的数据库层并没有通过总线接入到权限引擎系统,数据库层的密码修改权限引擎并不知道。", ex); } if (account == null) { addVisitingLogCommand.Description = "用户名错误"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } else { addVisitingLogCommand.AccountId = account.Id; } if (password != account.Password) { addVisitingLogCommand.Description = "密码错误"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } if (account.IsEnabled == 0) { addVisitingLogCommand.Description = "对不起,该账户已被禁用"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } string auditState = account.AuditState == null ? account.AuditState : account.AuditState.ToLower(); CatalogState dicItem; if (!acDomain.CatalogSet.TryGetCatalog(auditState, out dicItem)) { throw new GeneralException("意外的字典编码" + auditState); } if (auditState == null || auditState == "notaudit") { addVisitingLogCommand.Description = "对不起,该账户尚未审核"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } if (auditState == "auditnotpass") { addVisitingLogCommand.Description = "对不起,该账户未通过审核"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } if (account.AllowStartTime.HasValue && SystemTime.Now() < account.AllowStartTime.Value) { addVisitingLogCommand.Description = "对不起,该账户的允许登录开始时间还没到。请在" + account.AllowStartTime + "后登录"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } if (account.AllowEndTime.HasValue && SystemTime.Now() > account.AllowEndTime.Value) { addVisitingLogCommand.Description = "对不起,该账户的允许登录时间已经过期"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } if (account.LockEndTime.HasValue || account.LockStartTime.HasValue) { DateTime lockStartTime = account.LockStartTime ?? DateTime.MinValue; DateTime lockEndTime = account.LockEndTime ?? DateTime.MaxValue; if (SystemTime.Now() > lockStartTime && SystemTime.Now() < lockEndTime) { addVisitingLogCommand.Description = "对不起,该账户暂被锁定"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } } if (account.PreviousLoginOn.HasValue && account.PreviousLoginOn.Value >= SystemTime.Now().AddMinutes(5)) { addVisitingLogCommand.Description = "检测到您的上次登录时间在未来。这可能是因为本站点服务器的时间落后导致的,请联系管理员。"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); throw new ValidationException(addVisitingLogCommand.Description); } account.PreviousLoginOn = SystemTime.Now(); if (!account.FirstLoginOn.HasValue) { account.FirstLoginOn = SystemTime.Now(); } account.LoginCount = (account.LoginCount ?? 0) + 1; account.IpAddress = IpHelper.GetClientIp(); // 使用账户标识作为会话标识会导致一个账户只有一个会话 // TODO:支持账户和会话的一对多,为会话级的动态责任分离做准备 var sessionEntity = AcSessionState.AcMethod.GetAcSessionEntity(acDomain, account.Id); IAcSession acSession; if (sessionEntity != null) { acSession = new AcSessionState(acDomain, sessionEntity.Id, AccountState.Create(account)); sessionEntity.IsAuthenticated = true; AcSessionState.AcMethod.UpdateAcSession(acDomain, sessionEntity); } else { var accountState = AccountState.Create(account); var identity = new AnycmdIdentity(account.LoginName); var acSessionEntity = new AcSession(account.Id) { AccountId = account.Id, AuthenticationType = identity.AuthenticationType, Description = null, IsAuthenticated = identity.IsAuthenticated, IsEnabled = 1, LoginName = account.LoginName }; AcSessionState.AcMethod.AddAcSession(acDomain, acSessionEntity); acSession = new AcSessionState(acDomain, account.Id, accountState); } if (HttpContext.Current != null) { HttpContext.Current.User = acSession; bool createPersistentCookie = rememberMe.Equals("rememberMe", StringComparison.OrdinalIgnoreCase); FormsAuthentication.SetAuthCookie(account.LoginName, createPersistentCookie); } else { Thread.CurrentPrincipal = acSession; } Guid?visitingLogId = Guid.NewGuid(); acSession.SetData("UserContext_Current_VisitingLogId", visitingLogId); acSession.SetData(acDomain.Config.CurrentAcSessionCacheKey, acSession); acDomain.EventBus.Publish(new AccountLoginedEvent(acSession, account)); acDomain.EventBus.Commit(); addVisitingLogCommand.StateCode = (int)VisitState.Logged; addVisitingLogCommand.ReasonPhrase = VisitState.Logged.ToName(); addVisitingLogCommand.Description = "登录成功"; acDomain.MessageDispatcher.DispatchMessage(addVisitingLogCommand); }
public string Server() { var r = IpHelper.GetServerIp(); return(r); }
public string Client() { var r = IpHelper.GetClientIp(); return(r); }
public JsonResult Login(Models.LoginModel model) { if (ModelState.IsValid) { //首先判断下验证码是否正确 if (Session["ValidateImgCode"] != null && string.Equals(Session["ValidateImgCode"].ToString(), model.ValidateCode, StringComparison.OrdinalIgnoreCase)) { Model.Admin adminModel = new Model.Admin(); if (new Regex("1[3|5|7|8|][0-9]{9}").IsMatch(model.UserName)) {//匹配手机号码 adminModel = EnterRepository.GetRepositoryEnter().GetAdminRepository.LoadEntities(m => m.Mobile == model.UserName && m.IsLogin == 1).FirstOrDefault(); } else if (new Regex(@"[A-Za-z0-9.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}").IsMatch(model.UserName)) {//匹配邮箱 adminModel = EnterRepository.GetRepositoryEnter().GetAdminRepository.LoadEntities(m => m.Email == model.UserName && m.IsLogin == 1).FirstOrDefault(); } else {//匹配用户名 adminModel = EnterRepository.GetRepositoryEnter().GetAdminRepository.LoadEntities(m => m.AdminName == model.UserName && m.IsLogin == 1).FirstOrDefault(); } if (adminModel == null) { return(Json(new { state = "error", message = "用户名不存在" })); } else { //判断密码是否正确 if (adminModel.Password == MD5Helper.CreatePasswordMd5(model.Password, adminModel.Salt)) { adminModel.LastLoginTime = DateTime.Now; adminModel.LastLoginIp = IpHelper.GetRealIP(); adminModel.LastLoginAddress = IpHelper.GetAdrByIp(adminModel.LastLoginIp); adminModel.LastLoginInfo = IpHelper.GetBrowerVersion(); //添加登录日志并修改上次登录信息 EnterRepository.GetRepositoryEnter().GetAdminLoginLogRepository.AddEntity(new Model.AdminLoginLog() { AdminId = adminModel.Id, AdminLoginAddress = adminModel.LastLoginAddress, AdminLoginIP = adminModel.LastLoginIp, AdminLoginTime = adminModel.LastLoginTime, AdminLoginInfo = adminModel.LastLoginInfo }); if (EnterRepository.GetRepositoryEnter().SaveChange() > 0) { //先清除原来的cookie WebCookieHelper.AdminLoginOut(); //登录成功,保存cookie WebCookieHelper.SetCookie(adminModel.Id, model.UserName, adminModel.LastLoginTime, adminModel.LastLoginIp, adminModel.LastLoginAddress, adminModel.IsSuperAdmin, adminModel.AuthoryId, (model.IsRemind != null && model.IsRemind) ? 15 : 0); return(Json(new { state = "success", message = "登录成功" })); } else { return(Json(new { state = "success", message = "服务器泡妞去了" })); } } else { return(Json(new { state = "error", message = "密码错误" })); } } } else { return(Json(new { state = "error", message = "验证码错误" })); } } else { return(Json(new { state = "error", message = "输入信息不完整" })); } }
public JsonResult SetAgree(Respond respond) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_text = "没有登陆或登陆失效,请重新登陆后操作。"; json.msg_code = "notLogin"; return(Json(json, JsonRequestBehavior.AllowGet)); } int user = PageValidate.FilterParam(User.Identity.Name); if (!RoleCheck.CheckHasAuthority(user, db, "批复管理", "批复")) { json.msg_text = "没有权限。"; json.msg_code = "paramErr"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (respond.id == null || respond.id == 0) { json.msg_text = "参数传递失败,请重试。"; json.msg_code = "paramErr"; return(Json(json, JsonRequestBehavior.AllowGet)); } Process_Respond model = db.Process_Respond.Find(respond.id); if (model == null) { json.msg_text = "没找到该流程,可能已经撤销,请重试。"; json.msg_code = "None"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (user != model.pr_user_id) { json.msg_text = "非该流程的当前批复人。"; json.msg_code = "paramErr"; return(Json(json, JsonRequestBehavior.AllowGet)); } var exists = db.Process_Respond.Where(x => x.pr_reimbursement_code == model.pr_reimbursement_code && x.pr_user_id == respond.next); if (exists.Count() > 0) { json.msg_text = "该审核人已存在审批列表中。"; json.msg_code = "Exists"; return(Json(json, JsonRequestBehavior.AllowGet)); } //批复当前流程 int state = respond.state; model.pr_state = state; model.pr_time = DateTime.Now; model.pr_content = PageValidate.InputText(Server.UrlDecode(respond.reason), 2000); db.Entry(model).State = System.Data.Entity.EntityState.Modified; //是否为批复不通过 Reimbursement bill = db.Reimbursement.Find(model.pr_reimbursement_code); if (bill == null) { json.msg_text = "操作失败,该报销单已被删除。"; json.msg_code = "Error"; return(Json(json, JsonRequestBehavior.AllowGet)); } if (state == 1) { Funds fmodel = db.Funds.Find(bill.r_funds_id); if (fmodel == null) { json.msg_text = "所申请的经费已不存在,无法继续。"; json.msg_code = "applyError"; json.state = 0; return(Json(json, JsonRequestBehavior.AllowGet)); } //是否有next if (respond.next != null && respond.next != 0) { Process_Respond pr = new Process_Respond(); pr.pr_reimbursement_code = model.pr_reimbursement_code; pr.pr_user_id = (int)respond.next; pr.pr_number = model.pr_number + 1; db.Process_Respond.Add(pr); model.next = pr.pr_id; db.Entry(model).State = System.Data.Entity.EntityState.Modified; } else { if (fmodel.f_balance < bill.r_bill_amount) { //经费不足,回退批复 json.msg_text = "当前经费余额不足,无法继续。"; json.msg_code = "applyError"; json.state = 0; return(Json(json, JsonRequestBehavior.AllowGet)); } else { fmodel.f_balance = fmodel.f_balance - bill.r_bill_amount; db.Entry(fmodel).State = System.Data.Entity.EntityState.Modified; bill.r_bill_state = state; bill.r_fact_amount = bill.r_bill_amount; db.Entry(bill).State = System.Data.Entity.EntityState.Modified; } } } else { bill.r_bill_state = state; db.Entry(bill).State = System.Data.Entity.EntityState.Modified; } try { db.SaveChanges(); SysLog.WriteLog(user, string.Format("批复报帐单[{0}],结果为[{1}]", bill.reimbursement_code, state), IpHelper.GetIP(), bill.reimbursement_code, 3, "", db); } catch (DbEntityValidationException et) { StringBuilder errors = new StringBuilder(); IEnumerable <DbEntityValidationResult> validationResult = et.EntityValidationErrors; foreach (DbEntityValidationResult result in validationResult) { ICollection <DbValidationError> validationError = result.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n"); } } ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name); json.msg_text = "审核失败。"; json.msg_code = "respondError"; json.state = 0; return(Json(json, JsonRequestBehavior.AllowGet)); } json.msg_text = "操作成功。"; json.msg_code = "success"; json.state = 1; return(Json(json, JsonRequestBehavior.AllowGet)); }
public JsonResult Edit(ApplyListModel viewBill) { BaseJsonData json = new BaseJsonData(); if (!User.Identity.IsAuthenticated) { json.msg_code = "nologin"; goto next; } int user = Common.PageValidate.FilterParam(User.Identity.Name); SetSelect(0); if (ModelState.IsValid) { Reimbursement bill = db.Reimbursement.Find(viewBill.reimbursementCode); if (bill == null) { json.msg_code = "error"; json.msg_text = "没有主申请单,更新失败。"; goto next; } if (viewBill.next == 0) { json.msg_code = "error"; json.msg_text = "必需选择批复人。"; goto next; } var funds = (from fs in db.Funds where fs.f_id == viewBill.Fid select fs).FirstOrDefault(); if (funds.f_amount == 0) { json.msg_code = "error"; json.msg_text = string.Format("报销单提交失败,经费{0}没有设置总额。", funds.f_code); goto next; } if (funds.f_balance < viewBill.amount) { json.msg_code = "error"; json.msg_text = string.Format("申请单提交失败,经费{0}不足。", funds.f_code); goto next; } StringBuilder sbmsg = new StringBuilder(); if (bill.r_bill_state == 1) { json.msg_code = "error"; json.msg_text = "该报销单已经批复完成,不允许修改。"; goto next; } else { bill.r_bill_amount = viewBill.amount; bill.r_fact_amount = viewBill.amount; bill.r_bill_state = 0; bill.r_add_date = DateTime.Now; bill.r_funds_id = viewBill.Fid; bill.reimbursement_info = viewBill.info; db.Entry(bill).State = EntityState.Modified; //录入报销事由 Reimbursement_Content content = null; foreach (ViewContentModel citem in viewBill.contents) { if (citem.contentId != null && citem.contentId != 0) { content = db.Reimbursement_Content.Find(citem.contentId); if (content != null) { content.c_amount = citem.amount; db.Entry(content).State = EntityState.Modified; } } else { content = new Reimbursement_Content(); content.c_reimbursement_code = bill.reimbursement_code; content.c_dic_id = citem.selectId; content.c_amount = citem.amount; db.Reimbursement_Content.Add(content); } try { db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); sbmsg.Append("报销内容录入失败<br />"); continue; } //录入明细 if (citem.details != null && citem.details.Count() > 0) { Reimbursement_Detail detail = null; foreach (ViewDetailContent item in citem.details) { if (item.detailId != null && item.detailId != 0) { detail = db.Reimbursement_Detail.Find(item.detailId); } else { detail = new Reimbursement_Detail(); detail.detail_content_id = content.content_id; } detail.detail_amount = item.amount; detail.detail_date = DateTime.Parse(item.strDate + " 00:00"); detail.detail_info = item.detailInfo; detail.detail_content_id = content.content_id; if (item.detailId != null && item.detailId != 0) { db.Entry(detail).State = EntityState.Modified; } else { db.Reimbursement_Detail.Add(detail); } } } //录入附件 if (citem.attachments != null && citem.attachments.Count() > 0) { string attachment_path = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd")); string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();; if (!Directory.Exists(attachment_path)) { Directory.CreateDirectory(attachment_path); } string filePath, tempFile, saveFileName = "", storeFileName; foreach (ViewAttachment item in citem.attachments) { if (item.id > 0) { continue; } try { saveFileName = Path.GetFileName(item.fileName); storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName); tempFile = attachment_temp_path + item.fileName; filePath = string.Format("{0}{1}", attachment_path, saveFileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } System.IO.File.Move(tempFile, filePath); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); sbmsg.Append("文件【").Append(item.fileName).Append("】保存失败,请重新上传"); continue; } Reimbursement_Attachment attachment = new Reimbursement_Attachment { attachment_path = storeFileName, atta_detail_id = (int)citem.contentId, atta_reimbursement_code = bill.reimbursement_code }; db.Reimbursement_Attachment.Add(attachment); } } try { db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); sbmsg.Append("报销明细录入失败<br />"); continue; } } //录入附件 if (viewBill.attachments != null && viewBill.attachments.Count() > 0) { string attachment_path = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd")); string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();; if (!Directory.Exists(attachment_path)) { Directory.CreateDirectory(attachment_path); } string filePath, tempFile, saveFileName = "", storeFileName; foreach (ViewAttachment item in viewBill.attachments) { if (item.id > 0) { continue; } try { saveFileName = Path.GetFileName(item.fileName); storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName); tempFile = attachment_temp_path + item.fileName; filePath = string.Format("{0}{1}", attachment_path, saveFileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } System.IO.File.Move(tempFile, filePath); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); sbmsg.Append("文件【").Append(item.fileName).Append("】保存失败,请重新上传"); continue; } Reimbursement_Attachment attachment = new Reimbursement_Attachment { attachment_path = storeFileName, atta_detail_id = 0, atta_reimbursement_code = bill.reimbursement_code }; db.Reimbursement_Attachment.Add(attachment); } try { //干脆都先提交得了 db.SaveChanges(); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); Delete(bill.reimbursement_code); json.msg_code = "error"; json.msg_text = "报销单附件提交失败。"; goto next; } } //录入批复流程 db.Process_Respond.RemoveRange(db.Process_Respond.Where(x => x.pr_reimbursement_code == bill.reimbursement_code)); //添加批复人 Process_Respond pr = new Process_Respond(); pr.pr_reimbursement_code = bill.reimbursement_code; pr.pr_user_id = viewBill.next; pr.pr_number = 1; db.Process_Respond.Add(pr); try { db.SaveChanges(); SysLog.WriteLog(user, string.Format("修改报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db); } catch (Exception e) { ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString()); Delete(bill.reimbursement_code); json.msg_code = "error"; json.msg_text = "报销单提交失败。"; goto next; } } json.state = 1; json.msg_code = bill.reimbursement_code; json.msg_text = sbmsg.ToString(); } next: return(Json(json, JsonRequestBehavior.AllowGet)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { CbIps.ItemsSource = IpHelper.GetLocalList(); CbIps.SelectedIndex = 0; }