public MembershipsType GetById(int id)
        {
            MembershipsType type = new MembershipsType();

            try
            {
                OpenConnection();
                string queryString = "select * from MembershipsType where idMembershipsType = " + id;

                MySqlCommand command = new MySqlCommand(queryString, conn);
                command.ExecuteNonQuery();
                MySqlDataAdapter adapter = new MySqlDataAdapter(command);

                DataTable dt = new DataTable();
                adapter.Fill(dt);
                type = new MembershipsType(int.Parse(dt.Rows[0].ItemArray[0].ToString()),
                                           dt.Rows[0].ItemArray[1].ToString(), long.Parse(dt.Rows[0].ItemArray[2].ToString()));
            }
            catch
            {
            }
            finally
            {
                CloseConnection();
            }
            return(type);
        }
        public List <MembershipsType> GetList()
        {
            List <MembershipsType> memberships = new List <MembershipsType>();

            try
            {
                OpenConnection();

                string          query      = "select * from membershipsType";
                MySqlCommand    cmd        = new MySqlCommand(query, conn);
                MySqlDataReader dataReader = cmd.ExecuteReader();
                DataTable       dt         = new DataTable();
                dt.Load(dataReader);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    MembershipsType type = new MembershipsType(int.Parse(dt.Rows[i].ItemArray[0].ToString()),
                                                               dt.Rows[i].ItemArray[1].ToString(), long.Parse(dt.Rows[i].ItemArray[2].ToString()));
                    memberships.Add(type);
                }
            }
            catch
            {
                return(new List <MembershipsType>());
            }
            return(memberships);
        }
        public void InsertOrUpdate(MembershipsType membership, bool isUpdating = false)
        {
            try
            {
                OpenConnection();
                string query = "";
                if (isUpdating)
                {
                    query = "update membershipsType set membership=@membership, target=@target "
                            + "where idMembershipsType = " + membership.IdMembershipsType;
                }
                else
                {
                    query = "insert into membershipsType " +
                            "(idMembershipsType, membership, target) " +
                            "values(@idMembershipsType, @membership, @target)";
                }
                MySqlCommand cmd = new MySqlCommand(query, conn);

                cmd.Parameters.AddWithValue("@idMembershipsType", membership.IdMembershipsType);
                cmd.Parameters.AddWithValue("@membership", membership.Membership);
                cmd.Parameters.AddWithValue("@target", membership.Target);

                int row = cmd.ExecuteNonQuery();
                if (row != 1)
                {
                    throw new Exception();
                }
                if (isUpdating)
                {
                    CustomMessageBox.Show("Cập nhật hạng thành viên thành công!", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
                else
                {
                    CustomMessageBox.Show("Thêm hạng thành viên thành công!", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            catch (Exception e)
            {
                CustomMessageBox.Show(e.Message.ToString(), "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            finally
            {
                CloseConnection();
            }
        }