Exemplo n.º 1
0
 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>"));
     }
 }
Exemplo n.º 2
0
        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());
        }