Ejemplo n.º 1
0
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            int deptID = GetSelectedDataKeyID(Grid1);

            if (e.CommandName == "Delete")
            {
                // 在操作之前进行权限检查

                int userCount = DB.Users.Where(u => u.Department.ID == deptID).Count();
                if (userCount > 0)
                {
                    Alert.ShowInTop("删除失败!需要先清空属于此部门的员工!");
                    return;
                }

                int childCount = DB.Departments.Where(d => d.ParentDepartment.ID == deptID).Count();
                if (childCount > 0)
                {
                    Alert.ShowInTop("删除失败!请先删除子部门!");
                    return;
                }

                IInfobasisDataSource db = InfobasisDataSource.Create();
                if (db.ExecuteNonQuery("DELETE FROM SYtbDepartment WHERE ID = @ID AND CompanyID = @CompanyID", deptID, UserInfo.Current.CompanyID) == 0)
                {
                    Alert.ShowInTop("删除失败!");
                }
                BindGrid();
            }
        }
Ejemplo n.º 2
0
        private DataTable GetSource()
        {
            string sortField            = Grid1.SortField;
            string sortDirection        = Grid1.SortDirection;
            IInfobasisDataSource db     = InfobasisDataSource.Create();
            DataTable            table2 = db.ExecuteTable("SELECT ID, 'test' AS DeptName, ChineseName, Gender FROM SYtbUser WHERE CompanyID = @CompanyID", UserInfo.Current.CompanyID);

            DataView view2 = table2.DefaultView;

            view2.Sort = String.Format("{0} {1}", sortField, sortDirection);

            List <string> filters = new List <string>();

            string searchKeyword = ttbSearch.Text.Trim();

            if (!String.IsNullOrEmpty(searchKeyword) && ttbSearch.ShowTrigger1)
            {
                // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/
                filters.Add(String.Format("ChineseName LIKE '*{0}*'", EscapeLikeValue(searchKeyword)));
            }

            if (filters.Count > 0)
            {
                view2.RowFilter = String.Join(" AND ", filters.ToArray());
            }

            return(view2.ToTable());
        }
Ejemplo n.º 3
0
        private void BindGrid()
        {
            IInfobasisDataSource db    = InfobasisDataSource.Create();
            DataTable            table = db.ExecuteTable("SELECT * FROM SYtbModule ORDER BY DisplayOrder");

            ModuleGrid.DataSource = table;
            ModuleGrid.DataBind();
        }
Ejemplo n.º 4
0
        private void InitCheckBoxListRoomType()
        {
            IInfobasisDataSource db = InfobasisDataSource.Create();
            int       companyID     = UserInfo.Current.CompanyID;
            DataTable table         = GetEntityListTable("FJBW");

            CheckBoxListRoomType.DataSource     = table;
            CheckBoxListRoomType.DataTextField  = "Name";
            CheckBoxListRoomType.DataValueField = "ID";
            CheckBoxListRoomType.DataBind();
        }
Ejemplo n.º 5
0
        private void InitCheckBoxListBudgetType()
        {
            IInfobasisDataSource db = InfobasisDataSource.Create();
            int       companyID     = UserInfo.Current.CompanyID;
            DataTable table         = GetEntityListTable("YSLX");

            DropDownCustomType.DataSource     = table;
            DropDownCustomType.DataTextField  = "Name";
            DropDownCustomType.DataValueField = "ID";
            DropDownCustomType.DataBind();
            DropDownCustomType.Items.Insert(0, new FineUIPro.ListItem("", "0"));
        }
Ejemplo n.º 6
0
        private void BindTree()
        {
            int roleId = GetSelectedDataKeyID(Grid1);
            IInfobasisDataSource db     = InfobasisDataSource.Create();
            XmlDocument          xmlDoc = db.ExecuteXmlDoc("Tree", "EXEC usp_SY_GetModuleTreeSetupXML @CompanyID, @UserID, @PermissionRoleID",
                                                           UserInfo.Current.CompanyID, UserInfo.Current.ID, roleId);

            XmlNodeList xmlNodes = xmlDoc.SelectNodes("/Tree/TreeNode");

            TreeModule.DataSource = xmlDoc;
            TreeModule.DataBind();
        }
Ejemplo n.º 7
0
        private Tree InitTreeMenu()
        {
            Tree treeMenu = new Tree();

            treeMenu.ID                      = "treeMenu";
            treeMenu.ShowBorder              = false;
            treeMenu.ShowHeader              = false;
            treeMenu.EnableIcons             = true;
            treeMenu.AutoScroll              = true;
            treeMenu.EnableSingleClickExpand = true;

            if (_menuType == "tree" || _menuType == "tree_minimode")
            {
                treeMenu.HideHScrollbar  = true;
                treeMenu.ExpanderToRight = true;
                treeMenu.HeaderStyle     = true;

                //leftPanel.RegionSplit = false;
                //leftPanel.CssStyle = "border-right-width:0;";


                if (_menuType == "tree_minimode")
                {
                    treeMenu.MiniMode         = true;
                    treeMenu.MiniModePopWidth = Unit.Pixel(300);

                    leftPanelToolGear.Hidden       = true;
                    leftPanelBottomToolbar.Hidden  = true;
                    leftPanelToolCollapse.IconFont = IconFont.ChevronCircleRight;

                    leftPanel.Width    = Unit.Pixel(50);
                    leftPanel.CssClass = "minimodeinside";
                }
            }

            leftPanel.Items.Add(treeMenu);

            IInfobasisDataSource db     = InfobasisDataSource.Create();
            XmlDocument          xmlDoc = db.ExecuteXmlDoc("Tree", "EXEC usp_SY_GetModuleTreeXML @CompanyID, @UserID",
                                                           UserInfo.Current.CompanyID, UserInfo.Current.ID);

            ResolveXmlDocument(xmlDoc);

            // 绑定 XML 数据源到树控件
            treeMenu.NodeDataBound    += treeMenu_NodeDataBound;
            treeMenu.PreNodeDataBound += treeMenu_PreNodeDataBound;
            treeMenu.DataSource        = xmlDoc;
            treeMenu.DataBind();

            return(treeMenu);
        }
Ejemplo n.º 8
0
        private void InitDropDownMainMaterialType()
        {
            IInfobasisDataSource db = InfobasisDataSource.Create();
            int       companyID     = UserInfo.Current.CompanyID;
            DataTable table         = db.ExecuteTable("SELECT * FROM SYtbEntityList WHERE GroupCode = 'Material' AND CompanyID = @CompanyID ORDER BY DisplayOrder", companyID);

            DropDownMainMaterialType.DataSource     = table;
            DropDownMainMaterialType.DataTextField  = "Name";
            DropDownMainMaterialType.DataValueField = "ID";
            DropDownMainMaterialType.DataBind();

            DropDownMainMaterialType.Items.Insert(0, new FineUIPro.ListItem("", "-1"));
            //DropDownMainMaterialType.Items[0].Selected = true;
        }
Ejemplo n.º 9
0
        //=======================================================================
        public static UserInfo LogonAs(string accessToken)
        {
            if (accessToken == null)
            {
                throw new ArgumentNullException("accessToken");
            }
            if (accessToken.Length == 0)
            {
                throw new ArgumentException("accessToken cannot be an empty string", "accessToken");
            }

            System.Diagnostics.Debug.WriteLine("LogonAs(" + accessToken + ")");


            CurrentlyRetrievingUserInfo = true;

            UserToken userToken = UserToken.ParseAccessToken(accessToken);

            if (userToken == null)
            {
                throw new ApplicationException("验证JWT信息错误");
            }

            try
            {
                // Look up person
                IInfobasisDataSource db = InfobasisDataSource.Create();
                DataRow userRow         = db.ExecuteRow("SELECT * FROM SYtbUser WHERE ID = @ID", userToken.ID);

                // Not found?
                if (userRow == null)
                {
                    throw new ApplicationException("找不到此用户");
                }

                // Finally, create and cache in Session
                UserInfo userInfo = new UserInfo(userRow);

                HttpContext.Current.Items["JustLoggedIn"] = true;

                System.Diagnostics.Debug.WriteLine("LogonAs complete: " + userInfo);

                return(userInfo);
            }
            finally
            {
                CurrentlyRetrievingUserInfo = false;
            }
        }
Ejemplo n.º 10
0
        private void SaveItem()
        {
            Infobasis.Data.DataEntity.Company item = new Infobasis.Data.DataEntity.Company();
            item.Name        = tbxName.Text.Trim();
            item.CompanyCode = tbxCompanyCode.Text.Trim();
            item.Notes       = tbxRemark.Text;
            if (tbxExpiredDatetime.SelectedDate.HasValue)
            {
                item.ExpiredDatetime = tbxExpiredDatetime.SelectedDate.Value;
            }
            item.MaxUsers           = Infobasis.Web.Util.Change.ToInt(tbxMaxUsers.Text);
            item.ClientAdminAccount = tbxClientAdminAccount.Text;
            item.CompanyStatus      = CompanyStatus.Enabled;
            item.CreateDatetime     = DateTime.Now;
            item.CreateByID         = UserInfo.Current.ID;
            item.CreateByName       = UserInfo.Current.ChineseName;

            string clientAdminPwd = tbxClientAdminAccountPwd.Text.Trim();

            // 添加管理员
            item.Users = new List <Infobasis.Data.DataEntity.User>();
            item.Users.Add(new Infobasis.Data.DataEntity.User()
            {
                CompanyID       = item.ID,
                Name            = item.ClientAdminAccount,
                ChineseName     = "系统管理员",
                IsClientAdmin   = true,
                Password        = PasswordUtil.CreateDbPassword(clientAdminPwd),
                DefaultPageSize = 20,
                Enabled         = true,
                CreateByID      = UserInfo.Current.ID,
                CreateByName    = UserInfo.Current.ChineseName,
                CreateDatetime  = DateTime.Now
            });

            DB.Companys.Add(item);
            DB.SaveChanges();

            int companyID           = item.ID;
            IInfobasisDataSource db = InfobasisDataSource.Create();
            int userID = item.Users.FirstOrDefault().ID;

            //需要手动更新,因为CompanyID被直接赋为当前登录人
            db.ExecuteNonQuery("UPDATE SYtbUser SET CompanyID = @CompanyID WHERE ID = @UserID", companyID, userID);
            db.ExecuteNonQuery("EXEC usp_SY_CreateNewComanyDefaultData @CompanyID, @UserID", companyID, userID);

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
Ejemplo n.º 11
0
        private void InitUserDept()
        {
            int provinceID = 0;

            if (DropDownProvince.SelectedValue != null)
            {
                provinceID = Infobasis.Web.Util.Change.ToInt(DropDownProvince.SelectedValue);
            }

            IInfobasisDataSource db    = InfobasisDataSource.Create();
            DataTable            table = db.ExecuteTable("EXEC usp_SY_GetDeptByType @CompanyID, @DepartmentControlType, @ProvinceID", UserInfo.Current.CompanyID,
                                                         Infobasis.Data.DataEntity.DepartmentControlType.Design, provinceID);

            gridDept.DataSource = table;
            gridDept.DataBind();
        }
Ejemplo n.º 12
0
        private void InitDesigner()
        {
            int deptID = Infobasis.Web.Util.Change.ToInt(ddbDesignerDept.Value);

            if (deptID > 0)
            {
                IInfobasisDataSource db    = InfobasisDataSource.Create();
                DataTable            table = db.ExecuteTable("EXEC usp_SY_GetEmployeeByDept @CompanyID, @DeptID", UserInfo.Current.CompanyID,
                                                             deptID);

                gridDesigner.DataSource = table;
                gridDesigner.DataBind();
                ddbDesigner.Enabled = true;
            }
            else
            {
                ddbDesigner.Enabled = false;
            }
        }
Ejemplo n.º 13
0
        private void LoadData()
        {
            IInfobasisDataSource db = InfobasisDataSource.Create();

            // 权限检查

            //ResolveDeleteMenuButtonForGrid(mbDeleteRows, Grid1);
            ResolveDeleteButtonForGrid(btnDeleteSelected, Grid1);
            ResolveDeleteMenuButtonForGrid(mbEnableRows, Grid1, "确定要启用选中的{0}项记录吗?");
            ResolveDeleteMenuButtonForGrid(mbDisableRows, Grid1, "确定要禁用选中的{0}项记录吗?");


            btnNew.OnClientClick = Window1.GetShowReference("~/Pages/Design/Budget_Form.aspx", "新增模板");

            // 每页记录数
            Grid1.PageSize = UserInfo.Current.DefaultPageSize;
            ddlGridPageSize.SelectedValue = UserInfo.Current.DefaultPageSize.ToString();

            BindGrid();
        }
Ejemplo n.º 14
0
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            int titleID = GetSelectedDataKeyID(Grid1);

            if (e.CommandName == "Delete")
            {
                int userCount = DB.Users.Where(u => u.JobRole.ID == titleID).Count();
                if (userCount > 0)
                {
                    Alert.ShowInTop("删除失败!需要先清空拥有此职务的用户!");
                    return;
                }

                IInfobasisDataSource db = InfobasisDataSource.Create();
                if (db.ExecuteNonQuery("DELETE FROM SKtbJobRole WHERE ID = @ID AND CompanyID = @CompanyID", titleID, UserInfo.Current.CompanyID) == 0)
                {
                    Alert.ShowInTop("删除失败!");
                }

                BindGrid();
            }
        }
Ejemplo n.º 15
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            String term      = context.Request.QueryString["term"];
            int    companyID = UserInfo.Current.CompanyID;

            IInfobasisDataSource db = InfobasisDataSource.Create();
            DataTable            _t = db.ExecuteTable("SELECT [Name] FROM [SYtbUser] Where CompanyID = @companyID AND [Name] like '%' + @ke + '%'", companyID, term);

            DataRow[] list = new DataRow[_t.Rows.Count];
            _t.Rows.CopyTo(list, 0);

            var wapper = new
            {
                query       = term,
                suggestions = (from row in list select row["Name"].ToString()).ToArray()
                              //, data = new[] { "LR", "LY", "LI", "LT" }
            };
            var suggestions = (from row in list select row["Name"].ToString()).ToArray();

            context.Response.Write(JsonConvert.SerializeObject(suggestions));
        }
Ejemplo n.º 16
0
        private void LoadData()
        {
            //TODO backend
            IInfobasisDataSource db = InfobasisDataSource.Create();

            db.ExecuteNonQuery("UPDATE SYtbCompany SET CompanyStatus = @CompanyStatus WHERE ExpiredDatetime IS NOT NULL AND DATEDIFF(dd, GETDATE(), ExpiredDatetime) <= 0", CompanyStatus.Expired);

            // 权限检查

            //ResolveDeleteMenuButtonForGrid(mbDeleteRows, Grid1);
            ResolveDeleteButtonForGrid(btnDeleteSelected, Grid1);
            ResolveDeleteMenuButtonForGrid(mbEnableRows, Grid1, "确定要启用选中的{0}项记录吗?");
            ResolveDeleteMenuButtonForGrid(mbDisableRows, Grid1, "确定要禁用选中的{0}项记录吗?");


            btnNew.OnClientClick = Window1.GetShowReference("~/Pages/Admin/Client_Form.aspx", "新增客户");

            // 每页记录数
            Grid1.PageSize = UserInfo.Current.DefaultPageSize;
            ddlGridPageSize.SelectedValue = UserInfo.Current.DefaultPageSize.ToString();

            BindGrid();
        }
Ejemplo n.º 17
0
        protected void ProcessEntityFieldPermission <T>(T entity, string entityCode)
        {
            int companyID                 = UserInfo.GetCurrentCompanyID();
            IInfobasisDataSource db       = InfobasisDataSource.Create();
            DataTable            dtFields = db.ExecuteTable("EXEC usp_EasyHR_GetFieldPermission @CompanyID, @EntityCode", companyID, entityCode);
            List <string>        columns  = dtFields.AsEnumerable().Select(r => Change.ToString(r["ColumnName"])).Distinct().ToList();

            Type type = entity.GetType();

            foreach (PropertyInfo pi in type.GetProperties())
            {
                string name = pi.Name;
                if (columns.Contains(name))
                {
                    continue;
                }

                Type valueType = pi.PropertyType;
                if (pi.CanWrite)
                {
                    if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        // If it is NULLABLE, then get the underlying type. eg if "Nullable<int>" then this will return just "int"
                        //columnType = p.PropertyType.GetGenericArguments()[0];
                        pi.SetValue(entity, null, null);
                        continue;
                    }

                    switch (valueType.ToString())
                    {
                    case "System.Nullable":
                        pi.SetValue(entity, null, null);
                        break;

                    case "System.String":
                        pi.SetValue(entity, "", null);
                        break;

                    case "System.Boolean":
                        pi.SetValue(entity, null, null);
                        break;

                    case "System.Int32":
                        pi.SetValue(entity, 0, null);
                        break;

                    case "System.Decimal":
                        pi.SetValue(entity, 0, null);
                        break;

                    case "System.DateTime":
                        pi.SetValue(entity, DateTime.MinValue, null);
                        break;

                    default:
                        pi.SetValue(entity, null, null);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private Accordion InitAccordionMenu()
        {
            Accordion accordionMenu = new Accordion();

            accordionMenu.ID         = "accordionMenu";
            accordionMenu.EnableFill = false;
            accordionMenu.ShowBorder = false;
            accordionMenu.ShowHeader = false;
            leftPanel.Items.Add(accordionMenu);


            IInfobasisDataSource db     = InfobasisDataSource.Create();
            XmlDocument          xmlDoc = db.ExecuteXmlDoc("Tree", "EXEC usp_SY_GetModuleTreeXML @CompanyID, @UserID",
                                                           UserInfo.Current.CompanyID, UserInfo.Current.ID);

            XmlNodeList xmlNodes = xmlDoc.SelectNodes("/Tree/TreeNode");

            foreach (XmlNode xmlNode in xmlNodes)
            {
                if (xmlNode.HasChildNodes)
                {
                    string accordionPaneTitle = xmlNode.Attributes["Text"].Value;
                    string isNewHtml          = GetIsNewHtml(xmlNode);
                    if (!String.IsNullOrEmpty(isNewHtml))
                    {
                        accordionPaneTitle += isNewHtml;
                    }

                    AccordionPane accordionPane = new AccordionPane();
                    accordionPane.Title      = accordionPaneTitle;
                    accordionPane.Layout     = Layout.Fit;
                    accordionPane.ShowBorder = false;

                    var accordionPaneIconAttr = xmlNode.Attributes["Icon"];
                    if (accordionPaneIconAttr != null)
                    {
                        accordionPane.Icon = (Icon)Enum.Parse(typeof(Icon), accordionPaneIconAttr.Value, true);
                    }

                    accordionMenu.Items.Add(accordionPane);

                    Tree innerTree = new Tree();
                    innerTree.ShowBorder              = false;
                    innerTree.ShowHeader              = false;
                    innerTree.EnableIcons             = true;
                    innerTree.AutoScroll              = true;
                    innerTree.EnableSingleClickExpand = true;
                    accordionPane.Items.Add(innerTree);

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(String.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?><Tree>{0}</Tree>", xmlNode.InnerXml));
                    ResolveXmlDocument(doc);

                    // 绑定AccordionPane内部的树控件
                    innerTree.NodeDataBound    += treeMenu_NodeDataBound;
                    innerTree.PreNodeDataBound += treeMenu_PreNodeDataBound;
                    innerTree.DataSource        = doc;
                    innerTree.DataBind();
                }
            }

            return(accordionMenu);
        }
Ejemplo n.º 19
0
        public IHttpActionResult SignIn([FromBody] UserSigninDTO user)
        {
            if (user == null)
            {
                return(BadRequest("Invalid Data"));
            }

            if (user.CompanyCode == null || user.CompanyCode == "")
            {
                return(BadRequest("公司代号不能为空!"));
            }

            if (user.UserName == null || user.UserName == "")
            {
                return(BadRequest("用户名不能为空!"));
            }

            if (user.Password == null || user.Password == "")
            {
                return(BadRequest("密码不能为空!"));
            }

            IInfobasisDataSource db = InfobasisDataSource.Create();
            int?companyID           = db.ExecuteScalar("SELECT ID FROM SYtbCompany WHERE CompanyCode = @CompanyCode", user.CompanyCode) as int?;

            var existedUser = _repository.Get(includeProperties: "Company")
                              .Where(u => u.Name == user.UserName && u.CompanyID == companyID)
                              .FirstOrDefault();

            if (existedUser == null)
            {
                return(BadRequest("用户或密码错误,请重新输入!"));
            }

            string currentPasswordHash = existedUser.Password;

            if (!PasswordUtil.ComparePasswords(currentPasswordHash, user.Password))
            {
                updateUserInfo(existedUser, null, false);
                return(BadRequest("用户或密码错误,请重新输入!"));
            }

            if (!existedUser.Enabled)
            {
                updateUserInfo(existedUser, null, false);
                return(BadRequest("该用户帐号已经被停用,请与系统管理员联系!"));
            }

            /*
             *          string authInfo = user.Name + ":" + user.Password; //user.Name + ":" + token;
             *          byte[] byteValue = System.Text.Encoding.Default.GetBytes(authInfo);
             *          string accessToken = Convert.ToBase64String(byteValue);
             */
            var payload = new Dictionary <string, object>()
            {
                { "id", existedUser.ID },
                { "companyID", existedUser.CompanyID },
                { "userName", existedUser.Name }
            };
            var    secretKey = WebApiApplication.SECRETKEY;
            string token     = JWT.JsonWebToken.Encode(payload, secretKey, JWT.JwtHashAlgorithm.HS256);

            if (token == null)
            {
                return(BadRequest("Token获取失败, 请与系统管理员联系!"));
            }

            updateUserInfo(existedUser, token, true);

            var currentUser = new SqlParameter {
                ParameterName = "UserID", Value = existedUser.ID
            };
            var levelParam = new SqlParameter {
                ParameterName = "Level", Value = 1
            };
            //var privileges = _repository.ExecuteStoredProcedureList<UserPermissionRolePrivilege>("EXEC usp_EasyHR_GetPermissionRolePrivilegeByUser", currentUser, levelParam);

            LoginResultDTO loginResult = buildUserInfoToClient(existedUser, token, null);

            return(Ok <LoginResultDTO>(loginResult));
        }