Пример #1
0
        private void Follow(object sender, EventArgs e, string project)
        {
            // need a timestamp for the notification, also needs some leeway as sending to the server may take a second
            // or more depending on connection.
            DateTime timestamp    = DateTime.Now;
            string   stringTime   = timestamp.ToString("yyyy-MM-dd HH:mm:ss");;
            string   toStringTime = timestamp.AddSeconds(5).ToString("yyyy-MM-dd HH:mm:ss");
            // create a follow project object which will notify the project poster that a user wants access
            SqlFollow sq = new SqlFollow();

            Connection.GetDbConn().CreateCommand(SqlFollow.FollowProject(UserObject.loggedUser.iduser, currentProject));

            // has to create a notification with relevant deatils
            SqlNotifications notif = new SqlNotifications();

            notif.InsertNotification(UserObject.loggedUser.iduser, project, "", "", "follow", "", timestamp);
            // have to get the new notif's id to make a toNotif object, have to use time here as its possible
            // that a user might make multiple requests or might follow, unfollow, then want back in
            DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" +
                                                                   $" WHERE usernotif = {UserObject.loggedUser.iduser} AND project = {project}  AND timestamp BETWEEN '{stringTime}' AND '{toStringTime}' ");
            string newNotifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();
            // need to get the project owner's id
            DataSet projectOwner = Connection.GetDbConn().GetDataSet($"SELECT user FROM project WHERE idproject = {project}");
            string  ownerId      = projectOwner.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();

            notif.InsertToNotify(newNotifId, ownerId, "0");


            MessageBox.Show("Followed");
            //catch (Exception)
            //{
            //    MessageBox.Show("Request already sent");
            //}
        }
Пример #2
0
        private void Follow(object sender, EventArgs e)
        {
            // add a folow object to link the logged in user and this bug
            // need a timestamp for the notification, also needs some leeway as sending to the server may take a second
            // or more depending on connection.
            DateTime timestamp    = DateTime.Now;
            string   stringTime   = timestamp.ToString("yyyy-MM-dd HH:mm:ss");;
            string   toStringTime = timestamp.AddSeconds(5).ToString("yyyy-MM-dd HH:mm:ss");
            // create a follow project object which will notify the project poster that a user wants access
            SqlFollow sq = new SqlFollow();

            Connection.GetDbConn().CreateCommand(SqlFollow.FollowBug(UserObject.loggedUser.iduser, currentBug.idbug));

            // has to create a notification with relevant deatils
            SqlNotifications notif = new SqlNotifications();

            notif.InsertNotification(UserObject.loggedUser.iduser, currentBug.project, currentBug.idbug, "", "bugfollow", "", timestamp);
            // have to get the new notif's id to make a toNotif object, have to use time here as its possible
            // that a user might make multiple requests or might follow, unfollow, then want back in
            // copied logic from following a project here as unlikely user will have multiple notifications on the same project
            // with the same timestamp
            DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" +
                                                                   $" WHERE usernotif = {UserObject.loggedUser.iduser} AND project = {currentBug.project}  AND timestamp BETWEEN '{stringTime}' AND '{toStringTime}' ");
            string newNotifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();
            // need to notify the bug's poster
            DataSet bugPoster = Connection.GetDbConn().GetDataSet($"SELECT poster FROM bug WHERE idbug = {currentBug.idbug}");
            string  posterId  = bugPoster.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();

            notif.InsertToNotify(newNotifId, posterId, "0");


            MessageBox.Show("Followed");
        }
Пример #3
0
        private void RequestAccess(object sender, EventArgs e, ProjectObject project)
        {
            // create a follow project object which will notify the project poster that a user wants access
            try
            { // creates follow table row, as this is a private project (public projects are followed on bugsform)
                // sends a notification to the poster of the project to advise the user wants access.
                DateTime         now         = DateTime.Now;
                string           timestamp   = now.ToString("yyyy-MM-dd HH:mm:ss");
                string           timestampTo = now.AddSeconds(5).ToString("yyyy-MM-dd HH:mm:ss");
                SqlProject       sq          = new SqlProject();
                SqlNotifications notif       = new SqlNotifications();

                Connection.GetDbConn().CreateCommand(SqlFollow.FollowProject(UserObject.loggedUser.iduser, project.idproject));

                notif.InsertNotification(UserObject.loggedUser.iduser, project.idproject, "", "", "request access", "", now);

                DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" +
                                                                       $" WHERE usernotif = {UserObject.loggedUser.iduser} AND project = {project.idproject} AND timestamp BETWEEN '{timestamp}' AND '{timestampTo}'");
                string notifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();

                DataSet getProjectOwner = Connection.GetDbConn().GetDataSet($"SELECT user FROM project WHERE idproject = { project.idproject}");
                string  projOwner       = getProjectOwner.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();

                notif.InsertToNotify(notifId, projOwner, "0");
                MessageBox.Show("Request sent to project creator");
            }
            catch (Exception)
            {
                MessageBox.Show("Request already sent");
            }
        }
        private void Button_PostUpdate_Click(object sender, EventArgs e)
        {
            string   comment, status, postedBy, bug, timeString, timeStringTo;
            DateTime now = DateTime.Now;

            timeString   = now.ToString("yyyy-MM-dd HH:mm:ss");
            timeStringTo = now.AddSeconds(5).ToString("yyyy-MM-dd HH:mm:ss");
            comment      = RichText_Update.Text;
            status       = ComboBox_Status.Text;
            postedBy     = UserObject.loggedUser.username; //comment
            bug          = currentBug.idbug;
            SqlBug updateStatus = new SqlBug();

            updateStatus.UpdateStatus(bug, status);
            SqlUpdate newUpdate = new SqlUpdate();

            newUpdate.InsertUpdate(postedBy, comment, bug, status, timeString);
            Thread.Sleep(1000); // to try and allow status update to reflect when form reloaded

            DataSet toGetUpdateId = Connection.GetDbConn().GetDataSet($"SELECT idupdate FROM `update`" +
                                                                      $" WHERE postedBy = '{postedBy}' AND timestamp BETWEEN '{timeString}' AND '{timeStringTo}'");
            //DataSet ds = Connection.GetDbConn().GetDataSet($"SELECT @@identity");
            string newUpdateId = toGetUpdateId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();

            //i dont there's there's enough time inbetween this update and the form displaying for the
            // status change to register on the db, changed so that bug's status is changed first to see if this helps.
            SqlNotifications notif = new SqlNotifications();

            notif.InsertNotification(UserObject.loggedUser.iduser, currentBug.project, currentBug.idbug,
                                     newUpdateId, "new update", status, now);

            DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" +
                                                                   $" WHERE usernotif = {UserObject.loggedUser.iduser} AND project = {currentBug.project} AND timestamp BETWEEN '{timeString}' AND '{timeStringTo}'");
            string notifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();

            DataTable getBugFollowers = Connection.GetDbConn().GetDataTable($"SELECT user FROM followbug WHERE bug = { currentBug.idbug}");

            foreach (DataRow follower in getBugFollowers.Rows)
            {
                notif.InsertToNotify(notifId, follower["user"].ToString(), "0");
            }
            //string projOwner = getProjectOwner.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();



            display.DisplayBugInfoForm(currentBug);
        }
Пример #5
0
        /// <summary>
        /// Save button clicked, makes a new bug in the database with entered information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Save_Click(object sender, EventArgs e)
        {
            string title,
                   description,
                   location,
                   status,
                   poster,
                   project,
                   referencedBug,
                   priority;
            DateTime timePosted;

            //var referencedBug = "";
            title       = TextBox_Title.Text;
            description = RichText_Description.Text;
            location    = TextBox_Location.Text;
            timePosted  = System.DateTime.Now;
            status      = "In Progress";
            //maybe on log in have a class (loggedUser) which stores the logged in user's ID, then go to that class
            //for this info, for now we're using 41 as test user in DB
            poster  = UserObject.loggedUser.iduser;
            project = currentProject;
            var prior = (Item)ComboBox_Priority.SelectedItem;

            priority = prior.Value;
            if (Combo_RefExistBug.SelectedItem == null)
            {
                referencedBug = "0";
            }
            else
            {
                referencedBug = Combo_RefExistBug.SelectedValue.ToString();
            }

            SqlBug newBug = new SqlBug();

            newBug.InsertBug(title, description, location, timePosted, status, poster, project, priority, referencedBug);
            // now we need to get the bug's id
            Thread.Sleep(2000);
            //string time = timePosted.ToString("yyyy-MM-dd HH:mm:ss");
            DataSet ds = Connection.GetDbConn().GetDataSet($"SELECT idbug FROM bug WHERE poster = {poster} AND " +
                                                           $"title = '{title}' AND project = {project}");
            //DataSet ds = Connection.GetDbConn().GetDataSet($"SELECT @@identity");
            string newBugId = ds.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();
            // not we make a notification for the new bug
            SqlNotifications notif = new SqlNotifications();

            notif.InsertNotification(poster, project, newBugId, "", "new bug", status, timePosted);
            Thread.Sleep(2000);
            // get the notification's id
            DataSet getNotifId = Connection.GetDbConn().GetDataSet($"SELECT idnotification FROM notification" +
                                                                   $" WHERE usernotif = {poster} AND project = {project} AND bug = {newBugId} AND `update` = '{"new bug"}'");
            string newNotifId = getNotifId.Tables[0].Rows[0].ItemArray.GetValue(0).ToString();
            // now we can make a line to notify each user of this new bug
            // creates a line for each user where the user is following this project

            DataTable toNotify = Connection.GetDbConn().GetDataTable($"SELECT user FROM followproject " +
                                                                     $"WHERE project = {project}");

            Connection.connToDb.Close(); // advising conn already open for query below
            foreach (DataRow follower in toNotify.Rows)
            {
                notif.InsertToNotify(newNotifId, follower["user"].ToString(), "0");
            }


            //InsertBug(string title, int description, string location, DateTime timePosted, string status,
            //string poster, string project, string priority)
            display.DisplayBugsForm(currentProject);
        }