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(NHOMBENH businessObject)
        {
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = "dbo.[NHOMBENH_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("@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("NHOMBENH::Update::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Example #2
0
        private NHOMBENH getNHOMBENHByForm()
        {
            NHOMBENH ans = new NHOMBENH();

            ans.TEN = txtNHOMBENH.Text;

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

            while (dataReader.Read())
            {
                NHOMBENH businessObject = new NHOMBENH();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
Example #4
0
        private void btnSuaNhomBenh_Click(object sender, EventArgs e)
        {
            if (!CheckLuaChonNHOMBENH())
            {
                return;
            }

            if (btnSuaNHOMBENH.Text == "Sửa")
            {
                btnSuaNHOMBENH.Text     = "Lưu";
                btnXoaNHOMBENH.Text     = "Hủy";
                btnThemNHOMBENH.Enabled = false;

                UnlockControlNHOMBENH();

                return;
            }

            if (btnSuaNHOMBENH.Text == "Lưu")
            {
                if (CheckNHOMBENH())
                {
                    btnSuaNHOMBENH.Text = "Sửa";
                    btnXoaNHOMBENH.Text = "Xóa";

                    LockControl();

                    NHOMBENH cu  = getNHOMBENHByID();
                    NHOMBENH moi = getNHOMBENHByForm();
                    CapNhatNHOMBENH(ref cu, moi);

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

                return;
            }
        }
Example #5
0
        private void btnXoaNhomBenh_Click(object sender, EventArgs e)
        {
            if (btnXoaNHOMBENH.Text == "Xóa")
            {
                if (!CheckLuaChonNHOMBENH())
                {
                    return;
                }

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

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

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

                return;
            }
            if (btnXoaNHOMBENH.Text == "Hủy")
            {
                btnSuaNHOMBENH.Text  = "Sửa";
                btnThemNHOMBENH.Text = "Thêm";
                btnXoaNHOMBENH.Text  = "Xóa";

                LockControl();
                UpdateDetailNHOMBENH();
                return;
            }
        }
Example #6
0
        private bool CheckLuaChonNHOMBENH()
        {
            NHOMBENH tg = getNHOMBENHByID();

            if (tg.ID == 0)
            {
                MessageBox.Show("Chưa có nhóm bệnh nào được chọn",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Example #7
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(NHOMBENH businessObject, IDataReader dataReader)
        {
            businessObject.ID = dataReader.GetInt32(dataReader.GetOrdinal(NHOMBENH.NHOMBENHFields.ID.ToString()));

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

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(NHOMBENH.NHOMBENHFields.GHICHU.ToString())))
            {
                businessObject.GHICHU = dataReader.GetString(dataReader.GetOrdinal(NHOMBENH.NHOMBENHFields.GHICHU.ToString()));
            }
        }
Example #8
0
        private void UpdateDetailNHOMBENH()
        {
            try
            {
                NHOMBENH tg = getNHOMBENHByID();

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

                txtNHOMBENH.Text = tg.TEN;
            }
            catch
            {
            }
        }
Example #9
0
 private NHOMBENH getNHOMBENHByID()
 {
     try
     {
         int      id  = (int)dgvNHOMBENH.GetFocusedRowCellValue("ID");
         NHOMBENH ans = NHOMBENHService.GetAllBy(NHOMBENH.NHOMBENHFields.ID, id).FirstOrDefault();
         if (ans == null)
         {
             return(new NHOMBENH());
         }
         return(ans);
     }
     catch
     {
         return(new NHOMBENH());
     }
 }
Example #10
0
        private void btnThemNhomBenh_Click(object sender, EventArgs e)
        {
            if (btnThemNHOMBENH.Text == "Thêm")
            {
                btnSuaNHOMBENH.Enabled = false;
                btnThemNHOMBENH.Text   = "Lưu";
                btnXoaNHOMBENH.Text    = "Hủy";

                ClearControlNHOMBENH();
                UnlockControlNHOMBENH();


                return;
            }

            if (btnThemNHOMBENH.Text == "Lưu")
            {
                if (CheckNHOMBENH())
                {
                    btnThemNHOMBENH.Text = "Thêm";
                    btnXoaNHOMBENH.Text  = "Xóa";
                    LockControl();

                    NHOMBENH moi = getNHOMBENHByForm();
                    if (NHOMBENHService.Insert(moi))
                    {
                        MessageBox.Show("Thêm thông tin nhóm bệnh thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Thêm thông tin nhóm bệnh thất bại\n",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvNHOMBENH();
                }
                return;
            }
        }
Example #11
0
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>NHOMBENH business object</returns>
        public NHOMBENH SelectByPrimaryKey(NHOMBENHKeys keys)
        {
            SqlCommand sqlCommand = new SqlCommand();

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

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return(businessObject);
                }
                else
                {
                    return(null);
                }
            }
            catch             //(Exception ex)
            {
                return(null); //throw new Exception("NHOMBENH::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Example #12
0
 private void CapNhatNHOMBENH(ref NHOMBENH cu, NHOMBENH moi)
 {
     cu.TEN = moi.TEN;
 }