public bool EditDoiTuong(int madoituong, string loaidoituong, double diemcongdtuong) { DOITUONG obj = new DOITUONG(madoituong, loaidoituong, diemcongdtuong); context.setState(new EditState()); return(context.doAction(obj)); }
/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update(DOITUONG businessObject) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[DOITUONG_Update]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.ID)); sqlCommand.Parameters.Add(new SqlParameter("@TEN", SqlDbType.NVarChar, 2147483647, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.TEN)); sqlCommand.Parameters.Add(new SqlParameter("@KYHIEU", SqlDbType.NVarChar, 2147483647, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.KYHIEU)); sqlCommand.Parameters.Add(new SqlParameter("@GHICHU", SqlDbType.NVarChar, 2147483647, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.GHICHU)); MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch //(Exception ex) { return(false); //throw new Exception("DOITUONG::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
public bool DeleteDoiTuong(int id) { DOITUONG obj = new DOITUONG(id); context.setState(new DeleteState()); return(context.doAction(obj)); }
public ActionResult DeleteConfirmed(string id) { DOITUONG dOITUONG = db.DOITUONGs.Find(id); db.DOITUONGs.Remove(dOITUONG); db.SaveChanges(); return(RedirectToAction("Index")); }
private DOITUONG getDOITUONGByForm() { DOITUONG ans = new DOITUONG(); ans.TEN = txtTen.Text; ans.KYHIEU = txtKiHieu.Text; return(ans); }
public ActionResult Edit([Bind(Include = "MaDoiTuong,TenDoiTuong,TiLeGiamHocPhi")] DOITUONG dOITUONG) { if (ModelState.IsValid) { db.Entry(dOITUONG).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dOITUONG)); }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of DOITUONG</returns> internal List <DOITUONG> PopulateObjectsFromReader(IDataReader dataReader) { List <DOITUONG> list = new List <DOITUONG>(); while (dataReader.Read()) { DOITUONG businessObject = new DOITUONG(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
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(); DOITUONG cu = getDOITUONGByID(); DOITUONG moi = getDOITUONGByForm(); CapNhat(ref cu, moi); if (DOITUONGService.Update(cu)) { MessageBox.Show("Sửa thông tin đối tượng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa thông tin đối tượng thất bại\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvDOITUONG(); } return; } }
private bool CheckLuaChon() { DOITUONG tg = getDOITUONGByID(); if (tg.ID == 0) { MessageBox.Show("Chưa có đối tượng nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
// GET: PDT/DOITUONGs/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DOITUONG dOITUONG = db.DOITUONGs.Find(id); if (dOITUONG == null) { return(HttpNotFound()); } return(View(dOITUONG)); }
public ActionResult DeleteConfirmed(string id) { try { DOITUONG dOITUONG = db.DOITUONGs.Find(id); db.DOITUONGs.Remove(dOITUONG); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(RedirectToAction("Delete", "DOITUONGs", new { id = id })); } }
private void btnXoa_Click(object sender, EventArgs e) { if (btnXoa.Text == "Xóa") { if (!CheckLuaChon()) { return; } DOITUONG cu = getDOITUONGByID(); DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa đối tượng " + cu.TEN + "?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (rs == DialogResult.Cancel) { return; } try { DOITUONGService.Delete(new DOITUONGKeys(cu.ID)); MessageBox.Show("Xóa thông tin đối tượng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Xóa thông tin đối tượng thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvDOITUONG(); return; } if (btnXoa.Text == "Hủy") { btnSua.Text = "Sửa"; btnThem.Text = "Thêm"; btnXoa.Text = "Xóa"; LockControl(); UpdateDetail(); return; } }
public void CreatePostDoiTuong() { DOITUONGsController doituongController = new DOITUONGsController(); doituongController.DeleteConfirmed("DT07"); DOITUONG doituong = new DOITUONG { MaDoiTuong = "DT07", TenDoiTuong = "Đối tượng test", TiLeGiamHocPhi = 10 }; RedirectToRouteResult result = doituongController.Create(doituong) as RedirectToRouteResult; Assert.IsNotNull(result); string expected = "Index"; string actual = result.RouteValues["action"].ToString(); Assert.AreEqual(expected, actual); }
private DOITUONG getDOITUONGByID() { try { int id = (int)dgvDOITUONG.GetFocusedRowCellValue("ID"); DOITUONG ans = DOITUONGService.GetAllBy(DOITUONG.DOITUONGFields.ID, id).FirstOrDefault(); if (ans == null) { return(new DOITUONG()); } return(ans); } catch { return(new DOITUONG()); } }
public void DeleteViewDoiTuong() { DOITUONGsController doituongController = new DOITUONGsController(); DOITUONG doituong = new DOITUONG { MaDoiTuong = "DT07", TenDoiTuong = "Đối tượng test", TiLeGiamHocPhi = 10 }; doituongController.Create(doituong); ViewResult result = doituongController.Delete("DT07") as ViewResult; Assert.IsNotNull(result); string expected = ""; string actual = result.ViewName; Assert.AreEqual(expected, actual); }
private void UpdateDetail() { try { DOITUONG tg = getDOITUONGByID(); if (tg.ID == 0) { return; } txtTen.Text = tg.TEN; txtKiHieu.Text = tg.KYHIEU; } catch { } }
public ActionResult Create([Bind(Include = "MaDoiTuong,TenDoiTuong,TiLeGiamHocPhi")] DOITUONG dOITUONG) { try { if (ModelState.IsValid) { db.DOITUONGs.Add(dOITUONG); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dOITUONG)); } catch (Exception e) { return(RedirectToAction("Create", "DOITUONGs", new { id = 1 })); } }
private void btnThem_Click(object sender, EventArgs e) { if (btnThem.Text == "Thêm") { btnSua.Enabled = false; btnThem.Text = "Lưu"; btnXoa.Text = "Hủy"; ClearControl(); UnlockControl(); return; } if (btnThem.Text == "Lưu") { if (Check()) { btnThem.Text = "Thêm"; btnXoa.Text = "Xóa"; LockControl(); DOITUONG moi = getDOITUONGByForm(); if (DOITUONGService.Insert(moi)) { MessageBox.Show("Thêm thông tin đối tượng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm thông tin đối tượng thất bại\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvDOITUONG(); } return; } }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(DOITUONG businessObject, IDataReader dataReader) { businessObject.ID = dataReader.GetInt32(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.ID.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.TEN.ToString()))) { businessObject.TEN = dataReader.GetString(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.TEN.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.KYHIEU.ToString()))) { businessObject.KYHIEU = dataReader.GetString(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.KYHIEU.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.GHICHU.ToString()))) { businessObject.GHICHU = dataReader.GetString(dataReader.GetOrdinal(DOITUONG.DOITUONGFields.GHICHU.ToString())); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>DOITUONG business object</returns> public DOITUONG SelectByPrimaryKey(DOITUONGKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[DOITUONG_SelectByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys.ID)); MainConnection.Open(); IDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { DOITUONG businessObject = new DOITUONG(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch //(Exception ex) { return(null); //throw new Exception("DOITUONG::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
private void CapNhat(ref DOITUONG cu, DOITUONG moi) { cu.TEN = moi.TEN; cu.KYHIEU = moi.KYHIEU; }