示例#1
0
        private static bool SetUnitSecUser(string sid, DBSource dbsource, Project prjProject, string strCompanyCode, string strCompanyDesc, ref string strSecretarilman)
        {
            try
            {
                #region 自动设置文控,如果没有与单位代码一样的用户,就自动添加用户
                User secUser = null;
                if (string.IsNullOrEmpty(strSecretarilman))
                {
                    secUser = dbsource.GetUserByCode(strCompanyCode);
                    if (secUser == null)
                    {
                        ////UserController. CreateUser(sid, strCompanyCode, strCompanyDesc + "文控", "", "0",
                        ////            "0", "", strCompanyCode, strCompanyCode);
                        ////secUser = dbsource.GetUserByCode(strCompanyCode);
                        secUser = dbsource.NewUser(
                            enUserFlage.OnLine,
                            enUserType.Default,
                            "",
                            strCompanyCode,
                            strCompanyDesc + "文控",
                            strCompanyCode,
                            "",
                            null
                            );

                        if (secUser != null)
                        {
                            User m_user = secUser;
                            m_user.O_suser1 = m_user.dBSource.GUID;

                            m_user.Modify();



                            // 强制刷新共享数据源
                            //
                            //DBSourceController.RefreshShareDBManager();
                            DBSourceController.RefreshDBSource(sid);
                            strSecretarilman = secUser.ToString;
                        }
                    }
                    else
                    {
                        strSecretarilman = secUser.ToString;
                    }
                }
                else
                {
                    secUser = dbsource.GetUserByCode(strCompanyCode);
                }

                if (secUser != null)
                {
                    //把用户添加到项目管理类里面的项目单位用户组
                    Group group = dbsource.GetGroupByName(prjProject.Code + "_ALLUnit");

                    if (group != null)
                    {
                        if (!group.UserList.Contains(secUser))
                        {
                            group.AddUser(secUser);
                            group.Modify();
                        }
                    }
                }
                #endregion
            }
            catch { }
            return(true);
        }