public List <ProjectUsersEntity> GetProjectSunnetUserList(int projectID) { List <ProjectUsersEntity> list = new List <ProjectUsersEntity>(); StringBuilder strSql = new StringBuilder(); strSql.Append(" select A.*,B.RoleID from ProjectUsers A inner join [Users] B on A.UserID=B.UserID "); strSql.Append(" where ProjectID=@ProjectID and IsClient=0 "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { db.AddInParameter(dbCommand, "ProjectID", DbType.Int32, projectID); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { try { while (dataReader.Read()) { list.Add(ProjectUsersEntity.ReaderBind(dataReader)); } } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString() , base.FormatParameters(dbCommand.Parameters), ex.Message)); return(null); } } return(list); } }
private void AssignUsers(string userids, bool isClient) { string[] users = userids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int id = QS("id", 0); if (projApp.RemoveAllUsers(id, isClient)) { List <BrokenRuleMessage> listmsgs = new List <BrokenRuleMessage>(); foreach (string user in users) { ProjectUsersEntity model = ProjectsFactory.CreateProjectUser(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.ProjectID = id; model.UserID = int.Parse(user); model.ISClient = QueryISClient(user); model.ISClient = isClient; if (projApp.AssignUserToProject(model) < 0) { RecordMsg(listmsgs, projApp.BrokenRuleMessages); } } if (listmsgs.Count > 0) { this.ShowFailMessageToClient(); } else { if (!isClient) { InitSunnetUsers(); } this.ShowSuccessMessageToClient(false, false); } } }
/// <summary> /// Get an object entity /// </summary> public ProjectUsersEntity Get(int PUID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select PUID,ProjectID,UserID,ISClient from ProjectUsers "); strSql.Append(" where PUID=@PUID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { db.AddInParameter(dbCommand, "PUID", DbType.Int32, PUID); ProjectUsersEntity model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { try { if (dataReader.Read()) { model = ProjectUsersEntity.ReaderBind(dataReader); } } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters) , ex.Message)); return(null); } } return(model); } }
public int AssignUserToProject(ProjectUsersEntity model) { this.ClearBrokenRuleMessages(); int id = mgr.AssignUserToProject(model); this.AddBrokenRuleMessages(mgr.BrokenRuleMessages); return(id); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { if (IdentityContext.UserID <= 0) { return; } string isClient = context.Request["isClient"]; string projectIdList = context.Request["checkboxList"]; int uid = int.Parse(context.Request["uid"]); string[] projectIds = projectIdList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //这里原本传的是project的Id而我只需要保证弹出的窗口中没有已选择的project就ok了 List <BrokenRuleMessage> listmsgs = new List <BrokenRuleMessage>(); foreach (string projectId in projectIds) { ProjectUsersEntity model = ProjectsFactory.CreateProjectUser(IdentityContext.UserID , ObjectFactory.GetInstance <ISystemDateTime>()); model.ProjectID = int.Parse(projectId); model.UserID = uid; model.ISClient = Boolean.Parse(isClient); if (projApp.AssignUserToProject(model) < 0) { RecordMsg(listmsgs, projApp.BrokenRuleMessages); } } if (listmsgs.Count > 0) { context.Response.Write("Assign Fail!"); } else { context.Response.Write("The project has been assigned."); } } catch (Exception ex) { context.Response.Write("Input special symbol is not allowed,please check title and description!"); WebLogAgent.Write(string.Format("Error Ashx:DoAddTicketHandler.ashx Messages:\r\n{0}", ex)); return; } }
/// <summary> /// Add a record /// </summary> public int Insert(ProjectUsersEntity model) { StringBuilder strSql = new StringBuilder("IF NOT EXISTS(SELECT 1 FROM [ProjectUsers] WHERE [ProjectID] = @ProjectID AND [UserID] = @UserID ) BEGIN "); strSql.Append("insert into ProjectUsers("); strSql.Append("ProjectID,UserID,ISClient)"); strSql.Append(" values ("); strSql.Append("@ProjectID,@UserID,@ISClient)"); strSql.Append(";select ISNULL( SCOPE_IDENTITY(),0);"); strSql.Append("END ELSE BEGIN "); strSql.Append(@"Set @PUID = (SELECT TOP 1 [PUID] FROM [ProjectUsers] WHERE [ProjectID] = @ProjectID AND [UserID] = @UserID ) "); strSql.Append("update ProjectUsers set "); strSql.Append("ProjectID=@ProjectID,"); strSql.Append("UserID=@UserID,"); strSql.Append("ISClient=@ISClient"); strSql.Append(" where PUID=@PUID ; SELECT @PUID ;"); strSql.Append("END "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "PUID", DbType.Int32, 0); db.AddInParameter(dbCommand, "ProjectID", DbType.Int32, model.ProjectID); db.AddInParameter(dbCommand, "UserID", DbType.Int32, model.UserID); db.AddInParameter(dbCommand, "ISClient", DbType.Boolean, model.ISClient); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(0); } } }
/// <summary> /// Update a record /// </summary> public bool Update(ProjectUsersEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ProjectUsers set "); strSql.Append("ProjectID=@ProjectID,"); strSql.Append("UserID=@UserID,"); strSql.Append("ISClient=@ISClient"); strSql.Append(" where PUID=@PUID "); Database db = DatabaseFactory.CreateDatabase(); using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString())) { try { db.AddInParameter(dbCommand, "PUID", DbType.Int32, model.PUID); db.AddInParameter(dbCommand, "ProjectID", DbType.Int32, model.ProjectID); db.AddInParameter(dbCommand, "UserID", DbType.Int32, model.UserID); db.AddInParameter(dbCommand, "ISClient", DbType.Boolean, model.ISClient); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } } catch (Exception ex) { WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]", strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message)); return(false); } } }
protected void btnSave_Click(object sender, EventArgs e) { string msg = string.Empty; if (!CheckInput(out msg)) { this.ShowMessageToClient(msg, 2, false, false); return; } ProjectsEntity model = GetEntity(); int id = projApp.Insert(model); if (id > 0) { ProjectUsersEntity projectUsersEntity = new ProjectUsersEntity(); projectUsersEntity.ISClient = false; projectUsersEntity.CreatedBy = UserInfo.UserID; projectUsersEntity.CreatedOn = DateTime.Now; projectUsersEntity.ProjectID = id; projectUsersEntity.RoleID = (int)RolesEnum.PM; projectUsersEntity.UserID = model.PMID; int result = projApp.AssignUserToProject(projectUsersEntity); if (result > 0) { this.ShowSuccessMessageToClient(); } else { this.ShowFailMessageToClient(projApp.BrokenRuleMessages); } } else { this.ShowFailMessageToClient(projApp.BrokenRuleMessages); } }
protected void btnSave_Click(object sender, EventArgs e) { string msg = string.Empty; if (!CheckInput(out msg)) { this.ShowMessageToClient(msg, 2, false, false); return; } ProjectsEntity model = GetEntity(); int id = projApp.Insert(model); if (id > 0) { ProjectUsersEntity projectUsersEntity = new ProjectUsersEntity(); projectUsersEntity.ISClient = false; projectUsersEntity.CreatedBy = UserInfo.UserID; projectUsersEntity.CreatedOn = DateTime.Now; projectUsersEntity.ProjectID = id; projectUsersEntity.UserID = model.PMID; int result = projApp.AssignUserToProject(projectUsersEntity); if (result > 0) { Redirect(string.Format("EditProject.aspx?ID={0}&returnurl={1}", id, Server.UrlEncode("/Admin/Projects/Projects.aspx"))); } else { this.ShowFailMessageToClient(projApp.BrokenRuleMessages); } } else { this.ShowFailMessageToClient(projApp.BrokenRuleMessages); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { if (IdentityContext.UserID <= 0) { return; } string isClient = context.Request["isClient"]; string projectIdList = context.Request["checkboxList"]; int uid = int.Parse(context.Request["uid"]); string[] projectIds = projectIdList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); #region 获取已经分配了的project SearchProjectsRequest request = new SearchProjectsRequest(SearchProjectsType.ListByUserID , false, "projectId", "ASC"); request.UserID = uid; SearchProjectsResponse projectList = new ProjectApplication().SearchProjects(request); for (int i = 0; i < projectIds.Length; i++) { int projectId = 0; int.TryParse(projectIds[i], out projectId); ProjectDetailDTO project = projectList.ResultList.Find(t => t.ProjectID == projectId); if (project != null && project.ProjectID != 0) { context.Response.Write("some of the selected projects have been assigned to this user!"); return; } } #endregion List <BrokenRuleMessage> listmsgs = new List <BrokenRuleMessage>(); foreach (string projectId in projectIds) { ProjectUsersEntity model = ProjectsFactory.CreateProjectUser(IdentityContext.UserID , ObjectFactory.GetInstance <ISystemDateTime>()); model.ProjectID = int.Parse(projectId); model.UserID = uid; model.ISClient = Boolean.Parse(isClient); if (projApp.AssignUserToProject(model) < 0) { RecordMsg(listmsgs, projApp.BrokenRuleMessages); } } if (listmsgs.Count > 0) { context.Response.Write("Assign Fail!"); } else { context.Response.Write("The project has been assigned."); } } catch (Exception ex) { context.Response.Write("Input special symbol is not allowed,please check title and description!"); WebLogAgent.Write(string.Format("Error Ashx:DoAddTicketHandler.ashx Messages:\r\n{0}", ex)); return; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (IdentityContext.UserID <= 0) { return; } UsersEntity userEntity = userApp.GetUser(IdentityContext.UserID); if (userEntity == null || (userEntity.Role != RolesEnum.ADMIN && userEntity.Role != RolesEnum.PM)) { context.Response.Write("Not authority"); return; } string project = context.Request.Form["projectId"]; int projectId; if (!int.TryParse(project, out projectId)) { context.Response.Write("Parameter errors."); return; } string optionType = context.Request.Form["type"] + ""; optionType = optionType.ToLower(); if (string.IsNullOrEmpty(optionType.Trim()) || (optionType != "add" && optionType != "del")) { context.Response.Write("Parameter errors."); return; } string user = context.Request.Form["UserId"]; int userId; if (!int.TryParse(user, out userId)) { context.Response.Write("Parameter errors."); return; } if (optionType == "del") { proApp.DeleteProjectUser(projectId, userId); } else { string client = context.Request.Form["client"] + ""; if (string.IsNullOrEmpty(client) || (client != "sunnet" && client != "client")) { context.Response.Write("Parameter errors."); return; } UsersEntity assentUserEntity = userApp.GetUser(userId); if (assentUserEntity == null) { context.Response.Write("Parameter errors."); return; } ProjectUsersEntity projectuserEntity = new ProjectUsersEntity() { ProjectID = projectId, UserID = userId, ISClient = client.Equals("client", StringComparison.CurrentCultureIgnoreCase) }; proApp.AssignUserToProject(projectuserEntity); } }