Example #1
0
        }//queryAvaliacao()

        private static URLDesejo populateURLDesejo(SqlDataReader dr)
        {
            //id_desejo, ordinal_url, url

            URLDesejo urlDesejoReturn = new URLDesejo();
            urlDesejoReturn.IdDesejo = System.Convert.ToInt64(dr["id_desejo"]);
            urlDesejoReturn.Ordinal = System.Convert.ToByte(dr["ordinal_url"]);
            urlDesejoReturn.URL = System.Convert.ToString(dr["url"]);
            return urlDesejoReturn;
        }
Example #2
0
        }//queryUsuario()

        public static URLDesejo.EnumErroURL deleteURLDesejo(URLDesejo urlDesejo)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;
            SqlDataReader dr = null;
            int iTemp;

            //dando um LOCK:
            String strSql = "SELECT id_desejo FROM Desejo WHERE id_desejo = " + urlDesejo.IdDesejo.ToString();

            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = strSql;
                trans = conn.BeginTransaction();
                cmd.Transaction = trans;

                dr = cmd.ExecuteReader();
                dr.Read();
                dr.Close();

                strSql = "SELECT count(*) num from URLDesejo where id_desejo = " + urlDesejo.IdDesejo.ToString();
                cmd.CommandText = strSql;
                dr = cmd.ExecuteReader();
                dr.Read();
                iTemp = System.Convert.ToInt32(dr["num"]);
                dr.Close();

                strSql = "DELETE from URLDesejo WHERE id_desejo = " + urlDesejo.IdDesejo.ToString();
                strSql += " AND ordinal_url = " + urlDesejo.Ordinal.ToString();
                cmd.CommandText = strSql;
                cmd.ExecuteNonQuery();

                if (urlDesejo.Ordinal < iTemp - 1)
                {
                    for (int i = urlDesejo.Ordinal + 1; i < iTemp; i++)
                    {
                        strSql = "UPDATE URLDesejo SET ordinal_url = " + (i - 1).ToString();
                        strSql += " WHERE id_desejo = " + urlDesejo.IdDesejo.ToString();
                        strSql += " AND ordinal_url = " + i.ToString();
                        cmd.CommandText = strSql;
                        cmd.ExecuteNonQuery();
                    }
                }

                trans.Commit();
                return URLDesejo.EnumErroURL.SUCESSO;
            }
            catch
            {
                trans.Rollback();
                return URLDesejo.EnumErroURL.ERRO_DESCONHECIDO;
            }
            finally
            {
                if (dr != null) dr.Close();
                if (conn != null) conn.Close();
            }
        }//deleteURLDesejo()
        }//Page_Load()

        void imgBtnApagarURL_Click(object sender, ImageClickEventArgs e)
        {
            String strTemp = ((ImageButton)sender).ID;
            strTemp = (strTemp.Split('_'))[1];

            URLDesejo urlDesejo = new URLDesejo();
            urlDesejo.IdDesejo = desejo.IdDesejo;
            urlDesejo.Ordinal = System.Convert.ToByte(strTemp);

            Session["mensagem"] = "Tem certeza de que deseja apagar o link?";
            Session["PedirConfirmacao"] = true;
            Session["deleteObject"] = urlDesejo;
            Response.Redirect("ShowDesejo.aspx?id_desejo=" + desejo.IdDesejo.ToString());
        }