public TaiLieu getTaiLieuTheoMa(string ma) { try { TaiLieu taiLieu = new TaiLieu(); SqlCommand command = truyVan1("select * from TaiLieu5 where MaTLieu = @ma"); command.Parameters.Add("@ma", SqlDbType.NVarChar).Value = ma; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { taiLieu.MaTLieu = reader.GetString(0); taiLieu.TenTLieu = reader.GetString(1); taiLieu.MaTLoai = reader.GetString(2); taiLieu.SLuong = reader.GetInt32(3); taiLieu.NXB = reader.GetString(4); taiLieu.NamXB = reader.GetInt32(5); taiLieu.Anh = reader.GetString(6); taiLieu.MaTG = reader.GetString(7); } reader.Close(); return(taiLieu); } catch { } return(null); }
public ActionResult Create(TaiLieu tailieu, HttpPostedFileBase fileUpload) { try { if (ModelState.IsValid) { //Upload file var fileName = Path.GetFileName(fileUpload.FileName); //Lưu đường dẫn file ảnh var path = Path.Combine(Server.MapPath("~/Content/Image"), fileName); //Kiểm tra file đã tồn tại if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } //Them Sach Moi tailieu.TL_HinhAnh = fileUpload.FileName; db.TaiLieux.Add(tailieu); db.SaveChanges(); } } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Error Save Data"); } //Cập nhật lại danh sách hiển thị var listBook = from s in db.TaiLieux select s; return(View("Index", listBook)); }
public ActionResult File(HttpPostedFileBase file, int idlh) { //try // if (file.ContentLength > 0) { var lh = new LopHocDAO().GetByID(idlh); string _FileName = Path.GetFileName(file.FileName); string _path = Path.Combine(Server.MapPath("~/Content/img/"), _FileName); file.SaveAs(_path); int fileSize = file.ContentLength; int Size = fileSize / 1000000; var dao = new TaiLieuDAO(); var tailieu = new TaiLieu(); tailieu.ten = _FileName; tailieu.FileSize = Size; tailieu.link = _path; tailieu.idLH = lh.ID; tailieu.thoiGian = DateTime.Now; tailieu.idTK = lh.Giangvien.TaiKhoan.iD; tailieu.idKN = 5; dao.Insert(tailieu); } ViewBag.Message = "File Uploaded Successfully!!"; return(RedirectToAction("File")); //} //catch //{ // ViewBag.Message = "File upload failed!!"; // return RedirectToAction("File"); //} }
public List <TaiLieu> dsTaiLieu() { openConnection(); List <TaiLieu> dsTL = new List <TaiLieu>(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; command.CommandText = "SELECT * FROM TaiLieu5"; command.Connection = conn; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { TaiLieu taiLieu = new TaiLieu(); taiLieu.MaTLieu = reader.GetString(0); taiLieu.TenTLieu = reader.GetString(1); taiLieu.MaTLoai = reader.GetString(2); taiLieu.SoLuong = reader.GetInt32(3); taiLieu.NhaXB = reader.GetString(4); taiLieu.NamXB = reader.GetInt32(5); taiLieu.TacGia = reader.GetString(6); dsTL.Add(taiLieu); } reader.Close(); return(dsTL); }
public ActionResult Create(HttpPostedFileBase TaiLieusUpload, TaiLieu tailieu) { NguoiDung NguoiDungCurrent = (NguoiDung)Session["NguoiDungCurrent"]; if (ModelState.IsValid) { if (Request != null) { HttpPostedFileBase file = Request.Files["TaiLieuUpload"]; if ((file != null) && !string.IsNullOrEmpty(file.FileName)) { string filePath = Path.Combine(Server.MapPath(TaiLieuPath), file.FileName); file.SaveAs(filePath); tailieu.DinhDang = Path.GetExtension(file.FileName); tailieu.DuongDan = file.FileName; tailieu.DungLuong = file.ContentLength.ToString(); tailieu.IdNguoiDung = NguoiDungCurrent.IdNguoiDung; db.TaiLieux.Add(tailieu); db.SaveChanges(); return(RedirectToAction("Index")); } //NguoiDung NguoiDungCurrent = (NguoiDung)Session["NguoiDungCurrent"]; //tailieu.IdNguoiDung = NguoiDungCurrent.IdNguoiDung; } } return(View(tailieu)); }
public List <TaiLieu> dsTaiLieuTimKiem(string maTL) { openConnection(); List <TaiLieu> dsTL = new List <TaiLieu>(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; command.CommandText = "SELECT * FROM TaiLieu5 where MaTLoai=@ma"; command.Parameters.Add("@ma", SqlDbType.NVarChar).Value = maTL; command.Connection = conn; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { TaiLieu taiLieu = new TaiLieu(); taiLieu.MaTLieu = reader.GetString(0); taiLieu.TenTLieu = reader.GetString(1); taiLieu.MaTLoai = reader.GetString(2); taiLieu.SoLuong = reader.GetInt32(3); taiLieu.NhaXB = reader.GetString(4); taiLieu.NamXB = reader.GetInt32(5); taiLieu.TacGia = reader.GetString(6); dsTL.Add(taiLieu); } reader.Close(); return(dsTL); }
public ActionResult InsertData() { try { //int maTaiLieu = int.Parse(Request.QueryString["maTaiLieu"]); int maTaiLieu = int.Parse(Request.Form["maTaiLieu"].ToString()); string chuDe = Request.Form["chuDe"].ToString(); string tieuDe = Request.Form["tieuDe"].ToString(); string noiDung = Request.Form["noiDung"].ToString(); string linkAnh = Request.Form["linkAnh"].ToString(); DateTime ngayDang = DateTime.Now; TaiLieu taiLieu = new TaiLieu(); taiLieu.MaTaiLieu = maTaiLieu; taiLieu.ChuDe = chuDe; taiLieu.TieuDe = tieuDe; taiLieu.NoiDung = noiDung; taiLieu.LinkAnh = linkAnh; taiLieu.NgayDang = ngayDang; taiLieu.TenNguoiDang = "HuyAdmin"; db.TaiLieux.Add(taiLieu); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { } return(RedirectToAction("Index")); }
public List <TaiLieu> getListDocument(string ten) { List <TaiLieu> list = new List <TaiLieu>(); openConnection(); string sql = "SELECT *FROM TaiLieu5 WHERE TenTLieu like @ten"; SqlCommand cmd = truyVan1(sql); cmd.Parameters.Add("@ten", SqlDbType.NVarChar).Value = ten; SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { TaiLieu tl = new TaiLieu(); tl.MaTLieu = (string)rd["matlieu"]; tl.TenTLieu = (string)rd["tentlieu"]; tl.MaTLoai = (string)rd["matloai"]; tl.SLuong = (int)rd["sluong"]; tl.NXB = (string)rd["nxb"]; tl.NamXB = (int)rd["namxb"]; tl.Anh = (string)rd["anh"]; tl.MaTG = (string)rd["matg"]; list.Add(tl); } rd.Close(); return(list); }
private void btnXoa_Click(object sender, EventArgs e) { TaiLieu taiLieu = new TaiLieu(); taiLieu.MaTLieu = txtMaTL.Text; taiLieu.TenTLieu = txtTenTL.Text; taiLieu.MaTLoai = cboMaTLoai.SelectedValue.ToString(); taiLieu.SoLuong = int.Parse(txtSL.Text); taiLieu.NhaXB = txtNXB.Text; taiLieu.NamXB = int.Parse(txtNamXB.Text); taiLieu.TacGia = txtTacGia.Text; TaiLieuBUS taiLieuBUS = new TaiLieuBUS(); DialogResult dialog = MessageBox.Show("Bạn có chắc xoá tài liệu " + taiLieu.MaTLieu + "?", "Xác nhận xoá", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { if (taiLieuBUS.xoaTaiLieu(taiLieu)) { MessageBox.Show("Xoá tài liệu thành công !"); loadData(); } else { MessageBox.Show("Xoá tài liệu thất bại !"); return; } } else { return; } }
public ActionResult Zoom(string ten, string trangthai, string ma, int idlh, string thoigian) { var lh = new LopHocDAO().GetByID(idlh); var dao = new TaiLieuDAO(); var tailieu = new TaiLieu(); tailieu.ten = ten; tailieu.link = ma; tailieu.moTa = trangthai; tailieu.idLH = lh.ID; tailieu.idTK = lh.Giangvien.TaiKhoan.iD; //tailieu.idKN = 6; try { tailieu.thoiGian = DateTime.Parse(thoigian); dao.Insert(tailieu); TempData["testmsg"] = "Tạo phòng ZOOM thành công."; } catch (Exception ex) { TempData["testmsg"] = "Lỗi tạo phòng ZOOM: " + ex.Message; } return(RedirectToAction("ChiTiet/" + lh.ID, "QLLopHoc")); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { panel3.Visible = true; panel1.Width = 803; panel1.Height = 659; cbbMaChiTiet.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString(); cbbMaTaiLieu.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString(); cbbTenChiTiet.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString(); cbbNhaCC.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString(); cbbNhaXB.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString(); cbbTacGia.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString(); cbbViTri.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString(); cbbSoLuong.Text = dataGridView1.CurrentRow.Cells[7].Value.ToString(); txtLink.Text = dataGridView1.CurrentRow.Cells[8].Value.ToString(); txtSoTrang.Text = dataGridView1.CurrentRow.Cells[9].Value.ToString(); txtGiaBia.Text = dataGridView1.CurrentRow.Cells[10].Value.ToString(); txtGiaNhap.Text = dataGridView1.CurrentRow.Cells[11].Value.ToString(); txtNgayNhap.Text = dataGridView1.CurrentRow.Cells[12].Value.ToString(); txtNguoiNhap.Text = dataGridView1.CurrentRow.Cells[13].Value.ToString(); TaiLieu tl = new TaiLieu(); pictureBox2.Image = byteArrayToImage(tl.loadAnhQR(cbbTenChiTiet.Text).ToArray()); pictureBox1.Image = byteArrayToImage(tl.loadAnhTaiLieu(cbbTenChiTiet.Text).ToArray()); }
protected void btnThem_Click(object sender, EventArgs e) { messenger.Text = ""; try { string path = Server.MapPath(srcImage); fileAnh.PostedFile.SaveAs(path + fileAnh.FileName); taiLieuBLL = new TaiLieuBLL(); TaiLieu taiLieu = new TaiLieu(); taiLieu.MaTLieu = txtMaTLieu.Text; taiLieu.MaTLoai = dropTheLoai.SelectedValue; taiLieu.TenTLieu = txtTenTLieu.Text; taiLieu.SLuong = Int32.Parse(txtSoLuong.Text); taiLieu.NXB = txtNXB.Text; taiLieu.NamXB = Int32.Parse(txtNamXB.Text); taiLieu.MaTG = drTacGia.SelectedValue; if (fileAnh.HasFile) { taiLieu.Anh = fileAnh.FileName; } taiLieuBLL.addDocument(taiLieu); LoadData(); messenger.Text = "Thêm thành công tài liệu."; } catch (Exception e1) { messenger.Text = "Thêm tài liệu thất bại" + e1.Message; } }
public ActionResult DeleteConfirmed(decimal id) { TaiLieu taiLieu = db.TaiLieux.Find(id); db.TaiLieux.Remove(taiLieu); db.SaveChanges(); return(RedirectToAction("Index")); }
public void GiamSL(string MaTL, int Num) { using (DHP_07Entities db = new DHP_07Entities()) { TaiLieu s = db.TaiLieux.Find(MaTL); s.SoLuong -= Num; db.SaveChanges(); } }
public void AddTL(TaiLieu s) { using (DHP_07Entities db = new DHP_07Entities()) { db.TaiLieux.Add(s); db.SaveChanges(); Instance.AddCTL(s.MaTL, (int)s.SoLuong); } }
public ActionResult XemVanBan(int id) { if (KiemTraSession() == true) { return(RedirectToAction("DangNhap", "QuanTri")); } NhanVien nv = (NhanVien)Session["DangNhap"]; DateTime dNow = DateTime.Now.Date; LuotXemTai lxt = db.LuotXemTais.SingleOrDefault(n => n.MaVanBan == id && n.NgayXT.Value == dNow); if (lxt == null) { LuotXemTai themLXT = new LuotXemTai(); themLXT.MaVanBan = id; themLXT.NgayXT = dNow; themLXT.LuotXem = 1; themLXT.LuotTai = 0; db.LuotXemTais.Add(themLXT); CT_LuotXemTai themct_luotxemtai = new CT_LuotXemTai(); // them tai lieu xem lan dau trong ngay themct_luotxemtai.MaLuotXemTai = themLXT.Id; themct_luotxemtai.IDNguoiDung = nv.Id; themct_luotxemtai.Xem = 1; themct_luotxemtai.Tai = 0; db.CT_LuotXemTai.Add(themct_luotxemtai); db.SaveChanges(); } else { lxt.LuotXem += 1; CT_LuotXemTai ct_luotxemtai = db.CT_LuotXemTai.SingleOrDefault(n => n.MaLuotXemTai == lxt.Id && n.IDNguoiDung == nv.Id); if (ct_luotxemtai == null) // them nguoi xem thu 2 > { CT_LuotXemTai themct_luotxemtai = new CT_LuotXemTai(); themct_luotxemtai.MaLuotXemTai = lxt.Id; themct_luotxemtai.IDNguoiDung = nv.Id; themct_luotxemtai.Xem = 1; themct_luotxemtai.Tai = 0; db.CT_LuotXemTai.Add(themct_luotxemtai); } else // cap nhat lan xem nguoi da xem { ct_luotxemtai.Xem += 1; } db.SaveChanges(); } TaiLieu layTaiLieu = db.TaiLieux.SingleOrDefault(n => n.MaTaiLieu == id); string sUrl = "/van-ban/" + Tools.RemoveDiacritics(layTaiLieu.TenTaiLieu) + "-" + id; return(Redirect(sUrl)); //return RedirectToAction("ChiTietVanBan", "TrangChinh", new { @id = id }); }
public ActionResult Edit([Bind(Include = "TL_SoDangKyCaBiet,TL_ChuDe,TL_TieuDe,TL_TacGia,TL_NhaXuatBan,TL_NamSanXuat,TL_SoTrang,TL_TomTat,TL_KhoSach,TL_TrangThai,TL_HinhAnh,TL_NgayNhap")] TaiLieu taiLieu) { if (ModelState.IsValid) { db.Entry(taiLieu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(taiLieu)); }
void loadcbb() { TaiLieu tl = new TaiLieu(); cbbTenChiTiet.DataSource = tl.loadcbbtentheloai(); cbbTacGia.DataSource = tl.loadcbbtacgia(); cbbNhaXB.DataSource = tl.loadcbbnxb(); cbbNhaCC.DataSource = tl.loadcbbncc(); cbbViTri.DataSource = tl.loadcbbvitri(); }
// // GET: /TaiLieu/Delete/5 public ActionResult Delete(int id = 0) { TaiLieu tailieu = db.TaiLieux.Find(id); if (tailieu == null) { return(HttpNotFound()); } return(View(tailieu)); }
private void btnThemMoi_Click(object sender, EventArgs e) { try { if (btnThemMoi.Text == "OK") //Nếu đang trạng thái nhập liệu { //--thuc hien tao du lieu cho doi tuong sach #region set giá trị TaiLieu taiLieu = new TaiLieu(); taiLieu.MaTaiLieu = txtMaTL.Text; taiLieu.NhanDe = txtNhanDe.Text; taiLieu.SoTrang = int.Parse(txtSoTrang.Text); taiLieu.NamXuatBan = int.Parse(txtnamxuatban.Text); taiLieu.LanXuatBan = int.Parse(txtlanxuatban.Text); taiLieu.NgayNhap = DateTime.Parse(txtNgayNhap.Text); taiLieu.IDTheLoai = cbloaisach.SelectedValue.ToString(); taiLieu.IDNgonNgu = (int)cbNgonNgu.SelectedValue; taiLieu.IDTacGia = (int)cbTacGia.SelectedValue; taiLieu.IDNXB = (int)cbNhaXuatBan.SelectedValue; taiLieu.TheThuc = String.IsNullOrEmpty(cbTheThuc.Text) ? "Không mượn về nhà" : cbTheThuc.Text; taiLieu.IDGiaXep = (int)cbGiaXep.SelectedValue; if (TaiLieu.ThemMoi(taiLieu)) { MessageBox.Show("Thêm mới thành công"); Load_treeview(); trvListTaiLieu.Enabled = true; set_enable(false); btCapNhat.Enabled = true; btxoa.Enabled = true; btnThemMoi.Text = "Thêm mới"; } #endregion } else { trvListTaiLieu.Enabled = false; set_enable(true); btCapNhat.Enabled = false; btxoa.Enabled = false; txtNgayNhap.Text = DateTime.Now.ToString("dd/MM/yyyy"); btnThemMoi.Text = "OK"; txtlanxuatban.Text = "0"; txtnamxuatban.Text = ""; txtNhanDe.Text = ""; txtSoTrang.Text = "0"; txtMaTL.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public ActionResult GuiYKien(int MaVanBan, string HoTen, string Email, string DienThoai, string NoiDung) { string sMailGui = System.Configuration.ConfigurationManager.AppSettings["MailSend"]; string sPass = System.Configuration.ConfigurationManager.AppSettings["MailPass"]; string sHost = System.Configuration.ConfigurationManager.AppSettings["MailHost"]; string sPort = System.Configuration.ConfigurationManager.AppSettings["MailPort"]; string sTieuDe = System.Configuration.ConfigurationManager.AppSettings["MailSubject"]; // luu y kien FeedBack themFeedBack = new FeedBack(); themFeedBack.HoTenGui = HoTen; themFeedBack.Email = Email; themFeedBack.DienThoai = DienThoai; themFeedBack.NoiDung = NoiDung; themFeedBack.NgayGui = DateTime.Now; db.FeedBacks.Add(themFeedBack); db.SaveChanges(); TaiLieu tl = db.TaiLieux.SingleOrDefault(n => n.MaTaiLieu == MaVanBan); //lay mail ban he thong CauHinh ch = db.CauHinhs.SingleOrDefault(n => n.MaCauHinh == "EMAIL-FEEDBACK"); // gui mail var fromAddress = new MailAddress(sMailGui, "Hệ thống Coteccons"); var toAddress = new MailAddress(ch.DuLieu, "To Name"); string fromPassword = sPass; string subject = sTieuDe; string body = "<b>Tên tài liệu: </b>" + tl.TenTaiLieu; body += "<br/ > <b>Họ tên người gửi: </b>" + HoTen; body += "<br /> <b>Email: </b>" + Email; body += "<br /> <b>Điện thoại: </b>" + DienThoai; body += "<br /> <b>Nội dung: </b> <br/>" + NoiDung; var smtp = new SmtpClient { Host = sHost, Port = int.Parse(sPort), EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { IsBodyHtml = true, Subject = subject, Body = body }) { smtp.Send(message); } return(Content("1")); }
public ActionResult Edit([Bind(Include = "TaiLieuId,TenTaiLieu,TepTinDinhKem,DeTaiId")] TaiLieu taiLieu) { if (ModelState.IsValid) { db.Entry(taiLieu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DeTaiId = new SelectList(db.DeTais, "DeTaiId", "TenDeTai", taiLieu.DeTaiId); return(View(taiLieu)); }
// // GET: /TaiLieu/Edit/5 public ActionResult Edit(int id = 0) { TaiLieu tailieu = db.TaiLieux.Find(id); if (tailieu == null) { return(HttpNotFound()); } ViewBag.IdNguoiDung = new SelectList(db.NguoiDungs, "IdNguoiDung", "HoTen", tailieu.IdNguoiDung); return(View(tailieu)); }
public ActionResult Edit(TaiLieu tailieu) { if (ModelState.IsValid) { db.Entry(tailieu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdNguoiDung = new SelectList(db.NguoiDungs, "IdNguoiDung", "HoTen", tailieu.IdNguoiDung); return(View(tailieu)); }
public void TraSLTL(List <TaiLieu_DTO> data) { using (DHP_07Entities db = new DHP_07Entities()) { foreach (TaiLieu_DTO i in data) { TaiLieu s = db.TaiLieux.Find(i.MaTL); s.SoLuong++; } db.SaveChanges(); } }
public async Task <bool> UpdateExistingFile(TaiLieu model, int fileId) { var p = GetParams(model, ignoreKey: new string[] { nameof(model.FileKey), nameof(model.ProfileId) }); p.Add("fileId", fileId); using (var con = GetConnection()) { var result = await con.ExecuteAsync("updateExistingFile", p, commandType : CommandType.StoredProcedure); return(true); } }
public ActionResult Create(HttpPostedFileBase DeBaiTapUpload, FormCollection collection, BaiTap baitap) { NguoiDung NguoiDungCurrent = (NguoiDung)Session["NguoiDungCurrent"]; TaiLieu tailieu = null; // Thêm đề cương bài giảng vào csdl và vào lớp string TenTaiLieu = Convert.ToString(collection["TenTaiLieu"]); if (Request != null) { HttpPostedFileBase file = Request.Files["DeBaiTapUpload"]; if ((file != null) && !string.IsNullOrEmpty(file.FileName)) { tailieu = new TaiLieu(); string filePath = Path.Combine(Server.MapPath(TaiLieuPath), file.FileName); file.SaveAs(filePath); tailieu.TenTaiLieu = TenTaiLieu; tailieu.DinhDang = Path.GetExtension(file.FileName); tailieu.DuongDan = file.FileName; tailieu.DungLuong = file.ContentLength.ToString(); tailieu.IdNguoiDung = NguoiDungCurrent.IdNguoiDung; tailieu.IdLoaiTaiLieu = 5; // 5 = đề bài tập // Thêm đề cương bài giảng vào csdl db.TaiLieux.Add(tailieu); db.SaveChanges(); } else { return(View()); } } if (ModelState.IsValid) { LopMonHoc LopMonHocCurrent = (LopMonHoc)Session["LopMonHocCurrent"]; if (tailieu != null) { baitap.IdDeBaiTap = tailieu.IdTaiLieu; } baitap.IdLopMonHoc = LopMonHocCurrent.IdLopMonHoc; db.BaiTaps.Add(baitap); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdLopMonHoc = new SelectList(db.LopMonHocs, "IdLopMonHoc", "TenLopMonHoc", baitap.IdLopMonHoc); return(View(baitap)); }
public frmTaiLieu2(string matailieu) { InitializeComponent(); load(); this.matailieu = matailieu; loadDataG(); customdataG(); loadcbb(); // load ten danh muc TaiLieu tl = new TaiLieu(); label17.Text = tl.loadTenDanhMuc(matailieu); TaiLieuu tl2 = new TaiLieuu(); }
// GET: TaiLieu/Details/5 public ActionResult Details(decimal id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TaiLieu taiLieu = db.TaiLieux.Find(id); if (taiLieu == null) { return(HttpNotFound()); } return(View(taiLieu)); }
// GET: TaiLieu/Edit/5 public ActionResult Edit(decimal id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TaiLieu taiLieu = db.TaiLieux.Find(id); if (taiLieu == null) { return(HttpNotFound()); } ViewBag.DeTaiId = new SelectList(db.DeTais, "DeTaiId", "TenDeTai", taiLieu.DeTaiId); return(View(taiLieu)); }
protected override void Render(HtmlTextWriter writer) { #region biến StringBuilder sb = new StringBuilder(); ClientScriptManager cs = this.Page.ClientScript; string _File = Request["File"]; string _F_ID = Request["F_ID"]; string _ID = Request["ID"]; string _PID = Request["DMID"]; string _PTen = Request["DMTen"]; string _Ten = Request["Ten"]; string _ThuTu = Request["ThuTu"]; string _TacGia = Request["TacGia"]; string _NhaXuatBan = Request["NhaXuatBan"]; string _NgonNgu = Request["NgonNgu"]; string _GiaBan = Request["GiaBan"]; string _KichThuoc = Request["KichThuoc"]; string _Url = Request["QUrl"]; string _Anh = Request["Anh"]; string _q = Request["q"]; List<jgridRow> ListRow; #endregion switch (subAct) { case "get": #region lấy danh sách if (string.IsNullOrEmpty(jgrsidx)) jgrsidx = "TL_ThuTu"; if (string.IsNullOrEmpty(jgrsord)) jgrsord = "asc"; Pager<TaiLieu> pager = TaiLieuDal.pagerNormal("", false, jgrsidx + " " + jgrsord, _q, _PID); ListRow = new List<jgridRow>(); foreach (TaiLieu item in pager.List) { ListRow.Add(new jgridRow(item.ID.ToString(), new string[] { item.ID.ToString() ,item.ThuTu.ToString() ,string.Format("<img src=\"../up/i/{0}\"/>",item.Anh) ,item.DM_ID.ToString() ,item.DM_Ten ,item.Ten ,item.TacGia ,item.NhaXuatBan ,item.NgonNgu ,item.GiaBan ,item.Url })); } jgrid grid = new jgrid("1", "1", pager.Total.ToString(), ListRow); sb.Append(JavaScriptConvert.SerializeObject(grid)); break; #endregion case "insert": #region lưu dữ liệu tạm TaiLieu ItemInsert = new TaiLieu(); ItemInsert.RowId = Guid.NewGuid(); ItemInsert.NgayTao = DateTime.Now; ItemInsert.NguoiTao = Security.Username; ItemInsert.NguoiCapNhat = Security.Username; ItemInsert.NgayCapNhat = DateTime.Now; ItemInsert.Draff = true; ItemInsert = TaiLieuDal.InsertDraff(ItemInsert); sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(ItemInsert)); break; #endregion case "add": #region thêm mới break; #endregion case "edit": #region chỉnh sửa if (!string.IsNullOrEmpty(_ID)) { TaiLieu itemGetVanBan = TaiLieuDal.SelectByIdView(Convert.ToInt32(_ID)); if (itemGetVanBan.Filelist.Count > 0) { if (itemGetVanBan.Filelist[0].ID != 0) { foreach (Files item in itemGetVanBan.Filelist) { itemGetVanBan.FileListStr += string.Format(@"<span _value=""{0}"" class=""adm-token-item"">{1}{2}<a href=""javascript:;"">x</a></span>" , item.ID, item.Ten,item.MimeType); } } sb.AppendFormat("({0})", JavaScriptConvert.SerializeObject(itemGetVanBan)); } } break; #endregion case "del": #region Xóa if (!string.IsNullOrEmpty(_ID)) { TaiLieuDal.DeleteMultiById(_ID); } break; #endregion case "saveDoc": #region Lưu tài liệu if (!string.IsNullOrEmpty(_F_ID)) { Files item = FilesDal.SelectById(Convert.ToInt32(_F_ID)); item.PID = new Guid(_ID); item = FilesDal.Update(item); sb.AppendFormat(item.Size.ToString()); } break; #endregion case "DeleteDoc": #region Xóa tài liệu đính kèm if (!string.IsNullOrEmpty(_F_ID)) { Files item = FilesDal.SelectById(Convert.ToInt32(_F_ID)); string _directory = Server.MapPath("~/up/d/") + item.ThuMuc; string _files = Server.MapPath("~/up/d/") + item.ThuMuc + "/" + item.Ten + item.MimeType; if (Directory.Exists(_files)) { File.Delete(_files); Directory.Delete(_directory); } FilesDal.DeleteById(item.ID); } break; #endregion case "save": #region lưu TaiLieu ItemSave = new TaiLieu(); if (string.IsNullOrEmpty(_Ten)) { sb.Append("0"); break; } if (!string.IsNullOrEmpty(_ID)) { ItemSave = TaiLieuDal.SelectById(Convert.ToInt32(_ID)); } ItemSave.Ten = _Ten; if (string.IsNullOrEmpty(_ThuTu)) { _ThuTu = "1"; } ItemSave.ThuTu = Convert.ToInt32(_ThuTu); ItemSave.Url = _Url; ItemSave.DM_ID = Convert.ToInt32(_PID); ItemSave.DM_Ten = _PTen; ItemSave.NguoiCapNhat = Security.Username; ItemSave.NgayCapNhat = DateTime.Now; ItemSave.Draff = false; ItemSave.TacGia = _TacGia; ItemSave.NhaXuatBan = _NhaXuatBan; ItemSave.NgonNgu = _NgonNgu; ItemSave.KichThuoc = _KichThuoc; ItemSave.GiaBan = _GiaBan; ItemSave.Anh = _Anh; if (!string.IsNullOrEmpty(_ID)) { ItemSave = TaiLieuDal.Update(ItemSave); } else { ItemSave.NguoiTao = Security.Username; ItemSave.NgayTao = DateTime.Now; ItemSave.RowId = Guid.NewGuid(); ItemSave = TaiLieuDal.Insert(ItemSave); } sb.Append("1"); break; #endregion case "scpt": #region Nạp js sb.AppendFormat(@"{0}" , cs.GetWebResourceUrl(typeof(Class1), "mpig.plugin.backend.tailieu.JScript1.js")); break; #endregion default: #region nạp FunctionCollection ListFn = FunctionDal.SelectByUserAndFNID(Security.Username, fnId); sb.Append(@"<div class=""mdl-head""> <span class=""mdl-head-searchPnl ui-state-default ui-corner-all""> <a href=""javascript:;"" class=""mdl-head-clearSearch""></a> <input type=""text"" class=""mdl-head-txt mdl-head-search mdl-head-search-tailieu"" /> </span> <a class=""mdl-head-btn mdl-head-add"" id=""tailieumdl-addBtn"" href=""javascript:tailieufn.add();"">Thêm mới</a> <a class=""mdl-head-btn mdl-head-edit"" id=""tailieumdl-editBtn"" href=""javascript:tailieufn.edit();"">Sửa</a> <a class=""mdl-head-btn mdl-head-del"" id=""tailieumdl-delBtn"" href=""javascript:tailieufn.del();"">Xóa</a> <span class=""mdl-head-filterPnl ui-state-default ui-corner-all""> <a href=""javascript:;"" class=""mdl-head-clearSearch""></a> <input type=""text"" _value="""" class=""mdl-head-filter mdl-head-filterdanhmuc""/> </span> </div> <table id=""tailieumdl-List"" class=""mdl-list""></table> <div id=""tailieumdl-Pager""></div>"); sb.AppendFormat(@"<script>$.getScript('{0}',function(){1});</script>" , cs.GetWebResourceUrl(typeof(Class1), "projectMgr.plugin.backend.taiLieu.JScript1.js") , "{tailieufn.loadgrid();}"); sb.AppendFormat("<script>adm.validFn('{0}');</script>", JavaScriptConvert.SerializeObject(ListFn)); break; #endregion } writer.Write(sb.ToString()); base.Render(writer); }