예제 #1
0
        public NewsRelation GetNewsRelationByID(int newsGroupID, int newsID)
        {
            NewsRelation _newRelation = null;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_NewsRelationGetByID", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@NewsGroupID", newsGroupID);
                command.Parameters.AddWithValue("@NewsID", newsID);
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        _newRelation = NewsRelationReader(reader);
                    }
                    else
                    {
                        // throw new DataAccessException("Không tìm thấy tin");
                        _newRelation = null;
                    }
                }
                command.Dispose();
            }
            return(_newRelation);
        }
예제 #2
0
        public int CreateNewsRelationGet(NewsRelation newsRelation)
        {
            int i = 0;

            using (SqlConnection connection = GetConnection())
            {
                SqlCommand command = new SqlCommand("_NewsRelationInsert", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Type", 0);
                command.Parameters.AddWithValue("@Id", 0);
                command.Parameters.AddWithValue("@NewsID", newsRelation.NewsID);
                command.Parameters.AddWithValue("@NewsGroupID", newsRelation.NewsGroupID);

                SqlParameter parameter = new SqlParameter("@ReturnId", SqlDbType.Int);
                parameter.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(parameter);
                connection.Open();
                if (command.ExecuteNonQuery() <= 0)
                {
                    throw new DataAccessException("Khong them duoc");
                }
                else
                {
                    i = (int)parameter.Value;
                    command.Dispose();
                }
            }
            return(i);
        }
예제 #3
0
    protected void btn_add_Click(object sender, EventArgs e)
    {
        NewsRelationBSO _newsRelationBSO = new NewsRelationBSO();
        NewsRelation    _newsRelation    = new NewsRelation();

        foreach (GridViewRow rows in grvNewsGroup.Rows)
        {
            CheckBox checkbox = (CheckBox)rows.Cells[0].FindControl("chkId");
            if (checkbox.Checked)
            {
                _newsRelation = _newsRelationBSO.GetNewsRelationByID(Convert.ToInt32(rows.Cells[0].Text), Convert.ToInt32(hddNewsID.Value));

                if (_newsRelation == null)
                {
                    _newsRelation             = new NewsRelation();
                    _newsRelation.NewsGroupID = Convert.ToInt32(rows.Cells[0].Text);
                    _newsRelation.NewsID      = Convert.ToInt32(hddNewsID.Value);

                    int i = _newsRelationBSO.CreateNewsRelationGet(_newsRelation);
                }
            }
        }

        ViewNewsReleation(Convert.ToInt32(hddNewsID.Value));
        clientview.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Cập nhật thành công !</div>";
        AspNetCache.Reset();
    }
예제 #4
0
    protected void grvRelation_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int             Id = Convert.ToInt32(e.CommandArgument.ToString());
        NewsRelationBSO _newsRelationBSO = new NewsRelationBSO();
        NewsRelation    _newsRelation    = _newsRelationBSO.GetNewsRelationByID(Id, Convert.ToInt32(hddNewsID.Value));

        NewsGroupBSO newsGroupBSO = new NewsGroupBSO();
        NewsGroup    newsgroup    = newsGroupBSO.GetNewsGroupById(Id);

        string   nName    = e.CommandName.ToLower();
        AdminBSO adminBSO = new AdminBSO();
        Admin    admin    = new Admin();

        switch (nName)
        {
        case "_view":
            break;

        case "_edit":
            Response.Redirect("~/Admin/editnewsbyuser/" + newsgroup.GroupCate + "/" + Id + "/Default.aspx");
            break;

        case "_delete":
            _newsRelationBSO.DeleteNewsRelation(_newsRelation.Id);
            ViewNewsReleation(Convert.ToInt32(hddNewsID.Value));
            AspNetCache.Reset();

            break;
        }
    }
예제 #5
0
        private NewsRelation NewsRelationReader(SqlDataReader reader)
        {
            NewsRelation newsRelation = new NewsRelation();

            newsRelation.Id          = (int)reader["Id"];
            newsRelation.NewsID      = (int)reader["NewsID"];
            newsRelation.NewsGroupID = (int)reader["NewsGroupID"];

            return(newsRelation);
        }
예제 #6
0
 public void UpdateNewsRelation(NewsRelation newsRelation)
 {
     using (SqlConnection connection = GetConnection())
     {
         SqlCommand command = new SqlCommand("_NewsRelationUpdate", connection);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Type", 1);
         command.Parameters.AddWithValue("@Id", newsRelation.Id);
         command.Parameters.AddWithValue("@NewsID", newsRelation.NewsID);
         command.Parameters.AddWithValue("@NewsGroupID", newsRelation.NewsGroupID);
         connection.Open();
         if (command.ExecuteNonQuery() <= 0)
         {
             throw new DataAccessException("khong cap nhat duoc newsRelation");
         }
         else
         {
             command.Dispose();
         }
     }
 }
예제 #7
0
        public void UpdateNewsRelation(NewsRelation newsRelation)
        {
            NewsRelationDAO newsRelationDAO = new NewsRelationDAO();

            newsRelationDAO.UpdateNewsRelation(newsRelation);
        }
예제 #8
0
        public int CreateNewsRelationGet(NewsRelation newsRelation)
        {
            NewsRelationDAO newsRelationDAO = new NewsRelationDAO();

            return(newsRelationDAO.CreateNewsRelationGet(newsRelation));
        }