예제 #1
0
        public ActionResult EditModule(string Set, int Id)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    var Module = db.SysThemeSets.Where(m => m.SysLibraryId == Id).AsNoTracking().FirstOrDefault();
                    if (Module != null)
                    {
                        SysThemeSet sysModule = new SysThemeSet()
                        {
                            ID        = Module.ID,
                            SysSeting = Set,
                            EditTime  = DateTime.Now,
                        };

                        db.Entry(sysModule).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysModule).Property(x => x.SysStyle).IsModified     = false;
                        db.Entry(sysModule).Property(x => x.SysLibraryId).IsModified = false;
                        db.Entry(sysModule).Property(x => x.CrateTime).IsModified    = false;
                        db.Entry(sysModule).Property(x => x.IsEnable).IsModified     = false;
                        db.Entry(sysModule).Property(x => x.DelState).IsModified     = false;
                        db.SaveChanges();
                    }
                    else
                    {
                        SysThemeSet sysModule = new SysThemeSet()
                        {
                            SysStyle     = 1,
                            SysSeting    = Set,
                            SysLibraryId = Id,
                            CrateTime    = DateTime.Now,
                            EditTime     = DateTime.Now,
                            IsEnable     = 0,
                            DelState     = 0
                        };
                        db.SysThemeSets.Add(sysModule);
                        //添加
                        db.SaveChanges();
                    }

                    Lg.AddLog("修改主题", "Module", 2, GetUserName());

                    //推送更新
                    PushUpdate(Id, "主题更新", 6);

                    return(Json(new { code = "200", msg = "修改成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("内容状态修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联/系管理员!" }));
            }
        }
예제 #2
0
        public ActionResult CustDeviceEditEnable(int id, int enable)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    SysCustDevice sysCustDevice = new SysCustDevice()
                    {
                        ID       = id,
                        IsEnable = enable,
                        EditTime = DateTime.Now
                    };

                    db.Entry(sysCustDevice).State = EntityState.Modified;
                    //不更新的字段
                    db.Entry(sysCustDevice).Property(x => x.CustDeviceName).IsModified = false;
                    db.Entry(sysCustDevice).Property(x => x.Uuid).IsModified           = false;
                    db.Entry(sysCustDevice).Property(x => x.DataGuid).IsModified       = false;
                    db.Entry(sysCustDevice).Property(x => x.SysLibraryId).IsModified   = false;
                    db.Entry(sysCustDevice).Property(x => x.CrateTime).IsModified      = false;
                    db.Entry(sysCustDevice).Property(x => x.DelState).IsModified       = false;
                    db.SaveChanges();

                    Lg.AddLog("修改客流设备状态", "Other", 2, GetUserName());
                    return(Json(new { code = "200", msg = "修改成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("客流设备状态修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联/系管理员!" }));
            }
        }
예제 #3
0
        //添加日志
        public void AddLog(string Details, string Modular, int Type, string UserName)
        {
            string ip     = IpHelper.GetWebClientIp();
            Action action = new Action(() =>
            {
                try
                {
                    using (DataWallContext db = new DataWallContext())
                    {
                        string city      = IpHelper.GetCity(ip);
                        SysLog sysLog    = new SysLog();
                        sysLog.Type      = Type;
                        sysLog.Modular   = Modular;
                        sysLog.Details   = Details;
                        sysLog.UserName  = UserName;
                        sysLog.CrateTime = DateTime.Now;
                        sysLog.Ip        = ip;
                        sysLog.Address   = city;
                        db.SysLogs.Add(sysLog);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.ErrorLog(Details + "操作日志添加失败!" + ex.Message);
                }
            });

            action.BeginInvoke(null, null);
        }
예제 #4
0
        public ActionResult EditEnable(int id, int enable)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    SysLibrary sysLibrary = new SysLibrary()
                    {
                        ID       = id,
                        IsEnable = enable,
                        EditTime = DateTime.Now
                    };

                    db.Entry(sysLibrary).State = EntityState.Modified;
                    //不更新的字段
                    db.Entry(sysLibrary).Property(x => x.LibraryName).IsModified     = false;
                    db.Entry(sysLibrary).Property(x => x.LibraryDescribe).IsModified = false;
                    db.Entry(sysLibrary).Property(x => x.Type).IsModified            = false;
                    db.Entry(sysLibrary).Property(x => x.City).IsModified            = false;
                    db.Entry(sysLibrary).Property(x => x.LibraryCode).IsModified     = false;
                    db.Entry(sysLibrary).Property(x => x.CrateTime).IsModified       = false;
                    db.Entry(sysLibrary).Property(x => x.DelState).IsModified        = false;
                    db.SaveChanges();

                    Lg.AddLog("修改场馆状态", "Library", 2, GetUserName());
                    return(Json(new { code = "200", msg = "修改成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("场馆状态修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联/系管理员!" }));
            }
        }
예제 #5
0
        public void CustCountingServlet([FromBody] string value)
        {
            try
            {
                HttpContextBase context  = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context
                HttpRequestBase request  = context.Request;                                       //定义传统request对象
                string          uuid     = request["uuid"];
                string          dataguid = request["dataguid"];
                string          innum    = request["innum"];
                string          outnum   = request["outnum"];
                string          curtime  = request["curtime"];
                string          accessid = request["accessid"];

                using (DataWallContext db = new DataWallContext())
                {
                    SysCustDevice sysCustDevice = db.SysCustDevices.Where(s => s.Uuid == uuid & s.DataGuid == dataguid).FirstOrDefault();
                    if (sysCustDevice != null)
                    {
                        SysCustData sysCustData = new SysCustData()
                        {
                            SysCustDeviceId = sysCustDevice.ID,
                            D_Date          = DateTime.Parse(curtime),
                            D_InNum         = int.Parse(innum),
                            D_OutNum        = int.Parse(outnum)
                        };
                        db.SysCustDatas.Add(sysCustData);
                        db.SaveChanges();

                        LogHelper.InfoLog("客流数据插入成功,入馆:" + innum + ";出馆:" + outnum);

                        //推送客流更新
                        string ToLibraryName = db.SysLibrarys.Find(sysCustDevice.SysLibraryId).LibraryName;
                        int    type          = 3;
                        var    msg           = "客流数据更新";
                        MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new
                        {
                            msg    = msg,
                            action = "Other",
                            type   = type
                        }));
                    }
                    else
                    {
                        LogHelper.ErrorLog("客流设备不存在;uuid:" + request["uuid"] + ",dataguid:" + request["dataguid"]);
                    }
                    HttpContext.Current.Response.Charset         = "GB2312";
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    HttpContext.Current.Response.Write("JunYuFr_CustFlow_ReturnCode=0");
                    HttpContext.Current.Response.End();
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("客流数据插入失败:" + ex.ToString());
                HttpContext.Current.Response.Charset         = "GB2312";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                HttpContext.Current.Response.Write("JunYuFr_CustFlow_ReturnCode=0");
                HttpContext.Current.Response.End();
            }
        }
예제 #6
0
        public ActionResult DelLibraryUser(int id, int LibraryId)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    SysLibraryUser sysLibraryUser = db.SysLibraryUsers.FirstOrDefault(u => u.SysUserID == id & u.SysLibraryId == LibraryId);
                    string         RoleName       = "";
                    foreach (var item in db.SysUsers.AsNoTracking().FirstOrDefault(u => u.ID == sysLibraryUser.SysUserID).SysUserRoles)
                    {
                        RoleName = item.SysRole.RoleName;
                    }
                    if (RoleName != "Administrator")
                    {
                        db.SysLibraryUsers.Remove(sysLibraryUser);
                        db.SaveChanges();

                        Lg.AddLog("删除场馆", "Library", 3, GetUserName());

                        return(Json(new { code = "200", msg = "删除成功!" }));
                    }
                    else
                    {
                        return(Json(new { code = "201", msg = "管理员用户不可删除!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("场馆用户删除失败:" + ex.Message);
                return(Json(new { code = "201", msg = "删除失败,请重试或联/系管理员!" }));
            }
        }
예제 #7
0
        public ActionResult AddLibraryUser(int id, int LibraryId)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    if (db.SysLibraryUsers.Where(lu => lu.SysUserID == id && lu.SysLibraryId == LibraryId).AsNoTracking().Count() == 0)
                    {
                        SysLibraryUser sysLibraryUser = new SysLibraryUser()
                        {
                            SysUserID    = id,
                            SysLibraryId = LibraryId
                        };

                        db.SysLibraryUsers.Add(sysLibraryUser);
                        db.SaveChanges();

                        Lg.AddLog("添加场馆", "Library", 1, GetUserName());

                        return(Json(new { code = "200", msg = "添加成功!" }));
                    }
                    else
                    {
                        return(Json(new { code = "201", msg = "用户已存在于该场馆用户列表中!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("场馆用户添加失败:" + ex.Message);
                return(Json(new { code = "201", msg = "添加失败,请重试或联/系管理员!" }));
            }
        }
예제 #8
0
        public ActionResult CustDeviceAdd(FormCollection CustDevice)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    //当前用户可管理场馆
                    List <SysLibrary> libList = GetLibraryList();
                    if (libList.Count == 0)
                    {
                        return(Json(new { code = "202", msg = "当前用户未分配可管理场馆,请联系系统管理员!" }));
                    }
                    ViewData["datalist"] = libList;

                    //客流设备
                    if (CustDevice["Library"] != null)
                    {
                        string CustDeviceName = CustDevice["CustDeviceName"];
                        if (db.SysCustDevices.Where(d => d.CustDeviceName == DbFunctions.AsNonUnicode(CustDeviceName)).AsNoTracking().Count() >= 1)
                        {
                            return(Json(new { code = "202", msg = "设备名已存在!" }));
                        }
                        int    LibraryId   = int.Parse(CustDevice["Library"]);
                        string LibraryName = db.SysLibrarys.Find(LibraryId).LibraryName;
                        string Uuid        = PingYinHelper.GetFirstSpell(LibraryName + CustDevice["CustDeviceName"]) + DateTime.Now.Millisecond;
                        string DataGuid    = System.Guid.NewGuid().ToString("D");

                        SysCustDevice sysCustDevice = new SysCustDevice()
                        {
                            CustDeviceName = CustDevice["CustDeviceName"],
                            Uuid           = Uuid,
                            DataGuid       = DataGuid,
                            SysLibraryId   = LibraryId,
                            CrateTime      = DateTime.Now,
                            EditTime       = DateTime.Now,
                            IsEnable       = 0,
                            DelState       = 0
                        };

                        db.SysCustDevices.Add(sysCustDevice);

                        //添加客流设备
                        db.SaveChanges();

                        Lg.AddLog("添加客流设备", "Other", 1, GetUserName());

                        return(Json(new { code = "200", msg = "添加成功!" }));
                    }
                    else
                    {
                        return(Json(new { code = "202", msg = "请选择内容所属场馆!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("客流设备添加失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联系管理员!" }));
            }
        }
예제 #9
0
 //添加用户
 public void Add(SysUser sysUser)
 {
     using (DataWallContext db = new DataWallContext())
     {
         db.SysUsers.Add(sysUser);
         db.SaveChanges();
     }
 }
예제 #10
0
        public ActionResult DelAdditionalData(int id, int page)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    SysAdditionalData sysAdditionalData = new SysAdditionalData()
                    {
                        ID       = id,
                        DelState = 1,
                        EditTime = DateTime.Now
                    };

                    db.Entry(sysAdditionalData).State = EntityState.Modified;
                    //不更新的字段
                    db.Entry(sysAdditionalData).Property(x => x.Type).IsModified           = false;
                    db.Entry(sysAdditionalData).Property(x => x.PeopleNum).IsModified      = false;
                    db.Entry(sysAdditionalData).Property(x => x.BookNum).IsModified        = false;
                    db.Entry(sysAdditionalData).Property(x => x.StillPeopleNum).IsModified = false;
                    db.Entry(sysAdditionalData).Property(x => x.StillBookNum).IsModified   = false;
                    db.Entry(sysAdditionalData).Property(x => x.DataDatetime).IsModified   = false;
                    db.Entry(sysAdditionalData).Property(x => x.SysLibraryId).IsModified   = false;
                    db.Entry(sysAdditionalData).Property(x => x.CrateTime).IsModified      = false;
                    db.Entry(sysAdditionalData).Property(x => x.IsEnable).IsModified       = false;
                    db.SaveChanges();
                    int    npage   = 0;
                    int    Count   = db.SysAdditionalDatas.Where(u => u.DelState == 0).Count();
                    double MaxPage = Convert.ToDouble(Convert.ToDouble(Count + 10) / Convert.ToDouble(10));
                    if (MaxPage > page)
                    {
                        npage = page;
                    }
                    else
                    {
                        if (Count <= 10)
                        {
                            npage = 1;
                        }
                        else
                        {
                            npage = page - 1;
                        }
                    }

                    Lg.AddLog("删除额外数据", "Other", 3, GetUserName());

                    return(Json(new { code = "200", page = npage, msg = "删除成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("额外数据删除失败:" + ex.Message);
                return(Json(new { code = "201", msg = "删除失败,请重试或联/系管理员!" }));
            }
        }
예제 #11
0
        public ActionResult UserEdit(FormCollection User)
        {
            try
            {
                if (Check("UserEdit", int.Parse(User["ID"]), User["UserName"]))
                {
                    using (DataWallContext db = new DataWallContext())
                    {
                        SysUser sysUser = new SysUser()
                        {
                            ID       = int.Parse(User["ID"]),
                            UserName = User["UserName"],
                            Email    = User["Email"],
                            EditTime = DateTime.Now
                        };

                        db.Entry(sysUser).State = EntityState.Modified;

                        //修改密码
                        if (!string.IsNullOrEmpty(User["Password"]))
                        {
                            sysUser.Password = MD5Helper.MD5Encrypt32(User["Password"]);
                        }
                        //不修改密码
                        else
                        {
                            //不更新的字段
                            db.Entry(sysUser).Property(x => x.Password).IsModified = false;
                        }
                        //不更新的字段
                        db.Entry(sysUser).Property(x => x.CrateTime).IsModified = false;
                        db.Entry(sysUser).Property(x => x.IsEnable).IsModified  = false;
                        db.Entry(sysUser).Property(x => x.DelState).IsModified  = false;
                        db.SaveChanges();

                        Lg.AddLog("修改用户", "User", 2, GetUserName());

                        return(Json(new { code = "200", msg = "修改成功!" }));
                    }
                }
                else
                {
                    return(Json(new { code = "202", msg = "用户名已存在!" }));
                }
            }
            catch (Exception ex)
            {
                if (User.Count > 0)
                {
                    LogHelper.ErrorLog("用户修改失败:" + ex.Message);
                }

                return(Json(new { code = "201", msg = "修改失败,请重试或联系管理员!" }));
            }
        }
예제 #12
0
        public ActionResult DelLibrary(int id, int page)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    SysLibrary sysLibrary = new SysLibrary()
                    {
                        ID       = id,
                        DelState = 1,
                        EditTime = DateTime.Now
                    };

                    db.Entry(sysLibrary).State = EntityState.Modified;
                    //不更新的字段
                    db.Entry(sysLibrary).Property(x => x.LibraryName).IsModified     = false;
                    db.Entry(sysLibrary).Property(x => x.LibraryDescribe).IsModified = false;
                    db.Entry(sysLibrary).Property(x => x.Type).IsModified            = false;
                    db.Entry(sysLibrary).Property(x => x.City).IsModified            = false;
                    db.Entry(sysLibrary).Property(x => x.LibraryCode).IsModified     = false;
                    db.Entry(sysLibrary).Property(x => x.CrateTime).IsModified       = false;
                    db.Entry(sysLibrary).Property(x => x.IsEnable).IsModified        = false;
                    db.SaveChanges();
                    int    npage   = 0;
                    int    Count   = db.SysLibrarys.Where(u => u.DelState == 0).AsNoTracking().Count();
                    double MaxPage = Convert.ToDouble(Convert.ToDouble(Count + 10) / Convert.ToDouble(10));
                    if (MaxPage > page)
                    {
                        npage = page;
                    }
                    else
                    {
                        if (Count <= 10)
                        {
                            npage = 1;
                        }
                        else
                        {
                            npage = page - 1;
                        }
                    }

                    Lg.AddLog("删除场馆", "Library", 3, GetUserName());

                    return(Json(new { code = "200", page = npage, msg = "删除成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("场馆删除失败:" + ex.Message);
                return(Json(new { code = "201", msg = "删除失败,请重试或联/系管理员!" }));
            }
        }
예제 #13
0
        public ActionResult CustDeviceEdit(FormCollection CustDevice)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    //当前用户可管理场馆
                    List <SysLibrary> libList = GetLibraryList();
                    if (libList.Count == 0)
                    {
                        return(Json(new { code = "202", msg = "当前用户未分配可管理场馆,请联系系统管理员!" }));
                    }
                    ViewData["datalist"] = libList;

                    //客流设备
                    if (CustDevice["Library"] != null)
                    {
                        SysCustDevice sysCustDevice = new SysCustDevice()
                        {
                            ID             = int.Parse(CustDevice["ID"]),
                            CustDeviceName = CustDevice["CustDeviceName"],
                            SysLibraryId   = int.Parse(CustDevice["Library"]),
                            EditTime       = DateTime.Now
                        };

                        db.Entry(sysCustDevice).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysCustDevice).Property(x => x.Uuid).IsModified      = false;
                        db.Entry(sysCustDevice).Property(x => x.DataGuid).IsModified  = false;
                        db.Entry(sysCustDevice).Property(x => x.CrateTime).IsModified = false;
                        db.Entry(sysCustDevice).Property(x => x.IsEnable).IsModified  = false;
                        db.Entry(sysCustDevice).Property(x => x.DelState).IsModified  = false;

                        db.SaveChanges();

                        Lg.AddLog("修改客流设备", "Other", 2, GetUserName());

                        return(Json(new { code = "200", msg = "修改成功!" }));
                    }
                    else
                    {
                        return(Json(new { code = "202", msg = "请选择内容所属场馆!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("客流设备修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联系管理员!" }));
            }
        }
예제 #14
0
        public ActionResult UserAdd(FormCollection User)
        {
            try
            {
                if (Check("UserAdd", 0, User["UserName"]))
                {
                    using (DataWallContext db = new DataWallContext())
                    {
                        //用户
                        SysUser sysUser = new SysUser();
                        sysUser.UserName  = User["UserName"];
                        sysUser.Email     = User["Email"];
                        sysUser.Password  = MD5Helper.MD5Encrypt32(User["Password"]);
                        sysUser.IsEnable  = 0;
                        sysUser.CrateTime = DateTime.Now;
                        sysUser.EditTime  = DateTime.Now;
                        sysUser.DelState  = 0;
                        db.SysUsers.Add(sysUser);

                        //权限
                        var sysUserRoles = new List <SysUserRole> {
                            new SysUserRole {
                                SysUserID = sysUser.ID, SysRoleId = 2
                            }
                        };
                        sysUserRoles.ForEach(s => db.SysUserRoles.Add(s));

                        //添加
                        db.SaveChanges();

                        Lg.AddLog("添加用户", "User", 1, GetUserName());

                        return(Json(new { code = "200", msg = "添加成功!" }));
                    }
                }
                else
                {
                    return(Json(new { code = "202", msg = "用户名已存在!" }));
                }
            }
            catch (Exception ex)
            {
                if (User.Count > 0)
                {
                    LogHelper.ErrorLog("用户添加失败:" + ex.Message);
                }

                return(Json(new { code = "201", msg = "添加失败,请重试或联/系管理员!" }));
            }
        }
예제 #15
0
 //删除用户
 public bool Delete(int id)
 {
     using (DataWallContext db = new DataWallContext())
     {
         var delSysUser = db.SysUsers.FirstOrDefault(u => u.ID == id);
         if (delSysUser != null)
         {
             db.SysUsers.Remove(delSysUser);
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #16
0
        public ActionResult EditEnable(int id, int enable)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    string RoleName = "";
                    foreach (var item in db.SysUsers.AsNoTracking().FirstOrDefault(u => u.ID == id).SysUserRoles)
                    {
                        RoleName = item.SysRole.RoleName;
                    }
                    if (RoleName != "Administrator")
                    {
                        SysUser sysUser = new SysUser()
                        {
                            ID       = id,
                            IsEnable = enable,
                            EditTime = DateTime.Now
                        };

                        db.Entry(sysUser).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysUser).Property(x => x.UserName).IsModified  = false;
                        db.Entry(sysUser).Property(x => x.Email).IsModified     = false;
                        db.Entry(sysUser).Property(x => x.Password).IsModified  = false;
                        db.Entry(sysUser).Property(x => x.CrateTime).IsModified = false;
                        db.Entry(sysUser).Property(x => x.DelState).IsModified  = false;
                        db.SaveChanges();

                        Lg.AddLog("修改用户状态", "User", 2, GetUserName());
                        return(Json(new { code = "200", msg = "修改成功!" }));
                    }
                    else
                    {
                        LogHelper.ErrorLog("管理员状态修改失败");
                        return(Json(new { code = "201", msg = "超级管理员用户不可进行该操作!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("用户状态修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联/系管理员!" }));
            }
        }
예제 #17
0
        public ActionResult AdditionalDataEditEnable(int id, int enable)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    SysAdditionalData sysAdditionalData = new SysAdditionalData()
                    {
                        ID       = id,
                        IsEnable = enable,
                        EditTime = DateTime.Now
                    };

                    db.Entry(sysAdditionalData).State = EntityState.Modified;
                    //不更新的字段
                    db.Entry(sysAdditionalData).Property(x => x.Type).IsModified           = false;
                    db.Entry(sysAdditionalData).Property(x => x.PeopleNum).IsModified      = false;
                    db.Entry(sysAdditionalData).Property(x => x.BookNum).IsModified        = false;
                    db.Entry(sysAdditionalData).Property(x => x.StillPeopleNum).IsModified = false;
                    db.Entry(sysAdditionalData).Property(x => x.StillBookNum).IsModified   = false;
                    db.Entry(sysAdditionalData).Property(x => x.DataDatetime).IsModified   = false;
                    db.Entry(sysAdditionalData).Property(x => x.SysLibraryId).IsModified   = false;
                    db.Entry(sysAdditionalData).Property(x => x.CrateTime).IsModified      = false;
                    db.Entry(sysAdditionalData).Property(x => x.DelState).IsModified       = false;
                    db.SaveChanges();

                    Lg.AddLog("修改额外数据状态", "Other", 2, GetUserName());
                    return(Json(new { code = "200", msg = "修改成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("额外数据状态修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联/系管理员!" }));
            }
        }
예제 #18
0
        public ActionResult LibraryAdd(FormCollection Library)
        {
            try
            {
                if (Check("LibraryAdd", 0, Library["LibraryName"]))
                {
                    using (DataWallContext db = new DataWallContext())
                    {
                        int               Type           = int.Parse(Library["Type"]);
                        SysProgramInfo    sysProgramInfo = db.SysProgramInfos.AsNoTracking().FirstOrDefault();
                        List <SysLibrary> sysLibraryList = db.SysLibrarys.AsNoTracking().Where(s => s.DelState == 0).ToList();
                        switch (Type)
                        {
                        case 0:
                            if (sysLibraryList.Where(s => s.Type == 0).Count() >= sysProgramInfo.MasterNum)
                            {
                                return(Json(new { code = "202", msg = "总馆数量已达上限" }));
                            }
                            break;

                        case 1:
                            if (sysLibraryList.Where(s => s.Type == 1).Count() >= sysProgramInfo.BranchNum)
                            {
                                return(Json(new { code = "202", msg = "分馆数量已达上限" }));
                            }
                            break;
                        }
                        //场馆
                        int FatherLibraryId = 0;
                        if (Type == 0)
                        {
                            FatherLibraryId = 0;
                        }
                        else
                        {
                            if (Library["FatherLibraryId"] == null)
                            {
                                return(Json(new { code = "201", msg = "请选择上级场馆" }));
                            }
                            FatherLibraryId = int.Parse(Library["FatherLibraryId"]);
                        }
                        string     LibraryName = Library["LibraryName"];
                        string     LibraryCode = PingYinHelper.GetFirstSpell(Library["LibraryName"]) + DateTime.Now.Millisecond;
                        SysLibrary sysLibrary  = new SysLibrary()
                        {
                            City            = "上海",
                            LibraryName     = LibraryName,
                            FatherLibraryId = FatherLibraryId,
                            LibraryDescribe = HttpUtility.UrlDecode(Library["Describe"]).Replace("'", "‘"),
                            Type            = Type,
                            LibraryCode     = LibraryCode,
                            CrateTime       = DateTime.Now,
                            EditTime        = DateTime.Now,
                            IsEnable        = 0,
                            DelState        = 0
                        };

                        db.SysLibrarys.Add(sysLibrary);
                        //添加
                        db.SaveChanges();

                        //添加管理员为管理用户
                        int SysLibraryId = sysLibrary.ID;
                        List <SysLibraryUser> sysLibraryUsers = new List <SysLibraryUser> {
                            new SysLibraryUser {
                                SysUserID = 1, SysLibraryId = SysLibraryId
                            }
                        };
                        sysLibraryUsers.ForEach(s => db.SysLibraryUsers.Add(s));

                        //添加
                        db.SaveChanges();

                        Lg.AddLog("添加场馆", "Library", 1, GetUserName());

                        return(Json(new { code = "200", msg = "添加成功!" }));
                    }
                }
                else
                {
                    return(Json(new { code = "202", msg = "场馆已存在!" }));
                }
            }
            catch (Exception ex)
            {
                if (Library.Count > 0)
                {
                    LogHelper.ErrorLog("场馆添加失败:" + ex.Message);
                }

                return(Json(new { code = "201", msg = "添加失败,请重试或联系管理员!" }));
            }
        }
예제 #19
0
        public ActionResult DelUser(int id, int page)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    string RoleName = "";
                    foreach (var item in db.SysUsers.AsNoTracking().FirstOrDefault(u => u.ID == id).SysUserRoles)
                    {
                        RoleName = item.SysRole.RoleName;
                    }
                    if (RoleName != "Administrator")
                    {
                        SysUser sysUser = new SysUser()
                        {
                            ID       = id,
                            DelState = 1,
                            EditTime = DateTime.Now
                        };

                        db.Entry(sysUser).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysUser).Property(x => x.UserName).IsModified  = false;
                        db.Entry(sysUser).Property(x => x.Email).IsModified     = false;
                        db.Entry(sysUser).Property(x => x.Password).IsModified  = false;
                        db.Entry(sysUser).Property(x => x.CrateTime).IsModified = false;
                        db.Entry(sysUser).Property(x => x.IsEnable).IsModified  = false;
                        db.SaveChanges();
                        int    npage   = 0;
                        int    Count   = db.SysUsers.Where(u => u.DelState == 0).AsNoTracking().Count();
                        double MaxPage = Convert.ToDouble(Convert.ToDouble(Count + 10) / Convert.ToDouble(10));
                        if (MaxPage > page)
                        {
                            npage = page;
                        }
                        else
                        {
                            if (Count <= 10)
                            {
                                npage = 1;
                            }
                            else
                            {
                                npage = page - 1;
                            }
                        }

                        Lg.AddLog("删除用户", "User", 3, GetUserName());

                        return(Json(new { code = "200", page = npage, msg = "删除成功!" }));
                    }
                    else
                    {
                        LogHelper.ErrorLog("管理员删除失败");
                        return(Json(new { code = "201", msg = "超级管理员用户不可进行该操作!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("用户删除失败:" + ex.Message);
                return(Json(new { code = "201", msg = "删除失败,请重试或联/系管理员!" }));
            }
        }
예제 #20
0
        public ActionResult DelUserAll(string idList, int page)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    //获取待删除用户id集
                    string[] sArray = idList.Split(',');
                    int[]    IdList = new int[sArray.Length];
                    for (int i = 0; i < sArray.Length; i++)
                    {
                        IdList[i] = Int32.Parse(sArray[i]);
                    }
                    for (int i = 0; i < IdList.Length; i++)
                    {
                        int id = IdList[i];

                        string RoleName = "";
                        foreach (var item in db.SysUsers.AsNoTracking().FirstOrDefault(u => u.ID == id).SysUserRoles)
                        {
                            RoleName = item.SysRole.RoleName;
                        }
                        if (RoleName != "Administrator")
                        {
                            SysUser sysUser = new SysUser()
                            {
                                ID       = id,
                                DelState = 1,
                                EditTime = DateTime.Now
                            };

                            db.Entry(sysUser).State = EntityState.Modified;
                            //不更新的字段
                            db.Entry(sysUser).Property(x => x.ID).IsModified        = false;
                            db.Entry(sysUser).Property(x => x.UserName).IsModified  = false;
                            db.Entry(sysUser).Property(x => x.Email).IsModified     = false;
                            db.Entry(sysUser).Property(x => x.Password).IsModified  = false;
                            db.Entry(sysUser).Property(x => x.CrateTime).IsModified = false;
                            db.Entry(sysUser).Property(x => x.IsEnable).IsModified  = false;
                            db.SaveChanges();
                        }
                    }
                    int    npage   = 0;
                    int    Count   = db.SysUsers.Where(u => u.DelState == 0).AsNoTracking().Count();
                    double MaxPage = Convert.ToDouble(Convert.ToDouble(Count + 10) / Convert.ToDouble(10));
                    if (MaxPage > page)
                    {
                        npage = page;
                    }
                    else
                    {
                        if (Count <= 10)
                        {
                            npage = 1;
                        }
                        else
                        {
                            if ((Count % 10) <= page)
                            {
                                npage = page - 1;
                            }
                        }
                    }

                    Lg.AddLog("删除用户", "User", 3, GetUserName());

                    return(Json(new { code = "200", page = npage, msg = "删除成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("用户删除失败:" + ex.Message);
                return(Json(new { code = "201", msg = "删除失败,请重试或联/系管理员!" }));
            }
        }
예제 #21
0
        public ActionResult DelLibraryAll(string idList, int page)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    //获取待删除场馆id集
                    string[] sArray = idList.Split(',');
                    int[]    IdList = new int[sArray.Length];
                    for (int i = 0; i < sArray.Length; i++)
                    {
                        IdList[i] = Int32.Parse(sArray[i]);
                    }
                    for (int i = 0; i < IdList.Length; i++)
                    {
                        int id = IdList[i];

                        SysLibrary sysLibrary = new SysLibrary()
                        {
                            ID       = id,
                            DelState = 1,
                            EditTime = DateTime.Now
                        };

                        db.Entry(sysLibrary).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysLibrary).Property(x => x.LibraryName).IsModified     = false;
                        db.Entry(sysLibrary).Property(x => x.LibraryDescribe).IsModified = false;
                        db.Entry(sysLibrary).Property(x => x.Type).IsModified            = false;
                        db.Entry(sysLibrary).Property(x => x.City).IsModified            = false;
                        db.Entry(sysLibrary).Property(x => x.LibraryCode).IsModified     = false;
                        db.Entry(sysLibrary).Property(x => x.CrateTime).IsModified       = false;
                        db.Entry(sysLibrary).Property(x => x.IsEnable).IsModified        = false;
                        db.SaveChanges();
                    }
                    int    npage   = 0;
                    int    Count   = db.SysLibrarys.Where(u => u.DelState == 0).AsNoTracking().Count();
                    double MaxPage = Convert.ToDouble(Convert.ToDouble(Count + 10) / Convert.ToDouble(10));
                    if (MaxPage > page)
                    {
                        npage = page;
                    }
                    else
                    {
                        if (Count <= 10)
                        {
                            npage = 1;
                        }
                        else
                        {
                            if ((Count % 10) <= page)
                            {
                                npage = page - 1;
                            }
                        }
                    }

                    Lg.AddLog("删除场馆", "User", 3, GetUserName());

                    return(Json(new { code = "200", page = npage, msg = "删除成功!" }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("场馆删除失败:" + ex.Message);
                return(Json(new { code = "201", msg = "删除失败,请重试或联/系管理员!" }));
            }
        }
예제 #22
0
        public ActionResult LibraryEdit(FormCollection Library)
        {
            try
            {
                if (Check("LibraryEdit", int.Parse(Library["ID"]), Library["LibraryName"]))
                {
                    using (DataWallContext db = new DataWallContext())
                    {
                        int               LbraryId       = int.Parse(Library["ID"]);
                        int               Type           = int.Parse(Library["Type"]);
                        SysProgramInfo    sysProgramInfo = db.SysProgramInfos.AsNoTracking().FirstOrDefault();
                        List <SysLibrary> sysLibraryList = db.SysLibrarys.AsNoTracking().Where(s => s.DelState == 0).ToList();
                        switch (Type)
                        {
                        case 0:
                            if (sysLibraryList.Where(s => s.Type == 0).Count() >= sysProgramInfo.MasterNum)
                            {
                                if (sysLibraryList.Where(s => s.Type == 0 & s.ID == LbraryId & s.DelState == 0).Count() < 1)
                                {
                                    return(Json(new { code = "202", msg = "总馆数量已达上限" }));
                                }
                            }
                            break;

                        case 1:
                            if (sysLibraryList.Where(s => s.Type == 1).Count() >= sysProgramInfo.BranchNum)
                            {
                                if (sysLibraryList.Where(s => s.Type == 1 & s.ID == LbraryId & s.DelState == 0).Count() < 1)
                                {
                                    return(Json(new { code = "202", msg = "分馆数量已达上限" }));
                                }
                            }
                            break;
                        }
                        //场馆
                        int FatherLibraryId = 0;
                        if (Type == 0)
                        {
                            FatherLibraryId = 0;
                        }
                        else
                        {
                            if (Library["FatherLibraryId"] == null)
                            {
                                return(Json(new { code = "201", msg = "请选择上级场馆" }));
                            }
                            FatherLibraryId = int.Parse(Library["FatherLibraryId"]);
                            if (int.Parse(Library["ID"]) == FatherLibraryId)
                            {
                                return(Json(new { code = "202", msg = "不可以选择自身为上级场馆" }));
                            }
                        }
                        string LibraryName = Library["LibraryName"];
                        string LibraryCode = PingYinHelper.GetFirstSpell(Library["LibraryName"]) + DateTime.Now.Millisecond;

                        SysLibrary sysLibrary = new SysLibrary()
                        {
                            ID              = LbraryId,
                            LibraryName     = Library["LibraryName"],
                            LibraryDescribe = HttpUtility.UrlDecode(Library["Describe"]).Replace("'", "‘"),
                            FatherLibraryId = FatherLibraryId,
                            Type            = int.Parse(Library["Type"]),
                            EditTime        = DateTime.Now
                        };

                        db.Entry(sysLibrary).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysLibrary).Property(x => x.City).IsModified        = false;
                        db.Entry(sysLibrary).Property(x => x.LibraryCode).IsModified = false;
                        db.Entry(sysLibrary).Property(x => x.CrateTime).IsModified   = false;
                        db.Entry(sysLibrary).Property(x => x.IsEnable).IsModified    = false;
                        db.Entry(sysLibrary).Property(x => x.DelState).IsModified    = false;
                        db.SaveChanges();

                        Lg.AddLog("修改场馆", "Library", 2, GetUserName());

                        return(Json(new { code = "200", msg = "修改成功!" }));
                    }
                }
                else
                {
                    return(Json(new { code = "202", msg = "场馆已存在!" }));
                }
            }
            catch (Exception ex)
            {
                if (Library.Count > 0)
                {
                    LogHelper.ErrorLog("场馆修改失败:" + ex.Message);
                }

                return(Json(new { code = "201", msg = "修改失败,请重试或联系管理员!" }));
            }
        }
예제 #23
0
        public ActionResult AdditionalDataEdit(FormCollection AdditionalData)
        {
            try
            {
                using (DataWallContext db = new DataWallContext())
                {
                    //当前用户可管理场馆
                    List <SysLibrary> libList = GetLibraryList();
                    if (libList.Count == 0)
                    {
                        return(Json(new { code = "202", msg = "当前用户未分配可管理场馆,请联系系统管理员!" }));
                    }
                    ViewData["datalist"] = libList;

                    //额外数据
                    if (AdditionalData["Library"] != null)
                    {
                        int BookNum        = 0;
                        int StillPeopleNum = 0;
                        int StillBookNum   = 0;

                        int    LibraryId     = int.Parse(AdditionalData["Library"]);
                        string ToLibraryName = db.SysLibrarys.Find(LibraryId).LibraryName;
                        if (AdditionalData["Type"] == "0")
                        {
                            BookNum        = 0;
                            StillPeopleNum = 0;
                            StillPeopleNum = 0;

                            int type = 3;
                            var msg  = "客流数据更新";
                            MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new
                            {
                                msg    = msg,
                                action = "Other",
                                type   = type
                            }));
                        }
                        else
                        {
                            BookNum        = int.Parse(AdditionalData["BookNum"]);
                            StillPeopleNum = int.Parse(AdditionalData["StillPeopleNum"]);
                            StillBookNum   = int.Parse(AdditionalData["StillBookNum"]);

                            int type = 4;
                            var msg  = "借还数据更新";
                            MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new
                            {
                                msg    = msg,
                                action = "Other",
                                type   = type
                            }));
                        }

                        SysAdditionalData sysAdditionalData = new SysAdditionalData()
                        {
                            ID             = int.Parse(AdditionalData["ID"]),
                            PeopleNum      = int.Parse(AdditionalData["PeopleNum"]),
                            BookNum        = BookNum,
                            StillPeopleNum = StillPeopleNum,
                            StillBookNum   = StillBookNum,
                            DataDatetime   = DateTime.Parse(AdditionalData["DataDatetime"]),
                            SysLibraryId   = int.Parse(AdditionalData["Library"]),
                            EditTime       = DateTime.Now
                        };

                        db.Entry(sysAdditionalData).State = EntityState.Modified;
                        //不更新的字段
                        db.Entry(sysAdditionalData).Property(x => x.Type).IsModified      = false;
                        db.Entry(sysAdditionalData).Property(x => x.CrateTime).IsModified = false;
                        db.Entry(sysAdditionalData).Property(x => x.IsEnable).IsModified  = false;
                        db.Entry(sysAdditionalData).Property(x => x.DelState).IsModified  = false;

                        db.SaveChanges();

                        Lg.AddLog("修改额外数据", "Other", 2, GetUserName());

                        return(Json(new { code = "200", msg = "修改成功!" }));
                    }
                    else
                    {
                        return(Json(new { code = "202", msg = "请选择内容所属场馆!" }));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("额外数据修改失败:" + ex.Message);
                return(Json(new { code = "201", msg = "修改失败,请重试或联系管理员!" }));
            }
        }
예제 #24
0
        public ActionResult UploadExcel(int Type)
        {
            int location = 0;

            try
            {
                var file       = Request.Files[0];
                var filecombin = file.FileName.Split('.');
                if (file == null || String.IsNullOrEmpty(file.FileName) || file.ContentLength == 0 || filecombin.Length < 2)
                {
                    return(Json(new
                    {
                        code = "201",
                        msg = "上传出错请检查文件名或文件内容"
                    }));
                }

                using (ExcelPackage package = new ExcelPackage(file.InputStream))
                {
                    int            count     = package.Workbook.Worksheets.Count;
                    ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
                    //获取表格的列数和行数
                    int rowCount           = worksheet.Dimension.Rows;
                    int ColCount           = worksheet.Dimension.Columns;
                    var sysAdditionalDatas = new List <SysAdditionalData>();
                    //插入数据
                    using (DataWallContext db = new DataWallContext())
                    {
                        for (int row = 2; row <= rowCount; row++)
                        {
                            location = row;
                            int      PeopleNum      = 0;
                            int      BookNum        = 0;
                            int      StillPeopleNum = 0;
                            int      StillBookNum   = 0;
                            DateTime DataDatetime   = DateTime.Now;

                            switch (Type)
                            {
                            case 0:
                                PeopleNum    = int.Parse(worksheet.Cells[row, 3].Value.ToString());
                                DataDatetime = DateTime.Parse(worksheet.Cells[row, 4].Value.ToString());
                                break;

                            case 1:
                                PeopleNum      = int.Parse(worksheet.Cells[row, 3].Value.ToString());
                                BookNum        = int.Parse(worksheet.Cells[row, 4].Value.ToString());
                                StillPeopleNum = int.Parse(worksheet.Cells[row, 5].Value.ToString());
                                StillBookNum   = int.Parse(worksheet.Cells[row, 6].Value.ToString());
                                DataDatetime   = DateTime.Parse(worksheet.Cells[row, 7].Value.ToString());
                                break;
                            }

                            SysAdditionalData sysAdditionalData = new SysAdditionalData()
                            {
                                PeopleNum      = PeopleNum,
                                BookNum        = BookNum,
                                StillPeopleNum = StillPeopleNum,
                                StillBookNum   = StillBookNum,
                                DataDatetime   = DataDatetime,
                                SysLibraryId   = int.Parse(worksheet.Cells[row, 2].Value.ToString()),
                                CrateTime      = DateTime.Now,
                                EditTime       = DateTime.Now,
                                DelState       = 0,
                                Type           = Type
                            };

                            sysAdditionalDatas.Add(sysAdditionalData);

                            //数据检查
                            if (!CheckLibraryId(worksheet.Cells[row, 2].Value.ToString(), worksheet.Cells[row, 1].Value.ToString()))
                            {
                                return(Json(new
                                {
                                    code = "201",
                                    msg = "场馆不存在或您没有场馆" + worksheet.Cells[row, 1].Value.ToString() + "(ID:" + worksheet.Cells[row, 2].Value.ToString() + ")" + "的数据导入权限"
                                }));
                            }

                            //推送客流更新
                            string ToLibraryName = db.SysLibrarys.Find(sysAdditionalData.SysLibraryId).LibraryName;
                            int    type          = 3;
                            var    msg           = "客流数据更新";
                            MyHub.Show(ToLibraryName, JsonConvert.SerializeObject(new
                            {
                                msg    = msg,
                                action = "CustData",
                                type   = type
                            }));
                        }

                        sysAdditionalDatas.ForEach(s => db.SysAdditionalDatas.Add(s));
                        db.SaveChanges();
                    }

                    Lg.AddLog("导入额外数据", "Other", 1, GetUserName());

                    return(Json(new
                    {
                        code = "200",
                        msg = "导入成功"
                    }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("数据导入失败:" + ex.Message);
                return(Json(new
                {
                    code = "201",
                    msg = "导入失败,请检查内容格式,错误行号:" + location
                }));
            }
        }