Example #1
0
        /// <summary>
        /// update row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true for successfully updated</returns>
        public bool Update(BENH businessObject)
        {
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = "dbo.[BENH_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("@MOTA", SqlDbType.NVarChar, 2147483647, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.MOTA));
                sqlCommand.Parameters.Add(new SqlParameter("@LOAIBENHID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.LOAIBENHID));
                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("BENH::Update::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Example #2
0
        private void btnXoaBenh_Click(object sender, EventArgs e)
        {
            if (!CheckLuaChonNHOMBENH())
            {
                return;
            }
            if (!CheckLuaChonLOAIBENH())
            {
                return;
            }

            if (btnXoaBENH.Text == "Xóa")
            {
                if (!CheckLuaChonBENH())
                {
                    return;
                }

                BENH         cu = getBENHByID();
                DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa bệnh " + cu.TEN + "?",
                                                  "Thông báo",
                                                  MessageBoxButtons.OKCancel,
                                                  MessageBoxIcon.Warning);

                if (rs == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    BENHService.Delete(new BENHKeys(cu.ID));
                    MessageBox.Show("Xóa thông tin bệnh thành công",
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Xóa thông tin bệnh thất bại\n" + ex.Message,
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                LoadDgvBENH();

                return;
            }
            if (btnXoaBENH.Text == "Hủy")
            {
                btnSuaBENH.Text  = "Sửa";
                btnThemBENH.Text = "Thêm";
                btnXoaBENH.Text  = "Xóa";

                LockControl();
                UpdateDetailBENH();
                return;
            }
        }
Example #3
0
        private void btnSuaBenh_Click(object sender, EventArgs e)
        {
            if (!CheckLuaChonNHOMBENH())
            {
                return;
            }
            if (!CheckLuaChonLOAIBENH())
            {
                return;
            }
            if (!CheckLuaChonBENH())
            {
                return;
            }

            if (btnSuaBENH.Text == "Sửa")
            {
                btnSuaBENH.Text     = "Lưu";
                btnXoaBENH.Text     = "Hủy";
                btnThemBENH.Enabled = false;

                UnlockControlBENH();

                return;
            }

            if (btnSuaBENH.Text == "Lưu")
            {
                if (CheckBENH())
                {
                    btnSuaBENH.Text = "Sửa";
                    btnXoaBENH.Text = "Xóa";

                    LockControl();

                    BENH cu  = getBENHByID();
                    BENH moi = getBENHByForm();
                    CapNhatBENH(ref cu, moi);

                    if (BENHService.Update(cu))
                    {
                        MessageBox.Show("Sửa thông tin bệnh thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Sửa thông tin bệnh thất bại\n",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvBENH();
                }

                return;
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            BENH bENH = db.BENHs.Find(id);

            db.BENHs.Remove(bENH);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "MABENH,TENBENH")] BENH bENH)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bENH).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bENH));
 }
Example #6
0
        private BENH getBENHByForm()
        {
            BENH ans = new BENH();

            ans.TEN        = txtBENH.Text;
            ans.MOTA       = txtMoTa.Text;
            ans.LOAIBENHID = getLOAIBENHByID().ID;

            return(ans);
        }
        public ActionResult Create([Bind(Include = "MABENH,TENBENH")] BENH bENH)
        {
            if (ModelState.IsValid)
            {
                db.BENHs.Add(bENH);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bENH));
        }
Example #8
0
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of BENH</returns>
        internal List <BENH> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <BENH> list = new List <BENH>();

            while (dataReader.Read())
            {
                BENH businessObject = new BENH();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
        // GET: BENHs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BENH bENH = db.BENHs.Find(id);

            if (bENH == null)
            {
                return(HttpNotFound());
            }
            return(View(bENH));
        }
Example #10
0
        private bool CheckLuaChonBENH()
        {
            BENH tg = getBENHByID();

            if (tg.ID == 0)
            {
                MessageBox.Show("Chưa có bệnh nào được chọn",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Example #11
0
 private BENH getBENHByID()
 {
     try
     {
         int  id  = (int)dgvBENH.GetFocusedRowCellValue("ID");
         BENH ans = BENHService.GetAllBy(BENH.BENHFields.ID, id).FirstOrDefault();
         if (ans == null)
         {
             return(new BENH());
         }
         return(ans);
     }
     catch
     {
         return(new BENH());
     }
 }
Example #12
0
        private void UpdateDetailBENH()
        {
            try
            {
                BENH tg = getBENHByID();

                if (tg.ID == 0)
                {
                    return;
                }

                txtBENH.Text = tg.TEN;
                txtMoTa.Text = tg.MOTA;
            }
            catch
            {
            }
        }
Example #13
0
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>BENH business object</returns>
        public BENH SelectByPrimaryKey(BENHKeys keys)
        {
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = "dbo.[BENH_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())
                {
                    BENH businessObject = new BENH();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch             //(Exception ex)
            {
                return(null); //throw new Exception("BENH::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Example #14
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(BENH businessObject, IDataReader dataReader)
        {
            businessObject.ID = dataReader.GetInt32(dataReader.GetOrdinal(BENH.BENHFields.ID.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(BENH.BENHFields.TEN.ToString())))
            {
                businessObject.TEN = dataReader.GetString(dataReader.GetOrdinal(BENH.BENHFields.TEN.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(BENH.BENHFields.MOTA.ToString())))
            {
                businessObject.MOTA = dataReader.GetString(dataReader.GetOrdinal(BENH.BENHFields.MOTA.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(BENH.BENHFields.LOAIBENHID.ToString())))
            {
                businessObject.LOAIBENHID = dataReader.GetInt32(dataReader.GetOrdinal(BENH.BENHFields.LOAIBENHID.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(BENH.BENHFields.GHICHU.ToString())))
            {
                businessObject.GHICHU = dataReader.GetString(dataReader.GetOrdinal(BENH.BENHFields.GHICHU.ToString()));
            }
        }
Example #15
0
 private void CapNhatBENH(ref BENH cu, BENH moi)
 {
     cu.TEN        = moi.TEN;
     cu.MOTA       = moi.MOTA;
     cu.LOAIBENHID = moi.LOAIBENHID;
 }