protected void btn_AddNewPermission_OnClick(object sender, EventArgs e) { btn_AddNewPermission.Enabled = false; bool userFound = false; bool roleSelected = false; string newAlias = ""; string role = roles_DropDownList.SelectedItem.Text; // Check if name/user id selected foreach (TableRow TR in tbl_possibleNames.Rows) { RadioButton rb = (RadioButton)(TR.Cells[0].Controls[0]); if (rb.Checked) { userFound = true; newAlias = rb.ID; break; } } if (!userFound) { foreach (TableRow TR in tbl_possibleNames2.Rows) { RadioButton rb = (RadioButton)(TR.Cells[0].Controls[0]); if (rb.Checked) { userFound = true; newAlias = rb.ID; break; } } } // Check for User role selected int index = Convert.ToInt32(roles_DropDownList.SelectedItem.Value); if (index >= 0) { roleSelected = true; } if (userFound && roleSelected) { int[] permissions = Roles.getPermissions(Convert.ToInt32(roles_DropDownList.SelectedItem.Value)); string IP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]; TTDB.addNewPermission(Int32.Parse(Request.QueryString["ID"].ToString()), newAlias, theCake.getActiveUserName(IP), permissions[0], permissions[1], permissions[2], permissions[3], role); Response.Redirect("PSharing.aspx?ID=" + Request.QueryString["ID"].ToString()); } else { ValidationLabel.Text = "***Select User and Role to give them permissions***"; } }
//Add new task functions public static int addNewTask(string taskName, string taskDescription, DateTime expectedStart, DateTime expectedStop, string userName) { int userID = userClass.getUserID(userName); if (userID == -1) { userID = userClass.addNewUser(userName); } SqlCommand cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO [TrackingTool_Projects] VALUES(@taskName, @taskDescription, @expectedStart, @expectedStop, NULL, NULL, 0, @ownerID, NULL, 0, 0, 1)"; cmd.Parameters.AddWithValue("@taskName", taskName); cmd.Parameters.AddWithValue("@taskDescription", taskDescription); cmd.Parameters.AddWithValue("@expectedStart", expectedStart); cmd.Parameters.AddWithValue("@expectedStop", expectedStop); cmd.Parameters.AddWithValue("@ownerID", userID); TTDB.TTQuery(cmd); cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM [TrackingTool_Projects] WHERE [taskName] = @taskName AND [taskDescription] = @taskDescription AND [expectedStart] = @expectedStart AND [expectedStop] = @expectedStop and [ownerID] = @ownerID"; cmd.Parameters.AddWithValue("@taskName", taskName); cmd.Parameters.AddWithValue("@taskDescription", taskDescription); cmd.Parameters.AddWithValue("@expectedStart", expectedStart); cmd.Parameters.AddWithValue("@expectedStop", expectedStop); cmd.Parameters.AddWithValue("@ownerID", userID); DataTable DT = TTDB.TTQuery(cmd); int taskID = Int32.Parse(DT.Rows[0]["ID"].ToString()); TTDB.addNewPermission(taskID, userName, userName, 1, 1, 1, 1, "Owner"); if (DT.Rows.Count > 0) { return(taskID); } else { return(-1); } }