示例#1
0
        public static void CheckToken(string Token)
        {
            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbUserToken       temp        = myDbContext.tbUserToken.Where(p => p.Token == Token).FirstOrDefault();
                if (temp != null)
                {
                    if (temp.UpdateTime > DateTime.Now.AddHours(-1) && temp.CreateTime > DateTime.Now.AddHours(-12))
                    {
                        temp.UpdateTime = DateTime.Now;
                        myDbContext.SaveChanges();
                    }
                    else if (temp.IsLoginOut == 1)
                    {
                        throw new Exception("用户已退出系统");
                    }
                    else
                    {
                        throw new Exception("验证Token已过期");
                    }
                }
                else
                {
                    throw new Exception("验证Token已过期");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        public static string UpdateParameter(string Parameterstr)
        {
            string str = string.Empty;

            try
            {
                tbParameter       tb          = JsonConvert.DeserializeObject <tbParameter>(Parameterstr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbParameter       data        = myDbContext.tbParameter.Where(p => p.id == tb.id).FirstOrDefault();
                if (data != null)
                {
                    int DataCount = myDbContext.tbParameter.Where(p => p.Code == tb.Code && p.id != tb.id).Count <tbParameter>();
                    if (DataCount > 0)
                    {
                        throw new Exception(string.Format("Code:{0}重复,请重新输入", data.Code));
                    }
                    string[] keys = { "id" };
                    ObjectHelper.CopyValueNotKey(tb, data, keys);
                }
                else
                {
                    throw new Exception(string.Format("Key:{0}找不到相关数据", tb.id));
                }


                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#3
0
        public static string UpdateRole(string Rolestr)
        {
            string str = string.Empty;

            try
            {
                tbRole            tb          = JsonConvert.DeserializeObject <tbRole>(Rolestr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbRole            data        = myDbContext.tbRole.Where(p => p.Id == tb.Id).FirstOrDefault();

                data.Description = tb.Description;
                data.RoleName    = tb.RoleName;
                data.UpdateBy    = tb.UpdateBy;
                data.UpdateTime  = DateTime.Now;


                int DataCount = myDbContext.tbRole.Where(p => p.RoleName == data.RoleName && p.Id != data.Id).Count <tbRole>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("角色名:{0}重复,请重新输入", data.RoleName));
                }


                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#4
0
        public static string UpdateMenu(string Menustr)
        {
            string str = string.Empty;

            try
            {
                tbMenu            tb          = JsonConvert.DeserializeObject <tbMenu>(Menustr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbMenu            data        = myDbContext.tbMenu.Where(p => p.Id == tb.Id).FirstOrDefault();


                data.Code        = tb.Code;
                data.LinkAddress = tb.LinkAddress;

                data.Icon       = tb.Icon;
                data.Name       = tb.Name;
                data.ParentId   = tb.ParentId;
                data.Sort       = tb.Sort;
                data.UpdateBy   = tb.UpdateBy;
                data.UpdateTime = DateTime.Now;



                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#5
0
        public static string AddMenu(string Menustr)
        {
            string str = string.Empty;

            try
            {
                tbMenu tb    = JsonConvert.DeserializeObject <tbMenu>(Menustr);
                tbMenu newtb = new tbMenu()
                {
                    Code        = tb.Code,
                    CreateTime  = DateTime.Now,
                    LinkAddress = tb.LinkAddress,
                    CreateBy    = tb.CreateBy,
                    Icon        = tb.Icon,
                    Name        = tb.Name,
                    ParentId    = tb.ParentId,
                    Sort        = tb.Sort,
                    UpdateBy    = tb.CreateBy,
                    UpdateTime  = DateTime.Now
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                myDbContext.tbMenu.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "取数成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
        public static string UpdateBlackList(string BlackListStr)
        {
            string str = string.Empty;

            try
            {
                tbBlackList       tb          = JsonConvert.DeserializeObject <tbBlackList>(BlackListStr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbBlackList       data        = myDbContext.tbBlackList.Where(p => p.Id == tb.Id).FirstOrDefault();
                //data.Address = tb.Address;
                //data.CreateTime = tb.CreateTime;
                //data.IsAble = tb.IsAble;
                //data.Notes = tb.Notes;
                //data.Port = tb.Port;
                string [] keys = { "Id" };
                ObjectHelper.CopyValueNotKey(tb, data, keys);

                int DataCount = myDbContext.tbBlackList.Where(p => p.Address == data.Address && p.Id != data.Id).Count <tbBlackList>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("黑名单IP:{0}重复,请重新输入", data.Address));
                }


                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#7
0
        public static string UpdateFlowStatus(string Code, int oldStatus, int newStatus, string UpdateBy)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbFlow            main        = myDbContext.tbFlow.Where(p => p.Code == Code).ToList().FirstOrDefault();
                if (main == null)
                {
                    throw new Exception("未找到相关数据!");
                }
                if (main.status != oldStatus)
                {
                    throw new Exception("数据已经被其它人操作,请刷新!");
                }
                main.status     = newStatus;
                main.UpdateTime = DateTime.Now;
                main.UpdateBy   = UpdateBy;
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#8
0
        public static string UpdateDept(string Deptstr)
        {
            string str = string.Empty;

            try
            {
                tbDepartment      tb          = JsonConvert.DeserializeObject <tbDepartment>(Deptstr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbDepartment      data        = myDbContext.tbDepartment.Where(p => p.Id == tb.Id).FirstOrDefault();
                data.DepartmentName = tb.DepartmentName;
                data.ParentId       = tb.ParentId;
                data.Sort           = tb.Sort;
                data.UpdateBy       = tb.UpdateBy;
                data.UpdateTime     = DateTime.Now;


                int DataCount = myDbContext.tbDepartment.Where(p => p.DepartmentName == data.DepartmentName && p.Id != data.Id).Count <tbDepartment>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("部门名:{0}重复,请重新输入", data.DepartmentName));
                }


                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#9
0
        public static string DeleteBillNo(string[] BillNoList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                foreach (string temp in BillNoList)
                {
                    int             delId   = Convert.ToInt32(temp);
                    List <tbBillNo> delList = myDbContext.tbBillNo.Where(p => p.Id == delId).ToList();
                    if (delList != null && delList.Count > 0)
                    {
                        myDbContext.tbBillNo.Remove(delList[0]);
                    }
                }



                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "删除成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#10
0
        public static string AddRole(string Rolestr)
        {
            string str = string.Empty;

            try
            {
                tbRole tb = JsonConvert.DeserializeObject <tbRole>(Rolestr);

                tbRole newtb = new tbRole()
                {
                    RoleName    = tb.RoleName,
                    CreateBy    = tb.CreateBy,
                    CreateTime  = DateTime.Now,
                    Description = tb.Description,
                    UpdateTime  = DateTime.Now,
                    UpdateBy    = tb.CreateBy
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbRole.Where(p => p.RoleName == newtb.RoleName).Count <tbRole>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("角色名:{0}重复,请重新输入", newtb.RoleName));
                }

                myDbContext.tbRole.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#11
0
        public static string UpdateBillNo(string tbBillNoStr)
        {
            string str = string.Empty;

            try
            {
                tbBillNo          tb          = JsonConvert.DeserializeObject <tbBillNo>(tbBillNoStr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbBillNo          data        = myDbContext.tbBillNo.Where(p => p.Id == tb.Id).FirstOrDefault();

                string[] keys = { "Id", "CurrentId", "CurrentBillNo", "CurrentTime" };
                ObjectHelper.CopyValueNotKey(tb, data, keys);
                data.UpdateTime = DateTime.Now;
                int DataCount = myDbContext.tbBillNo.Where(p => p.Code == data.Code && p.Id != data.Id).Count <tbBillNo>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("单据编号:{0}重复,请重新输入", data.Code));
                }


                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#12
0
        public static string AddParameter(string Parameterstr)
        {
            string str = string.Empty;

            try
            {
                tbParameter tb = JsonConvert.DeserializeObject <tbParameter>(Parameterstr);
                tb.CreateTime = DateTime.Now;
                tb.UpdateTime = DateTime.Now;
                string[]    keys  = { "id" };
                tbParameter newtb = new tbParameter();
                ObjectHelper.CopyValueNotKey(tb, newtb, keys);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbParameter.Where(p => p.Code == tb.Code).Count <tbParameter>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("Code:{0}重复,请重新输入", tb.Code));
                }
                myDbContext.tbParameter.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#13
0
        public static string AddFlow(string Flowstr)
        {
            string str = string.Empty;

            try
            {
                DateTime          now         = DateTime.Now;
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                FlowModel         tb          = JsonConvert.DeserializeObject <FlowModel>(Flowstr);
                tbFlow            Flow        = new tbFlow();
                ObjectHelper.CopyValue(tb.Flow, Flow);
                List <tbFlowStep>             FlowStep     = tb.FlowStep;
                List <v_FlowStepUserViewInfo> FlowStepUser = tb.FlowStepUser;
                if (tb == null)
                {
                    throw new Exception("流程数据异常!");
                }
                if (FlowStep == null || FlowStep.Count <= 0)
                {
                    throw new Exception("流程步骤数据异常!");
                }
                //if (FlowStepUser == null || FlowStepUser.Count <= 0)
                //{
                //    throw new Exception("流程步骤数据异常!");
                //}
                //string Code = Guid.NewGuid().ToString();
                string No = BillNoBill.GetBillNo(myDbContext, "LC");

                Flow.CreateTime = now;
                Flow.UpdateTime = now;
                Flow.status     = 0;
                //Flow.Code = Code;
                Flow.No = No;
                myDbContext.tbFlow.Add(Flow);
                foreach (var st in FlowStep)
                {
                    st.CreateTime = now;
                    st.UpdateTime = now;
                    myDbContext.tbFlowStep.Add(st);
                }
                foreach (var st in FlowStepUser)
                {
                    st.CreateTime = now;
                    st.UpdateTime = now;
                    tbFlowStepUser temp = new tbFlowStepUser();
                    string[]       keys = { "Id" };
                    ObjectHelper.CopyValue(st, temp);
                    myDbContext.tbFlowStepUser.Add(temp);
                }
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", Flow.Code);
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#14
0
        public static string DeleteMenu(string[] MenuList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                foreach (string temp in MenuList)
                {
                    int           delId   = Convert.ToInt32(temp);
                    List <tbMenu> delList = myDbContext.tbMenu.Where(p => p.Id == delId).ToList();
                    if (delList != null && delList.Count > 0)
                    {
                        myDbContext.tbMenu.Remove(delList[0]);
                    }
                    List <tbMenuButton> delMenuButtonList = new List <tbMenuButton>();
                    delMenuButtonList = myDbContext.tbMenuButton.Where(p => p.MenuId == delId).ToList();
                    if (delMenuButtonList != null && delMenuButtonList.Count > 0)
                    {
                        foreach (var t in delMenuButtonList)
                        {
                            myDbContext.tbMenuButton.Remove(t);
                        }
                    }
                    List <tbRoleMenu> delRoleMenuList = new List <tbRoleMenu>();
                    delRoleMenuList = myDbContext.tbRoleMenu.Where(p => p.MenuId == delId).ToList();
                    if (delRoleMenuList != null && delRoleMenuList.Count > 0)
                    {
                        foreach (var t in delRoleMenuList)
                        {
                            myDbContext.tbRoleMenu.Remove(t);
                        }
                    }
                    List <tbRoleMenuButton> delRoleMenuButtonList = new List <tbRoleMenuButton>();
                    delRoleMenuButtonList = myDbContext.tbRoleMenuButton.Where(p => p.MenuId == delId).ToList();

                    if (delRoleMenuButtonList != null && delRoleMenuButtonList.Count > 0)
                    {
                        foreach (var t in delRoleMenuButtonList)
                        {
                            myDbContext.tbRoleMenuButton.Remove(t);
                        }
                    }
                }



                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "取数成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#15
0
        public static string DeleteFlow(string[] FlowList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int i = 0;
                foreach (string temp in FlowList)
                {
                    tbFlow deltbFlow = myDbContext.tbFlow.Where(p => p.Code == temp).FirstOrDefault();
                    if (deltbFlow == null)
                    {
                        continue;
                    }
                    if (deltbFlow.status != 0)
                    {
                        continue;
                    }
                    myDbContext.tbFlow.Remove(deltbFlow);
                    List <tbFlowStep> delFlowStep = myDbContext.tbFlowStep.Where(p => p.FlowCode == temp).ToList();
                    if (delFlowStep != null && delFlowStep.Count > 0)
                    {
                        foreach (var st in delFlowStep)
                        {
                            myDbContext.tbFlowStep.Remove(st);
                        }
                    }
                    List <tbFlowStepUser> delFlowStepUser = myDbContext.tbFlowStepUser.Where(p => p.FlowCode == temp).ToList();
                    if (delFlowStepUser != null && delFlowStepUser.Count > 0)
                    {
                        foreach (var st in delFlowStepUser)
                        {
                            myDbContext.tbFlowStepUser.Remove(st);
                        }
                    }
                }



                myDbContext.SaveChanges();
                string msg = string.Format("提交{0}条数据,成功删除{1}条", FlowList.Length, i);
                str = ResponseHelper.ResponseMsg("1", msg, "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#16
0
        public static string AddUser(string Userstr)
        {
            string str = string.Empty;

            try
            {
                tbUser tb       = JsonConvert.DeserializeObject <tbUser>(Userstr);
                string passWord = Base64Helper.DecodeBase64(tb.Password);
                string password = Md5Helper.GetMD5String(passWord);
                tbUser newtb    = new tbUser()
                {
                    AccountName = tb.AccountName,
                    CreateBy    = tb.CreateBy,
                    CreateTime  = DateTime.Now,
                    Description = tb.Description,
                    Email       = tb.Email,
                    IfChangePwd = tb.IfChangePwd,
                    IsAble      = tb.IsAble,
                    MobilePhone = tb.MobilePhone,
                    Password    = password,
                    RealName    = tb.RealName,
                    UpdateTime  = DateTime.Now,
                    UpdateBy    = tb.CreateBy
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbUser.Where(p => p.AccountName == newtb.AccountName).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("帐号名:{0}重复,请重新输入", newtb.AccountName));
                }
                DataCount = myDbContext.tbUser.Where(p => p.Email == newtb.Email).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("邮箱:{0}重复,请重新输入", newtb.Email));
                }
                DataCount = myDbContext.tbUser.Where(p => p.MobilePhone == newtb.MobilePhone).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("手机号:{0}重复,请重新输入", newtb.MobilePhone));
                }
                myDbContext.tbUser.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#17
0
        public static string UpdateUserAllinfo(string Userstr)
        {
            string str = string.Empty;

            try
            {
                tbUser            tb          = JsonConvert.DeserializeObject <tbUser>(Userstr);
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbUser            data        = myDbContext.tbUser.Where(p => p.ID == tb.ID).FirstOrDefault();
                string            passWord    = Base64Helper.DecodeBase64(tb.Password);
                string            password    = Md5Helper.GetMD5String(passWord);
                data.AccountName = tb.AccountName;
                data.Description = tb.Description;
                data.Email       = tb.Email;
                data.IfChangePwd = tb.IfChangePwd;
                data.IsAble      = tb.IsAble;
                data.MobilePhone = tb.MobilePhone;
                data.Password    = password;
                data.RealName    = tb.RealName;
                data.UpdateBy    = tb.UpdateBy;
                data.UpdateTime  = DateTime.Now;


                int DataCount = myDbContext.tbUser.Where(p => p.AccountName == data.AccountName && p.ID != data.ID).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("帐号名:{0}重复,请重新输入", data.AccountName));
                }
                DataCount = myDbContext.tbUser.Where(p => p.Email == data.Email && p.ID != data.ID).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("邮箱:{0}重复,请重新输入", data.Email));
                }
                DataCount = myDbContext.tbUser.Where(p => p.MobilePhone == data.MobilePhone && p.ID != data.ID).Count <tbUser>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("手机号:{0}重复,请重新输入", data.MobilePhone));
                }

                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#18
0
        public static string AddNotice(string Noticetstr)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities      myDbContext = new AchieveDBEntities();
                NoticeModel            tb          = JsonConvert.DeserializeObject <NoticeModel>(Noticetstr);
                string                 Code        = Guid.NewGuid().ToString();
                string                 BillNo      = BillNoBill.GetBillNo(myDbContext, "TZ");
                tbNotice               main        = tb.Main;
                List <NoticeUserModel> item        = tb.Item;
                main.CreateTime = DateTime.Now;
                main.UpdateTime = DateTime.Now;
                main.NoticeTime = DateTime.Now;
                main.status     = 0;
                main.Code       = Code;
                main.No         = BillNo;
                if (item != null && item.Count > 0)
                {
                    foreach (var st in item)
                    {
                        st.NoticeCode = Code;
                        st.SendFlag   = 0;
                        st.UpdateTime = DateTime.Now;
                        st.CreateTime = DateTime.Now;
                    }
                }

                myDbContext.tbNotice.Add(main);
                foreach (var st in item)
                {
                    tbNoticeUser temp = new tbNoticeUser();
                    string[]     keys = { "id" };
                    ObjectHelper.CopyValueNotKey(st, temp, keys);
                    myDbContext.tbNoticeUser.Add(temp);
                }
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", Code);
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#19
0
        public static string AddButton(string Deptstr)
        {
            string str = string.Empty;

            try
            {
                tbButton tb = JsonConvert.DeserializeObject <tbButton>(Deptstr);

                tbButton newtb = new tbButton()
                {
                    Name        = tb.Name,
                    CreateBy    = tb.CreateBy,
                    CreateTime  = DateTime.Now,
                    Code        = tb.Code,
                    Description = tb.Description,
                    Icon        = tb.Icon,

                    Sort       = tb.Sort,
                    UpdateBy   = tb.CreateBy,
                    UpdateTime = DateTime.Now
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbButton.Where(p => p.Name == tb.Name && p.Id != tb.Id).Count <tbButton>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("按钮名:{0}重复,请重新输入", tb.Name));
                }
                DataCount = myDbContext.tbButton.Where(p => p.Code == tb.Code && p.Id != tb.Id).Count <tbButton>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("按钮代码:{0}重复,请重新输入", tb.Code));
                }

                myDbContext.tbButton.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#20
0
        public static string DeleteNotice(string[] NoticeList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int i = 0;
                foreach (string temp in NoticeList)
                {
                    tbNotice delMain = myDbContext.tbNotice.Where(p => p.Code == temp).FirstOrDefault();
                    if (delMain == null)
                    {
                        continue;
                    }
                    if (delMain.status != 0)
                    {
                        continue;
                    }
                    myDbContext.tbNotice.Remove(delMain);
                    List <tbNoticeUser> item = myDbContext.tbNoticeUser.Where(p => p.NoticeCode == temp).ToList();
                    if (item != null && item.Count > 0)
                    {
                        foreach (var st in item)
                        {
                            myDbContext.tbNoticeUser.Remove(st);
                        }
                    }
                }



                myDbContext.SaveChanges();
                string msg = string.Format("提交{0}条数据,成功删除{1}条", NoticeList.Length, i);
                str = ResponseHelper.ResponseMsg("1", msg, "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#21
0
        public static string DeleteParameter(string[] ParameterList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                foreach (string temp in ParameterList)
                {
                    if (string.IsNullOrEmpty(temp))
                    {
                        continue;
                    }
                    int id = Convert.ToInt32(temp);
                    List <tbParameter> delList = myDbContext.tbParameter.Where(p => p.id == id).ToList();
                    if (delList != null && delList.Count > 0)
                    {
                        myDbContext.tbParameter.Remove(delList[0]);
                        string             code        = delList[0].Code;
                        List <tbParameter> delNextList = myDbContext.tbParameter.Where(p => p.FatherCode == code).ToList();
                        if (delNextList != null && delNextList.Count > 0)
                        {
                            foreach (var tempNext in delNextList)
                            {
                                myDbContext.tbParameter.Remove(tempNext);
                            }
                        }
                    }
                }



                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#22
0
        public static string DeleteDept(string[] DeptList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                foreach (string temp in DeptList)
                {
                    int delId = Convert.ToInt32(temp);
                    List <tbDepartment> delList = myDbContext.tbDepartment.Where(p => p.Id == delId).ToList();
                    if (delList != null && delList.Count > 0)
                    {
                        myDbContext.tbDepartment.Remove(delList[0]);
                    }
                    List <tbUserDepartment> delUserDeptList = new List <tbUserDepartment>();
                    delUserDeptList = myDbContext.tbUserDepartment.Where(p => p.DepartmentId == delId).ToList();
                    if (delUserDeptList != null && delUserDeptList.Count > 0)
                    {
                        foreach (var t in delUserDeptList)
                        {
                            myDbContext.tbUserDepartment.Remove(t);
                        }
                    }
                }



                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#23
0
        public static string AddBlackList(string BlackListStr)
        {
            string str = string.Empty;

            try
            {
                tbBlackList tb = JsonConvert.DeserializeObject <tbBlackList>(BlackListStr);

                //tbBlackList newtb = new tbBlackList()
                //{
                //    Address = tb.Address,
                //    IsAble = tb.IsAble,
                //    Notes = tb.Notes,
                //    Port = tb.Port,
                //    CreateTime = DateTime.Now
                //};
                tbBlackList newtb = new tbBlackList();
                string[]    keys  = { "Id" };
                ObjectHelper.CopyValueNotKey(tb, newtb, keys);
                newtb.CreateTime = DateTime.Now;
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbBlackList.Where(p => p.Address == tb.Address).Count <tbBlackList>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("黑名单IP:{0}重复,请重新输入", tb.Address));
                }
                myDbContext.tbBlackList.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#24
0
        public static string AddDept(string Deptstr)
        {
            string str = string.Empty;

            try
            {
                tbDepartment tb = JsonConvert.DeserializeObject <tbDepartment>(Deptstr);

                tbDepartment newtb = new tbDepartment()
                {
                    CreateBy       = tb.CreateBy,
                    CreateTime     = DateTime.Now,
                    DepartmentName = tb.DepartmentName,
                    ParentId       = tb.ParentId,
                    Sort           = tb.Sort,
                    UpdateBy       = tb.CreateBy,
                    UpdateTime     = DateTime.Now
                };
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int DataCount = myDbContext.tbDepartment.Where(p => p.DepartmentName == newtb.DepartmentName).Count <tbDepartment>();
                if (DataCount > 0)
                {
                    throw new Exception(string.Format("部门名:{0}重复,请重新输入", newtb.DepartmentName));
                }

                myDbContext.tbDepartment.Add(newtb);
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#25
0
        public static void AnalysisBlackList()
        {
            try
            {
                Logger             logger      = LogManager.GetCurrentClassLogger();
                AchieveDBEntities  myDbContext = new AchieveDBEntities();
                List <tbBlackList> templist    = new List <tbBlackList>();
                logger.Log(LogLevel.Info, string.Format("启动分析黑名单进程!"));
                string BlackCount = System.Configuration.ConfigurationManager.AppSettings["BlackCount"];
                int    blackCount = string.IsNullOrEmpty(BlackCount) ? 0 : Convert.ToInt32(BlackCount);
                List <IPCountInfoModel> ipList = DataCacheHelper.GetData <IPCountInfoModel>();
                if (ipList != null && ipList.Count > 0)
                {
                    ipList = ipList.Where(p => p.Count > blackCount).ToList();
                    if (ipList != null && ipList.Count > 0)
                    {
                        foreach (var temp in ipList)
                        {
                            int DataCount = myDbContext.tbBlackList.Where(p => p.Address == temp.Address && p.IsAble == 1).Count <tbBlackList>();
                            if (DataCount > 0)
                            {
                            }
                            else
                            {
                                DataCount = myDbContext.tbBlackList.Where(p => p.Address == temp.Address).Count <tbBlackList>();
                                if (DataCount > 0)
                                {
                                    tbBlackList tp1 = new tbBlackList()
                                    {
                                        Address = temp.Address,
                                    };

                                    myDbContext.tbBlackList.Remove(tp1);
                                }

                                tbBlackList tp = new tbBlackList()
                                {
                                    Address    = temp.Address,
                                    IsAble     = 1,
                                    CreateTime = DateTime.Now,
                                    Notes      = string.Format("心跳周期内访问{0}次,系统自动屏蔽!", temp.Count)
                                };
                                myDbContext.tbBlackList.Add(tp);
                            }
                        }
                        myDbContext.SaveChanges();

                        logger.Log(LogLevel.Info, string.Format("通过本次分析,黑名单共新增{0}条记录!", ipList.Count));
                    }
                }
                ipList = new List <IPCountInfoModel>();
                DataCacheHelper.Updata <IPCountInfoModel>(ipList);
                logger.Log(LogLevel.Info, string.Format("结束分析黑名单进程!"));
                //缓存重新加载黑名单信息
                LoadBlackList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#26
0
        public static string GetUserByAccountName(string accountName, string passWord, string address, string port)
        {
            string str = string.Empty;

            try
            {
                passWord = Base64Helper.DecodeBase64(passWord);
                string md5passWord = Md5Helper.GetMD5String(passWord);
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                UserInfoModel     temp        = new UserInfoModel();
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                List <tbUser>     templist    = myDbContext.tbUser.Where(p => p.AccountName == accountName).ToList();
                if (templist != null && templist.Count > 0)
                {
                    tbUser tempUser = templist[0];
                    if (tempUser.Password == md5passWord)
                    {
                        if (tempUser.IsAble != 1)
                        {
                            throw new Exception("帐号未启用!");
                        }

                        string   Token       = Guid.NewGuid().ToString();
                        DateTime newDataTime = DateTime.Now;

                        List <tbUserToken> tempOldTokenlist = myDbContext.tbUserToken.Where(p => p.UserId == tempUser.ID && p.IsLoginOut != 1).ToList();
                        foreach (var st in tempOldTokenlist)
                        {
                            st.IsLoginOut = 1;
                        }

                        tbUserToken newtb = new tbUserToken();
                        newtb.UserId     = tempUser.ID;
                        newtb.Token      = Token;
                        newtb.CreateTime = newDataTime;
                        newtb.UpdateTime = newDataTime;
                        newtb.Address    = address;
                        newtb.Port       = port;
                        newtb.IsLoginOut = 0;
                        myDbContext.tbUserToken.Add(newtb);
                        myDbContext.SaveChanges();

                        temp.ID          = tempUser.ID;
                        temp.AccountName = tempUser.AccountName;
                        temp.CreateTime  = DateTime.Now;
                        temp.RealName    = tempUser.RealName;

                        temp.Token      = Token;
                        temp.CreateTime = newDataTime;
                        str             = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                        str             = ResponseHelper.ResponseMsg("1", "取数成功", str);
                    }
                    else
                    {
                        str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                        str = ResponseHelper.ResponseMsg("-1", "密码错误", str);
                    }
                }
                else
                {
                    str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "用户不存在", str);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#27
0
        public static string LoginOut(string Token, string accountName)
        {
            string str = string.Empty;

            try
            {
                IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
                timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbUserToken       temp        = myDbContext.tbUserToken.Where(p => p.Token == Token).FirstOrDefault();
                if (temp != null)
                {
                    if (temp != null)
                    {
                        if (temp.UpdateTime > DateTime.Now.AddHours(-1) && temp.CreateTime > DateTime.Now.AddHours(-12))
                        {
                            tbUser tb = myDbContext.tbUser.Where(p => p.ID == temp.UserId).FirstOrDefault();
                            if (tb != null)
                            {
                                if (tb.AccountName == accountName)
                                {
                                    temp.IsLoginOut   = 1;
                                    temp.LoginOutTime = DateTime.Now;
                                    myDbContext.SaveChanges();
                                }
                                else
                                {
                                    throw new Exception("用户信息不匹配");
                                }
                            }
                            else
                            {
                                throw new Exception("用户信息不存在");
                            }
                        }
                        else if (temp.IsLoginOut == 1)
                        {
                            throw new Exception("用户已退出系统");
                        }
                        else
                        {
                            throw new Exception("验证Token已过期");
                        }
                    }
                    else
                    {
                        throw new Exception("验证Token已过期");
                    }



                    str = ResponseHelper.ResponseMsg("1", "取数成功", "");
                }
                else
                {
                    str = JsonConvert.SerializeObject(temp, Formatting.Indented, timeFormat);
                    str = ResponseHelper.ResponseMsg("-1", "Token不存在", str);
                }
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#28
0
        public static string SetMenuRole(int roleId, string menuStr)
        {
            string str = string.Empty;

            try
            {
                string[] list = menuStr.Split(',');

                AchieveDBEntities myDbContext = new AchieveDBEntities();
                List <tbRoleMenu> tblist      = myDbContext.tbRoleMenu.Where(p => p.RoleId == roleId).ToList();
                foreach (tbRoleMenu st in tblist)
                {
                    bool findbj = false;
                    if (list.Length > 0)
                    {
                        if (!string.IsNullOrEmpty(list[0]))
                        {
                            foreach (string st1 in list)
                            {
                                if (st.MenuId.ToString() == st1)
                                {
                                    findbj = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!findbj)
                    {
                        //找子菜单 如果没有任何子菜单有权限则删除

                        findbj = CheckChildNode(myDbContext, Convert.ToInt32(st.MenuId), list);
                        int MenuId = Convert.ToInt32(st.MenuId);
                        if (!findbj)
                        {
                            myDbContext.tbRoleMenu.Remove(st);
                            List <tbRoleMenuButton> templist = myDbContext.tbRoleMenuButton.Where(p => p.MenuId == MenuId && p.RoleId == roleId).ToList();
                            if (templist != null && templist.Count > 0)
                            {
                                foreach (tbRoleMenuButton del in templist)
                                {
                                    myDbContext.tbRoleMenuButton.Remove(del);
                                }
                            }
                        }
                    }
                }

                if (list.Length > 0)
                {
                    List <int> addlist = new List <int>();
                    foreach (string st1 in list)
                    {
                        if (!string.IsNullOrEmpty(st1))
                        {
                            bool findbj = false;
                            foreach (tbRoleMenu st in tblist)
                            {
                                if (st.Id.ToString() == st1)
                                {
                                    findbj = true;
                                    break;
                                }
                            }
                            if (!findbj)
                            {
                                //tbRoleMenu newtb = new tbRoleMenu()
                                //{
                                //    MenuId = Convert.ToInt32(st1),
                                //    RoleId= roleId

                                //};
                                //myDbContext.tbRoleMenu.Add(newtb);
                                //找父菜单并添加权限


                                SetParentNode(myDbContext, Convert.ToInt32(st1), roleId, addlist);
                            }
                        }
                    }
                }

                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#29
0
        public static string UpdateFlow(string Flowstr)
        {
            string str = string.Empty;

            try
            {
                DateTime  now  = DateTime.Now;
                FlowModel tb   = JsonConvert.DeserializeObject <FlowModel>(Flowstr);
                tbFlow    Flow = new tbFlow();
                ObjectHelper.CopyValue(tb.Flow, Flow);
                List <tbFlowStep>             FlowStep     = tb.FlowStep;
                List <v_FlowStepUserViewInfo> FlowStepUser = tb.FlowStepUser;
                if (tb == null)
                {
                    throw new Exception("流程数据异常!");
                }
                if (FlowStep == null || FlowStep.Count <= 0)
                {
                    throw new Exception("流程步骤数据异常!");
                }
                if (FlowStepUser == null || FlowStepUser.Count <= 0)
                {
                    throw new Exception("流程步骤数据异常!");
                }
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbFlow            newFlow     = myDbContext.tbFlow.Where(p => p.Code == Flow.Code).ToList().FirstOrDefault();
                string[]          keys        = { "Code" };
                ObjectHelper.CopyValueNotKey(Flow, newFlow, keys);
                newFlow.UpdateTime = now;
                if (FlowStep != null && FlowStep.Count > 0)
                {
                    string [] FlowStepCode = new string[FlowStep.Count];
                    int       count        = 0;
                    foreach (var st in FlowStep)
                    {
                        FlowStepCode[count] = st.Code;
                        count++;
                        tbFlowStep temp = myDbContext.tbFlowStep.Where(p => p.Code == st.Code).ToList().FirstOrDefault();
                        if (temp != null)
                        {
                            ObjectHelper.CopyValueNotKey(st, temp, keys);
                            temp.UpdateTime = now;
                        }
                        else
                        {
                            st.FlowCode   = Flow.Code;
                            st.UpdateTime = now;
                            myDbContext.tbFlowStep.Add(st);
                        }
                    }
                    List <tbFlowStep> tempList = myDbContext.tbFlowStep.Where(p => !(FlowStepCode).Contains(p.Code) && p.FlowCode == Flow.Code).ToList();
                    if (tempList != null && tempList.Count > 0)
                    {
                        foreach (var st in tempList)
                        {
                            myDbContext.tbFlowStep.Remove(st);
                        }
                    }
                }

                if (FlowStepUser != null && FlowStepUser.Count > 0)
                {
                    string[] FlowStepUserCode = new string[FlowStepUser.Count];
                    int      count            = 0;
                    foreach (var st in FlowStepUser)
                    {
                        FlowStepUserCode[count] = st.Code;
                        count++;
                        tbFlowStepUser temp = myDbContext.tbFlowStepUser.Where(p => p.Code == st.Code).ToList().FirstOrDefault();
                        if (temp != null)
                        {
                            ObjectHelper.CopyValue(st, temp);
                            temp.UpdateTime = now;
                        }
                        else
                        {
                            st.FlowCode   = Flow.Code;
                            st.UpdateTime = now;
                            tbFlowStepUser newtemp = new tbFlowStepUser();
                            ObjectHelper.CopyValue(st, newtemp);
                            myDbContext.tbFlowStepUser.Add(newtemp);
                        }
                    }
                    List <tbFlowStepUser> tempList = myDbContext.tbFlowStepUser.Where(p => !(FlowStepUserCode).Contains(p.Code) && p.FlowCode == Flow.Code).ToList();
                    if (tempList != null && tempList.Count > 0)
                    {
                        foreach (var st in tempList)
                        {
                            myDbContext.tbFlowStepUser.Remove(st);
                        }
                    }
                }
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", Flow.Code);
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
示例#30
0
        public static string SetUserDept(int userId, string deptStr)
        {
            string str = string.Empty;

            try
            {
                string[] list = deptStr.Split(',');

                AchieveDBEntities       myDbContext = new AchieveDBEntities();
                List <tbUserDepartment> tblist      = myDbContext.tbUserDepartment.Where(p => p.UserId == userId).ToList();
                foreach (tbUserDepartment st in tblist)
                {
                    bool findbj = false;
                    if (list.Length > 0)
                    {
                        foreach (string st1 in list)
                        {
                            if (st.DepartmentId.ToString() == st1)
                            {
                                findbj = true;
                                break;
                            }
                        }
                    }
                    if (!findbj)
                    {
                        myDbContext.tbUserDepartment.Remove(st);
                    }
                }

                if (list.Length > 0)
                {
                    foreach (string st1 in list)
                    {
                        if (!string.IsNullOrEmpty(st1))
                        {
                            bool findbj = false;
                            foreach (tbUserDepartment st in tblist)
                            {
                                if (st.DepartmentId.ToString() == st1)
                                {
                                    findbj = true;
                                    break;
                                }
                            }
                            if (!findbj)
                            {
                                tbUserDepartment newtb = new tbUserDepartment()
                                {
                                    DepartmentId = Convert.ToInt32(st1),
                                    UserId       = userId
                                };
                                myDbContext.tbUserDepartment.Add(newtb);
                            }
                        }
                    }
                }

                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "更新成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }