public NewsGroupFile GetNewsGroupFileByID(int Id) { NewsGroupFile _newsGroupFile = null; using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsGroupFileGetByID", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@NewsGroupFileID", Id); connection.Open(); using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection)) { if (reader.Read()) { _newsGroupFile = NewsGroupFileReader(reader); } else { throw new DataAccessException("Không tìm thấy tin"); } } command.Dispose(); } return(_newsGroupFile); }
private void initControl(int Id) { if (Id > 0) { btn_add.Visible = false; btn_edit.Visible = true; btn_add1.Visible = false; btn_edit1.Visible = true; try { NewsGroupFileBSO newsgroupFileBSO = new NewsGroupFileBSO(); NewsGroupFile newsgroupFile = newsgroupFileBSO.GetNewsGroupFileByID(Id); hddNewsGroupFileID.Value = Convert.ToString(newsgroupFile.NewsGroupFileID); hddNewsGroupID.Value = Convert.ToString(newsgroupFile.NewsGroupID); hddFileName.Value = newsgroupFile.FileName; txtFileName.Text = newsgroupFile.FileName; txtTitle.Text = newsgroupFile.Title; } catch (Exception ex) { clientview.Text = ex.Message.ToString(); } } else { btn_edit.Visible = false; btn_add.Visible = true; btn_edit1.Visible = false; btn_add1.Visible = true; } }
protected void btn_add_Click(object sender, EventArgs e) { try { if (txtFileName.Text == "") { ViewFiles(Convert.ToInt32(hddNewsGroupID.Value)); clientview.Text = "Chưa có file đính kèm"; } else { NewsGroupFile file = new NewsGroupFile(); file = ReceiveHtml(); NewsGroupFileBSO filesBSO = new NewsGroupFileBSO(); filesBSO.CreateNewsGroupFile(file); ViewFiles(Convert.ToInt32(hddNewsGroupID.Value)); clientview.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Thêm mới thành công !</div>"; } } catch (Exception ex) { clientview.Text = ex.Message.ToString(); } }
private NewsGroupFile ReceiveHtml() { NewsGroupFile newsgroupFile = new NewsGroupFile(); newsgroupFile.NewsGroupFileID = (hddNewsGroupFileID.Value != "") ? Convert.ToInt32(hddNewsGroupFileID.Value) : 0; newsgroupFile.NewsGroupID = Convert.ToInt32(hddNewsGroupID.Value); newsgroupFile.Title = txtTitle.Text; newsgroupFile.FileName = (txtFileName.Text != "") ? txtFileName.Text : hddFileName.Value; return(newsgroupFile); }
private NewsGroupFile NewsGroupFileReader(SqlDataReader reader) { NewsGroupFile _newsGroupFile = new NewsGroupFile(); _newsGroupFile.NewsGroupFileID = (int)reader["NewsGroupFileID"]; _newsGroupFile.NewsGroupID = (int)reader["NewsGroupID"]; _newsGroupFile.FileName = (string)reader["FileName"]; _newsGroupFile.Title = (string)reader["Title"]; return(_newsGroupFile); }
protected void btn_edit_Click(object sender, EventArgs e) { try { NewsGroupFile file = new NewsGroupFile(); file = ReceiveHtml(); NewsGroupFileBSO filesBSO = new NewsGroupFileBSO(); filesBSO.UpdateNewsGroupFile(file); ViewFiles(Convert.ToInt32(hddNewsGroupID.Value)); clientview.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Cập nhật thành công !</div>"; } catch (Exception ex) { clientview.Text = ex.Message.ToString(); } }
public void UpdateNewsGroupFile(NewsGroupFile _newsGroupFile) { using (SqlConnection connection = GetConnection()) { SqlCommand command = new SqlCommand("_NewsGroupFileUpdate", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Type", 1); command.Parameters.AddWithValue("@NewsGroupFileID", _newsGroupFile.NewsGroupFileID); command.Parameters.AddWithValue("@NewsGroupID", _newsGroupFile.NewsGroupID); command.Parameters.AddWithValue("@FileName", _newsGroupFile.FileName); command.Parameters.AddWithValue("@Title", _newsGroupFile.Title); connection.Open(); if (command.ExecuteNonQuery() <= 0) { throw new DataAccessException("Không thể cập nhật hình ảnh"); } else { command.Dispose(); } } }
public void UpdateNewsGroupFile(NewsGroupFile _newsGroupFile) { NewsGroupFileDAO _newsGroupFileDAO = new NewsGroupFileDAO(); _newsGroupFileDAO.UpdateNewsGroupFile(_newsGroupFile); }
public void CreateNewsGroupFile(NewsGroupFile _newsGroupFile) { NewsGroupFileDAO _newsGroupFileDAO = new NewsGroupFileDAO(); _newsGroupFileDAO.CreateNewsGroupFile(_newsGroupFile); }