public NewsCate GetNewsCateByID(int newsGroupID, int cateNewsID) { NewsCate _newsCate = null; using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsCateGetByID", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@NewsGroupID", newsGroupID); command.Parameters.AddWithValue("@CateNewsID", cateNewsID); connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { if (reader.Read()) { _newsCate = NewsCateReader(reader); } else { // throw new DataAccessException("Không tìm thấy tin"); _newsCate = null; } } command.Dispose(); } return(_newsCate); }
protected void add_NewsCate(int _newsgroupID) { NewsCateBSO _newscateBSO = new NewsCateBSO(); NewsCate _newsCate = new NewsCate(); foreach (ListItem items in lboCateSelect.Items) { _newsCate.CateNewsID = Convert.ToInt32(items.Value); _newsCate.NewsGroupID = _newsgroupID; int i = _newscateBSO.CreateNewsCateGet(_newsCate); //strID += items.Value + ","; } //foreach (ListItem items in lboCateSelect.Items) //{ // if (items.Selected) // { // _newsCate.CateNewsID = Convert.ToInt32(items.Value); // _newsCate.NewsGroupID = _newsgroupID; // int i = _newscateBSO.CreateNewsCateGet(_newsCate); // } //} }
public int CreateNewsCateGet(NewsCate cateNews) { int i = 0; using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsCateInsert", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Type", 0); command.Parameters.AddWithValue("@Id", 0); command.Parameters.AddWithValue("@CateNewsID", cateNews.CateNewsID); command.Parameters.AddWithValue("@NewsGroupID", cateNews.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); }
private NewsCate NewsCateReader(SqlDataReader reader) { NewsCate cateNews = new NewsCate(); cateNews.Id = (int)reader["Id"]; cateNews.CateNewsID = (int)reader["CateNewsID"]; cateNews.NewsGroupID = (int)reader["NewsGroupID"]; return(cateNews); }
public ActionResult CateAdd(NewsCate cate) { ResultInfo resultInfo = new ResultInfo(1, "验证不通过"); if (ModelState.IsValid) { resultInfo = _newsCateService.Add(cate); } return Json(resultInfo); }
public void UpdateNewsCate(NewsCate cateNews) { using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsCateUpdate", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Type", 1); command.Parameters.AddWithValue("@Id", cateNews.Id); command.Parameters.AddWithValue("@CateNewsID", cateNews.CateNewsID); command.Parameters.AddWithValue("@NewsGroupID", cateNews.NewsGroupID); connection.Open(); if (command.ExecuteNonQuery() <= 0) { throw new DataAccessException("khong cap nhat duoc cateNews"); } else { command.Dispose(); } } }
public ActionResult CateEdit(NewsCate cate) { ResultInfo resultInfo = new ResultInfo(1, "验证不通过"); if (ModelState.IsValid) { NewsCate oldCate = _newsCateService.GetById(cate.CateId); if (oldCate == null) { resultInfo = new ResultInfo(1, "该信息已被删除或不存在,请刷新列表!"); return Json(resultInfo); } int oldPid = oldCate.Pid; oldCate.CateId = cate.CateId; oldCate.CateName = cate.CateName; oldCate.Pid = cate.Pid; resultInfo = _newsCateService.Update(oldCate, oldPid); } return Json(resultInfo); }
public void UpdateNewsCate(NewsCate newsCate) { NewsCateDAO newsCateDAO = new NewsCateDAO(); newsCateDAO.UpdateNewsCate(newsCate); }
public int CreateNewsCateGet(NewsCate newsCate) { NewsCateDAO newsCateDAO = new NewsCateDAO(); return(newsCateDAO.CreateNewsCateGet(newsCate)); }