/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update(LOAIBENH businessObject) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[LOAIBENH_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("@NHOMBENHID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.NHOMBENHID)); 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("LOAIBENH::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
private LOAIBENH getLOAIBENHByForm() { LOAIBENH ans = new LOAIBENH(); ans.TEN = txtLOAIBENH.Text; ans.NHOMBENHID = getNHOMBENHByID().ID; return(ans); }
private void btnXoaLoaiBenh_Click(object sender, EventArgs e) { if (!CheckLuaChonNHOMBENH()) { return; } if (btnXoaLOAIBENH.Text == "Xóa") { if (!CheckLuaChonLOAIBENH()) { return; } LOAIBENH cu = getLOAIBENHByID(); DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa loại bệnh " + cu.TEN + "?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (rs == DialogResult.Cancel) { return; } try { LOAIBENHService.Delete(new LOAIBENHKeys(cu.ID)); MessageBox.Show("Xóa thông tin loại bệnh thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Xóa thông tin loại bệnh thất bại\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvLOAIBENH(); return; } if (btnXoaLOAIBENH.Text == "Hủy") { btnSuaLOAIBENH.Text = "Sửa"; btnThemLOAIBENH.Text = "Thêm"; btnXoaLOAIBENH.Text = "Xóa"; LockControl(); UpdateDetailLOAIBENH(); return; } }
private void btnSuaLoaiBenh_Click(object sender, EventArgs e) { if (!CheckLuaChonNHOMBENH()) { return; } if (!CheckLuaChonLOAIBENH()) { return; } if (btnSuaLOAIBENH.Text == "Sửa") { btnSuaLOAIBENH.Text = "Lưu"; btnXoaLOAIBENH.Text = "Hủy"; btnThemLOAIBENH.Enabled = false; UnlockControlLOAIBENH(); return; } if (btnSuaLOAIBENH.Text == "Lưu") { if (CheckLOAIBENH()) { btnSuaLOAIBENH.Text = "Sửa"; btnXoaLOAIBENH.Text = "Xóa"; LockControl(); LOAIBENH cu = getLOAIBENHByID(); LOAIBENH moi = getLOAIBENHByForm(); CapNhatLOAIBENH(ref cu, moi); if (LOAIBENHService.Update(cu)) { MessageBox.Show("Sửa thông tin loại bệnh thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa thông tin loại bệnh thất bại\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadDgvLOAIBENH(); } return; } }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of LOAIBENH</returns> internal List <LOAIBENH> PopulateObjectsFromReader(IDataReader dataReader) { List <LOAIBENH> list = new List <LOAIBENH>(); while (dataReader.Read()) { LOAIBENH businessObject = new LOAIBENH(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
private bool CheckLuaChonLOAIBENH() { LOAIBENH tg = getLOAIBENHByID(); if (tg.ID == 0) { MessageBox.Show("Chưa có loại bệnh nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
private void UpdateDetailLOAIBENH() { try { LOAIBENH tg = getLOAIBENHByID(); if (tg.ID == 0) { return; } txtLOAIBENH.Text = tg.TEN; } catch { } }
private LOAIBENH getLOAIBENHByID() { try { int id = (int)dgvLOAIBENH.GetFocusedRowCellValue("ID"); LOAIBENH ans = LOAIBENHService.GetAllBy(LOAIBENH.LOAIBENHFields.ID, id).FirstOrDefault(); if (ans == null) { return(new LOAIBENH()); } return(ans); } catch { return(new LOAIBENH()); } }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(LOAIBENH businessObject, IDataReader dataReader) { businessObject.ID = dataReader.GetInt32(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.ID.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.TEN.ToString()))) { businessObject.TEN = dataReader.GetString(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.TEN.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.NHOMBENHID.ToString()))) { businessObject.NHOMBENHID = dataReader.GetInt32(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.NHOMBENHID.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.GHICHU.ToString()))) { businessObject.GHICHU = dataReader.GetString(dataReader.GetOrdinal(LOAIBENH.LOAIBENHFields.GHICHU.ToString())); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>LOAIBENH business object</returns> public LOAIBENH SelectByPrimaryKey(LOAIBENHKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[LOAIBENH_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()) { LOAIBENH businessObject = new LOAIBENH(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch //(Exception ex) { return(null); //throw new Exception("LOAIBENH::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
private void CapNhatLOAIBENH(ref LOAIBENH cu, LOAIBENH moi) { cu.TEN = moi.TEN; cu.NHOMBENHID = moi.NHOMBENHID; }