protected void btnDel_Click(object sender, EventArgs e) { LinkButton lbt = (LinkButton)sender; HiddenField h = (HiddenField)lbt.FindControl("hfID"); clsTour tl = new clsTour(); tl.Id = Convert.ToInt32(h.Value); clsBSTour t = new clsBSTour(); if (t.Del(tl)) { lblMes.Text = "<script>alert('Tàu đã được xóa');</script>"; mtvTour.ActiveViewIndex = 0; GridView1.DataBind(); } else { lblMes.Text = "<script>alert('Lỗi, không thể xóa !');</script>"; } }
public bool DeleteTour(clsTour to) { string sql = "Delete from tblTour where ID=@ID"; bool st = false; clsDAConnection conn = new clsDAConnection(); conn.openCon(); using (SqlCommand com = conn.getCon().CreateCommand()) { com.CommandType = CommandType.Text; com.CommandText = sql; com.Parameters.Add("@ID", SqlDbType.Int).Value = to.Id; // Execute the command and process the result. if (com.ExecuteNonQuery() == 1) { st = true; } conn.closeCon(); return st; } }
protected void Page_Load(object sender, EventArgs e) { try { IOBusiness.clsBSDetail obj = new IOBusiness.clsBSDetail(); List<clsDetail> objD = new List<clsDetail>(); objD=obj.GetByTour(Convert.ToInt32(Request.QueryString["id"])); foreach (IOEntity.clsDetail item in objD) { IOBusiness.clsBSTypeDetail type = new IOBusiness.clsBSTypeDetail(); IOEntity.clsTypeDetail typeobj = new IOEntity.clsTypeDetail(); typeobj = type.GetById(item.TypeDetail.Id); AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel(); tab.HeaderText = typeobj.TieuDe; Label lb = new Label(); lb.Text = item.NoiDung; tab.Controls.Add(lb); this.TabContainer1.Tabs.AddAt(0,tab); //this.TabContainer1.Tabs[1] } this.TabContainer1.Tabs.RemoveAt(objD.Count); clsBSTour objtour = new clsBSTour(); clsTour t = new clsTour(); t = objtour.GetById(Convert.ToInt32(Request.QueryString["id"])); this.lblTour.Text = t.TieuDe; this.Label1.Text = t.TieuDe; this.DataList2.DataSource = objtour.GetByLoai(t.TheLoai.Id, Convert.ToInt32(Request.QueryString["id"])); DataList2.DataBind(); if (!Page.IsPostBack) { BindCountry(); } } catch (Exception) { throw; } }
protected void btnCreate_Click(object sender, EventArgs e) { mtvTour.ActiveViewIndex = 1; clsTour tl = new clsTour(); tl.MyTheLoai = Convert.ToInt32(cbxTheLoai.SelectedValue); tl.TieuDe = txtTieuDe.Text; tl.GhiChu = txtGhiChu.Text; tl.Hot = ckbHot.Checked; tl.Stt = Convert.ToInt32(txtViTri.Text); tl.SearchID = Convert.ToInt32(cbxSearch.SelectedValue); if (fileUpload.HasFile) { tl.HinhAnh = fileUpload.FileName; } else { tl.HinhAnh = "demo.jpg"; } clsBSTour bsTL = new clsBSTour(); if (bsTL.Insert(tl)) { if (fileUpload.HasFile == true) { String file = fileUpload.FileName; fileUpload.SaveAs(Server.MapPath("~/Images/HinhAnh/") + file); } lblMes.Text = "<script>alert('Tàu đã được tạo');</script>"; mtvTour.ActiveViewIndex = 0; GridView1.DataBind(); } else { lblMes.Text = "<script>alert('Lỗi, vui lòng kiểm tra dữ liệu !');</script>"; } }
// Sua danh muc public bool EditTour(clsTour to) { string sql = "Update tbltour set Tieude=@tieude,GhiChu=@ghichu,TheLoaiID=@tlID,Hot=@hot,STT=@stt,HinhAnh=@HinhAnh,SearchID=@SearchID Where ID=@ID"; bool st = false; clsDAConnection conn = new clsDAConnection(); conn.openCon(); using (SqlCommand com = conn.getCon().CreateCommand()) { com.CommandType = CommandType.Text; com.CommandText = sql; // Create a SqlParameter object for the title parameter. SqlParameter p1 = com.CreateParameter(); p1.ParameterName = "@tieude"; p1.SqlDbType = SqlDbType.NVarChar; p1.Size = 50; p1.Value = to.TieuDe; com.Parameters.Add(p1); // Use a shorthand syntax to add the id parameter. com.Parameters.Add("@tlID", SqlDbType.Int).Value = to.MyTheLoai; com.Parameters.Add("@ghichu", SqlDbType.NVarChar, 1000).Value = to.GhiChu; com.Parameters.Add("@stt", SqlDbType.Int).Value = to.Stt; com.Parameters.Add("@hot", SqlDbType.Int).Value = to.Hot; com.Parameters.Add("@HinhAnh", SqlDbType.NVarChar, 50).Value = to.HinhAnh; com.Parameters.Add("@ID", SqlDbType.Int).Value = to.Id; com.Parameters.Add("@SearchID", SqlDbType.Int).Value = to.SearchID; // Execute the command and process the result. if (com.ExecuteNonQuery() == 1) { st = true; } conn.closeCon(); return st; } }
protected void btnEditSave_Click(object sender, EventArgs e) { mtvTour.ActiveViewIndex = 2; clsTour tl = new clsTour(); tl.MyTheLoai = Convert.ToInt32(cbxTheLoaiEdit.SelectedValue); tl.TieuDe = txtTieuDeEdit.Text; tl.GhiChu = txtGhiChuEdit.Text; tl.Hot = ckbHotEdit.Checked; tl.Stt = Convert.ToInt32(txtViTriEdit.Text); tl.Id = Convert.ToInt32(hfID.Value); tl.SearchID = Convert.ToInt32(cbxS.SelectedValue); if (btnIGM.Visible == false) { if (fileUploadEdit.FileName == null) { tl.HinhAnh = hfImage.Value; } else { tl.HinhAnh = fileUploadEdit.FileName; if (fileUploadEdit.HasFile) { fileUploadEdit.SaveAs(Server.MapPath("~/Images/HinhAnh/") + fileUploadEdit.FileName); } } } else { tl.HinhAnh = hfImage.Value; } clsBSTour bsTL = new clsBSTour(); if (bsTL.Edit(tl)) { lblMes.Text = "<script>alert('Tàu đã được sửa');</script>"; mtvTour.ActiveViewIndex = 0; GridView1.DataBind(); } else { lblMes.Text = "<script>alert('Lỗi, vui lòng kiểm tra dữ liệu !');</script>"; } }
public bool Edit(clsTour to) { clsDATour d = new clsDATour(); return d.EditTour(to); }
public bool Del(clsTour to) { clsDATour d = new clsDATour(); return d.DeleteTour(to); }
public bool Insert(clsTour to) { clsDATour d = new clsDATour(); return d.InsertTour(to); }
public List<clsTour> GetAll() { try { List<clsTour> list = new List<clsTour>(); string str = "select * from tblTour order by id DESC"; SqlCommand com = new SqlCommand(str, con.getCon()); con.openCon(); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { clsTour obj = new clsTour(); obj.TheLoai = new clsTheLoai(); if (dr["tieude"] != DBNull.Value) { obj.TieuDe = dr["tieude"].ToString(); } if (dr["ghichu"] != DBNull.Value) { obj.GhiChu = dr["ghichu"].ToString(); } if (dr["hinhanh"] != DBNull.Value) { obj.HinhAnh = dr["hinhanh"].ToString(); } if (dr["hot"] != DBNull.Value) { obj.Hot = Convert.ToBoolean(dr["hot"].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(); } }
public clsTour GetById(int id) { try { clsTour obj = new clsTour(); obj.TheLoai = new clsTheLoai(); string str = "select * from tbltour 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["ghichu"] != DBNull.Value) { obj.GhiChu = dr["ghichu"].ToString(); } if (dr["hinhanh"] != DBNull.Value) { obj.HinhAnh = dr["hinhanh"].ToString(); } if (dr["hot"] != DBNull.Value) { obj.Hot = Convert.ToBoolean(dr["hot"].ToString()); } if (dr["theloaiid"] != DBNull.Value) { obj.TheLoai.Id = Convert.ToInt32(dr["theloaiid"].ToString()); } } return obj; } catch (Exception) { throw; } finally { con.closeCon(); } }