// Cập nhật thông tin khi người dùng chỉnh sửa private void btn_Luu_Lai_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { string error = ""; bool isUpdate = false; foreach (int id in _listUpdate) { KHU_VUC _khuVuc = new KHU_VUC(); _khuVuc.ID_Khu_Vuc = int.Parse(gridView1.GetRowCellValue(id, "ID_Khu_Vuc").ToString()); _khuVuc.Ten_Khu_Vuc = gridView1.GetRowCellValue(id, "Ten_Khu_Vuc").ToString(); if (!_khuVucBLL.KiemTraTenKhuVucTonTai(_khuVuc.Ten_Khu_Vuc)) { _khuVucBLL.CapNhatKhuVuc(_khuVuc); isUpdate = true; } else { if (error == "") { error += _khuVuc.ID_Khu_Vuc; } else { error += " | " + _khuVuc.ID_Khu_Vuc; } } } if (isUpdate == true) { if (error.Length == 0) { Notification.Success("Cập dữ liệu thành công."); } else { Notification.Error("Có lỗi xảy ra khi cập nhật dữ liệu. Các ID chưa được cập nhật (" + error + "). Lỗi: Tên Khu Vực đã tồn tại."); } } else { Notification.Error("Có lỗi xảy ra khi cập nhật dữ liệu. Lỗi: Tên khu vực đã tồn tại."); } LoadDataSource(); }
private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (!Check()) { return; } try { if (tinh_trang == "them") { KHU_VUC kv = new KHU_VUC(); kv.Ma_Khu_Vuc = txtMaKhuVuc.Text; kv.Ten_Khu_Vuc = txtTenKhuVuc.Text; kv.Ghi_Chu = txtGhiChu.Text; kv.IsDeleted = false; kv.CreatedDate = DateTime.Now; db.KHU_VUCs.InsertOnSubmit(kv); } else { var kv = (from k in db.KHU_VUCs where k.Id == Id select k).FirstOrDefault(); kv.Ma_Khu_Vuc = txtMaKhuVuc.Text; kv.Ten_Khu_Vuc = txtTenKhuVuc.Text; kv.Ghi_Chu = txtGhiChu.Text; kv.ModifiedDate = DateTime.Now; } db.SubmitChanges(); RaiseReloadEventHander(); Close(); } catch (Exception ex) { MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult Edit(int id) { if (id <= 0) { ViewBag.Message = "Không tìm thấy khu vực tương ứng."; return(View("../Home/Error"));; } var ctx = new SmsContext(); KHU_VUC khuVuc = ctx.KHU_VUC.Find(id); if (khuVuc.ACTIVE.Equals("A")) { ctx.Dispose(); return(View(khuVuc)); } else { ctx.Dispose(); ViewBag.Message = "Không tìm thấy khu vực tương ứng."; return(View("../Home/Error"));; } }