protected void btnSave_Click(object sender, EventArgs e) { if (Request.QueryString["action"] != null) { clsInfomation about = new clsInfomation(); about.TieuDe = this.txtTieuDe.Text; about.NoiDung = this.txtNoiDung.Value; about.TheLoai.Id = Convert.ToInt32(this.ddlTheLoai.SelectedValue); if (Request.QueryString["action"].ToString().Equals("new")) { obj.Insert(about); this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Thêm mới thành công')</script>"); } else { if (Request.QueryString["action"].ToString().Equals("edit")) { if (Request.QueryString["ID"] != null) { clsBSInfomation bsi = new clsBSInfomation(); clsInfomation ifo = new clsInfomation(); int id = Convert.ToInt32(Request.QueryString["ID"]); ifo = bsi.GetById(id); about.TheLoai.Id = ifo.TheLoai.Id; about.Id = id; obj.Update(about); this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Cập nhật thành công')</script>"); } } } } this.odsInfomation.DataBind(); this.GridView1.DataBind(); }
public List<clsInfomation> GetAll() { try { List<clsInfomation> list = new List<clsInfomation>(); string str = "select * from tblInfomation"; SqlCommand com = new SqlCommand(str, con.getCon()); con.openCon(); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { clsInfomation obj = new clsInfomation(); if (dr["tieude"] != DBNull.Value) { obj.TieuDe = dr["tieude"].ToString(); } if (dr["noidung"] != DBNull.Value) { obj.NoiDung = dr["noidung"].ToString(); } if (dr["theloaiid"] != DBNull.Value) { obj.TheLoai.Id = Convert.ToInt32(dr["theloaiid"].ToString()); } if (dr["id"] != DBNull.Value) { obj.Id = Convert.ToInt32(dr["id"].ToString()); } list.Add(obj); } return list; } catch (Exception) { throw; } finally { con.closeCon(); } }
protected void Page_Load(object sender, EventArgs e) { try { if (Request.QueryString["action"] != null) { if (this.pnInfo.Visible == false) { if (Request.QueryString["action"].ToString().Equals("new")) { this.pnInfo.Visible = true; this.txtTieuDe.Text = ""; this.txtNoiDung.Value = ""; this.ddlQuocGia.Enabled = true; this.ddlTheLoai.Enabled = true; } else { if (Request.QueryString["action"].ToString().Equals("edit")) { if (Request.QueryString["ID"] != null) { this.pnInfo.Visible = true; int id = Convert.ToInt32(Request.QueryString["ID"]); clsInfomation about = new clsInfomation(); about = obj.GetById(id); this.txtTieuDe.Text = about.TieuDe; this.txtNoiDung.Value = about.NoiDung; this.ddlQuocGia.Enabled = false; this.ddlTheLoai.Enabled = false; } } } } } else { this.pnInfo.Visible = false; } } catch (Exception) { throw; } }
public clsInfomation GetById(int id) { try { clsInfomation obj = new clsInfomation(); string str = "select * from tblInfomation where id=@id"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@id", id); con.openCon(); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { obj.Id = id; if (dr["tieude"] != DBNull.Value) { obj.TieuDe = dr["tieude"].ToString(); } if (dr["noidung"] != DBNull.Value) { obj.NoiDung = dr["noidung"].ToString(); } if (dr["theloaiid"] != DBNull.Value) { obj.TheLoai.Id = Convert.ToInt32(dr["theloaiid"].ToString()); } } return obj; } catch (Exception) { throw; } finally { con.closeCon(); } }
public void Update(clsInfomation obj) { try { string str = "Update tblInfomation set tieude=@tieude,noidung=@noidung,theloaiid=@theloaiid where id=@id"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@tieude", obj.TieuDe); com.Parameters.AddWithValue("@noidung", obj.NoiDung); com.Parameters.AddWithValue("@theloaiid", obj.TheLoai.Id); com.Parameters.AddWithValue("@id", obj.Id); con.openCon(); com.ExecuteNonQuery(); con.closeCon(); } catch (Exception) { throw; } finally { con.closeCon(); } }
public int Insert(clsInfomation obj) { try { string str = "insert into tblInfomation(tieude,noidung,theloaiid) values(@tieude,@noidung,@theloaiid)"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@tieude", obj.TieuDe); com.Parameters.AddWithValue("@noidung", obj.NoiDung); com.Parameters.AddWithValue("@theloaiid", obj.TheLoai.Id); con.openCon(); com.ExecuteNonQuery(); con.closeCon(); return clsDAStaticMethod.getIDIdentity("tblInfomation"); } catch (Exception) { throw; } finally { con.closeCon(); } }