Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie userCookie;
            userCookie = Request.Cookies["UserID"];
            if (userCookie == null)
            {
                Response.Redirect("../Account/Login.aspx");
            }
            else
            {
                Party_Class party = new Party_Class();
                List<Party_Class> partyList = new List<Party_Class>();

                User_Class myUser = new User_Class();
                myUser = myUser.getUser(userCookie.Value);

                partyList = party.userGroups(myUser.Id);

                HyperLink link = new HyperLink();
                Panel p = new Panel();

                int i = partyList.Count() - 1;

                while(i>=0)
                {
                    string id = partyList[i].Id.ToString();
                    link = new HyperLink();
                    link.CssClass = "button white";
                    link.Width=300;
                    link.Height = 30;

                    p = new Panel();
                    link.ID = "link" + id;
                    p.ID = "panel" + id;

                    link.Text = partyList[i].Name;
                    link.NavigateUrl = "~/Asp_forms/Groups_Notes.aspx?ID=" + id;

                    p.Controls.Add(link);
                    Panel2.Controls.Add(p);
                    i--;

                }
            }
        }
Exemplo n.º 2
0
        protected void Delete(object sender, EventArgs e)
        {
            string s = Request.QueryString["ID"];
             if (s != null)
             {
                 Party_Class party = new Party_Class();
                 party.Id = Int32.Parse(s);

                 if (party.deleteParty())
                 {
                     Response.Redirect("~/Asp_forms/Groups.aspx");
                 }
                 else
                 {
                     Label l = new Label();
                     l.Text = "An error has occurred. Please clean up the cork table before perform this action.";
                     Panel2.Controls.Add(l);
                 }

             }
        }
Exemplo n.º 3
0
        protected void Create_Note(object sender, EventArgs e)
        {
            HttpCookie userCookie;
            userCookie = Request.Cookies["UserID"];
            if (userCookie == null)
            {
                Response.Redirect("../Account/Login.aspx");
            }
            else
            {

             string s = Request.QueryString["ID"];
             if (s != null)
             {
                 Party_Class party = new Party_Class();
                 party.Id = Int32.Parse(s);

                 User_Class user = new User_Class();
                 user = user.getUser(userCookie.Value);

                 Note_Class note = new Note_Class();
                 note.Text = DescripcionNota.Text;
                 note.Date = DateTime.Now.ToShortDateString();

                 if (party.addNote(note, user.Id))
                 {
                     Page.MaintainScrollPositionOnPostBack = true;
                     Response.Redirect("~/Asp_forms/Groups_Notes.aspx?ID=" + party.Id);
                 }
                 else
                     Label2.Text = "An error has occurred";
             }

            }

            /* Create note with the button 'New Note' */
        }
Exemplo n.º 4
0
        public bool createParty(Party_Class party)
        {
            bool creada=false;

            SqlConnection con = new SqlConnection(connection);

            try
            {
                //con.Open();
                Console.WriteLine("hola");
                string sql = "INSERT INTO PARTY (NAME) OUTPUT INSERTED.ID VALUES ('" + party.Name + "')";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                int id = -1;
                if (reader.Read())
                {
                    id = int.Parse(reader["ID"].ToString());
                }
                cmd.Connection.Close();

                SqlCommand cmd1;
                String sql2;
                foreach (User_Class user in party.Users)
                {

                    sql2 = "INSERT INTO US_PA_REL(UID, PID) VALUES (" + user.Id + "," + id + ")";
                    cmd1 = new SqlCommand(sql2, con);
                    cmd1.Connection.Open();
                    cmd1.ExecuteNonQuery();
                    cmd1.Connection.Close();
                }

                creada = true;
            }
            catch (Exception ex)
            {
                creada = false;
            }
            finally
            {
                con.Close();
            }

            return creada;
        }
Exemplo n.º 5
0
        //Devuelve una lista con los grupos de un usuario
        public List<Party_Class> userGroups(int id)
        {
            SqlConnection con = new SqlConnection(connection);
            List<Party_Class> partyList = new List<Party_Class>();

            try
            {

                con.Open();
                string sql = "SELECT * FROM PARTY WHERE ID IN (SELECT PID FROM US_PA_REL WHERE UID=" + id + ")";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataReader reader = cmd.ExecuteReader();

                Party_Class party = new Party_Class();

                while (reader.Read())
                {
                    party = new Party_Class();
                    party.Id = int.Parse(reader["ID"].ToString());
                    party.Name = reader["NAME"].ToString();

                    partyList.Add(party);
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                con.Close();
            }

            return partyList;
        }
Exemplo n.º 6
0
        public bool update(Party_Class myParty)
        {
            bool actualizado;

            SqlConnection con = new SqlConnection(connection);
            string sql = "UPDATE PARTY SET NAME = " + myParty.Name + "WHERE ID = " +  myParty.Id;
            SqlCommand cmd = new SqlCommand(sql,con);

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                actualizado = true;
            }
            catch (Exception ex)
            {
                actualizado = false;
            }
            finally
            {
                con.Close();
            }

            return actualizado;
        }
Exemplo n.º 7
0
        public bool deleteParty(Party_Class myParty)
        {
            bool borrado;

            SqlConnection con = new SqlConnection(connection);

            try
            {
                string sql1 = "DELETE FROM PARTY WHERE ID =" + myParty.Id.ToString();
                string sql2 = "DELETE FROM US_PA_REL WHERE PID =" + myParty.Id.ToString();
                string sql3 = "DELETE FROM NOTES WHERE PARTY_ID =" + myParty.Id.ToString();
                SqlCommand cmd2 = new SqlCommand(sql2, con);
                SqlCommand cmd1 = new SqlCommand(sql1, con);
                SqlCommand cmd3 = new SqlCommand(sql3, con);

                cmd3.Connection.Open();
                cmd3.ExecuteNonQuery();
                cmd3.Connection.Close();

                cmd2.Connection.Open();
                cmd2.ExecuteNonQuery();
                cmd2.Connection.Close();

                cmd1.Connection.Open();
                cmd1.ExecuteNonQuery();
                cmd2.Connection.Close();

                borrado = true;
            }
            catch (Exception ex)
            {
                borrado = false;
            }
            finally
            {
                con.Close();
            }

            return borrado;
        }
Exemplo n.º 8
0
        protected void SendGroup(object sender, EventArgs e)
        {
            HttpCookie userCookie;
            userCookie = Request.Cookies["UserID"];
            user = new User_Class();
            user = user.getUser(userCookie.Value);
            user.getFriends();

            Party_Class newParty = new Party_Class();
            newParty.Name = TextBox1.Text;

            Label3.Text = ListBox2.Items.Count.ToString();
            int indice=0;

            newParty.Users.Add(user);

            foreach (ListItem li in ListBox2.Items)
            {
                indice = Int32.Parse(li.Value);
                newParty.Users.Add(user.Friends[indice]);
            }

            if (ListBox2.Items.Count == 0 || TextBox1.Text == "")
            {
                Label3.Text = "Add users and set Name.";
            }
            else
            {
                if (newParty.createParty())
                    Response.Redirect("..//Asp_forms/Groups.aspx");
                else
                    Label3.Text = "error";
            }
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.MaintainScrollPositionOnPostBack = true;

            HttpCookie userCookie;
            userCookie = Request.Cookies["UserID"];
            if (userCookie == null)
            {
                Response.Redirect("../Account/Login.aspx");
            }
            else
            {

                string s = Request.QueryString["ID"];
                if (s != null && s!="")
                {

                    Party_Class party = new Party_Class();
                    party.Id = Int32.Parse(s);
                    party.obtainNotes();
                    party.getName();
                    Label1.Text = party.Name;

                    HyperLink3.NavigateUrl = "~/Asp_forms/Groups_Notes.aspx?ID=" + party.Id;
                    HyperLink3.Text = party.Name;

                    Panel p = new Panel();
                    Label t = new Label();
                    Label f = new Label();
                    Label a = new Label();

                    Button b = new Button();
                    ImageButton imgbuttone = new ImageButton();
                    ImageButton imgbuttonb = new ImageButton();

                    Panel psub = new Panel();

                    User_Class userTemp = new User_Class();
                    userTemp = userTemp.getUser(userCookie.Value);

                    User_Class userNote = new User_Class();

                    foreach (Note_Class note in party.Notes)
                    {

                        p = new Panel();
                        a = new Label();
                        userNote = new User_Class();
                        psub = new Panel();

                        t = new Label();
                        f = new Label();

                        imgbuttone = new ImageButton();
                        imgbuttonb = new ImageButton();

                        imgbuttone.ImageUrl = "../Images/editButton.png";
                        imgbuttone.PostBackUrl = "~/Asp_forms/Editnotes.aspx?ID=" + note.Id.ToString();
                        imgbuttone.Width = 30;

                        imgbuttonb.ImageUrl = "../Images/deleteButton.png";
                        imgbuttonb.PostBackUrl = "~/Asp_forms/Deletenote.aspx?ID=" + note.Id.ToString();

                        imgbuttonb.Width = 30;
                        imgbuttonb.ToolTip = "Delete";
                        imgbuttone.ToolTip = "Edit";

                        psub.CssClass = "default_panel";
                        psub.HorizontalAlign = HorizontalAlign.Right;

                        psub.Controls.Add(imgbuttonb);
                        psub.Controls.Add(imgbuttone);

                        string id = note.Id.ToString();

                        p.ID = "p" + id;
                        p.CssClass = "postitnotesblue";
                        t.ID = "t" + id;

                        f.ID = "f" + id;

                        t.Text = note.Text.ToString() + "<BR><BR>";
                        a.Text = "<BR>"+userNote.getUser(note.Author).Nick;
                        a.CssClass = "noteauthor";

                        p.Controls.Add(t);
                        p.Controls.Add(f);

                        psub.Controls.Add(a);
                        p.Controls.Add(psub);

                        Panel1.Controls.Add(p);

                    }

                }
                else
                    Response.Redirect("~/Asp_forms/Groups.aspx");

            }
        }