public ActionResult Create(TACGIA tg, HttpPostedFileBase fileUpload) { //kiểm tra đường dẫn ảnh if (fileUpload == null) { ViewBag.ThongBao = "Hãy chọn ảnh tác giả!"; return(View(tg)); } //Thêm vào cơ sở dữ liệu if (ModelState.IsValid) { //Lưu tên file var fileName = Path.GetFileName(fileUpload.FileName); //Lưu đường dẫn của file var path = Path.Combine(Server.MapPath("~/Content/HinhAnhTG"), fileName); //Kiểm tra hình ảnh đã tồn tại chưa if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } tg.PicTG = fileUpload.FileName; db.TACGIAs.Add(tg); db.SaveChanges(); ViewBag.ThongBao = "Thêm mới thành công"; } else { ViewBag.ThongBao = "Thêm mới thất bại"; } return(RedirectToAction("Index")); }
public ActionResult Edit(TACGIA tg, HttpPostedFileBase fileUpload) { if (fileUpload != null) { //Lưu tên file var fileName = Path.GetFileName(fileUpload.FileName); //Lưu đường dẫn của file var path = Path.Combine(Server.MapPath("~/Content/HinhAnhTG"), fileName); if (!System.IO.File.Exists(path)) { fileUpload.SaveAs(path); } tg.PicTG = fileName; } //Thêm vào cơ sở dữ liệu if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(tg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tg)); }
// GET: NXB/Details/5 public ActionResult Details(int?id) { if (id == null) // không có ID { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TACGIA tacgia = db.TACGIAs.Find(id); if (tacgia == null) // có ID nhưng không tìm thấy thông tin về id đó { return(HttpNotFound()); } else { DataTable dttbTACGIA = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); string SQL = "DECLARE @id INT; set @id = " + id + "; select * from DAUSACH" + " inner join TACGIA on DAUSACH.MaTG = TACGIA.MaTG where DAUSACH.MaTG = @id"; SqlDataAdapter sqlDa = new SqlDataAdapter(SQL, sqlCon); /**/ sqlDa.Fill(dttbTACGIA); } return(View(dttbTACGIA)); } }
// GET: NXB/Edit/5 public ActionResult Edit(int id) { TACGIA tacgia = new TACGIA(); DataTable dttbTACGIA = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); string query = "select * from TACGIA where MaTG = @MaTG"; SqlDataAdapter sqlDa = new SqlDataAdapter(query, sqlCon); sqlDa.SelectCommand.Parameters.AddWithValue("@MaTG", id); sqlDa.Fill(dttbTACGIA); } if (dttbTACGIA.Rows.Count == 1) { tacgia.MaTG = Convert.ToInt32(dttbTACGIA.Rows[0][0].ToString()); tacgia.TenTG = dttbTACGIA.Rows[0][1].ToString(); tacgia.Thongtingioithieu = dttbTACGIA.Rows[0][2].ToString(); tacgia.PicTG = dttbTACGIA.Rows[0][3].ToString(); return(View(tacgia)); } else { return(RedirectToAction("Index")); } }
private void ModelToView(TACGIA tg) { view.TENTG = tg.TENTG; view.NAMSINH = tg.NAMSINH; view.NAMMAT = tg.NAMMAT; view.QUEQUAN = tg.QUEQUAN; }
private void UpdateDetail() { try { TACGIA TACGIA = getTACGIAByID(); if (TACGIA.ID == 0) { return; } txtTenTacGia.Text = TACGIA.TEN; txtTitleTenTacGia.Text = TACGIA.TEN; txtTitleNgaySinh.Text = ((DateTime)TACGIA.NGAYSINH).ToString("dd/MM/yyyy"); dateNgaySinh.DateTime = (DateTime)TACGIA.NGAYSINH; txtEmail.Text = TACGIA.EMAIL; txtDiaChi.Text = TACGIA.DIACHI; cbxGioiTinh.SelectedIndex = (int)TACGIA.GIOITINH; imgAnh.Image = null; imgAnh.Image = Helper.byteArrayToImage(TACGIA.ANH); } catch { } }
public ActionResult SelectTG() { TACGIA tg = new TACGIA(); tg.ListTG = db.TACGIAs.ToList <TACGIA>(); return(PartialView(tg)); }
public ActionResult DeleteConfirmed(int id) { TACGIA tACGIA = db.TACGIAs.Find(id); db.TACGIAs.Remove(tACGIA); db.SaveChanges(); return(RedirectToAction("Index")); }
public TACGIA deleteTacGia(int MaTacGia) { TACGIA tg = (from c in entity.TACGIAs where c.MATG == MaTacGia select c).FirstOrDefault(); entity.TACGIAs.Remove(tg); entity.SaveChanges(); return(tg); }
private void CapNhat(ref TACGIA cu, TACGIA moi) { cu.TEN = moi.TEN; cu.GIOITINH = moi.GIOITINH; cu.NGAYSINH = moi.NGAYSINH; cu.EMAIL = moi.EMAIL; cu.DIACHI = moi.DIACHI; cu.ANH = moi.ANH; }
public void showSelected() { if (view.selectedTacGia != "") { TACGIA tg = repository.getTacGia(int.Parse(view.selectedTacGia)); ModelToView(tg); } //view.TacGia = tg; }
public ActionResult Edit([Bind(Include = "MaTG,TenTG,Diachi,Tieusu,Dienthoai,AnhTG")] TACGIA tACGIA) { if (ModelState.IsValid) { db.Entry(tACGIA).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tACGIA)); }
public ActionResult ChinhSua(TACGIA tg) { if (ModelState.IsValid) { db.Entry(tg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tg)); }
private TACGIA ViewToModel() { TACGIA tg = new TACGIA(); tg.TENTG = view.TENTG; tg.NAMSINH = view.NAMSINH; tg.NAMMAT = view.NAMMAT; tg.QUEQUAN = view.QUEQUAN; return(tg); }
public ActionResult Edit([Bind(Include = "MaTG,TenTG,ThongTinGioiThieu,PicTG")] TACGIA tACGIA) { if (ModelState.IsValid) { db.Entry(tACGIA).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tACGIA)); }
public ActionResult ThemMoi(TACGIA tg) { if (ModelState.IsValid) { ViewBag.ThongBao = "Thêm mới tác giả thành công."; db.TACGIAs.Add(tg); db.SaveChanges(); } return(View()); }
public ActionResult Xoa(int matacgia) { TACGIA tg = db.TACGIAs.SingleOrDefault(n => n.MaTG == matacgia); if (tg == null) { Response.StatusCode = 404; return(null); } return(View(tg)); }
public ActionResult Create([Bind(Include = "MaTG,TenTG,ThongTinGioiThieu,PicTG")] TACGIA tACGIA) { if (ModelState.IsValid) { db.TACGIAs.Add(tACGIA); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tACGIA)); }
public int delTacGia(string ma) { try { TACGIA s = linqToMySQL1.TACGIAs.Where(t => t.MATACGIA == ma).Select(t => t).FirstOrDefault(); linqToMySQL1.TACGIAs.DeleteOnSubmit(s); linqToMySQL1.SubmitChanges(); return(1); } catch { return(0); } }
private void frmThemTacGia_Load(object sender, EventArgs e) { //txbTenTacGia.DataBindings.Add("Text", txbTenTacGia, "Text"); try { TACGIA ttg = TACGIABUS.Instance.GetListTacGia()[TACGIABUS.Instance.GetListTacGia().Count - 1]; IdLast = ttg.MaTacGia; } catch { IdLast = ""; } txbMaTacGia.Text = HelpGUI.AutoIncreaseID.Load_AutoIncreaseID("TG", IdLast, 6); }
public ActionResult Create([Bind(Include = "MaTG,TenTG,Diachi,Tieusu,Dienthoai,AnhTG")] TACGIA tACGIA) { if (ModelState.IsValid) { db.TACGIAs.Add(tACGIA); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tACGIA)); }
public TACGIA editTacGia(TACGIA tg, int oldMaTacGia) { TACGIA tacgia = (from c in entity.TACGIAs where c.MATG == oldMaTacGia select c).FirstOrDefault(); tacgia.TENTG = tg.TENTG; tacgia.NAMSINH = tg.NAMSINH; tacgia.NAMMAT = tg.NAMMAT; tacgia.QUEQUAN = tg.QUEQUAN; entity.SaveChanges(); return(tacgia); //tac gia cu }
public List <TACGIA> LoadTACGIA() { List <TACGIA> result = new List <TACGIA>(); DataTable data = DataProvider.Instance.ExcuteQuery("Select * from dbo.TACGIA"); foreach (DataRow row in data.Rows) { TACGIA temp = new TACGIA(row); result.Add(temp); } return(result); }
private void btnSua_Click(object sender, EventArgs e) { if (!CheckLuaChon()) { return; } if (btnSua.Text == "Sửa") { btnSua.Text = "Lưu"; btnXoa.Text = "Hủy"; btnThem.Enabled = false; UnlockControl(); return; } if (btnSua.Text == "Lưu") { if (Check()) { btnSua.Text = "Sửa"; btnXoa.Text = "Xóa"; LockControl(); TACGIA cu = getTACGIAByID(); TACGIA moi = getTACGIAByForm(); CapNhat(ref cu, moi); try { db.SaveChanges(); MessageBox.Show("Sưa thông tin tác giả thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Sửa thông tin tác giả thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvTACGIA(); } return; } }
public void saveTacGia() { //TACGIA tg = repository.getTacGia(view.selectedTacGia); TACGIA tg = ViewToModel(); if (valid(tg)) { TACGIA kq = repository.saveTacGia(tg); //view.Log("Đã lưu thành công"); getListTacGia(); } }
public ActionResult XacNhanXoa(int matacgia) { TACGIA tg = db.TACGIAs.SingleOrDefault(n => n.MaTG == matacgia); if (tg == null) { Response.StatusCode = 404; return(null); } db.TACGIAs.Remove(tg); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { TACGIA cd = db.TACGIAs.SingleOrDefault(n => n.MaTG == id); if (cd == null) { Response.StatusCode = 404; return(null); } db.TACGIAs.Remove(cd); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(int MaTacGia) { //Lấy ra đối tượng sách theo mã TACGIA tg = db.TACGIAs.SingleOrDefault(n => n.MaTG == MaTacGia); if (tg == null) { Response.StatusCode = 404; return(null); } return(View(tg)); }
public TACGIA saveTacGia(TACGIA tg) { try { entity.TACGIAs.Add(tg); entity.SaveChanges(); return(tg); } catch (DbUpdateException) // tranh loi update { return(null); } }
private void btnXoa_Click(object sender, EventArgs e) { if (btnXoa.Text == "Xóa") { if (!CheckLuaChon()) { return; } TACGIA cu = getTACGIAByID(); DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa tác giả " + cu.TEN + "?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (rs == DialogResult.Cancel) { return; } try { db.TACGIAs.Remove(cu); db.SaveChanges(); MessageBox.Show("Xóa thông tin tác giả thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Xóa thông tin tác giả thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvTACGIA(); return; } if (btnXoa.Text == "Hủy") { btnSua.Text = "Sửa"; btnThem.Text = "Thêm"; btnXoa.Text = "Xóa"; LockControl(); UpdateDetail(); return; } }