/// <summary> /// 添加新的布控信息 /// </summary> /// <param name="audit">新布控信息</param> /// <returns>返回1为成功</returns> public int AddAudit(BKBJ.AuditInfo audit) { string sql = "INSERT INTO CasesInfo (Uid,ProID,CityID,AID,TaskName,CaseItem,NETWORK_APP,CaseType,CaseValue,HeadName,HeadMobile,DeployArea,IsEnabled,IsValid,MailWarn,WMail,StartTime,EndTime,Remark,CreateTime,NetbarType) VALUES (@uid,@proid,@cityid,@aid,@taskname,@caseitem,@networkapp,@casetype,@casevalue,@headname,@headmobile,@deployarea,2,0,@mailwarn,@wmail,GETDATE(),@endtime,@remark,GETDATE(),@NetbarType)"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@uid", audit.Uid), new SqlParameter("@proid", audit.ProID), new SqlParameter("@cityid", audit.CityID), new SqlParameter("@aid", audit.AID), new SqlParameter("@taskname", audit.TaskName), new SqlParameter("@caseitem", audit.CaseItem), new SqlParameter("@networkapp", audit.NETWORK_APP), new SqlParameter("@casetype", audit.CaseType), new SqlParameter("@casevalue", audit.CaseValue), new SqlParameter("@headname", audit.HeadName), new SqlParameter("@headmobile", audit.HeadMobile), new SqlParameter("@deployarea", audit.DeployArea), new SqlParameter("@mailwarn", audit.MailWarn), new SqlParameter("@wmail", audit.WMail), new SqlParameter("@endtime", audit.EndTime), new SqlParameter("@remark", audit.Remark), new SqlParameter("@NetbarType", audit.NetbarType) }; return(SqlHelper.ExecuteNonQuery(SqlHelper.DBConnStr, CommandType.Text, sql, param)); }
/// <summary> /// 修改审计任务 /// </summary> /// <param name="audit"></param> /// <returns></returns> public int UpdateAudit(BKBJ.AuditInfo audit) { string sql = "UPDATE CasesInfo SET TaskName=@taskname,CaseItem=@caseitem,CaseValue=@casevalue,HeadName=@headname,HeadMobile=@headmobile,DeployArea=@deployarea,MailWarn=@mailwarn,WMail=@wmail,EndTime=@endtime,Remark=@remark,NETWORK_APP=@network_app,NetbarType=@NetbarType WHERE ID=@id"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@taskname", audit.TaskName), new SqlParameter("@caseitem", audit.CaseItem), new SqlParameter("@casevalue", audit.CaseValue), new SqlParameter("@headname", audit.HeadName), new SqlParameter("@headmobile", audit.HeadMobile), new SqlParameter("@deployarea", audit.DeployArea), new SqlParameter("@mailwarn", audit.MailWarn), new SqlParameter("@wmail", audit.WMail), new SqlParameter("@endtime", audit.EndTime), new SqlParameter("@remark", audit.Remark), new SqlParameter("@network_app", audit.NETWORK_APP), new SqlParameter("@NetbarType", audit.NetbarType), new SqlParameter("@id", audit.ID) }; return(SqlHelper.ExecuteNonQuery(SqlHelper.DBConnStr, CommandType.Text, sql, param)); }
public ActionResult EditIndex(FormCollection form) { try { AuditDAL auditdal = new AuditDAL(); UserInfo user = (UserInfo)Session["userInfo"]; BKBJ.AuditInfo audit = new BKBJ.AuditInfo(); audit.ID = Convert.ToInt32(form["ID"]); if (string.IsNullOrEmpty(form["txtTaskName"])) { return(Content("<script>alert('审计任务名称不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["txtCaseValue"])) { return(Content("<script>alert('审计条件不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["txtEndTime"])) { return(Content("<script>alert('审计有效时间不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["txtDeployArea"])) { return(Content("<script>alert('布控范围不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["cbtype"])) { return(Content("<script>alert('布控场所类别不能为空。');history.go(-1);</script>")); } if (auditdal.GetCaseTaskNameCount(form["txtTaskName"], audit.ID, user.ID) > 0) { return(Content("<script>alert('审计任务名称已存在,请重新输入。');history.go(-1);</script>")); } if (auditdal.GetCaseMobileCount(audit.ID, Convert.ToInt32(form["txtCaseItem"]), form["txtCaseValue"], -1, user.ID, 1) > 0) { return(Content("<script>alert('该" + (Convert.ToInt32(form["txtCaseItem"]) == 1 ? "手机号码" : (Convert.ToInt32(form["txtCaseItem"]) == 2 ? "MAC地址" : "IMEI")) + "已存在,请重新输入。');history.go(-1);</script>")); } audit.TaskName = form["txtTaskName"]; audit.Uid = user.ID; audit.ProID = user.ProID; audit.CityID = user.CityID; audit.AID = user.AId; audit.CaseItem = Convert.ToInt32(form["txtCaseItem"]); audit.CaseType = 1; audit.CaseValue = form["txtCaseValue"]; audit.NETWORK_APP = 0; audit.HeadName = form["txtHeadName"]; audit.HeadMobile = form["txtHeadMobile"]; audit.DeployArea = string.IsNullOrEmpty(form["ckAll"]) ? form["txtDeployArea"] : "0"; audit.IsEnabled = 2; audit.IsValid = 0; audit.MailWarn = Convert.ToInt32(form["txtMailWarn"]); audit.WMail = audit.MailWarn == 1 ? form["txtWMail"] : ""; audit.StartTime = DateTime.Now; audit.EndTime = Convert.ToDateTime(form["txtEndTime"]); audit.CreateTime = DateTime.Now; audit.Remark = form["txtRemark"]; audit.NetbarType = form["cbtype"]; if (new AuditDAL().UpdateAudit(audit) > 0) { log.What = "修改人员审计," + "用户ID:" + user.ID + ";审计ID:" + audit.ID + ";审计类型:" + (audit.CaseItem == 1 ? "手机号码" : (audit.CaseItem == 2 ? "MAC地址" : "IMEI")) + ";审计内容:" + audit.CaseValue; new OPLogDAL().InsertLog(log); return(Content("<script>alert('修改成功');location.replace('" + Url.Content("~/Warning/Index") + "');</script>")); } else { return(Content("<script>alert('修改失败');history.go(-1);</script>")); } } catch (SqlException sqlException) { Logger.ErrorLog(sqlException, new Dictionary <string, string>() { { "Function", "AuditController.AddPersonAudit" } }); return(Content("<script>alert('修改失败,请稍后重试!');history.go(-1);</script>")); } }
public ActionResult AddIndex(FormCollection form) { AuditDAL auditdal = new AuditDAL(); UserInfo user = (UserInfo)Session["userInfo"]; BKBJ.AuditInfo audit = new BKBJ.AuditInfo(); try { if (form["txtCaseItem"] == "3") { if (Request.Files.Count >= 1 && Request.Files[0] != null) { HttpPostedFileBase file = Request.Files[0]; string path = Server.MapPath("~/UserData/Warning/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string ext = file.FileName.Substring(file.FileName.LastIndexOf(".")).Split('.')[1].ToString(); if (!(ext.ToLower() == "txt")) { return(Content("<script>alert('只支持后缀名为txt的文件格式');history.go(-1);</script>")); } else if (file.ContentLength == 0) { return(Content("<script>alert('导入文件不能为空');history.go(-1);</script>")); } else if (file.ContentLength > 20 * 1024 * 1024) { return(Content("<script>alert('文件不能大于20MB');history.go(-1);</script>")); } string extendName = file.FileName.Substring(file.FileName.LastIndexOf(".")).ToLower(); string wholePath = Path.Combine(path, DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + extendName); file.SaveAs(wholePath); string strval = string.Empty; FileStream fs = new FileStream(wholePath, FileMode.Open); StreamReader reader = new StreamReader(fs, Encoding.Default); int ErrNum = 0; int Count = 0; int skip = 0; while ((strval = reader.ReadLine()) != null) { if (strval.Contains("|")) { string[] TempArray = strval.Split('|'); for (int i = 0; i < TempArray.Length; i++) { audit.TaskName = i == 0 ? "黑名单:" + TempArray[0] : "黑名单:" + TempArray[1]; audit.Uid = user.ID; audit.ProID = user.ProID; audit.CityID = user.CityID; audit.AID = user.AId; audit.CaseItem = Convert.ToInt32(form["txtCaseItem"]); audit.CaseType = 1; audit.CaseValue = TempArray[i]; audit.NETWORK_APP = 0; audit.HeadName = form["txtHeadName"]; audit.HeadMobile = form["txtHeadMobile"]; audit.DeployArea = string.IsNullOrEmpty(form["ckAll"]) ? form["txtDeployArea"] : "0"; audit.IsEnabled = 2; audit.IsValid = 0; audit.MailWarn = Convert.ToInt32(form["txtMailWarn"]); audit.WMail = audit.MailWarn == 1 ? form["txtWMail"] : ""; audit.StartTime = DateTime.Now; audit.EndTime = Convert.ToDateTime(form["txtEndTime"]); audit.CreateTime = DateTime.Now; audit.Remark = form["txtRemark"]; audit.NetbarType = form["cbtype"]; if (auditdal.GetCaseTaskNameCount(audit.TaskName, 0, user.ID) > 0) { skip = skip + 1; //DirectoryInfo difo = new DirectoryInfo(file.FileName); //string path = difo.Parent.ToString(); //StreamWriter sw = new StreamWriter(file + "/布控失败" + difo.Name, true, Encoding.Default); //sw.WriteLine(string.Join("|", TempArray)); //sw.Close(); //sw.Dispose(); } else { if (new AuditDAL().AddAudit(audit) > 0) { log.What = "添加人员审计," + "用户ID:" + user.ID + ";审计类型:" + (audit.CaseItem == 1 ? "手机号码" : (audit.CaseItem == 2 ? "MAC地址" : "批量导入")) + ";审计内容:" + audit.CaseValue; } else { ErrNum = ErrNum + 1; } } } } Count = Count + 1; } fs.Close(); fs.Dispose(); reader.Close(); reader.Dispose(); return(Content("<script>alert('操作完成,成功‘" + ((Count - ErrNum - skip) > 0 ? (Count - ErrNum - skip) : 0) + "’条!,跳过重复添加‘" + (skip) + "’条,失败‘" + ErrNum + "’条,请重新添加。');location.replace('" + Url.Content("~/Warning/Index") + "');</script>")); } } else { if (string.IsNullOrEmpty(form["txtTaskName"])) { return(Content("<script>alert('布控任务名称不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["txtCaseItem"])) { return(Content("<script>alert('布控类型不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["keyWord"])) { return(Content("<script>alert('布控内容不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["txtEndTime"])) { return(Content("<script>alert('布控有效时间不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["txtDeployArea"])) { return(Content("<script>alert('布控范围不能为空。');history.go(-1);</script>")); } if (string.IsNullOrEmpty(form["cbtype"])) { return(Content("<script>alert('布控场所类别不能为空。');history.go(-1);</script>")); } if (auditdal.GetCaseTaskNameCount(form["txtTaskName"], 0, user.ID) > 0) { return(Content("<script>alert('布控任务名称已存在,请重新输入。');history.go(-1);</script>")); } if (auditdal.GetCaseMobileCount(0, Convert.ToInt32(form["txtCaseItem"]), form["txtCaseValue"], -1, user.ID, 1) > 0) { return(Content("<script>alert('该" + (Convert.ToInt32(form["txtCaseItem"]) == 1 ? "手机号码" : (Convert.ToInt32(form["txtCaseItem"]) == 2 ? "MAC地址" : "IMEI")) + "已存在,请重新输入。');history.go(-1);</script>")); } audit.TaskName = form["txtTaskName"]; audit.Uid = user.ID; audit.ProID = user.ProID; audit.CityID = user.CityID; audit.AID = user.AId; audit.CaseItem = Convert.ToInt32(form["txtCaseItem"]); audit.CaseType = 1; audit.CaseValue = form["txtCaseValue"]; audit.NETWORK_APP = 0; audit.HeadName = form["txtHeadName"]; audit.HeadMobile = form["txtHeadMobile"]; audit.DeployArea = string.IsNullOrEmpty(form["ckAll"]) ? form["txtDeployArea"] : "0"; audit.IsEnabled = 2; audit.IsValid = 0; audit.MailWarn = Convert.ToInt32(form["txtMailWarn"]); audit.WMail = audit.MailWarn == 1 ? form["txtWMail"] : ""; audit.StartTime = DateTime.Now; audit.EndTime = Convert.ToDateTime(form["txtEndTime"]); audit.CreateTime = DateTime.Now; audit.Remark = form["txtRemark"]; audit.NetbarType = form["cbtype"]; if (new AuditDAL().AddAudit(audit) > 0) { log.What = "添加人员审计," + "用户ID:" + user.ID + ";审计类型:" + (audit.CaseItem == 1 ? "手机号码" : (audit.CaseItem == 2 ? "MAC地址" : "批量导入")) + ";审计内容:" + audit.CaseValue; return(Content("<script>alert('添加成功');location.replace('" + Url.Content("~/Warning/Index") + "');</script>")); } else { return(Content("<script>alert('添加失败');history.go(-1);</script>")); } } } catch (SqlException sqlException) { Logger.ErrorLog(sqlException, null); return(Content("<script>alert('添加失败,请稍后重试!');history.go(-1);</script>")); } catch (Exception ex) { Logger.ErrorLog(ex, null); return(Content("<script>alert('添加失败');history.go(-1);</script>")); } return(View()); }